Removed depracated code and added Javadoc
This commit is contained in:
		| @@ -16,7 +16,6 @@ import java.util.Objects; | ||||
|  | ||||
| /** | ||||
|  * Class containing configuration for Redis db client | ||||
|  * | ||||
|  * @author Rafał Żukowicz | ||||
|  */ | ||||
| @Configuration | ||||
| @@ -30,7 +29,6 @@ public class RedisConfig { | ||||
|     /** | ||||
|      * Bean of JedisPool - the Redis client. It stores requests in "the pool" and then fires them at Redis. | ||||
|      * It's considered super lightweight and fast client variant | ||||
|      * | ||||
|      * @return lightweight client of the Redis - the JedisPool | ||||
|      */ | ||||
|     @Bean | ||||
| @@ -43,7 +41,6 @@ public class RedisConfig { | ||||
|     /** | ||||
|      * Bean of a factory for connenction object. | ||||
|      * It's initialized with Redis db url property and is fed to other methods. | ||||
|      * | ||||
|      * @return the factory for RedisTemplates | ||||
|      */ | ||||
|     @Bean | ||||
| @@ -58,7 +55,6 @@ public class RedisConfig { | ||||
|      * RedisTemplate is the tool to store and retrieve given type (object) of hash from the database. | ||||
|      * It's like you could store your Java object by just naming it inside database. You might thing about it | ||||
|      * as of DAO. | ||||
|      * | ||||
|      * @return RedisTemplate the redis dao. | ||||
|      */ | ||||
|     @Bean | ||||
|   | ||||
| @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| /** | ||||
|  * It's the REST api for {@link com.release11.klaus.model.Event} | ||||
|  * | ||||
|  * @author Gabriel Modzelewski | ||||
|  */ | ||||
| @Slf4j | ||||
| @@ -24,7 +23,6 @@ public class EventController { | ||||
|      * Returns the list of Events in given time bracket. | ||||
|      * The list of objects is received via {@link EventRequestDto}, which contains time brackets, | ||||
|      * as well as the key - uuid. | ||||
|      * | ||||
|      * @param event EventRequestDto object that contains data needed to query the database | ||||
|      * @return list of Event's | ||||
|      */ | ||||
|   | ||||
| @@ -24,7 +24,6 @@ import java.util.UUID; | ||||
|  * http parameters like: body, status, headers etc. | ||||
|  * Basicly the api is responsible for what a client is looking for - a mocked server response. | ||||
|  * Important note: {@link TrackingClient} use is to create logs - the history. | ||||
|  * | ||||
|  * @author Gabriel Modzelewski | ||||
|  * @author Rafał Żukowicz | ||||
|  */ | ||||
| @@ -36,9 +35,9 @@ public class KlausController { | ||||
|  | ||||
|     private final KlausService klausService; | ||||
|  | ||||
| //    TODO: Remove method. It's depracated and duplicated. | ||||
|     /** | ||||
|      * Deletes message of given id via client request | ||||
|      * | ||||
|      * @param clientUUID the key-uuid of given set of messages | ||||
|      * @param mockedResponseId unique id of given message | ||||
|      * @return after deletion the confirmation is send with status 200 OK | ||||
| @@ -53,10 +52,10 @@ public class KlausController { | ||||
|         return new ResponseEntity<>("message has been deleted", HttpStatus.OK); | ||||
|     } | ||||
|  | ||||
|     //TODO : Remove it's also depracated | ||||
|     /** | ||||
|      * Returns the full list of messages. It's used by javascript on the client side to initialize homepage | ||||
|      * with data from the database. | ||||
|      * | ||||
|      * @param clientUUID the key-uuid of given set of messages | ||||
|      * @return responds with 200 OK and list of {@link MockedMessageDto} | ||||
|      */ | ||||
| @@ -72,7 +71,6 @@ public class KlausController { | ||||
|     /** | ||||
|      * It's one of the most important features - the bread and butter of the Mocked Service. It's link that allows | ||||
|      * to receive mocked response from the server and use it to mock! | ||||
|      * | ||||
|      * @param requestEntity Logs the data of request | ||||
|      * @param clientUUID the key-uuid of given set of messages | ||||
|      * @param mockedResponseId unique id of given message | ||||
|   | ||||
| @@ -15,29 +15,34 @@ import org.springframework.web.servlet.ModelAndView; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.*; | ||||
|  | ||||
| /** | ||||
|  * Returns the homepage and provides the api for javascript async requests. | ||||
|  * @author Gabriel Modzelewski | ||||
|  */ | ||||
| @Slf4j | ||||
| @Controller | ||||
| @RequestMapping | ||||
| @AllArgsConstructor | ||||
| public class MockController { | ||||
|     private final KlausService klausService; | ||||
|     private final MockedMessageDto defaultMessage = MockedMessageDto.builder().build(); | ||||
|  | ||||
|     /** | ||||
|      * Responds to first user request. If UUID is given then it's set if it's not, then new one is generated. | ||||
|      * Next recalls method that populates model based on UUID | ||||
|      * @return | ||||
|      * Default path to get the homepage | ||||
|      * @return the view of homepage | ||||
|      */ | ||||
|     @SneakyThrows | ||||
|     @GetMapping | ||||
|     public ModelAndView showHome(){ | ||||
|         ModelAndView mov = new ModelAndView(); | ||||
|         mov.setViewName("html/mock"); | ||||
|         System.out.println("Trying to return view"); | ||||
|         return mov; | ||||
|     } | ||||
|  | ||||
| //    TODO: Remove object mapper | ||||
|     /** | ||||
|      * Updates queried message with given set of data | ||||
|      * @param body {@link MockedMessageDto} json representation | ||||
|      * @return confirmation and 200 OK | ||||
|      */ | ||||
|     @SneakyThrows | ||||
|     @ResponseBody | ||||
|     @PutMapping("/mock/json") | ||||
| @@ -47,9 +52,15 @@ public class MockController { | ||||
|         return klausService.setMockedResponse(message); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the full list of messages. It's used by javascript on the client side to initialize homepage | ||||
|      * with data from the database. | ||||
|      * @param uuidValue the key-uuid of given set of messages | ||||
|      * @return responds with 200 OK and list of {@link MockedMessageDto} | ||||
|      */ | ||||
|     @ResponseBody | ||||
|     @GetMapping({"/mock/json", "/mock/json/{uuidValue}"}) | ||||
|     public List<MockedMessageDto> getJson(@PathVariable(required = false) String uuidValue){ | ||||
|     public List<MockedMessageDto> getListOfMessages(@PathVariable(required = false) String uuidValue){ | ||||
|         UUID clientUUID; | ||||
|         if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID(); | ||||
|         else clientUUID = UUID.fromString(uuidValue); | ||||
| @@ -62,6 +73,12 @@ public class MockController { | ||||
|         return messages; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Accepts empty post request and creates new message in given set. The new message has default set of data, | ||||
|      * which is constructed in {@link #buildDefaultMessage(UUID, int)} method. | ||||
|      * @param uuidValue the key-uuid of given set of messages | ||||
|      * @return confirmation response with 200 OK | ||||
|      */ | ||||
|     @ResponseBody | ||||
|     @PostMapping("/mock/json/{uuidValue}") | ||||
|     public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){ | ||||
| @@ -71,6 +88,12 @@ public class MockController { | ||||
|         return klausService.setMockedResponse(nextMessage); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Deletes message of given id via client request | ||||
|      * @param uuidValue the key-uuid of given set of messages | ||||
|      * @param idValue unique id of given message | ||||
|      * @return after deletion the confirmation is send with status 200 OK | ||||
|      */ | ||||
|     @ResponseBody | ||||
|     @DeleteMapping("/mock/json/{uuidValue}/{idValue}") | ||||
|     public ResponseEntity<String> removeMessage(@PathVariable String uuidValue, | ||||
| @@ -81,13 +104,23 @@ public class MockController { | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Recalls {@link #buildDefaultMessage(UUID)} for message construction and sets id of message | ||||
|      * @param uuid the key-uuid of given set of messages | ||||
|      * @param id unique id of given message | ||||
|      * @return message with default dataset and set id | ||||
|      */ | ||||
|     private static MockedMessageDto buildDefaultMessage(UUID uuid, int id){ | ||||
|         MockedMessageDto message = buildDefaultMessage(uuid); | ||||
|         message.setMockedResponseId(id); | ||||
|         return message; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Constructs message with default set of data | ||||
|      * @param uuid the key-uuid of given set of messages | ||||
|      * @return message with default dataset | ||||
|      */ | ||||
|     private static MockedMessageDto buildDefaultMessage(UUID uuid){ | ||||
|         Map<String, String> headers = new HashMap<>(); | ||||
|         headers.put("Keep-Alive", "timeout=60"); | ||||
| @@ -109,6 +142,11 @@ public class MockController { | ||||
|                 .build(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds the highest id in the list and returns it incremented by 1 | ||||
|      * @param messages list of messages | ||||
|      * @return highest id incremented by 1 | ||||
|      */ | ||||
|     public static int findNextId(List<MockedMessageDto> messages) { | ||||
|         int highestId = 0; | ||||
|         for (MockedMessageDto m : messages) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user