View Javadoc
1   package de.japrost.jabudget.spring;
2   
3   import static de.japrost.jabudget.spring.PathMapping.BASE;
4   import static de.japrost.jabudget.spring.PathMapping.SERIALIZATION_DESERIALIZE;
5   import static de.japrost.jabudget.spring.PathMapping.SERIALIZATION_SERIALIZE;
6   
7   import org.springframework.web.bind.annotation.GetMapping;
8   import org.springframework.web.bind.annotation.RequestMapping;
9   import org.springframework.web.bind.annotation.RestController;
10  
11  import de.japrost.jabudget.service.SerializationService;
12  
13  /**
14   * Controller to expose serialization.
15   */
16  @RestController
17  @RequestMapping(BASE)
18  public class SerializationController {
19  
20  	private final SerializationService serializationService;
21  
22  	/**
23  	 * Instantiate with necessary dependencies.
24  	 * 
25  	 * @param serializationService the SerializationService to use.
26  	 */
27  	public SerializationController(SerializationService serializationService) {
28  		this.serializationService = serializationService;
29  	}
30  
31  	/**
32  	 * Serialize to the configured default serialization store.
33  	 */
34  	@GetMapping(SERIALIZATION_SERIALIZE)
35  	public void defaultSerialize() {
36  		serializationService.serialize();
37  	}
38  
39  	/**
40  	 * Deserialize from the configured default serialization store.
41  	 */
42  	// TODO GET is not the right verb since deserialization changes the whole system.
43  	@GetMapping(SERIALIZATION_DESERIALIZE)
44  	public void defaultDeserialize() {
45  		serializationService.deserialize();
46  	}
47  }