Removed depracated code and added Javadoc

This commit is contained in:
2021-03-22 14:20:11 +01:00
parent 9db03a35d8
commit db1f5c0bf1
4 changed files with 48 additions and 18 deletions

View File

@@ -16,7 +16,6 @@ import java.util.Objects;
/** /**
* Class containing configuration for Redis db client * Class containing configuration for Redis db client
*
* @author Rafał Żukowicz * @author Rafał Żukowicz
*/ */
@Configuration @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. * 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 * It's considered super lightweight and fast client variant
*
* @return lightweight client of the Redis - the JedisPool * @return lightweight client of the Redis - the JedisPool
*/ */
@Bean @Bean
@@ -43,7 +41,6 @@ public class RedisConfig {
/** /**
* Bean of a factory for connenction object. * Bean of a factory for connenction object.
* It's initialized with Redis db url property and is fed to other methods. * It's initialized with Redis db url property and is fed to other methods.
*
* @return the factory for RedisTemplates * @return the factory for RedisTemplates
*/ */
@Bean @Bean
@@ -58,7 +55,6 @@ public class RedisConfig {
* RedisTemplate is the tool to store and retrieve given type (object) of hash from the database. * 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 * It's like you could store your Java object by just naming it inside database. You might thing about it
* as of DAO. * as of DAO.
*
* @return RedisTemplate the redis dao. * @return RedisTemplate the redis dao.
*/ */
@Bean @Bean

View File

@@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.*;
/** /**
* It's the REST api for {@link com.release11.klaus.model.Event} * It's the REST api for {@link com.release11.klaus.model.Event}
*
* @author Gabriel Modzelewski * @author Gabriel Modzelewski
*/ */
@Slf4j @Slf4j
@@ -24,7 +23,6 @@ public class EventController {
* Returns the list of Events in given time bracket. * Returns the list of Events in given time bracket.
* The list of objects is received via {@link EventRequestDto}, which contains time brackets, * The list of objects is received via {@link EventRequestDto}, which contains time brackets,
* as well as the key - uuid. * as well as the key - uuid.
*
* @param event EventRequestDto object that contains data needed to query the database * @param event EventRequestDto object that contains data needed to query the database
* @return list of Event's * @return list of Event's
*/ */

View File

@@ -24,7 +24,6 @@ import java.util.UUID;
* http parameters like: body, status, headers etc. * http parameters like: body, status, headers etc.
* Basicly the api is responsible for what a client is looking for - a mocked server response. * 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. * Important note: {@link TrackingClient} use is to create logs - the history.
*
* @author Gabriel Modzelewski * @author Gabriel Modzelewski
* @author Rafał Żukowicz * @author Rafał Żukowicz
*/ */
@@ -36,9 +35,9 @@ public class KlausController {
private final KlausService klausService; private final KlausService klausService;
// TODO: Remove method. It's depracated and duplicated.
/** /**
* Deletes message of given id via client request * Deletes message of given id via client request
*
* @param clientUUID the key-uuid of given set of messages * @param clientUUID the key-uuid of given set of messages
* @param mockedResponseId unique id of given message * @param mockedResponseId unique id of given message
* @return after deletion the confirmation is send with status 200 OK * @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); 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 * Returns the full list of messages. It's used by javascript on the client side to initialize homepage
* with data from the database. * with data from the database.
*
* @param clientUUID the key-uuid of given set of messages * @param clientUUID the key-uuid of given set of messages
* @return responds with 200 OK and list of {@link MockedMessageDto} * @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 * 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! * to receive mocked response from the server and use it to mock!
*
* @param requestEntity Logs the data of request * @param requestEntity Logs the data of request
* @param clientUUID the key-uuid of given set of messages * @param clientUUID the key-uuid of given set of messages
* @param mockedResponseId unique id of given message * @param mockedResponseId unique id of given message

View File

@@ -15,29 +15,34 @@ import org.springframework.web.servlet.ModelAndView;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
/**
* Returns the homepage and provides the api for javascript async requests.
* @author Gabriel Modzelewski
*/
@Slf4j @Slf4j
@Controller @Controller
@RequestMapping @RequestMapping
@AllArgsConstructor @AllArgsConstructor
public class MockController { public class MockController {
private final KlausService klausService; 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. * Default path to get the homepage
* Next recalls method that populates model based on UUID * @return the view of homepage
* @return
*/ */
@SneakyThrows @SneakyThrows
@GetMapping @GetMapping
public ModelAndView showHome(){ public ModelAndView showHome(){
ModelAndView mov = new ModelAndView(); ModelAndView mov = new ModelAndView();
mov.setViewName("html/mock"); mov.setViewName("html/mock");
System.out.println("Trying to return view");
return mov; 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 @SneakyThrows
@ResponseBody @ResponseBody
@PutMapping("/mock/json") @PutMapping("/mock/json")
@@ -47,9 +52,15 @@ public class MockController {
return klausService.setMockedResponse(message); 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 @ResponseBody
@GetMapping({"/mock/json", "/mock/json/{uuidValue}"}) @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; UUID clientUUID;
if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID(); if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID();
else clientUUID = UUID.fromString(uuidValue); else clientUUID = UUID.fromString(uuidValue);
@@ -62,6 +73,12 @@ public class MockController {
return messages; 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 @ResponseBody
@PostMapping("/mock/json/{uuidValue}") @PostMapping("/mock/json/{uuidValue}")
public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){ public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){
@@ -71,6 +88,12 @@ public class MockController {
return klausService.setMockedResponse(nextMessage); 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 @ResponseBody
@DeleteMapping("/mock/json/{uuidValue}/{idValue}") @DeleteMapping("/mock/json/{uuidValue}/{idValue}")
public ResponseEntity<String> removeMessage(@PathVariable String uuidValue, 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){ private static MockedMessageDto buildDefaultMessage(UUID uuid, int id){
MockedMessageDto message = buildDefaultMessage(uuid); MockedMessageDto message = buildDefaultMessage(uuid);
message.setMockedResponseId(id); message.setMockedResponseId(id);
return message; 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){ private static MockedMessageDto buildDefaultMessage(UUID uuid){
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("Keep-Alive", "timeout=60"); headers.put("Keep-Alive", "timeout=60");
@@ -109,6 +142,11 @@ public class MockController {
.build(); .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) { public static int findNextId(List<MockedMessageDto> messages) {
int highestId = 0; int highestId = 0;
for (MockedMessageDto m : messages) for (MockedMessageDto m : messages)