From 1d7eed6591fb4d2b3d3999a7c51e9fe77032cd77 Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 12:34:47 +0100 Subject: [PATCH 1/6] Removed depracated code and added Javadoc --- .../com/release11/klaus/KlausApplication.java | 9 +++--- .../release11/klaus/config/RedisConfig.java | 29 ++++++++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/release11/klaus/KlausApplication.java b/src/main/java/com/release11/klaus/KlausApplication.java index abb6859..25eb996 100644 --- a/src/main/java/com/release11/klaus/KlausApplication.java +++ b/src/main/java/com/release11/klaus/KlausApplication.java @@ -4,8 +4,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; - - +/** + * It's generic Spring context starter. Move along... + * + * @author Rafał Żukowicz + */ @SpringBootApplication public class KlausApplication { @@ -14,5 +17,3 @@ public class KlausApplication { } } -//TODO JedisPool jedisPool = new JedisPool(jedisPoolConfig, redisHost, redisPort, timeout, redisPassword) -//TODO JedisPool optimalization https://partners-intl.aliyun.com/help/doc-detail/98726.htm diff --git a/src/main/java/com/release11/klaus/config/RedisConfig.java b/src/main/java/com/release11/klaus/config/RedisConfig.java index d79bcdc..9029270 100644 --- a/src/main/java/com/release11/klaus/config/RedisConfig.java +++ b/src/main/java/com/release11/klaus/config/RedisConfig.java @@ -15,11 +15,9 @@ import redis.clients.jedis.JedisPool; import java.util.Objects; /** - * RedisConfig is a class that reads properties from Environment singleton instance and builds beans based on them. - * JedisPool ?- an instance of the JedisPool class that contains info about host and port of Reddis - * JedisConnectionFactory - ConnectionFactory created based on host and port provided by Environment - * RedisTemplate - Creates map-like object which contains ConnectionFactory and sets parameters. Uses Jackson - * deserialiazer + * Class containing configuration for Redis db client + * + * @author Rafał Żukowicz */ @Configuration @EnableRedisRepositories @@ -29,15 +27,25 @@ public class RedisConfig { @Autowired private Environment environment; + /** + * 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 JedisPool jedisPool(){ - //TODO JedisPool jedisPool = new JedisPool(jedisPoolConfig, redisHost, redisPort, timeout, redisPassword) - //TODO JedisPool optimalization https://partners-intl.aliyun.com/help/doc-detail/98726.htm final JedisPool pool = new JedisPool(environment.getProperty("redis.host"), Integer.parseInt(environment.getProperty("redis.port"))); return pool; } + /** + * 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 JedisConnectionFactory jedisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = @@ -46,6 +54,13 @@ public class RedisConfig { return new JedisConnectionFactory(redisStandaloneConfiguration); } + /** + * 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 public RedisTemplate redisTemplate() { RedisTemplate redisTemplate = new RedisTemplate<>(); From 9db03a35d81fded4ce3df48e55f49f5ac0a870ca Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 13:09:57 +0100 Subject: [PATCH 2/6] Removed depracated code and added Javadoc --- .../klaus/controller/EventController.java | 27 ++++++-------- .../klaus/controller/KlausController.java | 35 ++++++++++++++++--- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/release11/klaus/controller/EventController.java b/src/main/java/com/release11/klaus/controller/EventController.java index ecfcd36..01c649b 100644 --- a/src/main/java/com/release11/klaus/controller/EventController.java +++ b/src/main/java/com/release11/klaus/controller/EventController.java @@ -1,30 +1,17 @@ package com.release11.klaus.controller; -import com.release11.klaus.model.Event; import com.release11.klaus.model.EventRequestDto; import com.release11.klaus.service.EtrackService; -import com.release11.klaus.service.KlausService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - - /** - * Class responds to request asking about history of messages. + * It's the REST api for {@link com.release11.klaus.model.Event} + * + * @author Gabriel Modzelewski */ @Slf4j @RestController @@ -33,6 +20,14 @@ import java.util.UUID; public class EventController { private final EtrackService service; + /** + * 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 + */ @PostMapping public ResponseEntity getHistory(@RequestBody EventRequestDto event){ return new ResponseEntity(service.getEventsByDateTimeAndBusinessKeys(event), HttpStatus.OK); diff --git a/src/main/java/com/release11/klaus/controller/KlausController.java b/src/main/java/com/release11/klaus/controller/KlausController.java index dfb479c..6ef9e03 100644 --- a/src/main/java/com/release11/klaus/controller/KlausController.java +++ b/src/main/java/com/release11/klaus/controller/KlausController.java @@ -11,7 +11,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -21,8 +20,13 @@ import java.util.UUID; /** - * A class responds to generated message uri's requests. - * It deletes or fetches the requested message + * This controller is responsible for returning the data of given mocked message. The content is made of usual + * 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 */ @RestController @Slf4j @@ -32,7 +36,13 @@ public class KlausController { private final KlausService klausService; - + /** + * 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 + */ @DeleteMapping(value = "/delete/{clientUUID}/{mockedResponseId}") public ResponseEntity deleteMockedResponse(@PathVariable UUID clientUUID, @PathVariable int mockedResponseId){ @@ -43,6 +53,13 @@ public class KlausController { return new ResponseEntity<>("message has been deleted", HttpStatus.OK); } + /** + * 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} + */ @GetMapping(value = "/getAll/{clientUUID}") public ResponseEntity getAllMockedResponses(@PathVariable UUID clientUUID){ TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getAllMockedResponse", @@ -51,6 +68,16 @@ public class KlausController { return new ResponseEntity<>(mockedMessages.toString(), HttpStatus.OK); } + + /** + * 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 + * @return + */ @RequestMapping(value = "/get/{clientUUID}/{mockedResponseId}") public ResponseEntity getMockedResponse(RequestEntity requestEntity, @PathVariable UUID clientUUID, From db1f5c0bf118afd6e6d28b13f49eb8bd0ca6a4d6 Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 14:20:11 +0100 Subject: [PATCH 3/6] Removed depracated code and added Javadoc --- .../release11/klaus/config/RedisConfig.java | 4 -- .../klaus/controller/EventController.java | 2 - .../klaus/controller/KlausController.java | 6 +-- .../klaus/controller/MockController.java | 54 ++++++++++++++++--- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/release11/klaus/config/RedisConfig.java b/src/main/java/com/release11/klaus/config/RedisConfig.java index 9029270..f440a70 100644 --- a/src/main/java/com/release11/klaus/config/RedisConfig.java +++ b/src/main/java/com/release11/klaus/config/RedisConfig.java @@ -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 diff --git a/src/main/java/com/release11/klaus/controller/EventController.java b/src/main/java/com/release11/klaus/controller/EventController.java index 01c649b..4a4e03f 100644 --- a/src/main/java/com/release11/klaus/controller/EventController.java +++ b/src/main/java/com/release11/klaus/controller/EventController.java @@ -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 */ diff --git a/src/main/java/com/release11/klaus/controller/KlausController.java b/src/main/java/com/release11/klaus/controller/KlausController.java index 6ef9e03..0cac0fc 100644 --- a/src/main/java/com/release11/klaus/controller/KlausController.java +++ b/src/main/java/com/release11/klaus/controller/KlausController.java @@ -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 diff --git a/src/main/java/com/release11/klaus/controller/MockController.java b/src/main/java/com/release11/klaus/controller/MockController.java index 951746e..1378fc4 100644 --- a/src/main/java/com/release11/klaus/controller/MockController.java +++ b/src/main/java/com/release11/klaus/controller/MockController.java @@ -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 getJson(@PathVariable(required = false) String uuidValue){ + public List 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 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 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 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 messages) { int highestId = 0; for (MockedMessageDto m : messages) From e3e45939e2a1830db63fd20ae1390f98c96cfc7c Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 14:52:32 +0100 Subject: [PATCH 4/6] Removed depracated code and added Javadoc --- .../klaus/controller/MvcExceptionHandler.java | 1 + .../release11/klaus/mappers/MockedMessageMapper.java | 4 ++++ src/main/java/com/release11/klaus/model/Event.java | 4 ++++ .../com/release11/klaus/model/EventRequestDto.java | 3 ++- .../java/com/release11/klaus/model/MockedMessage.java | 4 ++++ .../com/release11/klaus/model/MockedMessageDto.java | 7 ++++--- .../release11/klaus/model/constraints/HttpCode.java | 2 +- .../klaus/model/constraints/HttpCodeValidation.java | 4 +--- .../release11/klaus/repository/EventRepository.java | 4 ++++ .../klaus/repository/EventRepositoryImpl.java | 1 + .../klaus/repository/MockedResponseRepository.java | 10 ++++++++++ 11 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/release11/klaus/controller/MvcExceptionHandler.java b/src/main/java/com/release11/klaus/controller/MvcExceptionHandler.java index 7011ffd..d995ac7 100644 --- a/src/main/java/com/release11/klaus/controller/MvcExceptionHandler.java +++ b/src/main/java/com/release11/klaus/controller/MvcExceptionHandler.java @@ -10,6 +10,7 @@ import javax.validation.ConstraintViolationException; import java.util.ArrayList; import java.util.List; +//TODO: Find usage and document or remove it @ControllerAdvice public class MvcExceptionHandler { diff --git a/src/main/java/com/release11/klaus/mappers/MockedMessageMapper.java b/src/main/java/com/release11/klaus/mappers/MockedMessageMapper.java index 7fd42d3..de4613c 100644 --- a/src/main/java/com/release11/klaus/mappers/MockedMessageMapper.java +++ b/src/main/java/com/release11/klaus/mappers/MockedMessageMapper.java @@ -4,6 +4,10 @@ import com.release11.klaus.model.MockedMessage; import com.release11.klaus.model.MockedMessageDto; import org.mapstruct.*; +/** + * Creates key value for redis entry + * @author Rafał Źukowicz + */ @Mapper public interface MockedMessageMapper { @Mapping( target = "compositePrimaryKey", expression = "java(mockedMessageDto.getClientUUID() + \"_\"" + diff --git a/src/main/java/com/release11/klaus/model/Event.java b/src/main/java/com/release11/klaus/model/Event.java index 6c820f4..b4092d9 100644 --- a/src/main/java/com/release11/klaus/model/Event.java +++ b/src/main/java/com/release11/klaus/model/Event.java @@ -6,6 +6,10 @@ import org.springframework.lang.Nullable; import java.time.LocalDateTime; +/** + * Pojo class for Event entity + * @author Rafał Żukowicz + */ @Data @Builder @ToString diff --git a/src/main/java/com/release11/klaus/model/EventRequestDto.java b/src/main/java/com/release11/klaus/model/EventRequestDto.java index 6150007..df2403d 100644 --- a/src/main/java/com/release11/klaus/model/EventRequestDto.java +++ b/src/main/java/com/release11/klaus/model/EventRequestDto.java @@ -10,7 +10,8 @@ import java.time.LocalDateTime; import java.util.UUID; /** - * Pojo for client request + * Pojo for history query request. Contains information necessary to obtain {@link Event} list + * @author Rafał Żukowicz */ @Data @Builder diff --git a/src/main/java/com/release11/klaus/model/MockedMessage.java b/src/main/java/com/release11/klaus/model/MockedMessage.java index 3446bd4..76e451a 100644 --- a/src/main/java/com/release11/klaus/model/MockedMessage.java +++ b/src/main/java/com/release11/klaus/model/MockedMessage.java @@ -14,6 +14,10 @@ import java.io.Serializable; import java.util.Map; import java.util.UUID; +/** + * MockedMessage redis entity pojo + * @author Rafał Żukowicz + */ @Data @ToString @RedisHash("mockedMessage") diff --git a/src/main/java/com/release11/klaus/model/MockedMessageDto.java b/src/main/java/com/release11/klaus/model/MockedMessageDto.java index b37bcca..7c462ff 100644 --- a/src/main/java/com/release11/klaus/model/MockedMessageDto.java +++ b/src/main/java/com/release11/klaus/model/MockedMessageDto.java @@ -10,9 +10,9 @@ import java.util.Map; import java.util.UUID; /** - * it appears that instance of this class contains info about mocked response - * To which UUID it is bound, whats its id, the list of headers, type of content and message body, - * as well as status it has to return. + * Alternative version of {@link MockedMessage} used in http body + * @author Rafał Żukowicz + * @author Gabriel Modzelewski */ @Data @Builder @@ -30,6 +30,7 @@ public class MockedMessageDto implements Serializable, Comparable { private Set allowedValues; diff --git a/src/main/java/com/release11/klaus/repository/EventRepository.java b/src/main/java/com/release11/klaus/repository/EventRepository.java index c7c1d12..f2555d0 100644 --- a/src/main/java/com/release11/klaus/repository/EventRepository.java +++ b/src/main/java/com/release11/klaus/repository/EventRepository.java @@ -9,6 +9,10 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Map; +/** + * Event entity dao interface + * @author Rafał Żukowicz + */ @Repository @Transactional public interface EventRepository { diff --git a/src/main/java/com/release11/klaus/repository/EventRepositoryImpl.java b/src/main/java/com/release11/klaus/repository/EventRepositoryImpl.java index 33bc252..906aa4e 100644 --- a/src/main/java/com/release11/klaus/repository/EventRepositoryImpl.java +++ b/src/main/java/com/release11/klaus/repository/EventRepositoryImpl.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +//TODO: Add javadoc @Repository @AllArgsConstructor public class EventRepositoryImpl implements EventRepository { diff --git a/src/main/java/com/release11/klaus/repository/MockedResponseRepository.java b/src/main/java/com/release11/klaus/repository/MockedResponseRepository.java index 2858f3a..570c120 100644 --- a/src/main/java/com/release11/klaus/repository/MockedResponseRepository.java +++ b/src/main/java/com/release11/klaus/repository/MockedResponseRepository.java @@ -8,9 +8,19 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.UUID; +/** + * Spring repository that allows to retrieve message list by key-uuid from redis database + * @author Rafał Żukowicz + */ @Repository @Transactional public interface MockedResponseRepository extends CrudRepository { + /** + * Finds all messages by their uuid + * @param clientUUID the key-uuid of given set of messages + * @return list of {@link com.release11.klaus.model.MockedMessage} + */ List findAllByClientUUID(UUID clientUUID); +// TODO: Remove if no use MockedMessage getByCompositePrimaryKey(String compositePrimaryKey); } From 742e3253008b209e51c27c2995101c31899b612d Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 15:57:53 +0100 Subject: [PATCH 5/6] Removed depracated code and added Javadoc --- .../klaus/service/EtrackService.java | 9 ++++++ .../klaus/service/EtrackServiceImpl.java | 11 +++++++ .../release11/klaus/service/KlausService.java | 4 +++ .../klaus/service/KlausServiceImpl.java | 31 ++++++++++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/release11/klaus/service/EtrackService.java b/src/main/java/com/release11/klaus/service/EtrackService.java index 8e409a3..dcd8360 100644 --- a/src/main/java/com/release11/klaus/service/EtrackService.java +++ b/src/main/java/com/release11/klaus/service/EtrackService.java @@ -6,7 +6,16 @@ import org.springframework.stereotype.Service; import java.util.List; +/** + * Spring service interface for {@link com.release11.klaus.controller.EventController} + * @author Rafał Żukowicz + */ @Service public interface EtrackService { + /** + * Searches for {@link Event} objects between date brackets + * @param eventsDto object containing required data for request + * @return list of {@link Event} + */ List getEventsByDateTimeAndBusinessKeys(EventRequestDto eventsDto); } diff --git a/src/main/java/com/release11/klaus/service/EtrackServiceImpl.java b/src/main/java/com/release11/klaus/service/EtrackServiceImpl.java index c4ad3f5..35d052f 100644 --- a/src/main/java/com/release11/klaus/service/EtrackServiceImpl.java +++ b/src/main/java/com/release11/klaus/service/EtrackServiceImpl.java @@ -12,6 +12,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * Spring Service for {@link com.release11.klaus.controller.EventController}. Contains logic required for quering + * the database for {@link Event} objects + * @author Rafał Żukowicz + */ @Slf4j @Service @AllArgsConstructor @@ -19,6 +24,12 @@ public class EtrackServiceImpl implements EtrackService { private final EventRepository eventRepository; + /** + * Adds {@link BusinessKey} to {@link EventRequestDto} + * in order to create query via{@link com.release11.klaus.repository.EventRepositoryImpl} + * @param eventsDto object containing required data for request + * @return list of {@link Event} + */ @Override public List getEventsByDateTimeAndBusinessKeys(EventRequestDto eventsDto) { Map businessKeys = new HashMap<>(); diff --git a/src/main/java/com/release11/klaus/service/KlausService.java b/src/main/java/com/release11/klaus/service/KlausService.java index 57499e8..e221499 100644 --- a/src/main/java/com/release11/klaus/service/KlausService.java +++ b/src/main/java/com/release11/klaus/service/KlausService.java @@ -7,6 +7,10 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; +/** + * Service interface for {@link com.release11.klaus.controller.KlausController} and {@link com.release11.klaus.controller.MockController} + * @author Rafał Żukowicz + */ @Service public interface KlausService { ResponseEntity deleteMockedResponse(UUID clientUUID, int mockedResponseId); diff --git a/src/main/java/com/release11/klaus/service/KlausServiceImpl.java b/src/main/java/com/release11/klaus/service/KlausServiceImpl.java index 5d4a769..48bee88 100644 --- a/src/main/java/com/release11/klaus/service/KlausServiceImpl.java +++ b/src/main/java/com/release11/klaus/service/KlausServiceImpl.java @@ -18,6 +18,12 @@ import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; +/** + * Service for {@link com.release11.klaus.controller.KlausController} and {@link com.release11.klaus.controller.MockController} + * Allows for performing CRUD operations on {@link MockedMessageDto} + * @author Rafał Żukowicz + * @author Gabriel Modzelewski + */ @Slf4j @Service @AllArgsConstructor @@ -26,6 +32,12 @@ public class KlausServiceImpl implements KlausService { private final MockedResponseRepository mockedResponseRepository; private final ObjectMapper objectMapper; + /** + * Removes message of given id in given key-uuid set + * @param clientUUID the key-uuid of given set of messages + * @param mockedResponseId unique id of given message + * @return confirmation and status 200 OK + */ @Override public ResponseEntity deleteMockedResponse(UUID clientUUID, int mockedResponseId) { String key = clientUUID.toString() + "_" + mockedResponseId; @@ -35,6 +47,11 @@ public class KlausServiceImpl implements KlausService { new HttpHeaders(), HttpStatus.ACCEPTED); } + /** + * Returns all messages of given key-uuid + * @param clientUUID the key-uuid of given set of messages + * @return List of {@link MockedMessageDto} + */ @Override public List getAllMockedResponses(UUID clientUUID) { return mockedResponseRepository.findAllByClientUUID(clientUUID).stream() @@ -42,6 +59,13 @@ public class KlausServiceImpl implements KlausService { .collect(Collectors.toList()); } +// TODO: check logic + /** + * Returns {@link MockedMessageDto} of given id and key-uuid. If message doesn't then empty message is returned + * @param clientUUID the key-uuid of given set of messages + * @param mockedResponseId unique id of given message + * @return {@link MockedMessageDto} object + */ @SneakyThrows @Override public MockedMessageDto getMockedResponse(UUID clientUUID, int mockedResponseId){ @@ -60,10 +84,15 @@ public class KlausServiceImpl implements KlausService { return mockedMessageDto; } +// TODO: Remove code of no use + /** + * Allows to modify mocked message. If message of given id and key-uuid doesn't exist a new entry is created + * @param mockedMessageDto message to be saved + * @return Confirmation and status 200 OK + */ @SneakyThrows @Override public ResponseEntity setMockedResponse(MockedMessageDto mockedMessageDto) { - mockedResponseRepository.save(mockedMessageMapper.mockedMessageDtoToMockedMessage(mockedMessageDto)); String s = objectMapper.writeValueAsString(mockedMessageDto); String s1 = mockedMessageDto.toString(); From febed51b2cb3ac462dd6fc3a7e30e7d624e98445 Mon Sep 17 00:00:00 2001 From: modzeleg Date: Mon, 22 Mar 2021 16:14:46 +0100 Subject: [PATCH 6/6] Removed depracated code and added Javadoc --- .../java/com/release11/klaus/utilis/BusinessKey.java | 8 ++++++++ .../java/com/release11/klaus/utilis/ObjectConfig.java | 1 + .../java/com/release11/klaus/utilis/RedisAppender.java | 1 + .../com/release11/klaus/utilis/TrackingClient.java | 10 ++++++++++ 4 files changed, 20 insertions(+) diff --git a/src/main/java/com/release11/klaus/utilis/BusinessKey.java b/src/main/java/com/release11/klaus/utilis/BusinessKey.java index d647c75..6de7a14 100644 --- a/src/main/java/com/release11/klaus/utilis/BusinessKey.java +++ b/src/main/java/com/release11/klaus/utilis/BusinessKey.java @@ -2,6 +2,10 @@ package com.release11.klaus.utilis; import lombok.AllArgsConstructor; +/** + * Enum of keys for redis database. + * @author Rafał Żukowicz + */ @AllArgsConstructor public enum BusinessKey { INTERFACE_NAME("interfaceName"), @@ -10,6 +14,10 @@ public enum BusinessKey { private final String phrase; + /** + * Returns string value of given enum variant + * @return string value of enum + */ public String getReasonPhrase() { return this.phrase; } diff --git a/src/main/java/com/release11/klaus/utilis/ObjectConfig.java b/src/main/java/com/release11/klaus/utilis/ObjectConfig.java index 470708b..895456a 100644 --- a/src/main/java/com/release11/klaus/utilis/ObjectConfig.java +++ b/src/main/java/com/release11/klaus/utilis/ObjectConfig.java @@ -4,6 +4,7 @@ import com.release11.klaus.model.MockedMessageDto; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +//TODO: is it really necessary? kekw @Configuration public class ObjectConfig { @Bean diff --git a/src/main/java/com/release11/klaus/utilis/RedisAppender.java b/src/main/java/com/release11/klaus/utilis/RedisAppender.java index f8be5ae..a6dd5aa 100644 --- a/src/main/java/com/release11/klaus/utilis/RedisAppender.java +++ b/src/main/java/com/release11/klaus/utilis/RedisAppender.java @@ -15,6 +15,7 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.Protocol; +//TODO: The check? Check if any of the following methods might be removed... public class RedisAppender extends UnsynchronizedAppenderBase { JedisPool pool; diff --git a/src/main/java/com/release11/klaus/utilis/TrackingClient.java b/src/main/java/com/release11/klaus/utilis/TrackingClient.java index c546e65..27fddbf 100644 --- a/src/main/java/com/release11/klaus/utilis/TrackingClient.java +++ b/src/main/java/com/release11/klaus/utilis/TrackingClient.java @@ -4,10 +4,20 @@ import org.slf4j.MDC; import java.util.Map; +//TODO: Check if constructor might be safely removed. It's static class tho +/** + * This static class has one purpose and one purpose only. It logs data about incomming requests. + * The data from logs is received via {@link com.release11.klaus.repository.EventRepositoryImpl} + * @author Rafał Żukowski + */ public final class TrackingClient { private TrackingClient(){} + /** + * Logs data inside the given map + * @param businessKeysMap map containing all the information about incomming request + */ public static void setBusinessKeys(Map businessKeysMap){ for (Map.Entry entry : businessKeysMap.entrySet()) { MDC.put(entry.getKey().getReasonPhrase(), entry.getValue());