Merge branch 'modzeleg' into developer

This commit is contained in:
2021-03-23 15:17:23 +01:00
26 changed files with 47 additions and 37 deletions

7
.idea/misc.xml generated
View File

@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Documents" />
<option name="OPTION_SCOPE" value="private" />
<option name="OPTION_DOCUMENT_TAG_USE" value="true" />
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="true" />
<option name="OPTION_DOCUMENT_TAG_VERSION" value="true" />
</component>
<component name="MavenBuildProjectComponent">
<option name="mavenExecutable" value="" />
<option name="Settings File" value="" />

View File

@@ -35,39 +35,7 @@ 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
*/
@DeleteMapping(value = "/delete/{clientUUID}/{mockedResponseId}")
public ResponseEntity<String> deleteMockedResponse(@PathVariable UUID clientUUID,
@PathVariable int mockedResponseId){
TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "deleteMockedResponse",
BusinessKey.CLIENT_UUID, String.valueOf(clientUUID),
BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId)));
klausService.deleteMockedResponse(clientUUID, mockedResponseId);
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}
*/
@GetMapping(value = "/getAll/{clientUUID}")
public ResponseEntity<String> getAllMockedResponses(@PathVariable UUID clientUUID){
TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getAllMockedResponse",
BusinessKey.CLIENT_UUID, String.valueOf(clientUUID)));
List<MockedMessageDto> mockedMessages = klausService.getAllMockedResponses(clientUUID);
return new ResponseEntity<>(mockedMessages.toString(), HttpStatus.OK);
}
// TODO: Move to MockController
/**
* 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!

View File

@@ -10,10 +10,20 @@ import javax.validation.ConstraintViolationException;
import java.util.ArrayList;
import java.util.List;
//TODO: Find usage and document or remove it
//TODO: Is it really necessary?
/**
* Custom exception handler for {@link ConstraintViolationException}
* @author Rafał Żukowicz
*/
@ControllerAdvice
public class MvcExceptionHandler {
/**
* Provides handling for {@link ConstraintViolationException}
* @param e exception argument
* @return response with error list and status 400 bad request
*/
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<List> validationErrorHandler(ConstraintViolationException e){
List<String> errors = new ArrayList<>(e.getConstraintViolations().size());
@@ -24,6 +34,11 @@ public class MvcExceptionHandler {
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
/**
* Provides handling for {@link BindException}
* @param ex exception argument
* @return response with error list and status 400 bad request
*/
@ExceptionHandler(BindException.class)
public ResponseEntity<List> handleBindException(BindException ex){
return new ResponseEntity(ex.getAllErrors(), HttpStatus.BAD_REQUEST);

View File

@@ -7,7 +7,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
//TODO: Find usage and document or remove it
/**
* Annotation interface that is used to annotate Integer fields that contain http status values.
* It provides validation and throws an error when trying to send response with incorrect status.
* @author Rafał Żukowicz
*/
@Target({ ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = HttpCodeValidation.class )

View File

@@ -1,5 +1,7 @@
package com.release11.klaus.model.constraints;
import com.release11.klaus.model.MockedMessage;
import com.release11.klaus.model.MockedMessageDto;
import org.springframework.http.HttpStatus;
import javax.validation.ConstraintValidator;
@@ -8,10 +10,18 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
//TODO: Find usage and document or remove it
/**
* It's validator class. It checks if status value of {@link com.release11.klaus.model.MockedMessageDto} is within bonds of http status values map.
* @author Rafał Żukowicz
*/
public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer> {
private Set<Integer> allowedValues;
//TODO: Find use of targetEnum
/**
* Initializes {@link #allowedValues} with possible http status values.
* @param targetEnum HttpCode context
*/
@Override
public void initialize(HttpCode targetEnum) {
allowedValues = Stream.of(HttpStatus.values())
@@ -19,6 +29,12 @@ public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer
.collect(Collectors.toSet());
}
//TODO: Find use of ConstraintValidatorContext
/**
* @param integer value of {@link MockedMessageDto#getHttpStatus()} or {@link MockedMessage#getHttpStatus()}
* @param context context for validation
* @return true if valid
*/
@Override
public boolean isValid(Integer integer, ConstraintValidatorContext context) {
return allowedValues.contains(integer);

View File

@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2021-03-17T14:12:54+0100",
date = "2021-03-23T11:19:42+0100",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 14.0.1 (Oracle Corporation)"
)
@Component