Skip to content

Commit

Permalink
limited fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kocmana committed Apr 8, 2021
1 parent 3d23a14 commit 0dc7650
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.aspectj.lang.annotation.Aspect;

@Aspect
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface NormallyDistributedEndpointDelaySimulation {

int mean() default 0;

int standardDeviation() default 0;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.aspectj.lang.annotation.Aspect;

@Aspect
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ProbabilisticEndpointDelaySimulation {

float probability() default 0;

int delayInMs() default 0;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Target({ElementType.METHOD})
public @interface ProbabilisticFailureSimulation {

float probability() default 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.technikum.masterproject.customerservice.customernetwork;

import at.technikum.masterproject.commons.delay.annotation.NormallyDistributedEndpointDelaySimulation;
import at.technikum.masterproject.customerservice.customernetwork.model.domain.CustomerInteraction;
import at.technikum.masterproject.customerservice.customernetwork.model.domain.CustomerNetwork;
import at.technikum.masterproject.customerservice.customernetwork.model.dto.CustomerInteractionDto;
Expand Down Expand Up @@ -32,6 +33,7 @@ public CustomerNetworkController(
this.customerRelationshipMapper = customerRelationshipMapper;
}

@NormallyDistributedEndpointDelaySimulation(mean = 100, standardDeviation = 25)
@GetMapping("/{customerId}")
public ResponseEntity<List<CustomerNetworkDto>> getCustomerNetworkForCustomer(@PathVariable int customerId) {
List<CustomerNetwork> customerNetworks = customerNetworkService.getCustomerNetworksForCustomer(customerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package at.technikum.masterproject.integrationservice.model.customer;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum Gender {
MALE, FEMALE
MALE, FEMALE;

@JsonValue
public String encode(){
return name().toLowerCase();
}

@JsonCreator
public static Gender decode(String input){
try {
return Gender.valueOf(input.toUpperCase());
} catch (Exception exception) {
throw new IllegalArgumentException("Illegal argument provided for gender, please use male or female.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private DataLoader<Integer, List<ProductReview>> createProductReviewByCustomerDa
return DataLoader.newMappedDataLoader(batchLoadFunction);
}


private DataLoader<Integer, Product> createProductInformationDataLoader() {
MappedBatchLoader<Integer, Product> batchLoadFunction = dataLoaderExecutor.generateBatchLoadFunction(
productInformationClient::getProductById, Product::getId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ voyager:
enabled: true

services:
resolver-mode: DATALOADER #DATALOADER, ASYNC or SERIAL
resolver-mode: ASYNC #DATALOADER, ASYNC or SERIAL
productservice:
authentication-type: BASIC_AUTH
url: localhost
Expand Down
2 changes: 1 addition & 1 deletion integration_service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ graphql:
tools:
schema-location-pattern: "schemas/**/*.graphqls"
servlet:
maxQueryDuration: 12345
maxQueryDuration: 9999999
maxQueryDepth: 20
#maxQueryComplexity: 10

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
schema {
query: Query
mutation: Mutation
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;

import at.technikum.masterproject.productservice.model.error.ErrorResponse;
import at.technikum.masterproject.commons.responses.ErrorResponse;
import at.technikum.masterproject.commons.responses.ValidationErrorResponse;
import at.technikum.masterproject.productservice.productinformation.model.ProductInformationNotFoundException;
import at.technikum.masterproject.productservice.productreview.model.ProductReviewNotFoundException;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ValidationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,63 +20,52 @@
@Slf4j
public class CommonControllerAdvice {

private static final String UUID_ATTRIBUTE = "request-id";
private static final String GENERIC_ERROR_MESSAGE = "An error has occured.";

@ExceptionHandler(MethodArgumentNotValidException.class)
ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(final MethodArgumentNotValidException ex,
final HttpServletRequest request) {
ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(final MethodArgumentNotValidException ex) {
log.warn(ex.getMessage());

return ResponseEntity
.status(BAD_REQUEST)
.body(new ErrorResponse(retrieveRequestUuid(request), ex.getMessage()));
.body(ValidationErrorResponse.forException(ex));
}

@ExceptionHandler(ValidationException.class)
ResponseEntity<ErrorResponse> handleValidationException(final ValidationException ex,
final HttpServletRequest request) {
ResponseEntity<ErrorResponse> handleValidationException(final ValidationException ex) {
log.warn(ex.getMessage());

return ResponseEntity
.status(BAD_REQUEST)
.body(new ErrorResponse(retrieveRequestUuid(request), ex.getMessage()));
.body(ErrorResponse.withMessage(ex.getMessage()));
}

@ExceptionHandler(HttpMessageNotReadableException.class)
ResponseEntity<ErrorResponse> handleMessageNotReadableException(final HttpMessageNotReadableException ex,
final HttpServletRequest request) {
ResponseEntity<ErrorResponse> handleMessageNotReadableException(final HttpMessageNotReadableException ex) {
log.warn(ex.getMessage());

return ResponseEntity
.status(BAD_REQUEST)
.body(new ErrorResponse(retrieveRequestUuid(request), ex.getMessage()));
.body(ErrorResponse.withMessage(ex.getMessage()));
}

@ExceptionHandler({ProductInformationNotFoundException.class, ProductReviewNotFoundException.class})
ResponseEntity<ErrorResponse> handleProductInformationNotFoundException(final ProductInformationNotFoundException ex,
final HttpServletRequest request) {
ResponseEntity<ErrorResponse> handleProductInformationNotFoundException(
final ProductInformationNotFoundException ex) {
log.warn(ex.getMessage());

return ResponseEntity
.status(NOT_FOUND)
.body(new ErrorResponse(retrieveRequestUuid(request), ex.getMessage()));
.body(ErrorResponse.withMessage(ex.getMessage()));
}

@ExceptionHandler(Exception.class)
ResponseEntity<ErrorResponse> handleGenericException(final Exception ex,
final HttpServletRequest request) {
ResponseEntity<ErrorResponse> handleGenericException(final Exception ex) {
log.warn("Uncaught exception has occurred: {}", ex.getMessage());

return ResponseEntity
.status(INTERNAL_SERVER_ERROR)
.body(new ErrorResponse(retrieveRequestUuid(request), GENERIC_ERROR_MESSAGE));
.body(ErrorResponse.withMessage(GENERIC_ERROR_MESSAGE));
}

private String retrieveRequestUuid(final HttpServletRequest request) {
return Optional.ofNullable(request.getAttribute(UUID_ATTRIBUTE))
.filter(String.class::isInstance)
.map(String.class::cast)
.orElse("No UUID defined.");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.springframework.http.ResponseEntity.ok;

import at.technikum.masterproject.productservice.model.ElementCreationResponse;
import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductCreationRequest;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductResponse;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductUpdateRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productinformation;

import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package at.technikum.masterproject.productservice.productinformation;

import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.ProductInformationNotFoundException;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.technikum.masterproject.productservice.productinformation.model;
package at.technikum.masterproject.productservice.productinformation.model.domain;

import javax.persistence.Embedded;
import javax.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.technikum.masterproject.productservice.productinformation.model;
package at.technikum.masterproject.productservice.productinformation.model.domain;

import javax.persistence.Embeddable;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productinformation.model.mapper;

import at.technikum.masterproject.productservice.productinformation.model.ProductDimension;
import at.technikum.masterproject.productservice.productinformation.model.domain.ProductDimension;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductDimensionDto;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productinformation.model.mapper;

import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductCreationRequest;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductResponse;
import at.technikum.masterproject.productservice.productinformation.model.dto.ProductUpdateRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import at.technikum.masterproject.productservice.model.ElementCreationResponse;
import at.technikum.masterproject.productservice.productinformation.ProductInformationService;
import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.ProductInformationNotFoundException;
import at.technikum.masterproject.productservice.productreview.model.ProductReview;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import at.technikum.masterproject.productservice.productreview.model.domain.ProductReview;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewCreationRequest;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewResponse;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewUpdateRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productreview;

import at.technikum.masterproject.productservice.productreview.model.ProductReview;
import at.technikum.masterproject.productservice.productreview.model.domain.ProductReview;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package at.technikum.masterproject.productservice.productreview;

import at.technikum.masterproject.productservice.productreview.model.ProductReview;
import at.technikum.masterproject.productservice.productreview.model.ProductReviewNotFoundException;
import at.technikum.masterproject.productservice.productreview.model.domain.ProductReview;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productreview.model;
package at.technikum.masterproject.productservice.productreview.model.domain;

import at.technikum.masterproject.productservice.productinformation.model.Product;
import at.technikum.masterproject.productservice.productinformation.model.domain.Product;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.technikum.masterproject.productservice.productreview.model.mapper;

import at.technikum.masterproject.productservice.productreview.model.ProductReview;
import at.technikum.masterproject.productservice.productreview.model.domain.ProductReview;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewCreationRequest;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewResponse;
import at.technikum.masterproject.productservice.productreview.model.dto.ProductReviewUpdateRequest;
Expand Down

0 comments on commit 0dc7650

Please sign in to comment.