diff --git a/pom.xml b/pom.xml
index cdbc5dd9..cc060702 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,23 +23,16 @@
2.2.4.RELEASE
1.0.9.RELEASE
1.5.5.Final
- 0.8.6
+ 0.8.12
3.1.0
0.9.10
2.8
1.18.22
3.0.0
-
- 0.6
- 3.13.1
- 3.3.0
- 4.1.50.Final
2.1.5
- 4.4.0
+ 3.5.2
jcmdsbr
https://sonarcloud.io
-
-
@@ -175,22 +168,6 @@
${caelum.stella.version}
-
- com.querydsl
- querydsl-apt
-
-
-
- com.querydsl
- querydsl-jpa
-
-
-
- com.querydsl
- querydsl-sql
- ${querydsl-apt.version}
-
-
org.slf4j
slf4j-api
@@ -199,35 +176,19 @@
com.google.zxing
core
- 3.5.2
+ ${google.zxing.version}
com.google.zxing
javase
- 3.5.2
+ ${google.zxing.version}
-
- com.mysema.maven
- apt-maven-plugin
- 1.1.3
-
-
-
- process
-
-
- target/generated-sources/java
- com.querydsl.apt.jpa.JPAAnnotationProcessor
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
@@ -258,8 +219,8 @@
${jacoco.version}
- com/fiap/tc/usecase/service/**/*
- com/fiap/tc/usecase/*
+ com/fiap/tc/core/usecase/**/*
+ com/fiap/tc/adapter/repository/output/**
@@ -269,8 +230,8 @@
- jacoco-report
- verify
+ report
+ prepare-package
report
diff --git a/src/main/java/com/fiap/tc/adapter/repository/CategoryRepository.java b/src/main/java/com/fiap/tc/adapter/repository/CategoryRepository.java
index fa5f93d0..507ff6b1 100644
--- a/src/main/java/com/fiap/tc/adapter/repository/CategoryRepository.java
+++ b/src/main/java/com/fiap/tc/adapter/repository/CategoryRepository.java
@@ -4,12 +4,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
+import java.util.Optional;
import java.util.UUID;
@Repository
public interface CategoryRepository extends JpaRepository {
- CategoryEntity findByNameOrDescription(String name, String description);
+ Optional findByName(String name);
- CategoryEntity findByUuid(UUID uuid);
+ Optional findByUuid(UUID uuid);
}
diff --git a/src/main/java/com/fiap/tc/adapter/repository/mapper/OrderListMapper.java b/src/main/java/com/fiap/tc/adapter/repository/mapper/OrderListMapper.java
index 3ebad7d0..4a458f3e 100644
--- a/src/main/java/com/fiap/tc/adapter/repository/mapper/OrderListMapper.java
+++ b/src/main/java/com/fiap/tc/adapter/repository/mapper/OrderListMapper.java
@@ -3,7 +3,6 @@
import com.fiap.tc.adapter.repository.entity.OrderEntity;
import com.fiap.tc.adapter.repository.entity.OrderHistoricEntity;
import com.fiap.tc.adapter.repository.mapper.base.MapperEntity;
-import com.fiap.tc.core.domain.model.Order;
import com.fiap.tc.core.domain.model.enums.OrderStatus;
import com.fiap.tc.core.domain.response.OrderListResponse;
import org.mapstruct.Mapper;
@@ -14,7 +13,6 @@
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;
-import java.util.stream.Collectors;
import static com.fiap.tc.common.constants.OrderConstants.WAIT_TIME_STATUS;
@@ -45,7 +43,7 @@ default Optional getPreparingRegisterDate(OrderEntity orderEntity
List preparingDates = orderEntity.getOrderHistoric().stream()
.filter(historic -> historic.getStatus().equals(OrderStatus.PREPARING))
.map(OrderHistoricEntity::getRegisterDate)
- .collect(Collectors.toList());
+ .toList();
return preparingDates.stream().findFirst();
}
diff --git a/src/main/java/com/fiap/tc/adapter/repository/output/CategoryOutputAdapter.java b/src/main/java/com/fiap/tc/adapter/repository/output/CategoryOutputAdapter.java
index 5af3b532..f4d97464 100644
--- a/src/main/java/com/fiap/tc/adapter/repository/output/CategoryOutputAdapter.java
+++ b/src/main/java/com/fiap/tc/adapter/repository/output/CategoryOutputAdapter.java
@@ -18,8 +18,6 @@
import static com.fiap.tc.adapter.repository.mapper.base.MapperConstants.CATEGORY_MAPPER;
import static java.lang.String.format;
-import static java.util.Objects.isNull;
-import static java.util.Objects.nonNull;
@Service
public class CategoryOutputAdapter implements SaveCategoryOutputPort, LoadCategoryOutputPort,
@@ -32,10 +30,8 @@ public CategoryOutputAdapter(CategoryRepository categoryPersistenceRepository) {
@Override
public void delete(UUID uuid) {
- var category = categoryRepository.findByUuid(uuid);
- if (nonNull(category)) {
- categoryRepository.delete(category);
- }
+ var categoryEntityOptional = categoryRepository.findByUuid(uuid);
+ categoryEntityOptional.ifPresent(categoryRepository::delete);
}
@Override
@@ -46,17 +42,18 @@ public Page list(Pageable pageable) {
@Override
public Category load(UUID uuid) {
- var category = categoryRepository.findByUuid(uuid);
- if (isNull(category)) {
+ var categoryEntityOptional = categoryRepository.findByUuid(uuid);
+ if (categoryEntityOptional.isEmpty()) {
throw new NotFoundException(format("Category with uuid %s not found!", uuid));
}
- return CATEGORY_MAPPER.fromEntity(category);
+ return CATEGORY_MAPPER.fromEntity(categoryEntityOptional.get());
}
@Override
public Category saveOrUpdate(String name, String description, boolean active) {
- var categoryEntity = categoryRepository.findByNameOrDescription(name, description);
- if (nonNull(categoryEntity)) {
+ var categoryEntityOptional = categoryRepository.findByName(name);
+ if (categoryEntityOptional.isPresent()) {
+ var categoryEntity = categoryEntityOptional.get();
categoryEntity.setName(name);
categoryEntity.setDescription(description);
categoryEntity.getAudit().setActive(active);
diff --git a/src/main/java/com/fiap/tc/common/config/AuthorizationServerConfig.java b/src/main/java/com/fiap/tc/common/config/AuthorizationServerConfig.java
index 713bb75b..ea0ccc65 100644
--- a/src/main/java/com/fiap/tc/common/config/AuthorizationServerConfig.java
+++ b/src/main/java/com/fiap/tc/common/config/AuthorizationServerConfig.java
@@ -36,8 +36,8 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
.secret(clientConfig.getSecret())
.scopes("read", "write")
.authorizedGrantTypes("password", "refresh_token")
- .accessTokenValiditySeconds(86400)
- .refreshTokenValiditySeconds(3600 * 24);
+ .accessTokenValiditySeconds(clientConfig.getTokenExpirationTime())
+ .refreshTokenValiditySeconds(clientConfig.getRefreshTokenExpirationTime());
}
@Override
@@ -45,11 +45,8 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
- endpoints
-
- .tokenStore(tokenStore())
+ endpoints.tokenStore(tokenStore())
.tokenEnhancer(tokenEnhancerChain)
- .reuseRefreshTokens(false)
.userDetailsService(userDetailsService)
.authenticationManager(authenticationManager);
}
diff --git a/src/main/java/com/fiap/tc/common/config/ClientConfig.java b/src/main/java/com/fiap/tc/common/config/ClientConfig.java
index 7dc9c110..feeb0877 100644
--- a/src/main/java/com/fiap/tc/common/config/ClientConfig.java
+++ b/src/main/java/com/fiap/tc/common/config/ClientConfig.java
@@ -11,4 +11,6 @@ public class ClientConfig {
private String name;
private String secret;
private String signKey;
+ private Integer tokenExpirationTime;
+ private Integer refreshTokenExpirationTime;
}
diff --git a/src/main/java/com/fiap/tc/common/config/WebConfig.java b/src/main/java/com/fiap/tc/common/config/WebConfig.java
index e261c51d..76134880 100644
--- a/src/main/java/com/fiap/tc/common/config/WebConfig.java
+++ b/src/main/java/com/fiap/tc/common/config/WebConfig.java
@@ -1,10 +1,20 @@
package com.fiap.tc.common.config;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.servlet.LocaleResolver;
+import org.springframework.web.servlet.i18n.SessionLocaleResolver;
+
+import java.util.Locale;
@Configuration
-@EnableScheduling
public class WebConfig {
+ @Bean
+ public LocaleResolver localeResolver() {
+ SessionLocaleResolver slr = new SessionLocaleResolver();
+ slr.setDefaultLocale(Locale.US);
+ return slr;
+ }
+
}
diff --git a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ConfirmedOrderStatusValidator.java b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ConfirmedOrderStatusValidator.java
deleted file mode 100644
index 5067ec8f..00000000
--- a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ConfirmedOrderStatusValidator.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.fiap.tc.core.domain.behavior.order.status.validator;
-
-import com.fiap.tc.core.domain.model.enums.OrderStatus;
-
-import java.util.List;
-
-
-public class ConfirmedOrderStatusValidator extends OrderStatusValidatorTemplate {
- @Override
- public List next() {
- return List.of(OrderStatus.PREPARING);
- }
-}
diff --git a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/OrderStatusValidatorTemplate.java b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/OrderStatusValidatorTemplate.java
index 526a156d..48b832ba 100644
--- a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/OrderStatusValidatorTemplate.java
+++ b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/OrderStatusValidatorTemplate.java
@@ -14,11 +14,9 @@ public abstract class OrderStatusValidatorTemplate implements OrderStatusValidat
public void validate(OrderStatus status) {
var allowedNextStatus = next();
if (!allowedNextStatus.contains(status)) {
- throw new BadRequestException(format("Status %s is a invalid next state!", status.name()));
+ throw new BadRequestException(format("Status %s is in a invalid next state!", status.name()));
}
- log.info("status {} is valid!", status.name());
-
}
public abstract List next();
diff --git a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/PendingOrderStatusValidator.java b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/PendingOrderStatusValidator.java
index 3a224ceb..ddada7d6 100644
--- a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/PendingOrderStatusValidator.java
+++ b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/PendingOrderStatusValidator.java
@@ -8,6 +8,6 @@
public class PendingOrderStatusValidator extends OrderStatusValidatorTemplate {
@Override
public List next() {
- return List.of(OrderStatus.CONFIRMED, OrderStatus.PENDING, OrderStatus.CANCELED);
+ return List.of(OrderStatus.PREPARING, OrderStatus.PENDING, OrderStatus.CANCELED);
}
}
diff --git a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ReceivedOrderStatusValidator.java b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ReceivedOrderStatusValidator.java
index 6de5427f..c94487a2 100644
--- a/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ReceivedOrderStatusValidator.java
+++ b/src/main/java/com/fiap/tc/core/domain/behavior/order/status/validator/ReceivedOrderStatusValidator.java
@@ -8,6 +8,6 @@
public class ReceivedOrderStatusValidator extends OrderStatusValidatorTemplate {
@Override
public List next() {
- return List.of(OrderStatus.CONFIRMED, OrderStatus.PENDING, OrderStatus.CANCELED);
+ return List.of(OrderStatus.PREPARING, OrderStatus.PENDING, OrderStatus.CANCELED);
}
}
diff --git a/src/main/java/com/fiap/tc/core/domain/exception/handler/ExceptionAdvice.java b/src/main/java/com/fiap/tc/core/domain/exception/handler/ExceptionAdvice.java
index a368c4b8..20193817 100644
--- a/src/main/java/com/fiap/tc/core/domain/exception/handler/ExceptionAdvice.java
+++ b/src/main/java/com/fiap/tc/core/domain/exception/handler/ExceptionAdvice.java
@@ -4,14 +4,10 @@
import com.fiap.tc.core.domain.exception.BadRequestException;
import com.fiap.tc.core.domain.exception.NotFoundException;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.MessageSource;
-import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.security.access.AccessDeniedException;
+import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -19,10 +15,10 @@
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
-import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.stream.Collectors;
-import static java.util.stream.Collectors.toList;
import static org.springframework.http.HttpStatus.*;
import static org.springframework.http.ResponseEntity.status;
@@ -30,9 +26,6 @@
@Slf4j
public class ExceptionAdvice extends ResponseEntityExceptionHandler {
- @Autowired
- private MessageSource messageSource;
-
@ExceptionHandler(value = Exception.class)
public ResponseEntity defaultExceptionHandler(Exception e) {
@@ -40,36 +33,20 @@ public ResponseEntity defaultExceptionHandler(Exception e) {
DefaultResponse response = new DefaultResponse();
response.setStatus("ERROR");
- response.setMessage("Ocorreu um erro inesperado!");
+ response.setMessage("Unexpected error!");
return status(INTERNAL_SERVER_ERROR).body(response);
}
- @Override
- protected ResponseEntity