From f5047cb57683d4a6b02b3899b6b3ea4e5f59ccc5 Mon Sep 17 00:00:00 2001 From: Francisco J Lopez-Pellicer Date: Sat, 20 Apr 2024 18:16:23 +0200 Subject: [PATCH] Maintenance: #178 remove old code plus update tests --- cli/build.gradle | 2 +- common/build.gradle | 15 +- .../config/AdministrationRestConfigurer.java | 2 +- .../DatabaseConnectionController.java | 6 +- .../FeatureTypeExtractorController.java | 3 +- ...erviceCapabilitiesExtractorController.java | 3 +- .../dashboard/DashboardInfoContributor.java | 27 ++- .../DatabaseConnectionTesterService.java | 2 - .../SimpleFeatureTypeExtractor.java | 2 +- .../UserPasswordAuthenticationRequest.java | 22 +- .../WorkspaceConfigurationController.java | 65 ------ .../dto/ClientConfiguration.java | 22 -- ...tConfigurationForApplicationTerritory.java | 28 --- .../decorators/QueryPaginationDecorator.java | 4 +- .../service/ClientConfigurationService.java | 171 --------------- .../service/ProxyConfigurationService.java | 2 +- .../org/sitmun/domain/CodeListsConstants.java | 2 +- .../sitmun/domain/PersistenceConstants.java | 2 +- .../domain/application/Application.java | 21 +- .../application/ApplicationProjection.java | 2 +- .../BeforeCreateApplicationValidator.java | 4 +- .../BeforeLinkSaveApplicationValidator.java | 4 +- .../background/ApplicationBackground.java | 20 +- .../ApplicationBackgroundProjection.java | 2 +- .../parameter/ApplicationParameter.java | 18 +- .../ApplicationParameterRepository.java | 2 +- .../territory/ApplicationTerritory.java | 20 +- .../ApplicationTerritoryRepository.java | 2 +- .../sitmun/domain/background/Background.java | 17 +- .../background/BackgroundProjection.java | 2 +- .../BeforeCreateBackgroundValidator.java | 4 +- .../BeforeLinkSaveBackgroundValidator.java | 4 +- .../BeforeLinkSaveCartographyValidator.java | 6 +- .../domain/cartography/Cartography.java | 21 +- .../cartography/CartographyProjection.java | 2 +- .../availability/CartographyAvailability.java | 20 +- .../CartographyAvailabilityProjection.java | 2 +- .../cartography/filter/CartographyFilter.java | 17 +- .../filter/CartographyFilterProjection.java | 2 +- .../parameter/CartographyParameter.java | 17 +- .../CartographySpatialSelectionParameter.java | 18 +- ...oreSaveCartographyPermissionValidator.java | 4 +- .../permission/CartographyPermission.java | 17 +- .../CartographyPermissionProjection.java | 2 +- ...eforeCreateCartographyStylesValidator.java | 4 +- .../BeforeSaveCartographyStylesValidator.java | 4 +- .../cartography/style/CartographyStyle.java | 17 +- .../org/sitmun/domain/comment/Comment.java | 17 +- .../configuration/ConfigurationParameter.java | 19 +- .../domain/database/DatabaseConnection.java | 17 +- .../main/java/org/sitmun/domain/log/Log.java | 17 +- .../java/org/sitmun/domain/role/Role.java | 20 +- .../org/sitmun/domain/service/Service.java | 21 +- .../service/parameter/ServiceParameter.java | 17 +- .../java/org/sitmun/domain/task/Task.java | 21 +- .../sitmun/domain/task/TaskProjection.java | 2 +- .../sitmun/domain/task/TaskRepository.java | 4 +- .../task/availability/TaskAvailability.java | 20 +- .../TaskAvailabilityProjection.java | 2 +- .../sitmun/domain/task/group/TaskGroup.java | 17 +- .../org/sitmun/domain/task/type/TaskType.java | 21 +- .../domain/task/type/TaskTypeProjection.java | 2 +- .../org/sitmun/domain/task/ui/TaskUI.java | 18 +- .../sitmun/domain/territory/Territory.java | 20 +- .../domain/territory/TerritoryProjection.java | 2 +- .../territory/type/TerritoryGroupType.java | 20 +- .../domain/territory/type/TerritoryType.java | 20 +- .../java/org/sitmun/domain/tree/Tree.java | 17 +- .../org/sitmun/domain/tree/node/TreeNode.java | 17 +- .../domain/tree/node/TreeNodeProjection.java | 2 +- .../java/org/sitmun/domain/user/User.java | 20 +- .../sitmun/domain/user/UserController.java | 41 ++-- .../user/configuration/UserConfiguration.java | 22 +- .../UserConfigurationProjection.java | 2 +- .../UserConfigurationRepository.java | 4 +- .../domain/user/position/UserPosition.java | 20 +- .../user/position/UserPositionProjection.java | 2 +- .../exception/RequirementException.java | 4 +- .../type/boundingbox/BoundingBox.java | 4 +- .../boundingbox/BoundingBoxValidator.java | 16 +- .../persistence/type/codelist/CodeList.java | 4 +- .../type/codelist/CodeListValidator.java | 2 +- .../type/codelist/CodeListValue.java | 20 +- ...ImmutableSystemCodeListValueException.java | 4 +- .../persistence/type/envelope/Envelope.java | 12 +- .../envelope/EnvelopeToStringConverter.java | 4 +- .../persistence/type/i18n/I18n.java | 2 +- .../persistence/type/i18n/I18nListener.java | 2 +- .../persistence/type/i18n/Language.java | 20 +- .../persistence/type/i18n/Translation.java | 20 +- .../type/i18n/TranslationProjection.java | 2 +- .../list/StringListAttributeConverter.java | 2 +- .../type/map/HashMapConverter.java | 10 +- .../persistence/type/point/Point.java | 12 +- .../type/point/PointToStringConverter.java | 4 +- .../persistence/type/srs/Srs.java | 2 +- .../type/srs/SrsSystemListValidator.java | 4 +- .../persistence/type/srs/SrsValidator.java | 2 +- .../config/WebSecurityConfigurer.java | 4 +- .../core/LdapUserAuthoritiesPopulator.java | 2 +- .../security/core/SecurityEntryPoint.java | 10 +- .../UserDetailsImplementation.java | 22 +- .../security/filter/JsonWebTokenFilter.java | 10 +- .../security/filter/ProxyTokenFilter.java | 8 +- .../security/storage/LdapPasswordStorage.java | 11 +- .../web/config/OpenApiConfigurer.java | 2 +- .../web/config/ProvidedOpenApiConfigurer.java | 2 +- .../controller/DomainExceptionHandler.java | 8 +- deploy/heroku-dev-full/build.gradle | 2 +- ...thenticationControllerLdapEnabledTest.java | 108 ---------- .../AuthenticationControllerTest.java | 47 ----- ...onfigurationApplicationControllerTest.java | 72 ------- .../ProxyConfigurationControllerTest.java | 197 ------------------ ...onfigurationApplicationControllerTest.java | 45 ---- .../WorkspaceConfigurationControllerTest.java | 55 ----- deploy/heroku-dev-lite/build.gradle | 2 +- .../changelog/04_initial_data_dev.yaml | 52 ++--- .../04_initial_data_dev/STM_GEOINFO.csv | 2 +- ...thenticationControllerLdapEnabledTest.java | 1 + .../AuthenticationControllerTest.java | 4 + ...ionApplicationTerritoryControllerTest.java | 16 +- .../ApplicationRepositoryDataRestTest.java | 75 ++----- .../ApplicationRepositoryTest.java | 18 +- .../application/ApplicationResourceTest.java | 36 ++-- ...cationParameterRepositoryDataRestTest.java | 9 +- .../BackgroundRepositoryDataRestTest.java | 62 +++--- .../CartographyRepositoryDataRestTest.java | 30 +-- .../CartographyRepositoryTest.java | 10 +- ...tographyFiltersRepositoryDataRestTest.java | 18 +- ...raphyParametersRepositoryDataRestTest.java | 10 +- ...aphyPermissionsRepositoryDataRestTest.java | 52 +++-- ...rmissionsRepositoryDataRestUpdateTest.java | 26 ++- ...rtographyStylesRepositoryDataRestTest.java | 21 +- ...rationParameterRepositoryDataRestTest.java | 3 + ...abaseConnectionRepositoryDataRestTest.java | 16 +- ...seConnectionRepositoryIntegrationTest.java | 36 ++-- .../java/org/sitmun/test/URIConstants.java | 4 +- legacy/build.gradle | 2 +- 138 files changed, 818 insertions(+), 1543 deletions(-) delete mode 100644 common/src/main/java/org/sitmun/authorization/controller/WorkspaceConfigurationController.java delete mode 100644 common/src/main/java/org/sitmun/authorization/dto/ClientConfiguration.java delete mode 100644 common/src/main/java/org/sitmun/authorization/dto/ClientConfigurationForApplicationTerritory.java delete mode 100644 common/src/main/java/org/sitmun/authorization/service/ClientConfigurationService.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationControllerTest.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ProxyConfigurationControllerTest.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationApplicationControllerTest.java delete mode 100644 deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationControllerTest.java diff --git a/cli/build.gradle b/cli/build.gradle index be025697..27695e4c 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -65,7 +65,7 @@ tasks.register('exportSchemas') { jacocoTestReport { reports { - xml.enabled true + xml.required.set(true) } } diff --git a/common/build.gradle b/common/build.gradle index 71119c7c..d20b74f1 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -18,6 +18,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.ldap:spring-ldap-core' implementation 'org.springframework.security:spring-security-ldap' testImplementation 'com.unboundid:unboundid-ldapsdk' @@ -31,18 +32,20 @@ dependencies { implementation platform("com.squareup.okhttp3:okhttp-bom:${okhttp_version}") implementation 'com.squareup.okhttp3:okhttp' implementation 'com.squareup.okhttp3:logging-interceptor' + implementation "org.json:json:${json_version}" implementation "io.jsonwebtoken:jjwt-api:${jjwt_version}" - implementation "org.springdoc:springdoc-openapi-common:${springdoc_openapi_version}" - implementation "org.springdoc:springdoc-openapi-ui:${springdoc_openapi_version}" - implementation "org.mapstruct:mapstruct:${mapstruct_version}" - implementation "org.apache.commons:commons-lang3:${commons_lang3_version}" - implementation "io.jsonwebtoken:jjwt-impl:${jjwt_version}" implementation "io.jsonwebtoken:jjwt-jackson:${jjwt_version}" + implementation "org.springdoc:springdoc-openapi-common:${springdoc_openapi_version}" + implementation "org.springdoc:springdoc-openapi-ui:${springdoc_openapi_version}" + + implementation "org.mapstruct:mapstruct:${mapstruct_version}" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}" + implementation "org.apache.commons:commons-lang3:${commons_lang3_version}" + testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'com.vaadin.external.google', module: 'android-json' } @@ -54,7 +57,7 @@ compileJava.inputs.files(processResources) jacocoTestReport { reports { - xml.enabled true + xml.required.set(true) } } diff --git a/common/src/main/java/org/sitmun/administration/config/AdministrationRestConfigurer.java b/common/src/main/java/org/sitmun/administration/config/AdministrationRestConfigurer.java index 907b24ed..a6531208 100644 --- a/common/src/main/java/org/sitmun/administration/config/AdministrationRestConfigurer.java +++ b/common/src/main/java/org/sitmun/administration/config/AdministrationRestConfigurer.java @@ -58,7 +58,7 @@ public void configureValidatingRepositoryEventListener(ValidatingRepositoryEvent } @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry corsRegistry) { + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) { config.setReturnBodyForPutAndPost(true); config.setBasePath("/api"); config.exposeIdsFor(entityManager.getMetamodel() diff --git a/common/src/main/java/org/sitmun/administration/controller/DatabaseConnectionController.java b/common/src/main/java/org/sitmun/administration/controller/DatabaseConnectionController.java index ed7023c0..d3b17550 100644 --- a/common/src/main/java/org/sitmun/administration/controller/DatabaseConnectionController.java +++ b/common/src/main/java/org/sitmun/administration/controller/DatabaseConnectionController.java @@ -40,7 +40,8 @@ public DatabaseConnectionController(DatabaseConnectionRepository repository, Dat * @return 200 if valid */ @GetMapping("/connections/{id}/test") - public @ResponseBody + @ResponseBody + public ResponseEntity testConnection(@PathVariable("id") Integer id) { Optional connectionOp = repository.findById(id); if (connectionOp.isPresent()) { @@ -60,7 +61,8 @@ ResponseEntity testConnection(@PathVariable("id") Integer id) { * @return 200 if valid */ @PostMapping("/connections/test") - public @ResponseBody + @ResponseBody + public ResponseEntity testConnection(@NotNull @RequestBody DatabaseConnection connection) { service.testDriver(connection); service.testConnection(connection); diff --git a/common/src/main/java/org/sitmun/administration/controller/FeatureTypeExtractorController.java b/common/src/main/java/org/sitmun/administration/controller/FeatureTypeExtractorController.java index 7413d977..88a3e2fd 100644 --- a/common/src/main/java/org/sitmun/administration/controller/FeatureTypeExtractorController.java +++ b/common/src/main/java/org/sitmun/administration/controller/FeatureTypeExtractorController.java @@ -30,7 +30,8 @@ public FeatureTypeExtractorController(@NonNull List extrac * @return 200 if a document is found; client should check this document or 400 if a document cannot be retrieved or the method is not found */ @GetMapping("/helpers/feature-type") - public @ResponseBody ResponseEntity extractCapabilities(@RequestParam("url") String url) { + @ResponseBody + public ResponseEntity extractCapabilities(@RequestParam("url") String url) { Iterator iterator = extractors.iterator(); ExtractedMetadata featureType = ExtractedMetadata.builder().success(false).reason("No available extractor").build(); while (iterator.hasNext()) { diff --git a/common/src/main/java/org/sitmun/administration/controller/ServiceCapabilitiesExtractorController.java b/common/src/main/java/org/sitmun/administration/controller/ServiceCapabilitiesExtractorController.java index 968d1022..72fc3866 100644 --- a/common/src/main/java/org/sitmun/administration/controller/ServiceCapabilitiesExtractorController.java +++ b/common/src/main/java/org/sitmun/administration/controller/ServiceCapabilitiesExtractorController.java @@ -30,7 +30,8 @@ public ServiceCapabilitiesExtractorController(@NonNull List extractCapabilities(@RequestParam("url") String url) { Iterator iterator = extractors.iterator(); ExtractedMetadata capabilities = ExtractedMetadata.builder().success(false).reason("No available extractor").build(); diff --git a/common/src/main/java/org/sitmun/administration/service/dashboard/DashboardInfoContributor.java b/common/src/main/java/org/sitmun/administration/service/dashboard/DashboardInfoContributor.java index a0b5af86..685fe85a 100644 --- a/common/src/main/java/org/sitmun/administration/service/dashboard/DashboardInfoContributor.java +++ b/common/src/main/java/org/sitmun/administration/service/dashboard/DashboardInfoContributor.java @@ -1,18 +1,15 @@ package org.sitmun.administration.service.dashboard; -import com.google.common.collect.Maps; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.search.Search; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.stereotype.Component; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import static java.util.stream.Collectors.groupingBy; @@ -45,7 +42,7 @@ private Map collectMetrics() { private Map hierarchiseMetrics(Map map) { return map.entrySet().stream() - .map(entry -> Maps.immutableEntry(entry.getKey().split("\\."), entry.getValue())) + .map(entry -> Pair.of(entry.getKey().split("\\."), entry.getValue())) .collect(groupingBy(entry -> entry.getKey()[0])) .entrySet().stream() .map(this::processEntry) @@ -53,18 +50,20 @@ private Map hierarchiseMetrics(Map map) { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private Map.Entry processEntry(Map.Entry>> entry) { + private Map.Entry processEntry(Map.Entry>> entry) { Object newValue = toValue(entry.getValue().stream() - .map(value -> Maps.immutableEntry( + .map(value -> Pair.of( Arrays.stream(value.getKey()).skip(1).toArray(String[]::new), value.getValue()) ).collect(toList())); if (newValue != null) { - return Maps.immutableEntry(entry.getKey(), newValue); - } else return null; + return new AbstractMap.SimpleEntry<>(entry.getKey(), newValue); + } else { + return null; + } } - private Object toValue(List> list) { + private Object toValue(List> list) { if (list.isEmpty()) { return null; } else if (list.size() == 1 && list.get(0).getKey().length == 0) { @@ -80,15 +79,15 @@ private Object toValue(List> list) { } } - private Map.Entry processMetric(Meter meter) { + private Pair processMetric(Meter meter) { if (meter instanceof Gauge) { Gauge gauge = (Gauge) meter; String id = gauge.getId().getName().substring(DashboardConfig.METRICS_PREFIX.length()); String suffix = gauge.getId().getTag(TAG); if (suffix != null) { - id = id + "." + suffix; + id = id + '.' + suffix; } - return Maps.immutableEntry(id, gauge.value()); + return Pair.of(id, gauge.value()); } else { return null; } diff --git a/common/src/main/java/org/sitmun/administration/service/database/tester/DatabaseConnectionTesterService.java b/common/src/main/java/org/sitmun/administration/service/database/tester/DatabaseConnectionTesterService.java index 50617446..901607bd 100644 --- a/common/src/main/java/org/sitmun/administration/service/database/tester/DatabaseConnectionTesterService.java +++ b/common/src/main/java/org/sitmun/administration/service/database/tester/DatabaseConnectionTesterService.java @@ -2,8 +2,6 @@ import lombok.extern.slf4j.Slf4j; import org.sitmun.domain.database.DatabaseConnection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.validation.constraints.NotNull; diff --git a/common/src/main/java/org/sitmun/administration/service/extractor/featuretype/SimpleFeatureTypeExtractor.java b/common/src/main/java/org/sitmun/administration/service/extractor/featuretype/SimpleFeatureTypeExtractor.java index 6928d3a7..82c1e171 100644 --- a/common/src/main/java/org/sitmun/administration/service/extractor/featuretype/SimpleFeatureTypeExtractor.java +++ b/common/src/main/java/org/sitmun/administration/service/extractor/featuretype/SimpleFeatureTypeExtractor.java @@ -48,7 +48,7 @@ public ExtractedMetadata extract(String url) { if (root.isPresent()) { JSONObject schema = json.getJSONObject(root.get()); String[] qname = root.get().split(":"); - String xmlnsKey = "xmlns" + (qname.length == 2 ? ":" + qname[0] : ""); + String xmlnsKey = "xmlns" + (qname.length == 2 ? ':' + qname[0] : ""); boolean isXSD = "http://www.w3.org/2001/XMLSchema".equals(schema.optString(xmlnsKey)); if (!isXSD) { builder.success(false).reason("Not a XML Schema"); diff --git a/common/src/main/java/org/sitmun/authentication/dto/UserPasswordAuthenticationRequest.java b/common/src/main/java/org/sitmun/authentication/dto/UserPasswordAuthenticationRequest.java index 89d232ae..be3e72f3 100644 --- a/common/src/main/java/org/sitmun/authentication/dto/UserPasswordAuthenticationRequest.java +++ b/common/src/main/java/org/sitmun/authentication/dto/UserPasswordAuthenticationRequest.java @@ -1,6 +1,8 @@ package org.sitmun.authentication.dto; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -8,6 +10,8 @@ /** * DTO object for storing a user's credentials. */ +@Setter +@Getter public class UserPasswordAuthenticationRequest { @Schema(description = "User identifier. It cannot be empty", example = "some_user") @@ -19,24 +23,8 @@ public class UserPasswordAuthenticationRequest { @NotNull private String password; - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - @Override public String toString() { - return "LoginDTO{username='" + username + "}"; + return "LoginDTO{username='" + username + '}'; } } diff --git a/common/src/main/java/org/sitmun/authorization/controller/WorkspaceConfigurationController.java b/common/src/main/java/org/sitmun/authorization/controller/WorkspaceConfigurationController.java deleted file mode 100644 index ead6dd04..00000000 --- a/common/src/main/java/org/sitmun/authorization/controller/WorkspaceConfigurationController.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.sitmun.authorization.controller; - -import com.fasterxml.jackson.annotation.JsonView; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.sitmun.authorization.dto.ClientConfiguration; -import org.sitmun.authorization.dto.ClientConfigurationForApplicationTerritory; -import org.sitmun.authorization.dto.ClientConfigurationViews; -import org.sitmun.authorization.service.ClientConfigurationService; -import org.springframework.http.ResponseEntity; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.*; - -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -/** - * @deprecated Use {@link org.sitmun.authorization.controller.ClientConfigurationController} instead. - */ -@RestController -@RequestMapping("/api/workspace") -@Tag(name = "workspace", description = "workspace") -@Deprecated(forRemoval = true) -public class WorkspaceConfigurationController { - - private final ClientConfigurationService clientConfigurationService; - - /** - * Constructor. - */ - public WorkspaceConfigurationController( - ClientConfigurationService clientConfigurationService) { - this.clientConfigurationService = clientConfigurationService; - } - - /** - * @deprecated proof of concept - */ - @GetMapping(path = "/application/{applicationId}/territory/{territoryId}", produces = APPLICATION_JSON_VALUE) - @ResponseBody - @JsonView(ClientConfigurationViews.ApplicationTerritory.class) - @Deprecated(forRemoval = true) - public ResponseEntity getDescription( - @PathVariable("applicationId") Integer applicationId, - @PathVariable("territoryId") Integer territoryId) { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - return clientConfigurationService.describeFor(authentication.getName(), applicationId, territoryId) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - - /** - * @deprecated proof of concept - */ - @GetMapping(produces = APPLICATION_JSON_VALUE) - @ResponseBody - @JsonView(ClientConfigurationViews.Base.class) - @Deprecated(forRemoval = true) - public ResponseEntity getDescription() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - return clientConfigurationService.describeFor(authentication.getName()) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - -} diff --git a/common/src/main/java/org/sitmun/authorization/dto/ClientConfiguration.java b/common/src/main/java/org/sitmun/authorization/dto/ClientConfiguration.java deleted file mode 100644 index e5fc4f77..00000000 --- a/common/src/main/java/org/sitmun/authorization/dto/ClientConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sitmun.authorization.dto; - -import com.fasterxml.jackson.annotation.JsonView; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import org.sitmun.domain.configuration.ConfigurationParameter; -import org.sitmun.domain.territory.Territory; - -import java.util.List; - -@Getter -@Setter -@Builder -@JsonView(ClientConfigurationViews.Base.class) -public class ClientConfiguration { - - List territories; - - List config; - -} diff --git a/common/src/main/java/org/sitmun/authorization/dto/ClientConfigurationForApplicationTerritory.java b/common/src/main/java/org/sitmun/authorization/dto/ClientConfigurationForApplicationTerritory.java deleted file mode 100644 index 46bf0fd6..00000000 --- a/common/src/main/java/org/sitmun/authorization/dto/ClientConfigurationForApplicationTerritory.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.sitmun.authorization.dto; - -import com.fasterxml.jackson.annotation.JsonView; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import org.sitmun.domain.application.Application; -import org.sitmun.domain.configuration.ConfigurationParameter; -import org.sitmun.domain.role.Role; -import org.sitmun.domain.territory.Territory; - -import java.util.List; - -@Getter -@Setter -@Builder -@JsonView(ClientConfigurationViews.ApplicationTerritory.class) -public class ClientConfigurationForApplicationTerritory { - - Territory territory; - - Application application; - - List roles; - - List config; - -} diff --git a/common/src/main/java/org/sitmun/authorization/dto/decorators/QueryPaginationDecorator.java b/common/src/main/java/org/sitmun/authorization/dto/decorators/QueryPaginationDecorator.java index d615e2ed..feef9bc7 100644 --- a/common/src/main/java/org/sitmun/authorization/dto/decorators/QueryPaginationDecorator.java +++ b/common/src/main/java/org/sitmun/authorization/dto/decorators/QueryPaginationDecorator.java @@ -25,10 +25,10 @@ public void addBehavior(Map target, PayloadDto payload) { String sql = datasourcePayloadDto.getSql(); if (sql != null && !sql.isEmpty()) { if (target.containsKey(SQL_LIMIT)) { - sql = sql + " " + SQL_LIMIT + " " + target.get(SQL_LIMIT); + sql = sql + ' ' + SQL_LIMIT + ' ' + target.get(SQL_LIMIT); } if (target.containsKey(SQL_OFFSET)) { - sql = sql + " " + SQL_OFFSET + " " + target.get(SQL_OFFSET); + sql = sql + ' ' + SQL_OFFSET + ' ' + target.get(SQL_OFFSET); } datasourcePayloadDto.setSql(sql); } diff --git a/common/src/main/java/org/sitmun/authorization/service/ClientConfigurationService.java b/common/src/main/java/org/sitmun/authorization/service/ClientConfigurationService.java deleted file mode 100644 index 0b071a4c..00000000 --- a/common/src/main/java/org/sitmun/authorization/service/ClientConfigurationService.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.sitmun.authorization.service; - -import com.google.common.collect.Lists; -import org.sitmun.authorization.dto.ClientConfiguration; -import org.sitmun.authorization.dto.ClientConfigurationForApplicationTerritory; -import org.sitmun.domain.application.Application; -import org.sitmun.domain.cartography.Cartography; -import org.sitmun.domain.cartography.permission.CartographyPermission; -import org.sitmun.domain.configuration.ConfigurationParameterRepository; -import org.sitmun.domain.role.Role; -import org.sitmun.domain.task.Task; -import org.sitmun.domain.territory.Territory; -import org.sitmun.domain.tree.Tree; -import org.sitmun.domain.tree.node.TreeNode; -import org.sitmun.domain.user.User; -import org.sitmun.domain.user.UserRepository; -import org.sitmun.domain.user.configuration.UserConfiguration; -import org.sitmun.domain.user.configuration.UserConfigurationRepository; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Service -public class ClientConfigurationService { - - private final UserRepository userRepository; - - private final UserConfigurationRepository userConfigurationRepository; - - private final ConfigurationParameterRepository configurationParameterRepository; - - /** - * Constructor. - */ - public ClientConfigurationService( - UserRepository userRepository, - UserConfigurationRepository userConfigurationRepository, - ConfigurationParameterRepository configurationParameterRepository) { - this.userRepository = userRepository; - this.userConfigurationRepository = userConfigurationRepository; - this.configurationParameterRepository = configurationParameterRepository; - } - - /** - * @deprecated proof of concept - */ - @Deprecated(forRemoval = true) - public Optional describeFor(String username, Integer applicationId, Integer territoryId) { - Optional user = userRepository.findByUsername(username); - if (user.isPresent()) { - User effectiveUser = user.get(); - if (Boolean.FALSE.equals(effectiveUser.getBlocked())) { - List territories = territoriesList(effectiveUser, applicationId, territoryId); - if (!territories.isEmpty()) { - Territory territory = territories.get(0); - Optional application = territory.getUserConfigurations().stream() - .flatMap(uc -> uc.getRole().getApplications().stream()) - .filter(app -> Objects.equals(app.getId(), applicationId)) - .findFirst(); - List roles = territory.getUserConfigurations().stream() - .map(UserConfiguration::getRole) - .map(role -> { - Set tasks = role.getTasks().stream().filter(task -> - task.getAvailabilities().stream() - .anyMatch(avail -> Objects.equals(avail.getTerritory().getId(), territory.getId()))) - .collect(Collectors.toSet()); - Set permissions = role.getPermissions().stream().map(cp -> { - Set cartographies = cp.getMembers().stream().filter(cartography -> - !cartography.getBlocked() && - cartography.getAvailabilities().stream() - .anyMatch(avail -> Objects.equals(avail.getTerritory().getId(), territory.getId())) - ).collect(Collectors.toSet()); - return cp.toBuilder().members(cartographies).build(); - } - ).filter(cp -> !cp.getMembers().isEmpty()) - .collect(Collectors.toSet()); - Set trees = role.getTrees().stream().map(tree -> { - Set nodes = tree.getAllNodes().stream().filter(node -> - node.getCartographyId() == null - || (!node.getCartography().getBlocked() && - node.getCartography().getAvailabilities().stream() - .anyMatch(avail -> Objects.equals(avail.getTerritory().getId(), territory.getId())) && - permissions.stream().anyMatch(permission -> permission.getMembers().contains(node.getCartography())) - ) - ).collect(Collectors.toSet()); - return tree.toBuilder().allNodes(nodes).build(); - }).collect(Collectors.toSet()); - return role.toBuilder() - .tasks(tasks) - .permissions(permissions) - .trees(trees).build(); - }) - .collect(Collectors.toList()); - if (application.isPresent()) { - return Optional.of(ClientConfigurationForApplicationTerritory.builder() - .territory(territories.get(0)) - .application(application.get()) - .roles(roles) - .config(Lists.newArrayList(configurationParameterRepository.findAll())) - .build()); - } - } - } - } - return Optional.empty(); - } - - private Stream territoriesStream(User user) { - return userConfigurationRepository.findByUser(user).stream() - .map(UserConfiguration::getTerritory) - .filter(territory -> !territory.getBlocked()) - .distinct(); - } - - private List territoriesList(User user, Integer applicationId, Integer territoryId) { - return territoriesStream(user) - .map(territory -> { - Set filtered = territory.getUserConfigurations() - .stream() - .filter(uc -> Objects.equals(uc.getUser(), user) && - Objects.equals(uc.getTerritory().getId(), territoryId) && - uc.getRole().getApplications().stream().anyMatch(app -> Objects.equals(app.getId(), applicationId)) - ) - .collect(Collectors.toSet()); - if (filtered.isEmpty()) { - return null; - } - return territory.toBuilder().userConfigurations(filtered).build(); - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - - /** - * @deprecated proof of concept - */ - @Deprecated(forRemoval = true) - public Optional describeFor(String username) { - Optional user = userRepository.findByUsername(username); - if (user.isPresent()) { - User effectiveUser = user.get(); - if (Boolean.FALSE.equals(effectiveUser.getBlocked())) { - return Optional.of(ClientConfiguration.builder() - .territories(territoriesList(effectiveUser)) - .config(Lists.newArrayList(configurationParameterRepository.findAll())) - .build()); - } - } - return Optional.empty(); - } - - private List territoriesList(User user) { - return userConfigurationRepository.findByUser(user).stream() - .map(UserConfiguration::getTerritory) - .filter(territory -> !territory.getBlocked()) - .distinct() - .map(territory -> { - Set filtered = territory.getUserConfigurations() - .stream() - .filter(uc -> Objects.equals(uc.getUser(), user)) - .collect(Collectors.toSet()); - return territory.toBuilder().userConfigurations(filtered).build(); - }) - .collect(Collectors.toList()); - } -} diff --git a/common/src/main/java/org/sitmun/authorization/service/ProxyConfigurationService.java b/common/src/main/java/org/sitmun/authorization/service/ProxyConfigurationService.java index 87ac2718..ea92d564 100644 --- a/common/src/main/java/org/sitmun/authorization/service/ProxyConfigurationService.java +++ b/common/src/main/java/org/sitmun/authorization/service/ProxyConfigurationService.java @@ -122,7 +122,7 @@ public boolean validateUserAccess(ConfigProxyRequest configProxyRequest, String return true; } - private DatasourcePayloadDto getDatasourceConfiguration(Task task) { + private static DatasourcePayloadDto getDatasourceConfiguration(Task task) { DatabaseConnection databaseConnection = task.getConnection(); String sql = getSqlByTask(task); return databaseConnection != null ? DatasourcePayloadDto.builder() diff --git a/common/src/main/java/org/sitmun/domain/CodeListsConstants.java b/common/src/main/java/org/sitmun/domain/CodeListsConstants.java index b0dd526b..d1ff8cf6 100644 --- a/common/src/main/java/org/sitmun/domain/CodeListsConstants.java +++ b/common/src/main/java/org/sitmun/domain/CodeListsConstants.java @@ -1,6 +1,6 @@ package org.sitmun.domain; -public class CodeListsConstants { +final public class CodeListsConstants { public static final String APPLICATION_TYPE = "application.type"; public static final String APPLICATION_PARAMETER_TYPE = "applicationParameter.type"; diff --git a/common/src/main/java/org/sitmun/domain/PersistenceConstants.java b/common/src/main/java/org/sitmun/domain/PersistenceConstants.java index cea0c917..d51644b7 100644 --- a/common/src/main/java/org/sitmun/domain/PersistenceConstants.java +++ b/common/src/main/java/org/sitmun/domain/PersistenceConstants.java @@ -3,7 +3,7 @@ /** * Constants and definitions. */ -public class PersistenceConstants { +final public class PersistenceConstants { /** * Identifier for BCP 47 Language Tag diff --git a/common/src/main/java/org/sitmun/domain/application/Application.java b/common/src/main/java/org/sitmun/domain/application/Application.java index ff804d7d..8b26123d 100755 --- a/common/src/main/java/org/sitmun/domain/application/Application.java +++ b/common/src/main/java/org/sitmun/domain/application/Application.java @@ -21,10 +21,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * A SITMUN application. @@ -184,16 +181,18 @@ public class Application { private Set territories = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Application)) - return false; + if (!(obj instanceof Application)) { + return false; + } - Application other = (Application) o; + Application other = (Application) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/ApplicationProjection.java b/common/src/main/java/org/sitmun/domain/application/ApplicationProjection.java index fa5b9c9b..0c53b92d 100644 --- a/common/src/main/java/org/sitmun/domain/application/ApplicationProjection.java +++ b/common/src/main/java/org/sitmun/domain/application/ApplicationProjection.java @@ -9,7 +9,7 @@ /** * Projections for REST views of an application. */ -@Projection(name = "view", types = {Application.class}) +@Projection(name = "view", types = Application.class) public interface ApplicationProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/application/BeforeCreateApplicationValidator.java b/common/src/main/java/org/sitmun/domain/application/BeforeCreateApplicationValidator.java index 80ed722d..3b2ae159 100644 --- a/common/src/main/java/org/sitmun/domain/application/BeforeCreateApplicationValidator.java +++ b/common/src/main/java/org/sitmun/domain/application/BeforeCreateApplicationValidator.java @@ -11,8 +11,8 @@ @Component public class BeforeCreateApplicationValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return Application.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return Application.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/BeforeLinkSaveApplicationValidator.java b/common/src/main/java/org/sitmun/domain/application/BeforeLinkSaveApplicationValidator.java index 0cc015d0..8d8eef8d 100644 --- a/common/src/main/java/org/sitmun/domain/application/BeforeLinkSaveApplicationValidator.java +++ b/common/src/main/java/org/sitmun/domain/application/BeforeLinkSaveApplicationValidator.java @@ -11,8 +11,8 @@ @Component public class BeforeLinkSaveApplicationValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return Application.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return Application.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackground.java b/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackground.java index a1e1ae7a..45939623 100755 --- a/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackground.java +++ b/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackground.java @@ -11,13 +11,13 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Relationship between applications and backgrounds. */ @Entity -@Table(name = "STM_APP_BCKG", uniqueConstraints = { - @UniqueConstraint(name = "STM_APF_UK", columnNames = {"ABC_APPID", "ABC_BACKID"})}) +@Table(name = "STM_APP_BCKG", uniqueConstraints = @UniqueConstraint(name = "STM_APF_UK", columnNames = {"ABC_APPID", "ABC_BACKID"})) @Builder @Getter @Setter @@ -68,16 +68,18 @@ public class ApplicationBackground { private Integer order; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof ApplicationBackground)) - return false; + if (!(obj instanceof ApplicationBackground)) { + return false; + } - ApplicationBackground other = (ApplicationBackground) o; + ApplicationBackground other = (ApplicationBackground) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackgroundProjection.java b/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackgroundProjection.java index 8cceb315..c5e7e51a 100644 --- a/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackgroundProjection.java +++ b/common/src/main/java/org/sitmun/domain/application/background/ApplicationBackgroundProjection.java @@ -6,7 +6,7 @@ /** * Projections for REST views of an application background. */ -@Projection(name = "view", types = {ApplicationBackground.class}) +@Projection(name = "view", types = ApplicationBackground.class) public interface ApplicationBackgroundProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameter.java b/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameter.java index b4a02cc0..805ebd5e 100755 --- a/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameter.java +++ b/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameter.java @@ -12,6 +12,8 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; + import static org.sitmun.domain.PersistenceConstants.IDENTIFIER; import static org.sitmun.domain.PersistenceConstants.VALUE; @@ -74,16 +76,18 @@ public class ApplicationParameter { private Application application; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof ApplicationParameter)) - return false; + if (!(obj instanceof ApplicationParameter)) { + return false; + } - ApplicationParameter other = (ApplicationParameter) o; + ApplicationParameter other = (ApplicationParameter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameterRepository.java b/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameterRepository.java index d4acbbb9..447c447a 100644 --- a/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameterRepository.java +++ b/common/src/main/java/org/sitmun/domain/application/parameter/ApplicationParameterRepository.java @@ -14,6 +14,6 @@ public interface ApplicationParameterRepository extends PagingAndSortingRepository, QuerydslPredicateExecutor, QuerydslBinderCustomizer { - default void customize(@NonNull QuerydslBindings bindings, @NonNull QApplicationParameter root) { + default void customize(@NonNull QuerydslBindings querydslBindings, @NonNull QApplicationParameter root) { } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritory.java b/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritory.java index 74cde5af..c591fcd5 100755 --- a/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritory.java +++ b/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritory.java @@ -14,13 +14,13 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Relationship between applications and territories. */ @Entity -@Table(name = "STM_APP_TER", uniqueConstraints = { - @UniqueConstraint(name = "STM_APT_UK", columnNames = {"ATE_APPID", "ATE_TERID"})}) +@Table(name = "STM_APP_TER", uniqueConstraints = @UniqueConstraint(name = "STM_APT_UK", columnNames = {"ATE_APPID", "ATE_TERID"})) @Builder @Getter @Setter @@ -74,16 +74,18 @@ public class ApplicationTerritory { @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof ApplicationTerritory)) - return false; + if (!(obj instanceof ApplicationTerritory)) { + return false; + } - ApplicationTerritory other = (ApplicationTerritory) o; + ApplicationTerritory other = (ApplicationTerritory) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritoryRepository.java b/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritoryRepository.java index 51e346df..db940a69 100644 --- a/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritoryRepository.java +++ b/common/src/main/java/org/sitmun/domain/application/territory/ApplicationTerritoryRepository.java @@ -14,6 +14,6 @@ public interface ApplicationTerritoryRepository extends PagingAndSortingRepository, QuerydslPredicateExecutor, QuerydslBinderCustomizer { - default void customize(@NonNull QuerydslBindings bindings, @NonNull QApplicationTerritory root) { + default void customize(@NonNull QuerydslBindings querydslBindings, @NonNull QApplicationTerritory root) { } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/domain/background/Background.java b/common/src/main/java/org/sitmun/domain/background/Background.java index ace648be..f90abb61 100644 --- a/common/src/main/java/org/sitmun/domain/background/Background.java +++ b/common/src/main/java/org/sitmun/domain/background/Background.java @@ -15,6 +15,7 @@ import javax.validation.constraints.NotBlank; import java.util.Date; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -97,16 +98,18 @@ public class Background { private Set applications = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Background)) - return false; + if (!(obj instanceof Background)) { + return false; + } - Background other = (Background) o; + Background other = (Background) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/background/BackgroundProjection.java b/common/src/main/java/org/sitmun/domain/background/BackgroundProjection.java index 4364ba85..be9e86a5 100644 --- a/common/src/main/java/org/sitmun/domain/background/BackgroundProjection.java +++ b/common/src/main/java/org/sitmun/domain/background/BackgroundProjection.java @@ -10,7 +10,7 @@ /** * Projections for REST views of a background. */ -@Projection(name = "view", types = {Background.class}) +@Projection(name = "view", types = Background.class) public interface BackgroundProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/background/BeforeCreateBackgroundValidator.java b/common/src/main/java/org/sitmun/domain/background/BeforeCreateBackgroundValidator.java index 959daac4..cd317257 100644 --- a/common/src/main/java/org/sitmun/domain/background/BeforeCreateBackgroundValidator.java +++ b/common/src/main/java/org/sitmun/domain/background/BeforeCreateBackgroundValidator.java @@ -11,8 +11,8 @@ @Component public class BeforeCreateBackgroundValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return Background.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return Background.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/background/BeforeLinkSaveBackgroundValidator.java b/common/src/main/java/org/sitmun/domain/background/BeforeLinkSaveBackgroundValidator.java index ada85bce..b04532b7 100644 --- a/common/src/main/java/org/sitmun/domain/background/BeforeLinkSaveBackgroundValidator.java +++ b/common/src/main/java/org/sitmun/domain/background/BeforeLinkSaveBackgroundValidator.java @@ -11,8 +11,8 @@ @Component public class BeforeLinkSaveBackgroundValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return Background.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return Background.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/BeforeLinkSaveCartographyValidator.java b/common/src/main/java/org/sitmun/domain/cartography/BeforeLinkSaveCartographyValidator.java index 05e9ee2c..5449051a 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/BeforeLinkSaveCartographyValidator.java +++ b/common/src/main/java/org/sitmun/domain/cartography/BeforeLinkSaveCartographyValidator.java @@ -8,8 +8,8 @@ @Component public class BeforeLinkSaveCartographyValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return Cartography.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return Cartography.class.equals(aClass); } @Override @@ -17,7 +17,7 @@ public void validate(@NonNull Object target, @NonNull Errors errors) { Cartography cartography = (Cartography) target; if (cartography.getStyles() != null && cartography.getStyles().stream() - .map(c -> Boolean.TRUE.equals(c.getDefaultStyle()) ? 1 : 0) + .map(style -> Boolean.TRUE.equals(style.getDefaultStyle()) ? 1 : 0) .reduce(0, Integer::sum) > 1) { errors.rejectValue("styles", "cartography.styles.invalid", "Multiple default styles for this cartography."); } diff --git a/common/src/main/java/org/sitmun/domain/cartography/Cartography.java b/common/src/main/java/org/sitmun/domain/cartography/Cartography.java index 01589129..0095dba5 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/Cartography.java +++ b/common/src/main/java/org/sitmun/domain/cartography/Cartography.java @@ -26,10 +26,7 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import static org.sitmun.domain.PersistenceConstants.*; @@ -357,16 +354,18 @@ public class Cartography { private Set permissions = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Cartography)) - return false; + if (!(obj instanceof Cartography)) { + return false; + } - Cartography other = (Cartography) o; + Cartography other = (Cartography) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/CartographyProjection.java b/common/src/main/java/org/sitmun/domain/cartography/CartographyProjection.java index e4574a51..fcd1367f 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/CartographyProjection.java +++ b/common/src/main/java/org/sitmun/domain/cartography/CartographyProjection.java @@ -9,7 +9,7 @@ /** * Projections for REST views of a cartography. */ -@Projection(name = "view", types = {Cartography.class}) +@Projection(name = "view", types = Cartography.class) public interface CartographyProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailability.java b/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailability.java index a9c0a195..b8fc2d16 100755 --- a/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailability.java +++ b/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailability.java @@ -12,14 +12,14 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.Objects; /** * Grants availability of a Geographic Information in a Territory. */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_AVAIL_GI", uniqueConstraints = { - @UniqueConstraint(name = "STM_DCA_UK", columnNames = {"AGI_TERID", "AGI_GIID"})}) +@Table(name = "STM_AVAIL_GI", uniqueConstraints = @UniqueConstraint(name = "STM_DCA_UK", columnNames = {"AGI_TERID", "AGI_GIID"})) @Builder @Getter @Setter @@ -76,16 +76,18 @@ public class CartographyAvailability { private Cartography cartography; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographyAvailability)) - return false; + if (!(obj instanceof CartographyAvailability)) { + return false; + } - CartographyAvailability other = (CartographyAvailability) o; + CartographyAvailability other = (CartographyAvailability) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailabilityProjection.java b/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailabilityProjection.java index 2fbd6ade..2cd0f854 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailabilityProjection.java +++ b/common/src/main/java/org/sitmun/domain/cartography/availability/CartographyAvailabilityProjection.java @@ -9,7 +9,7 @@ /** * Projections for REST views of an application. */ -@Projection(name = "view", types = {CartographyAvailability.class}) +@Projection(name = "view", types = CartographyAvailability.class) public interface CartographyAvailabilityProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilter.java b/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilter.java index e50edf25..5df122a2 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilter.java +++ b/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilter.java @@ -15,6 +15,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.List; +import java.util.Objects; /** * Geographic Information filter. @@ -102,16 +103,18 @@ public class CartographyFilter { private Cartography cartography; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographyFilter)) - return false; + if (!(obj instanceof CartographyFilter)) { + return false; + } - CartographyFilter other = (CartographyFilter) o; + CartographyFilter other = (CartographyFilter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilterProjection.java b/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilterProjection.java index b10cca60..bba2b90c 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilterProjection.java +++ b/common/src/main/java/org/sitmun/domain/cartography/filter/CartographyFilterProjection.java @@ -8,7 +8,7 @@ /** * Projections for REST views of an application. */ -@Projection(name = "view", types = {CartographyFilter.class}) +@Projection(name = "view", types = CartographyFilter.class) public interface CartographyFilterProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographyParameter.java b/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographyParameter.java index fcc8106d..a0bea038 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographyParameter.java +++ b/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographyParameter.java @@ -12,6 +12,7 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Geographic Information parameter. @@ -86,16 +87,18 @@ public class CartographyParameter { private Integer order; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographyParameter)) - return false; + if (!(obj instanceof CartographyParameter)) { + return false; + } - CartographyParameter other = (CartographyParameter) o; + CartographyParameter other = (CartographyParameter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographySpatialSelectionParameter.java b/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographySpatialSelectionParameter.java index 25db5436..fbe8a01b 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographySpatialSelectionParameter.java +++ b/common/src/main/java/org/sitmun/domain/cartography/parameter/CartographySpatialSelectionParameter.java @@ -13,6 +13,8 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; + import static org.sitmun.domain.PersistenceConstants.IDENTIFIER; import static org.sitmun.domain.PersistenceConstants.VALUE; @@ -92,16 +94,18 @@ public class CartographySpatialSelectionParameter { private Integer order; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographySpatialSelectionParameter)) - return false; + if (!(obj instanceof CartographySpatialSelectionParameter)) { + return false; + } - CartographySpatialSelectionParameter other = (CartographySpatialSelectionParameter) o; + CartographySpatialSelectionParameter other = (CartographySpatialSelectionParameter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/permission/BeforeSaveCartographyPermissionValidator.java b/common/src/main/java/org/sitmun/domain/cartography/permission/BeforeSaveCartographyPermissionValidator.java index 9e7f1c72..46345fce 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/permission/BeforeSaveCartographyPermissionValidator.java +++ b/common/src/main/java/org/sitmun/domain/cartography/permission/BeforeSaveCartographyPermissionValidator.java @@ -8,8 +8,8 @@ @Component public class BeforeSaveCartographyPermissionValidator implements Validator { @Override - public boolean supports(@NonNull Class clazz) { - return CartographyPermission.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return CartographyPermission.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermission.java b/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermission.java index 4b569dbb..32e1d030 100755 --- a/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermission.java +++ b/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermission.java @@ -16,6 +16,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -114,16 +115,18 @@ public void postLoad() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographyPermission)) - return false; + if (!(obj instanceof CartographyPermission)) { + return false; + } - CartographyPermission other = (CartographyPermission) o; + CartographyPermission other = (CartographyPermission) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermissionProjection.java b/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermissionProjection.java index 43a8e63b..071fd710 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermissionProjection.java +++ b/common/src/main/java/org/sitmun/domain/cartography/permission/CartographyPermissionProjection.java @@ -8,7 +8,7 @@ /** * Projections for REST views of an application. */ -@Projection(name = "view", types = {CartographyPermission.class}) +@Projection(name = "view", types = CartographyPermission.class) public interface CartographyPermissionProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/cartography/style/BeforeCreateCartographyStylesValidator.java b/common/src/main/java/org/sitmun/domain/cartography/style/BeforeCreateCartographyStylesValidator.java index 7ab3f302..95e3bbb2 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/style/BeforeCreateCartographyStylesValidator.java +++ b/common/src/main/java/org/sitmun/domain/cartography/style/BeforeCreateCartographyStylesValidator.java @@ -15,8 +15,8 @@ public BeforeCreateCartographyStylesValidator(CartographyStyleRepository reposit } @Override - public boolean supports(@NonNull Class clazz) { - return CartographyStyle.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return CartographyStyle.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/style/BeforeSaveCartographyStylesValidator.java b/common/src/main/java/org/sitmun/domain/cartography/style/BeforeSaveCartographyStylesValidator.java index 92c2be89..ae37373c 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/style/BeforeSaveCartographyStylesValidator.java +++ b/common/src/main/java/org/sitmun/domain/cartography/style/BeforeSaveCartographyStylesValidator.java @@ -15,8 +15,8 @@ public BeforeSaveCartographyStylesValidator(CartographyStyleRepository repositor } @Override - public boolean supports(@NonNull Class clazz) { - return CartographyStyle.class.equals(clazz); + public boolean supports(@NonNull Class aClass) { + return CartographyStyle.class.equals(aClass); } @Override diff --git a/common/src/main/java/org/sitmun/domain/cartography/style/CartographyStyle.java b/common/src/main/java/org/sitmun/domain/cartography/style/CartographyStyle.java index a972fb33..90e90ddd 100644 --- a/common/src/main/java/org/sitmun/domain/cartography/style/CartographyStyle.java +++ b/common/src/main/java/org/sitmun/domain/cartography/style/CartographyStyle.java @@ -9,6 +9,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Geographic Information style. @@ -85,16 +86,18 @@ public class CartographyStyle { private Cartography cartography; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CartographyStyle)) - return false; + if (!(obj instanceof CartographyStyle)) { + return false; + } - CartographyStyle other = (CartographyStyle) o; + CartographyStyle other = (CartographyStyle) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/comment/Comment.java b/common/src/main/java/org/sitmun/domain/comment/Comment.java index 751b5a54..5d1f8dc6 100644 --- a/common/src/main/java/org/sitmun/domain/comment/Comment.java +++ b/common/src/main/java/org/sitmun/domain/comment/Comment.java @@ -12,6 +12,7 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.Objects; /** * Comment or user's suggestion. @@ -107,16 +108,18 @@ public class Comment { private Application application; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Comment)) - return false; + if (!(obj instanceof Comment)) { + return false; + } - Comment other = (Comment) o; + Comment other = (Comment) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/configuration/ConfigurationParameter.java b/common/src/main/java/org/sitmun/domain/configuration/ConfigurationParameter.java index c48ca91b..9095ed8b 100644 --- a/common/src/main/java/org/sitmun/domain/configuration/ConfigurationParameter.java +++ b/common/src/main/java/org/sitmun/domain/configuration/ConfigurationParameter.java @@ -8,13 +8,14 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Objects; /** * Configuration parameter. */ @Entity @Table(name = "STM_CONF", - uniqueConstraints = @UniqueConstraint(name = "STM_CONF_NAME_UK", columnNames = {"CNF_NAME"})) + uniqueConstraints = @UniqueConstraint(name = "STM_CONF_NAME_UK", columnNames = "CNF_NAME")) @Builder @Getter @Setter @@ -53,16 +54,18 @@ public class ConfigurationParameter { private String value; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof ApplicationParameter)) - return false; + if (!(obj instanceof ApplicationParameter)) { + return false; + } - ApplicationParameter other = (ApplicationParameter) o; + ApplicationParameter other = (ApplicationParameter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/database/DatabaseConnection.java b/common/src/main/java/org/sitmun/domain/database/DatabaseConnection.java index 75910885..c5c97ee9 100755 --- a/common/src/main/java/org/sitmun/domain/database/DatabaseConnection.java +++ b/common/src/main/java/org/sitmun/domain/database/DatabaseConnection.java @@ -13,6 +13,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -109,16 +110,18 @@ public void postLoad() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof DatabaseConnection)) - return false; + if (!(obj instanceof DatabaseConnection)) { + return false; + } - DatabaseConnection other = (DatabaseConnection) o; + DatabaseConnection other = (DatabaseConnection) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/log/Log.java b/common/src/main/java/org/sitmun/domain/log/Log.java index 6767ed81..0c36ec4b 100755 --- a/common/src/main/java/org/sitmun/domain/log/Log.java +++ b/common/src/main/java/org/sitmun/domain/log/Log.java @@ -15,6 +15,7 @@ import javax.validation.constraints.Email; import java.util.Date; import java.util.List; +import java.util.Objects; /** * Log. @@ -150,16 +151,18 @@ public class Log { private String other; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Log)) - return false; + if (!(obj instanceof Log)) { + return false; + } - Log otherLog = (Log) o; + Log otherLog = (Log) obj; - return id != null && - id.equals(otherLog.getId()); + return Objects.equals(id, otherLog.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/role/Role.java b/common/src/main/java/org/sitmun/domain/role/Role.java index e31898a3..7d9a8963 100755 --- a/common/src/main/java/org/sitmun/domain/role/Role.java +++ b/common/src/main/java/org/sitmun/domain/role/Role.java @@ -14,14 +14,14 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** * Role. */ @Entity -@Table(name = "STM_ROLE", uniqueConstraints = { - @UniqueConstraint(name = "STM_ROL_NOM_UK", columnNames = {"ROL_NAME"})}) +@Table(name = "STM_ROLE", uniqueConstraints = @UniqueConstraint(name = "STM_ROL_NOM_UK", columnNames = "ROL_NAME")) @Builder(toBuilder = true) @Getter @Setter @@ -129,16 +129,18 @@ public class Role { private Set userConfigurations = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Role)) - return false; + if (!(obj instanceof Role)) { + return false; + } - Role other = (Role) o; + Role other = (Role) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/service/Service.java b/common/src/main/java/org/sitmun/domain/service/Service.java index 2aa827c4..d8eeec17 100755 --- a/common/src/main/java/org/sitmun/domain/service/Service.java +++ b/common/src/main/java/org/sitmun/domain/service/Service.java @@ -20,10 +20,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * Service. @@ -190,16 +187,18 @@ public void postLoad() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Service)) - return false; + if (!(obj instanceof Service)) { + return false; + } - Service other = (Service) o; + Service other = (Service) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/service/parameter/ServiceParameter.java b/common/src/main/java/org/sitmun/domain/service/parameter/ServiceParameter.java index 87946833..aaa96990 100755 --- a/common/src/main/java/org/sitmun/domain/service/parameter/ServiceParameter.java +++ b/common/src/main/java/org/sitmun/domain/service/parameter/ServiceParameter.java @@ -14,6 +14,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Service parameter. @@ -77,16 +78,18 @@ public class ServiceParameter { private Service service; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof ServiceParameter)) - return false; + if (!(obj instanceof ServiceParameter)) { + return false; + } - ServiceParameter other = (ServiceParameter) o; + ServiceParameter other = (ServiceParameter) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/task/Task.java b/common/src/main/java/org/sitmun/domain/task/Task.java index 61edc006..e1fc7997 100755 --- a/common/src/main/java/org/sitmun/domain/task/Task.java +++ b/common/src/main/java/org/sitmun/domain/task/Task.java @@ -19,10 +19,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; -import java.util.Date; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Task. @@ -170,16 +167,18 @@ public class Task { private Set relatedBy = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Task)) - return false; + if (!(obj instanceof Task)) { + return false; + } - Task other = (Task) o; + Task other = (Task) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/task/TaskProjection.java b/common/src/main/java/org/sitmun/domain/task/TaskProjection.java index 5513d94d..09b306d6 100644 --- a/common/src/main/java/org/sitmun/domain/task/TaskProjection.java +++ b/common/src/main/java/org/sitmun/domain/task/TaskProjection.java @@ -10,7 +10,7 @@ /** * Projections for REST views of a task. */ -@Projection(name = "view", types = {Task.class}) +@Projection(name = "view", types = Task.class) public interface TaskProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/task/TaskRepository.java b/common/src/main/java/org/sitmun/domain/task/TaskRepository.java index a1f162e7..83dd3304 100644 --- a/common/src/main/java/org/sitmun/domain/task/TaskRepository.java +++ b/common/src/main/java/org/sitmun/domain/task/TaskRepository.java @@ -25,7 +25,7 @@ public interface TaskRepository extends PagingAndSortingRepository available(@Param("applicationId") @NonNull Integer applicationId); @Override - default void customize(QuerydslBindings bindings, QTask root) { - bindings.bind(root.type.id).first(SimpleExpression::eq); + default void customize(QuerydslBindings querydslBindings, QTask root) { + querydslBindings.bind(root.type.id).first(SimpleExpression::eq); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailability.java b/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailability.java index 5941024e..58f1ec2d 100755 --- a/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailability.java +++ b/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailability.java @@ -12,14 +12,14 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.Objects; /** * Availability of Tasks in a Territory. */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_AVAIL_TSK", uniqueConstraints = { - @UniqueConstraint(name = "STM_DTA_UK", columnNames = {"ATS_TERID", "ATS_TASKID"})}) +@Table(name = "STM_AVAIL_TSK", uniqueConstraints = @UniqueConstraint(name = "STM_DTA_UK", columnNames = {"ATS_TERID", "ATS_TASKID"})) @Builder @Getter @Setter @@ -69,16 +69,18 @@ public class TaskAvailability { private Task task; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TaskAvailability)) - return false; + if (!(obj instanceof TaskAvailability)) { + return false; + } - TaskAvailability other = (TaskAvailability) o; + TaskAvailability other = (TaskAvailability) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailabilityProjection.java b/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailabilityProjection.java index 827a7b61..d596ca55 100644 --- a/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailabilityProjection.java +++ b/common/src/main/java/org/sitmun/domain/task/availability/TaskAvailabilityProjection.java @@ -5,7 +5,7 @@ import java.util.Date; -@Projection(name = "view", types = {TaskAvailability.class}) +@Projection(name = "view", types = TaskAvailability.class) public interface TaskAvailabilityProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/task/group/TaskGroup.java b/common/src/main/java/org/sitmun/domain/task/group/TaskGroup.java index 26f28219..93708216 100755 --- a/common/src/main/java/org/sitmun/domain/task/group/TaskGroup.java +++ b/common/src/main/java/org/sitmun/domain/task/group/TaskGroup.java @@ -8,6 +8,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Objects; /** * Task group. @@ -46,16 +47,18 @@ public class TaskGroup { private String name; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TaskGroup)) - return false; + if (!(obj instanceof TaskGroup)) { + return false; + } - TaskGroup other = (TaskGroup) o; + TaskGroup other = (TaskGroup) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/task/type/TaskType.java b/common/src/main/java/org/sitmun/domain/task/type/TaskType.java index bbfee2d1..be8e215c 100755 --- a/common/src/main/java/org/sitmun/domain/task/type/TaskType.java +++ b/common/src/main/java/org/sitmun/domain/task/type/TaskType.java @@ -13,6 +13,7 @@ import javax.persistence.*; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import static org.sitmun.domain.PersistenceConstants.IDENTIFIER; @@ -96,21 +97,25 @@ public class TaskType { private Map specification; public Boolean getFolder() { - if (children != null) return !children.isEmpty(); + if (children != null) { + return !children.isEmpty(); + } return false; } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TaskType)) - return false; + if (!(obj instanceof TaskType)) { + return false; + } - TaskType other = (TaskType) o; + TaskType other = (TaskType) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/task/type/TaskTypeProjection.java b/common/src/main/java/org/sitmun/domain/task/type/TaskTypeProjection.java index 5673b2a1..f7367afb 100644 --- a/common/src/main/java/org/sitmun/domain/task/type/TaskTypeProjection.java +++ b/common/src/main/java/org/sitmun/domain/task/type/TaskTypeProjection.java @@ -8,7 +8,7 @@ /** * Projections for REST views of a task type. */ -@Projection(name = "view", types = {TaskType.class}) +@Projection(name = "view", types = TaskType.class) public interface TaskTypeProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/task/ui/TaskUI.java b/common/src/main/java/org/sitmun/domain/task/ui/TaskUI.java index 77d87cbf..329a109b 100755 --- a/common/src/main/java/org/sitmun/domain/task/ui/TaskUI.java +++ b/common/src/main/java/org/sitmun/domain/task/ui/TaskUI.java @@ -10,6 +10,8 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; +import java.util.Objects; + import static org.sitmun.domain.PersistenceConstants.IDENTIFIER; /** @@ -71,16 +73,18 @@ public class TaskUI { private Integer order; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TaskType)) - return false; + if (!(obj instanceof TaskType)) { + return false; + } - TaskType other = (TaskType) o; + TaskType other = (TaskType) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/territory/Territory.java b/common/src/main/java/org/sitmun/domain/territory/Territory.java index d7c86abc..8ab42574 100755 --- a/common/src/main/java/org/sitmun/domain/territory/Territory.java +++ b/common/src/main/java/org/sitmun/domain/territory/Territory.java @@ -29,6 +29,7 @@ import javax.validation.constraints.NotNull; import java.util.Date; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -36,8 +37,7 @@ */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_TERRITORY", uniqueConstraints = { - @UniqueConstraint(name = "STM_TER_NOM_UK", columnNames = {"TER_NAME"})}) +@Table(name = "STM_TERRITORY", uniqueConstraints = @UniqueConstraint(name = "STM_TER_NOM_UK", columnNames = "TER_NAME")) @Builder(toBuilder = true) @Getter @Setter @@ -278,16 +278,18 @@ public void postLoad() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Territory)) - return false; + if (!(obj instanceof Territory)) { + return false; + } - Territory other = (Territory) o; + Territory other = (Territory) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/territory/TerritoryProjection.java b/common/src/main/java/org/sitmun/domain/territory/TerritoryProjection.java index 3baf1545..b0d3197b 100644 --- a/common/src/main/java/org/sitmun/domain/territory/TerritoryProjection.java +++ b/common/src/main/java/org/sitmun/domain/territory/TerritoryProjection.java @@ -10,7 +10,7 @@ /** * Projections for REST views of a territory. */ -@Projection(name = "view", types = {Territory.class}) +@Projection(name = "view", types = Territory.class) public interface TerritoryProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/domain/territory/type/TerritoryGroupType.java b/common/src/main/java/org/sitmun/domain/territory/type/TerritoryGroupType.java index b77879d7..226afce8 100755 --- a/common/src/main/java/org/sitmun/domain/territory/type/TerritoryGroupType.java +++ b/common/src/main/java/org/sitmun/domain/territory/type/TerritoryGroupType.java @@ -8,6 +8,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Objects; /** * Type of grouping of territorial entities. @@ -15,8 +16,7 @@ * @deprecated */ @Entity -@Table(name = "STM_GTER_TYP", uniqueConstraints = { - @UniqueConstraint(name = "STM_GTT_NOM_UK", columnNames = {"GTT_NAME"})}) +@Table(name = "STM_GTER_TYP", uniqueConstraints = @UniqueConstraint(name = "STM_GTT_NOM_UK", columnNames = "GTT_NAME")) @Builder @Getter @Setter @@ -49,16 +49,18 @@ public class TerritoryGroupType { private String name; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TerritoryGroupType)) - return false; + if (!(obj instanceof TerritoryGroupType)) { + return false; + } - TerritoryGroupType other = (TerritoryGroupType) o; + TerritoryGroupType other = (TerritoryGroupType) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/territory/type/TerritoryType.java b/common/src/main/java/org/sitmun/domain/territory/type/TerritoryType.java index aad9cc6a..073e176d 100755 --- a/common/src/main/java/org/sitmun/domain/territory/type/TerritoryType.java +++ b/common/src/main/java/org/sitmun/domain/territory/type/TerritoryType.java @@ -8,13 +8,13 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Objects; /** * Type of territorial entities. */ @Entity -@Table(name = "STM_TER_TYP", uniqueConstraints = { - @UniqueConstraint(name = "STM_TET_NOM_UK", columnNames = {"TET_NAME"})}) +@Table(name = "STM_TER_TYP", uniqueConstraints = @UniqueConstraint(name = "STM_TET_NOM_UK", columnNames = "TET_NAME")) @Builder @Getter @Setter @@ -73,16 +73,18 @@ public class TerritoryType { private Boolean bottomType = false; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TerritoryType)) - return false; + if (!(obj instanceof TerritoryType)) { + return false; + } - TerritoryType other = (TerritoryType) o; + TerritoryType other = (TerritoryType) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/tree/Tree.java b/common/src/main/java/org/sitmun/domain/tree/Tree.java index b79c2935..047e899d 100755 --- a/common/src/main/java/org/sitmun/domain/tree/Tree.java +++ b/common/src/main/java/org/sitmun/domain/tree/Tree.java @@ -14,6 +14,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -111,16 +112,18 @@ public class Tree { private Set availableApplications = new HashSet<>(); @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Tree)) - return false; + if (!(obj instanceof Tree)) { + return false; + } - Tree other = (Tree) o; + Tree other = (Tree) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/tree/node/TreeNode.java b/common/src/main/java/org/sitmun/domain/tree/node/TreeNode.java index 236000e1..b70cf5e5 100755 --- a/common/src/main/java/org/sitmun/domain/tree/node/TreeNode.java +++ b/common/src/main/java/org/sitmun/domain/tree/node/TreeNode.java @@ -14,6 +14,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Tree node. @@ -165,16 +166,18 @@ public Integer getCartographyId() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof TreeNode)) - return false; + if (!(obj instanceof TreeNode)) { + return false; + } - TreeNode other = (TreeNode) o; + TreeNode other = (TreeNode) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/tree/node/TreeNodeProjection.java b/common/src/main/java/org/sitmun/domain/tree/node/TreeNodeProjection.java index c54e9b5e..bc995ccd 100644 --- a/common/src/main/java/org/sitmun/domain/tree/node/TreeNodeProjection.java +++ b/common/src/main/java/org/sitmun/domain/tree/node/TreeNodeProjection.java @@ -7,7 +7,7 @@ /** * Projections for REST views of tree node. */ -@Projection(name = "view", types = {TreeNode.class}) +@Projection(name = "view", types = TreeNode.class) public interface TreeNodeProjection { /** diff --git a/common/src/main/java/org/sitmun/domain/user/User.java b/common/src/main/java/org/sitmun/domain/user/User.java index 266f840f..26e12935 100755 --- a/common/src/main/java/org/sitmun/domain/user/User.java +++ b/common/src/main/java/org/sitmun/domain/user/User.java @@ -17,6 +17,7 @@ import javax.validation.constraints.NotNull; import java.util.Date; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -24,8 +25,7 @@ */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_USER", uniqueConstraints = { - @UniqueConstraint(name = "STM_USU_USU_UK", columnNames = {"USE_USER"})}) +@Table(name = "STM_USER", uniqueConstraints = @UniqueConstraint(name = "STM_USU_USU_UK", columnNames = "USE_USER")) @Builder(toBuilder = true) @Getter @Setter @@ -153,16 +153,18 @@ public Boolean getPasswordSet() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof User)) - return false; + if (!(obj instanceof User)) { + return false; + } - User other = (User) o; + User other = (User) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/user/UserController.java b/common/src/main/java/org/sitmun/domain/user/UserController.java index 9e236393..075922e9 100644 --- a/common/src/main/java/org/sitmun/domain/user/UserController.java +++ b/common/src/main/java/org/sitmun/domain/user/UserController.java @@ -31,7 +31,7 @@ public class UserController { * Constructor. */ public UserController(Validator validator, UserRepository userRepository, ApplicationEventPublisher publisher) { - this.springValidator = new SpringValidatorAdapter(validator); + springValidator = new SpringValidatorAdapter(validator); this.userRepository = userRepository; this.publisher = publisher; } @@ -49,29 +49,34 @@ public ResponseEntity saveAccount(@RequestBody UserDTO updatedUser) { Optional storedUser = userRepository.findByUsername(authentication.getName()); if (storedUser.isPresent()) { User user = storedUser.get(); - user.setUsername(updatedUser.getUsername()); - user.setPassword(updatedUser.getPassword()); - user.setFirstName(updatedUser.getFirstName()); - user.setLastName(updatedUser.getLastName()); - user.setIdentificationNumber(updatedUser.getIdentificationNumber()); - user.setIdentificationType(updatedUser.getIdentificationType()); - user.setAdministrator(updatedUser.getAdministrator()); - user.setBlocked(updatedUser.getBlocked()); - user.setGeneric(updatedUser.getGeneric()); - BindingResult bindingResult = new BeanPropertyBindingResult(user, "user"); - springValidator.validate(user, bindingResult); + User mergedUser = getUser(updatedUser, user); + BindingResult bindingResult = new BeanPropertyBindingResult(mergedUser, "user"); + springValidator.validate(mergedUser, bindingResult); if (bindingResult.hasErrors()) { throw new RepositoryConstraintViolationException(bindingResult); } - publisher.publishEvent(new BeforeSaveEvent(user)); - user = userRepository.save(user); - publisher.publishEvent(new AfterSaveEvent(user)); - return ResponseEntity.ok(userToDto(user)); + publisher.publishEvent(new BeforeSaveEvent(mergedUser)); + mergedUser = userRepository.save(mergedUser); + publisher.publishEvent(new AfterSaveEvent(mergedUser)); + return ResponseEntity.ok(userToDto(mergedUser)); } else { return ResponseEntity.notFound().build(); } } + private static User getUser(UserDTO updatedUser, User user) { + user.setUsername(updatedUser.getUsername()); + user.setPassword(updatedUser.getPassword()); + user.setFirstName(updatedUser.getFirstName()); + user.setLastName(updatedUser.getLastName()); + user.setIdentificationNumber(updatedUser.getIdentificationNumber()); + user.setIdentificationType(updatedUser.getIdentificationType()); + user.setAdministrator(updatedUser.getAdministrator()); + user.setBlocked(updatedUser.getBlocked()); + user.setGeneric(updatedUser.getGeneric()); + return user; + } + /** * Get accounts. */ @@ -79,11 +84,11 @@ public ResponseEntity saveAccount(@RequestBody UserDTO updatedUser) { @ResponseBody public ResponseEntity getAccount() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - Optional storedUser = userRepository.findByUsername(authentication.getName()).map(this::userToDto); + Optional storedUser = userRepository.findByUsername(authentication.getName()).map(UserController::userToDto); return storedUser.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } - private UserDTO userToDto(User user) { + private static UserDTO userToDto(User user) { return UserDTO.builder() .id(user.getId()) .username(user.getUsername()) diff --git a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfiguration.java b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfiguration.java index 01ae6aec..ab452e01 100755 --- a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfiguration.java +++ b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfiguration.java @@ -16,15 +16,15 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.Objects; /** * User role in a territory. */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_USR_CONF", uniqueConstraints = { - @UniqueConstraint(name = "STM_UCF_UK", columnNames = {"UCO_USERID", "UCO_TERID", "UCO_ROLEID", - "UCO_ROLEM"})}) +@Table(name = "STM_USR_CONF", uniqueConstraints = @UniqueConstraint(name = "STM_UCF_UK", columnNames = {"UCO_USERID", "UCO_TERID", "UCO_ROLEID", + "UCO_ROLEM"})) @Builder @Getter @Setter @@ -95,16 +95,18 @@ public class UserConfiguration { private Date createdDate; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof UserConfiguration)) - return false; + if (!(obj instanceof UserConfiguration)) { + return false; + } - UserConfiguration other = (UserConfiguration) o; + UserConfiguration other = (UserConfiguration) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationProjection.java b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationProjection.java index 521b6e44..a1eeede9 100644 --- a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationProjection.java +++ b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationProjection.java @@ -9,7 +9,7 @@ /** * Projections for REST views of user configuration. */ -@Projection(name = "view", types = {UserConfiguration.class}) +@Projection(name = "view", types = UserConfiguration.class) public interface UserConfigurationProjection { /** diff --git a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationRepository.java b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationRepository.java index 9ec25a36..c5fda02e 100644 --- a/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationRepository.java +++ b/common/src/main/java/org/sitmun/domain/user/configuration/UserConfigurationRepository.java @@ -21,7 +21,7 @@ public interface UserConfigurationRepository extends List findByUser(User currentUser); @Override - default void customize(QuerydslBindings bindings, QUserConfiguration root) { - bindings.bind(root.role.id).first(SimpleExpression::eq); + default void customize(QuerydslBindings querydslBindings, QUserConfiguration root) { + querydslBindings.bind(root.role.id).first(SimpleExpression::eq); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/domain/user/position/UserPosition.java b/common/src/main/java/org/sitmun/domain/user/position/UserPosition.java index 2e4c1831..68eb1106 100755 --- a/common/src/main/java/org/sitmun/domain/user/position/UserPosition.java +++ b/common/src/main/java/org/sitmun/domain/user/position/UserPosition.java @@ -16,6 +16,7 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.Objects; import static org.sitmun.domain.PersistenceConstants.IDENTIFIER; @@ -24,8 +25,7 @@ */ @Entity @EntityListeners(AuditingEntityListener.class) -@Table(name = "STM_POST", uniqueConstraints = { - @UniqueConstraint(columnNames = {"POS_USERID", "POS_TERID"})}) +@Table(name = "STM_POST", uniqueConstraints = @UniqueConstraint(columnNames = {"POS_USERID", "POS_TERID"})) @Builder @Getter @Setter @@ -116,16 +116,18 @@ public class UserPosition { private Territory territory; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof UserPosition)) - return false; + if (!(obj instanceof UserPosition)) { + return false; + } - UserPosition other = (UserPosition) o; + UserPosition other = (UserPosition) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/domain/user/position/UserPositionProjection.java b/common/src/main/java/org/sitmun/domain/user/position/UserPositionProjection.java index 85b68d31..fc1cd688 100644 --- a/common/src/main/java/org/sitmun/domain/user/position/UserPositionProjection.java +++ b/common/src/main/java/org/sitmun/domain/user/position/UserPositionProjection.java @@ -8,7 +8,7 @@ /** * Projections for REST views of user position. */ -@Projection(name = "view", types = {UserPosition.class}) +@Projection(name = "view", types = UserPosition.class) public interface UserPositionProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/exception/RequirementException.java b/common/src/main/java/org/sitmun/infrastructure/persistence/exception/RequirementException.java index 8fda59be..ee5a40e1 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/exception/RequirementException.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/exception/RequirementException.java @@ -1,7 +1,7 @@ package org.sitmun.infrastructure.persistence.exception; public class RequirementException extends RuntimeException { - public RequirementException(String msg) { - super(msg); + public RequirementException(String message) { + super(message); } } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBox.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBox.java index 0d4c7d81..47a3365e 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBox.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBox.java @@ -9,9 +9,9 @@ import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; -@Target({FIELD}) +@Target(FIELD) @Retention(RUNTIME) -@Constraint(validatedBy = {BoundingBoxValidator.class}) +@Constraint(validatedBy = BoundingBoxValidator.class) @Documented public @interface BoundingBox { diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBoxValidator.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBoxValidator.java index ac46994f..034a7379 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBoxValidator.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/boundingbox/BoundingBoxValidator.java @@ -9,40 +9,40 @@ public class BoundingBoxValidator implements ConstraintValidator { @Override - public boolean isValid(Envelope value, ConstraintValidatorContext context) { + public boolean isValid(Envelope value, ConstraintValidatorContext constraintValidatorContext) { if (value == null) { return true; } boolean result = true; - context.disableDefaultConstraintViolation(); + constraintValidatorContext.disableDefaultConstraintViolation(); if (value.getMaxX() == null) { - context.buildConstraintViolationWithTemplate("maxX must not be null") + constraintValidatorContext.buildConstraintViolationWithTemplate("maxX must not be null") .addConstraintViolation(); result = false; } if (value.getMaxY() == null) { - context.buildConstraintViolationWithTemplate("maxY must not be null") + constraintValidatorContext.buildConstraintViolationWithTemplate("maxY must not be null") .addConstraintViolation(); result = false; } if (value.getMinX() == null) { - context.buildConstraintViolationWithTemplate("minX must not be null") + constraintValidatorContext.buildConstraintViolationWithTemplate("minX must not be null") .addConstraintViolation(); result = false; } if (value.getMinY() == null) { - context.buildConstraintViolationWithTemplate("minY must not be null") + constraintValidatorContext.buildConstraintViolationWithTemplate("minY must not be null") .addConstraintViolation(); result = false; } if (value.getMinX() != null && value.getMaxX() != null && value.getMaxX() <= value.getMinX()) { - context.buildConstraintViolationWithTemplate("maxX must be greater than minX") + constraintValidatorContext.buildConstraintViolationWithTemplate("maxX must be greater than minX") .addConstraintViolation(); result = false; } if (value.getMinY() != null && value.getMaxY() != null && value.getMaxY() <= value.getMinY()) { - context.buildConstraintViolationWithTemplate("maxY must be greater than minY") + constraintValidatorContext.buildConstraintViolationWithTemplate("maxY must be greater than minY") .addConstraintViolation(); result = false; } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeList.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeList.java index 2dd7c843..2a2dd631 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeList.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeList.java @@ -8,8 +8,8 @@ import static java.lang.annotation.ElementType.FIELD; -@Constraint(validatedBy = {CodeListValidator.class}) -@Target({FIELD}) +@Constraint(validatedBy = CodeListValidator.class) +@Target(FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface CodeList { diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValidator.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValidator.java index 8598dae5..cefbdce6 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValidator.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValidator.java @@ -18,7 +18,7 @@ public void initialize(CodeList constraintAnnotation) { } @Override - public boolean isValid(String value, ConstraintValidatorContext context) { + public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { if (value != null) { return codeRepository.existsByCodeListNameAndValue(codeList, value); } else { diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValue.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValue.java index f3271185..524ad601 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValue.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/CodeListValue.java @@ -9,13 +9,13 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Code list value. */ @Entity -@Table(name = "STM_CODELIST", - uniqueConstraints = {@UniqueConstraint(columnNames = {"COD_LIST", "COD_VALUE"})}) +@Table(name = "STM_CODELIST", uniqueConstraints = @UniqueConstraint(columnNames = {"COD_LIST", "COD_VALUE"})) @Builder @Getter @Setter @@ -94,16 +94,18 @@ public void postLoad() { } @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof CodeListValue)) - return false; + if (!(obj instanceof CodeListValue)) { + return false; + } - CodeListValue other = (CodeListValue) o; + CodeListValue other = (CodeListValue) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/ImmutableSystemCodeListValueException.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/ImmutableSystemCodeListValueException.java index e0c26c4d..3cd0f1a2 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/ImmutableSystemCodeListValueException.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/codelist/ImmutableSystemCodeListValueException.java @@ -5,7 +5,7 @@ @ResponseStatus(HttpStatus.BAD_REQUEST) public class ImmutableSystemCodeListValueException extends RuntimeException { - public ImmutableSystemCodeListValueException(String msg) { - super(msg); + public ImmutableSystemCodeListValueException(String message) { + super(message); } } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/Envelope.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/Envelope.java index f9ba3e8e..e2dcccb3 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/Envelope.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/Envelope.java @@ -39,10 +39,14 @@ public class Envelope { private Double minX; @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Envelope envelope = (Envelope) o; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Envelope envelope = (Envelope) obj; return Objects.equals(minY, envelope.minY) && Objects.equals(maxX, envelope.maxX) && Objects.equals(maxY, envelope.maxY) && Objects.equals(minX, envelope.minX); } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/EnvelopeToStringConverter.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/EnvelopeToStringConverter.java index 0d187a67..cff0446a 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/EnvelopeToStringConverter.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/envelope/EnvelopeToStringConverter.java @@ -16,7 +16,7 @@ public class EnvelopeToStringConverter implements AttributeConverter it.isAnnotationPresent(Id.class)) diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Language.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Language.java index c2799832..27329fbf 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Language.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Language.java @@ -5,13 +5,13 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import java.util.Objects; /** * Available languages. */ @Entity -@Table(name = "STM_LANGUAGE", - uniqueConstraints = {@UniqueConstraint(columnNames = {"LAN_SHORTNAME"})}) +@Table(name = "STM_LANGUAGE", uniqueConstraints = @UniqueConstraint(columnNames = "LAN_SHORTNAME")) @Builder @Getter @Setter @@ -51,16 +51,18 @@ public class Language { private String name; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Language)) - return false; + if (!(obj instanceof Language)) { + return false; + } - Language other = (Language) o; + Language other = (Language) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Translation.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Translation.java index eea1b21e..fe24de07 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Translation.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/Translation.java @@ -6,13 +6,13 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * Available translations. */ @Entity -@Table(name = "STM_TRANSLATION", uniqueConstraints = { - @UniqueConstraint(columnNames = {"TRA_ELEID", "TRA_COLUMN", "TRA_LANID"})}) +@Table(name = "STM_TRANSLATION", uniqueConstraints = @UniqueConstraint(columnNames = {"TRA_ELEID", "TRA_COLUMN", "TRA_LANID"})) @Builder @Getter @Setter @@ -65,16 +65,18 @@ public class Translation { private String translation; @Override - public boolean equals(Object o) { - if (this == o) return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } - if (!(o instanceof Translation)) - return false; + if (!(obj instanceof Translation)) { + return false; + } - Translation other = (Translation) o; + Translation other = (Translation) obj; - return id != null && - id.equals(other.getId()); + return Objects.equals(id, other.getId()); } @Override diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/TranslationProjection.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/TranslationProjection.java index f522e441..2625cc0b 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/TranslationProjection.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/i18n/TranslationProjection.java @@ -6,7 +6,7 @@ /** * Projections for REST views of translation. */ -@Projection(name = "view", types = {Translation.class}) +@Projection(name = "view", types = Translation.class) public interface TranslationProjection { @Value("#{target.id}") diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/list/StringListAttributeConverter.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/list/StringListAttributeConverter.java index bcb0864d..019e6587 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/list/StringListAttributeConverter.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/list/StringListAttributeConverter.java @@ -42,7 +42,7 @@ public String convertToDatabaseColumn(List list) { public List convertToEntityAttribute(String dbData) { if (dbData == null) { return null; - } else if (dbData.trim().length() == 0) { + } else if (dbData.trim().isEmpty()) { return Collections.emptyList(); } else { return Arrays.stream(dbData.split(DELIMITER)) diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/map/HashMapConverter.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/map/HashMapConverter.java index 101fbbfc..302edfa8 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/map/HashMapConverter.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/map/HashMapConverter.java @@ -26,13 +26,12 @@ public HashMapConverter() { @Override public String convertToDatabaseColumn(Map attribute) { - String converted = null; try { - converted = objectMapper.writeValueAsString(attribute); + return objectMapper.writeValueAsString(attribute); } catch (final JsonProcessingException e) { LOGGER.error("JSON writing error", e); } - return converted; + return null; } @Override @@ -40,13 +39,12 @@ public Map convertToEntityAttribute(String dbData) { if (dbData == null) { return null; } - Map attribute = null; JavaType type = objectMapper.getTypeFactory().constructParametricType(Map.class, String.class, Object.class); try { - attribute = objectMapper.readValue(dbData, type); + return objectMapper.readValue(dbData, type); } catch (final IOException e) { LOGGER.error("JSON reading error", e); } - return attribute; + return null; } } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/Point.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/Point.java index d2c4dc33..400e5d29 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/Point.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/Point.java @@ -29,10 +29,14 @@ public class Point { private Double y; @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Point point = (Point) o; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Point point = (Point) obj; return Objects.equals(x, point.x) && Objects.equals(y, point.y); } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/PointToStringConverter.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/PointToStringConverter.java index 01ab31cf..ab2f69de 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/PointToStringConverter.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/point/PointToStringConverter.java @@ -16,7 +16,7 @@ public class PointToStringConverter implements AttributeConverter public static final String PRECISION = "######"; - public static final String FORMAT = "{0,number,#." + PRECISION + "} {1,number,#." + PRECISION + "}"; + public static final String FORMAT = "{0,number,#." + PRECISION + "} {1,number,#." + PRECISION + '}'; public static final Locale defaultLocale = Locale.US; @@ -56,7 +56,7 @@ public Point convertToEntityAttribute(String dbData) { .y(extractDouble(values[1])) .build(); } catch (Exception e) { - log.error("[" + dbData + "] cannot be parsed to Point", e); + log.error('[' + dbData + "] cannot be parsed to Point", e); return null; } } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/Srs.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/Srs.java index a9acc87b..720bdfea 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/Srs.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/Srs.java @@ -9,7 +9,7 @@ import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; -@Target({FIELD}) +@Target(FIELD) @Retention(RUNTIME) @Constraint(validatedBy = {SrsValidator.class, SrsSystemListValidator.class}) diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsSystemListValidator.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsSystemListValidator.java index 43512e79..65f8bbd8 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsSystemListValidator.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsSystemListValidator.java @@ -12,10 +12,10 @@ public class SrsSystemListValidator .compile("^[A-Z_\\-]+:\\d+$", Pattern.CASE_INSENSITIVE); @Override - public boolean isValid(List value, ConstraintValidatorContext context) { + public boolean isValid(List value, ConstraintValidatorContext constraintValidatorContext) { if (value == null) { return true; } - return value.stream().allMatch(it -> pattern.matcher(it).matches()); + return value.stream().allMatch(pattern.asMatchPredicate()); } } diff --git a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsValidator.java b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsValidator.java index 415442a4..9de24236 100644 --- a/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsValidator.java +++ b/common/src/main/java/org/sitmun/infrastructure/persistence/type/srs/SrsValidator.java @@ -10,7 +10,7 @@ public class SrsValidator private static final Pattern pattern = Pattern.compile("^[A-Z\\-]+:\\d+$"); @Override - public boolean isValid(String value, ConstraintValidatorContext context) { + public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { if (value == null) { return true; } diff --git a/common/src/main/java/org/sitmun/infrastructure/security/config/WebSecurityConfigurer.java b/common/src/main/java/org/sitmun/infrastructure/security/config/WebSecurityConfigurer.java index c18fb85c..29aa7079 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/config/WebSecurityConfigurer.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/config/WebSecurityConfigurer.java @@ -65,8 +65,8 @@ public JsonWebTokenFilter authenticationJwtTokenFilter() { } @Override - public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { - authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); + public void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); } @Bean diff --git a/common/src/main/java/org/sitmun/infrastructure/security/core/LdapUserAuthoritiesPopulator.java b/common/src/main/java/org/sitmun/infrastructure/security/core/LdapUserAuthoritiesPopulator.java index 7a8df906..456d7140 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/core/LdapUserAuthoritiesPopulator.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/core/LdapUserAuthoritiesPopulator.java @@ -22,7 +22,7 @@ public class LdapUserAuthoritiesPopulator implements LdapAuthoritiesPopulator { private final UserDetailsService userDetailsService; @Override - public Collection getGrantedAuthorities(DirContextOperations userData, + public Collection getGrantedAuthorities(DirContextOperations dirContextOperations, String username) { Collection authorities = new HashSet<>(); try { diff --git a/common/src/main/java/org/sitmun/infrastructure/security/core/SecurityEntryPoint.java b/common/src/main/java/org/sitmun/infrastructure/security/core/SecurityEntryPoint.java index b5133df8..db2593c3 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/core/SecurityEntryPoint.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/core/SecurityEntryPoint.java @@ -20,21 +20,21 @@ public class SecurityEntryPoint implements AuthenticationEntryPoint { private static final Logger logger = LoggerFactory.getLogger(SecurityEntryPoint.class); @Override - public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) + public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException authException) throws IOException { logger.error("Unauthorized error: {}", authException.getMessage()); - response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); + httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); final Map body = new HashMap<>(); body.put("status", HttpServletResponse.SC_UNAUTHORIZED); body.put("error", "Unauthorized"); body.put("message", authException.getMessage()); - body.put("path", request.getServletPath()); + body.put("path", httpServletRequest.getServletPath()); final ObjectMapper mapper = new ObjectMapper(); - mapper.writeValue(response.getOutputStream(), body); + mapper.writeValue(httpServletResponse.getOutputStream(), body); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/infrastructure/security/core/userdetails/UserDetailsImplementation.java b/common/src/main/java/org/sitmun/infrastructure/security/core/userdetails/UserDetailsImplementation.java index efc6f634..069dc67b 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/core/userdetails/UserDetailsImplementation.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/core/userdetails/UserDetailsImplementation.java @@ -1,6 +1,7 @@ package org.sitmun.infrastructure.security.core.userdetails; import com.google.common.collect.Lists; +import lombok.Getter; import org.sitmun.domain.user.User; import org.sitmun.infrastructure.security.core.SecurityRole; import org.springframework.security.core.GrantedAuthority; @@ -15,6 +16,7 @@ public class UserDetailsImplementation implements UserDetails { private static final long serialVersionUID = 1L; + @Getter private final Integer id; private final String username; @@ -32,7 +34,7 @@ public UserDetailsImplementation(Integer id, String username, String password, this.username = username; this.password = password; this.authorities = authorities; - this.accountNonLocked = enabled; + accountNonLocked = enabled; } public static UserDetailsImplementation build(User user) { @@ -60,10 +62,6 @@ public Collection getAuthorities() { return authorities; } - public Integer getId() { - return id; - } - @Override public String getPassword() { return password; @@ -95,12 +93,14 @@ public boolean isEnabled() { } @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - UserDetailsImplementation user = (UserDetailsImplementation) o; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + UserDetailsImplementation user = (UserDetailsImplementation) obj; return Objects.equals(id, user.id); } diff --git a/common/src/main/java/org/sitmun/infrastructure/security/filter/JsonWebTokenFilter.java b/common/src/main/java/org/sitmun/infrastructure/security/filter/JsonWebTokenFilter.java index 0b41fbd5..db140398 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/filter/JsonWebTokenFilter.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/filter/JsonWebTokenFilter.java @@ -32,10 +32,10 @@ public JsonWebTokenFilter( } @Override - protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws ServletException, IOException { - final String requestTokenHeader = request.getHeader(HttpHeaders.AUTHORIZATION); + protected void doFilterInternal(@NonNull HttpServletRequest httpServletRequest, @NonNull HttpServletResponse httpServletResponse, @NonNull FilterChain filterChain) throws ServletException, IOException { + final String requestTokenHeader = httpServletRequest.getHeader(HttpHeaders.AUTHORIZATION); if (StringUtils.isEmpty(requestTokenHeader) || !StringUtils.startsWith(requestTokenHeader, "Bearer ")) { - filterChain.doFilter(request, response); + filterChain.doFilter(httpServletRequest, httpServletResponse); return; } String jwtToken = requestTokenHeader.substring(7); @@ -45,7 +45,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht UserDetails userDetails = userDetailsService.loadUserByUsername(username); if (jsonWebTokenService.validateToken(jwtToken, userDetails)) { UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); - usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest)); SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); } } @@ -56,7 +56,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht } catch (Exception e) { logger.error(e.getMessage(), e); } - filterChain.doFilter(request, response); + filterChain.doFilter(httpServletRequest, httpServletResponse); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/infrastructure/security/filter/ProxyTokenFilter.java b/common/src/main/java/org/sitmun/infrastructure/security/filter/ProxyTokenFilter.java index 7e4e3cb9..92ac4a90 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/filter/ProxyTokenFilter.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/filter/ProxyTokenFilter.java @@ -30,10 +30,10 @@ public ProxyTokenFilter(String principal, List authorities) { } @Override - protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) + protected void doFilterInternal(@NonNull HttpServletRequest httpServletRequest, @NonNull HttpServletResponse httpServletResponse, @NonNull FilterChain filterChain) throws ServletException, IOException { try { - String key = request.getHeader(X_SITMUN_PROXY_KEY) == null ? "" : request.getHeader(X_SITMUN_PROXY_KEY); + String key = httpServletRequest.getHeader(X_SITMUN_PROXY_KEY) == null ? "" : httpServletRequest.getHeader(X_SITMUN_PROXY_KEY); if (Objects.equals(key, middlewareSecret)) { UsernamePasswordAuthenticationToken authentication = @@ -41,7 +41,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht principal, null, authorities); - authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest)); SecurityContextHolder.getContext().setAuthentication(authentication); } } catch (Exception e) { @@ -49,6 +49,6 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht logger.error(msg, e); } - filterChain.doFilter(request, response); + filterChain.doFilter(httpServletRequest, httpServletResponse); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/infrastructure/security/storage/LdapPasswordStorage.java b/common/src/main/java/org/sitmun/infrastructure/security/storage/LdapPasswordStorage.java index 74486b49..f80c179e 100644 --- a/common/src/main/java/org/sitmun/infrastructure/security/storage/LdapPasswordStorage.java +++ b/common/src/main/java/org/sitmun/infrastructure/security/storage/LdapPasswordStorage.java @@ -38,19 +38,20 @@ public LdapPasswordStorage(LdapUserAuthoritiesPopulator ldapUserAuthoritiesPopul @Override public void addPasswordStorage(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { - String url = StringUtils.hasText(this.host) && StringUtils.hasText(this.baseDN) - ? this.host.concat("/").concat(this.baseDN) + String url = StringUtils.hasText(host) && StringUtils.hasText(baseDN) + ? this.host + "/" + this.baseDN : null; authenticationManagerBuilder.ldapAuthentication() .passwordEncoder(ldapPasswordEncoder()) - .userDnPatterns(this.userDNPattern) + .userDnPatterns(userDNPattern) .ldapAuthoritiesPopulator(ldapUserAuthoritiesPopulator) .contextSource().url(url) - .managerDn(StringUtils.hasText(this.userLdap) ? this.userLdap : null) - .managerPassword(StringUtils.hasText(this.passwordLdap) ? this.passwordLdap : null); + .managerDn(StringUtils.hasText(userLdap) ? userLdap : null) + .managerPassword(StringUtils.hasText(passwordLdap) ? passwordLdap : null); } public PasswordEncoder ldapPasswordEncoder() { + //noinspection deprecation return new LdapShaPasswordEncoder(); } } \ No newline at end of file diff --git a/common/src/main/java/org/sitmun/infrastructure/web/config/OpenApiConfigurer.java b/common/src/main/java/org/sitmun/infrastructure/web/config/OpenApiConfigurer.java index e32537ea..da557e38 100644 --- a/common/src/main/java/org/sitmun/infrastructure/web/config/OpenApiConfigurer.java +++ b/common/src/main/java/org/sitmun/infrastructure/web/config/OpenApiConfigurer.java @@ -15,7 +15,7 @@ import static java.util.Collections.emptyList; @Configuration -@Profile({"openapi"}) +@Profile("openapi") public class OpenApiConfigurer { private final String moduleName; diff --git a/common/src/main/java/org/sitmun/infrastructure/web/config/ProvidedOpenApiConfigurer.java b/common/src/main/java/org/sitmun/infrastructure/web/config/ProvidedOpenApiConfigurer.java index 9544cd35..0fa31830 100644 --- a/common/src/main/java/org/sitmun/infrastructure/web/config/ProvidedOpenApiConfigurer.java +++ b/common/src/main/java/org/sitmun/infrastructure/web/config/ProvidedOpenApiConfigurer.java @@ -9,7 +9,7 @@ import org.springframework.context.annotation.Profile; @Configuration -@Profile({"openapi-provided"}) +@Profile("openapi-provided") public class ProvidedOpenApiConfigurer { @Bean diff --git a/common/src/main/java/org/sitmun/infrastructure/web/controller/DomainExceptionHandler.java b/common/src/main/java/org/sitmun/infrastructure/web/controller/DomainExceptionHandler.java index 2d91ebb1..46bd31f8 100644 --- a/common/src/main/java/org/sitmun/infrastructure/web/controller/DomainExceptionHandler.java +++ b/common/src/main/java/org/sitmun/infrastructure/web/controller/DomainExceptionHandler.java @@ -31,7 +31,7 @@ public class DomainExceptionHandler extends ResponseEntityExceptionHandler { public DomainExceptionHandler(MessageSource messageSource) { Assert.notNull(messageSource, "MessageSource must not be null!"); - this.messageSourceAccessor = new MessageSourceAccessor(messageSource); + messageSourceAccessor = new MessageSourceAccessor(messageSource); } /** @@ -62,14 +62,14 @@ ResponseEntity handleRepositoryCo @Override @NonNull protected ResponseEntity handleHttpMessageNotReadable( - HttpMessageNotReadableException exception, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) { + HttpMessageNotReadableException ex, @NonNull HttpHeaders headers, @NonNull HttpStatus status, @NonNull WebRequest request) { DomainExceptionResponse response = DomainExceptionResponse.builder() .error(HttpStatus.UNPROCESSABLE_ENTITY.getReasonPhrase()) - .message(exception.getLocalizedMessage()) + .message(ex.getLocalizedMessage()) .status(HttpStatus.UNPROCESSABLE_ENTITY.value()) .timestamp(LocalDateTime.now(ZoneOffset.UTC)) .path(((ServletWebRequest) request).getRequest().getRequestURI()) .build(); - return handleExceptionInternal(exception, response, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); + return handleExceptionInternal(ex, response, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); } } diff --git a/deploy/heroku-dev-full/build.gradle b/deploy/heroku-dev-full/build.gradle index ad2b43d5..f5252744 100644 --- a/deploy/heroku-dev-full/build.gradle +++ b/deploy/heroku-dev-full/build.gradle @@ -51,7 +51,7 @@ dependencies { jacocoTestReport { reports { - xml.enabled true + xml.required.set(true) } } diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java deleted file mode 100644 index 6aa57deb..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.sitmun.authentication.controller; - -import com.unboundid.ldap.listener.InMemoryDirectoryServer; -import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; -import com.unboundid.ldap.listener.InMemoryListenerConfig; -import com.unboundid.ldap.sdk.LDAPException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.sitmun.authentication.dto.UserPasswordAuthenticationRequest; -import org.sitmun.test.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import java.net.URI; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -@ActiveProfiles({"test", "ldap"}) -class AuthenticationControllerLdapEnabledTest { - - @Value("${sitmun.authentication.ldap.url}") - private String url; - - @Value("${sitmun.authentication.ldap.base_dn}") - private String baseDN; - - @Value("${test.ldap.ldif}") - private String ldif; - - @Value("${test.ldap.schema}") - private String schema; - - @Autowired - private MockMvc mvc; - - private InMemoryDirectoryServer directoryServer; - - @BeforeEach - void setupLdapServer() throws LDAPException { - InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.baseDN); - int port = URI.create(url).getPort(); - config.setListenerConfigs( - InMemoryListenerConfig.createLDAPConfig("LDAP", port) - ); - directoryServer = new InMemoryDirectoryServer(config); - directoryServer.applyChangesFromLDIF(schema); - directoryServer.importFromLDIF(false, ldif); - directoryServer.startListening(); - } - - @AfterEach - void shutdownLdapServer() { - directoryServer.shutDown(true); - } - - @Test - @DisplayName("A user that fails in LDAP and exists in SITMUN, must pass.") - void ldapFailureUserDetailsSuccessfulLogin() throws Exception { - UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); - login.setUsername("admin"); - login.setPassword("admin"); - - mvc.perform(post("/api/authenticate") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.asJsonString(login))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id_token").exists()); - } - - @Test - @DisplayName("A user that exists in LDAP and exists in SITMUN, must pass.") - void successfulLdapLogin() throws Exception { - UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); - login.setUsername("internal"); - login.setPassword("password12"); - - mvc.perform(post("/api/authenticate") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.asJsonString(login))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id_token").exists()); - } - - @Test - @DisplayName("A user that exists in LDAP and does not exist in SITMUN, must fail.") - void successfulLdapLoginNoExistsSitmun() throws Exception { - UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); - login.setUsername("nositmunuser"); - login.setPassword("nositmunpassword"); - - mvc.perform(post("/api/authenticate") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.asJsonString(login))) - .andExpect(status().isUnauthorized()); - } - -} diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java deleted file mode 100644 index 1e24fb6b..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.sitmun.authentication.controller; - -import org.junit.jupiter.api.Test; -import org.sitmun.authentication.dto.UserPasswordAuthenticationRequest; -import org.sitmun.test.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -class AuthenticationControllerTest { - - @Autowired - private MockMvc mvc; - - @Test - void successfulLogin() throws Exception { - UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); - login.setUsername("admin"); - login.setPassword("admin"); - - mvc.perform(post("/api/authenticate") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.asJsonString(login))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id_token").exists()); - } - - @Test - void loginFailure() throws Exception { - UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); - login.setUsername("admin"); - login.setPassword("other"); - - mvc.perform(post("/api/authenticate") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.asJsonString(login))) - .andExpect(status().isUnauthorized()); - } -} diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationControllerTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationControllerTest.java deleted file mode 100644 index 54b001f8..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.sitmun.authorization.controller; - -import org.junit.jupiter.api.Test; -import org.sitmun.test.URIConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; - -import static org.hamcrest.Matchers.*; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -class ClientConfigurationApplicationControllerTest { - - @Value("${spring.data.rest.default-page-size}") - private int pageSize; - - @Autowired - private MockMvc mvc; - - @Test - void readPublicUser() throws Exception { - mvc.perform(get(URIConstants.CONFIG_CLIENT_APPLICATION_URI)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.content", hasSize(1))) - .andExpect(jsonPath("$.content[*].title", hasItem("SITMUN - Consulta municipal"))); - } - - @Test - void readOtherUser() throws Exception { - mvc.perform(get(URIConstants.CONFIG_CLIENT_APPLICATION_URI) - .with(user("user12")) - ) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.content", hasSize(3))) - .andExpect(jsonPath("$.size", is(pageSize))) - .andExpect(jsonPath("$.number", is(0))) - .andExpect(jsonPath("$.totalPages", is(1))) - .andExpect(jsonPath("$.content[*].title", containsInAnyOrder("SITMUN - Consulta municipal", "SITMUN - Consulta provincial", "SITMUN - Consulta supramunicipal"))); - } - - - @Test - void readOtherUserWithPagination() throws Exception { - mvc.perform(get(URIConstants.CONFIG_CLIENT_APPLICATION_URI + "?size=1&page=1") - .with(user("user12")) - ) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.content", hasSize(1))) - .andExpect(jsonPath("$.size", is(1))) - .andExpect(jsonPath("$.number", is(1))) - .andExpect(jsonPath("$.totalPages", is(3))); - } - - @Test - void readOtherUserWithPaginationOutOfBounds() throws Exception { - mvc.perform(get(URIConstants.CONFIG_CLIENT_APPLICATION_URI + "?size=1&page=3") - .with(user("user12")) - ) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.content").isEmpty()) - .andExpect(jsonPath("$.size", is(1))) - .andExpect(jsonPath("$.number", is(3))) - .andExpect(jsonPath("$.totalPages", is(3))); - } -} diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ProxyConfigurationControllerTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ProxyConfigurationControllerTest.java deleted file mode 100644 index ff9f145c..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/ProxyConfigurationControllerTest.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.sitmun.authorization.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.sitmun.authorization.dto.ConfigProxyRequest; -import org.sitmun.infrastructure.security.service.JsonWebTokenService; -import org.sitmun.test.URIConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.Date; -import java.util.HashMap; - -import static org.sitmun.infrastructure.security.filter.ProxyTokenFilter.X_SITMUN_PROXY_KEY; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -class ProxyConfigurationControllerTest { - - @Autowired - private MockMvc mvc; - - @Autowired - JsonWebTokenService jsonWebTokenService; - - @Value("${security.authentication.middleware.secret}") - private String secret; - - String getUserToken() { - return jsonWebTokenService.generateToken("admin", new Date()); - } - - /** - * Test a proxy configuration service for database connection with public user - */ - @Test - void readConnectionPublicUser() throws Exception { - - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(0).type("SQL").typeId(3279).method("GET").build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.uri").value("jdbc:database:@host:schema2")); - } - - /** - * Test a proxy configuration service for database connection with user token - */ - @Test - void readConnectionOtherUser() throws Exception { - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(0).type("SQL").typeId(3279).method("GET").token(getUserToken()).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.uri").value("jdbc:database:@host:schema2")); - } - - /** - * Test a proxy configuration service for service with public user - */ - @Test - void readServicePublicUser() throws Exception { - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(0).type("GEO").typeId(85) - .method("GET").parameters(new HashMap<>()).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.uri") - .value("http://sitmun.diba.cat/arcgis/services/PRIVAT/MUNI_DB_BASE/MapServer/WMSServer")) - .andExpect(jsonPath("$.payload.parameters.info_format").value("text/xml")) - .andExpect(jsonPath("$.payload.parameters.feature_count").value("5")) - .andExpect(jsonPath("$.payload.parameters.format").value("image/png8")) - .andExpect(jsonPath("$.payload.parameters.transparent").value("TRUE")) - .andExpect(jsonPath("$.payload.parameters.radius").value("5")); - } - - /** - * Test a proxy configuration service for database connection without sitmun - * proxy key - */ - @Test - void proxyUnauthorized() throws Exception { - - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(0).type("SQL").typeId(3279).method("GET").build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .content(json)) - .andExpect(status().isUnauthorized()); - } - - /** - * Test a proxy configuration service for database connection with pagination - */ - @Test - void readConnectionWithPagination() throws Exception { - HashMap parameters = new HashMap<>(); - parameters.put("OFFSET", "100"); - parameters.put("LIMIT", "100"); - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(0).type("SQL").typeId(3293) - .method("GET").parameters(parameters).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.sql").value("SELECT * FROM EXAMPLE LIMIT 100 OFFSET 100")); - } - - @Test - void readConnectionWithFixedFilters() throws Exception { - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(1).type("SQL").typeId(3280) - .method("GET").token(getUserToken()).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.sql") - .value("SELECT * FROM EXAMPLE WHERE USER_ID=1 AND TERR_ID=1 AND APP_ID=1 AND TERR_COD=80008")); - } - - @Test - void readConnectionWithVaryFilters() throws Exception { - HashMap parameters = new HashMap<>(); - parameters.put("columnA", "123"); - parameters.put("columnB", "valueB"); - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(1).type("SQL").typeId(3293) - .method("GET").parameters(parameters).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.payload.sql") - .value("SELECT * FROM EXAMPLE WHERE columnA=123 AND columnB='valueB'")); - } - - @Test - void readConnectionWithFixedAndVaryFilters() throws Exception { - HashMap parameters = new HashMap<>(); - parameters.put("columnA", "123"); - ConfigProxyRequest configProxyRequestBuilder = ConfigProxyRequest.builder() - .appId(1).terId(1).type("SQL").typeId(3294) - .method("GET").parameters(parameters).token(getUserToken()).build(); - - String json = new ObjectMapper().writeValueAsString(configProxyRequestBuilder); - - mvc.perform(post(URIConstants.CONFIG_PROXY_URI) - .contentType(MediaType.APPLICATION_JSON) - .header(X_SITMUN_PROXY_KEY, secret) - .content(json)) - .andExpect(status().isOk()) - .andExpect( - jsonPath("$.payload.sql").value("SELECT * FROM EXAMPLE WHERE TERR_COD=80008 AND columnA=123")); - } -} diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationApplicationControllerTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationApplicationControllerTest.java deleted file mode 100644 index d5615c68..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationApplicationControllerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.sitmun.authorization.controller; - -import org.junit.jupiter.api.Test; -import org.sitmun.test.URIConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -@SpringBootTest -@AutoConfigureMockMvc -@Deprecated -class WorkspaceConfigurationApplicationControllerTest { - - @Autowired - private MockMvc mvc; - - @Test - void readPublicUser() throws Exception { - mvc.perform(get(URIConstants.WORKSPACE_APPLICATION_URI, 1, 41)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.territory.name").value("Argentona")) - .andExpect(jsonPath("$.application.title").value("SITMUN - Consulta municipal")) - .andExpect(jsonPath("$.roles[*].id", containsInAnyOrder(10))); - } - - @Test - void readOtherUser() throws Exception { - mvc.perform(get(URIConstants.WORKSPACE_APPLICATION_URI, 1, 41) - .with(user("user12")) - ) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.territory.name").value("Argentona")) - .andExpect(jsonPath("$.application.title").value("SITMUN - Consulta municipal")) - .andExpect(jsonPath("$.roles[*].id", containsInAnyOrder(14, 17))); - } - -} diff --git a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationControllerTest.java b/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationControllerTest.java deleted file mode 100644 index ae20bf2f..00000000 --- a/deploy/heroku-dev-full/src/test/java/org/sitmun/authorization/controller/WorkspaceConfigurationControllerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.sitmun.authorization.controller; - -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.sitmun.infrastructure.security.service.JsonWebTokenService; -import org.sitmun.test.URIConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpHeaders; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.Date; - -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -@SpringBootTest -@AutoConfigureMockMvc -@Deprecated -class WorkspaceConfigurationControllerTest { - - @Autowired - private JsonWebTokenService jsonWebTokenService; - - @Autowired - private MockMvc mvc; - - @Test - void readPublicUser() throws Exception { - mvc.perform(get(URIConstants.WORKSPACE_URI)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.territories[*].userConfigurations[*].role.applications[*]", Matchers.hasSize(7))); - } - - @Test - void readOtherUser() throws Exception { - mvc.perform(get(URIConstants.WORKSPACE_URI) - .with(user("user12")) - ) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.territories[*].userConfigurations[*].role.applications[*]", Matchers.hasSize(465))); - } - - @Test - void readOtherUserWithToken() throws Exception { - mvc.perform(get(URIConstants.WORKSPACE_URI) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + jsonWebTokenService.generateToken("user12", new Date())) - ).andExpect(status().isOk()) - .andExpect(jsonPath("$.territories[*].userConfigurations[*].role.applications[*]", Matchers.hasSize(465))); - } -} diff --git a/deploy/heroku-dev-lite/build.gradle b/deploy/heroku-dev-lite/build.gradle index 2b47bdd9..52ff87c1 100644 --- a/deploy/heroku-dev-lite/build.gradle +++ b/deploy/heroku-dev-lite/build.gradle @@ -57,7 +57,7 @@ dependencies { jacocoTestReport { reports { - xml.enabled true + xml.required.set(true) } } diff --git a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev.yaml b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev.yaml index bd0cb23c..89247c8b 100644 --- a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev.yaml +++ b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev.yaml @@ -109,7 +109,7 @@ databaseChangeLog: name: ROL_NOTE type: STRING - sql: - sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('ROL_ID', 1); + sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('ROL_ID', 2); - loadData: encoding: UTF-8 file: 04_initial_data_dev/STM_GTER_TYP.csv @@ -513,7 +513,7 @@ databaseChangeLog: name: APP_CREATED type: DATETIME - sql: - sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('APP_ID', 4); + sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('APP_ID', 5); - loadData: encoding: UTF-8 file: 04_initial_data_dev/STM_APP_TREE.csv @@ -540,30 +540,30 @@ databaseChangeLog: - column: name: ARO_APPID type: NUMERIC - # - loadData: - # encoding: UTF-8 - # file: 04_initial_data_dev/STM_PAR_APP.csv - # relativeToChangelogFile: true - # tableName: STM_PAR_APP - # usePreparedStatements: true - # columns: - # - column: - # name: PAP_ID - # type: NUMERIC - # - column: - # name: PAP_NAME - # type: STRING - # - column: - # name: PAP_VALUE - # type: STRING - # - column: - # name: PAP_TYPE - # type: STRING - # - column: - # name: PAP_APPID - # type: NUMERIC - # - sql: - # sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('PAP_ID', 39); + - loadData: + encoding: UTF-8 + file: 04_initial_data_dev/STM_PAR_APP.csv + relativeToChangelogFile: true + tableName: STM_PAR_APP + usePreparedStatements: true + columns: + - column: + name: PAP_ID + type: NUMERIC + - column: + name: PAP_NAME + type: STRING + - column: + name: PAP_VALUE + type: STRING + - column: + name: PAP_TYPE + type: STRING + - column: + name: PAP_APPID + type: NUMERIC + - sql: + sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('PAP_ID', 22); - loadData: encoding: UTF-8 file: 04_initial_data_dev/STM_BACKGRD.csv diff --git a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev/STM_GEOINFO.csv b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev/STM_GEOINFO.csv index fc44da6d..a340e06d 100644 --- a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev/STM_GEOINFO.csv +++ b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/04_initial_data_dev/STM_GEOINFO.csv @@ -1,5 +1,5 @@ GEO_ID,GEO_NAME,GEO_LAYERS,GEO_MINSCALE,GEO_MAXSCALE,GEO_ORDER,GEO_TRANSP,GEO_QUERYABL,GEO_QUERYACT,GEO_QUERYLAY,GEO_SERID,GEO_SELECTABL,GEO_SELECTLAY,GEO_LEGENDTIP,GEO_SERSELID,GEO_CREATED,GEO_CONNID,GEO_METAURL,GEO_THEMATIC,GEO_GEOMTYPE,GEO_BLOCKED,GEO_FILTER_GFI,GEO_FILTER_SS -1,WMTS Bases - ICGC- Topo,topo,NULL,NULL,0,NULL,0,0,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,0,0,0 +1,WMTS Bases - ICGC- Topo,topo,NULL,NULL,0,NULL,0,0,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,0,1,1 2,WMTS Bases - ICGC- Orto,orto,NULL,NULL,0,NULL,0,0,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,0,0,0 3,PNOA,OI.OrthoimageCoverage,NULL,NULL,0,NULL,0,0,NULL,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,0,0,0 4,LĂ­mites administrativos,"DTE50_MUN,DTE50_PROV",NULL,NULL,0,NULL,0,0,NULL,3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,0,0,0 diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java index 6aa57deb..d8afc704 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerLdapEnabledTest.java @@ -27,6 +27,7 @@ @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles({"test", "ldap"}) +@DisplayName("Authentication Controller LDAP enabled tests") class AuthenticationControllerLdapEnabledTest { @Value("${sitmun.authentication.ldap.url}") diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java index 1e24fb6b..c7361c03 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authentication/controller/AuthenticationControllerTest.java @@ -1,5 +1,6 @@ package org.sitmun.authentication.controller; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.authentication.dto.UserPasswordAuthenticationRequest; import org.sitmun.test.TestUtils; @@ -15,12 +16,14 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("Authentication Controller basic tests") class AuthenticationControllerTest { @Autowired private MockMvc mvc; @Test + @DisplayName("Admin user must login") void successfulLogin() throws Exception { UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); login.setUsername("admin"); @@ -34,6 +37,7 @@ void successfulLogin() throws Exception { } @Test + @DisplayName("User with wrong credentials must fail") void loginFailure() throws Exception { UserPasswordAuthenticationRequest login = new UserPasswordAuthenticationRequest(); login.setUsername("admin"); diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationTerritoryControllerTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationTerritoryControllerTest.java index a71fce4e..b46a5c1e 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationTerritoryControllerTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationApplicationTerritoryControllerTest.java @@ -34,7 +34,7 @@ void readPublicUser() throws Exception { mvc.perform(get(URIConstants.CONFIG_CLIENT_APPLICATION_TERRITORIES_URI, 1)) .andExpect(status().isOk()) .andExpect(jsonPath("$.content", hasSize(3))) - .andExpect(jsonPath("$.content[*].name", hasItem("Municipio"))); + .andExpect(jsonPath("$.content[*].name", hasItem("Municipio B"))); } @Test @@ -50,9 +50,9 @@ void readOtherUser() throws Exception { .andExpect(jsonPath("$.number", is(0))) .andExpect(jsonPath("$.totalPages", is(1))) .andExpect(jsonPath("$.content[*].name", hasItems( - "Provincia", - "Municipio", - "Otro" + "Provincia A", + "Municipio B", + "Otro C" ))); } @@ -64,9 +64,9 @@ void territoriesAreInAlphabeticOrder() throws Exception { ) .andExpect(status().isOk()) .andExpect(jsonPath("$.content[*].name", containsInRelativeOrder( - "Municipio", - "Otro", - "Provincia" + "Municipio B", + "Otro C", + "Provincia A" ))); } @@ -81,7 +81,7 @@ void readOtherUserWithPagination() throws Exception { .andExpect(jsonPath("$.size", is(1))) .andExpect(jsonPath("$.number", is(1))) .andExpect(jsonPath("$.totalPages", is(3))) - .andExpect(jsonPath("$.content[*].name", hasItem("Otro"))); + .andExpect(jsonPath("$.content[*].name", hasItem("Otro C"))); } @Test diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryDataRestTest.java index f719ec55..4d792798 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryDataRestTest.java @@ -1,6 +1,8 @@ package org.sitmun.domain.application; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; import org.springframework.beans.factory.annotation.Autowired; @@ -9,6 +11,8 @@ import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.MockMvc; +import javax.annotation.Nullable; + import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.matchesPattern; import static org.sitmun.test.DateTimeMatchers.isIso8601DateAndTime; @@ -27,24 +31,18 @@ class ApplicationRepositoryDataRestTest { @Autowired private MockMvc mvc; + @Nullable private MockHttpServletResponse response; - @BeforeEach - public void setup() { - response = null; - } - @Test @DisplayName("POST: minimum set of properties") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void create() throws Exception { response = mvc.perform(post(URIConstants.APPLICATIONS_URI) - .content("{" + + .content('{' + "\"name\":\"test\"," + "\"jspTemplate\":\"test\"," + - "\"type\":\"I\"," + - "\"situationMap\":\"http://localhost/api/cartography-group/132\"" + - "}") + "\"type\":\"I\"" + + '}') .with(user(Fixtures.admin())) ) .andExpect(status().isCreated()) @@ -54,16 +52,13 @@ void create() throws Exception { @Test @DisplayName("POST: createDate is set by the server ") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void createDateValueIsIgnored() throws Exception { response = mvc.perform(post(URIConstants.APPLICATIONS_URI) - .content("{" + + .content('{' + "\"name\":\"test\"," + "\"jspTemplate\":\"test\"," + - "\"type\":\"I\"," + - "\"createdDate\":\"2020-01-01\"," + - "\"situationMap\":\"http://localhost/api/cartography-group/132\"" + - "}") + "\"type\":\"I\"" + + '}') .with(user(Fixtures.admin())) ) .andExpect(status().isCreated()) @@ -73,15 +68,13 @@ void createDateValueIsIgnored() throws Exception { @Test @DisplayName("PUT: createDate can be updated") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void createDateValueCanBeUpdated() throws Exception { response = mvc.perform(post(URIConstants.APPLICATIONS_URI) - .content("{" + + .content('{' + "\"name\":\"test\"," + "\"jspTemplate\":\"test\"," + - "\"type\":\"I\"," + - "\"situationMap\":\"http://localhost/api/cartography-group/132\"" + - "}") + "\"type\":\"I\"" + + '}') .with(user(Fixtures.admin())) ) .andDo(print()) @@ -92,49 +85,18 @@ void createDateValueCanBeUpdated() throws Exception { assertThat(location).isNotNull(); mvc.perform(put(location) - .content("{" + + .content('{' + "\"name\":\"test\"," + "\"jspTemplate\":\"test\"," + "\"type\":\"I\"," + - "\"createdDate\":\"2020-01-01\"," + - "\"situationMap\":\"http://localhost/api/cartography-group/132\"" + - "}") + "\"createdDate\":\"2020-01-01\"" + + '}') .with(user(Fixtures.admin())) ) - .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.createdDate").value("2020-01-01T00:00:00.000+00:00")); } - @Test - @DisplayName("POST: situationMap must point to a CartographyPermission") - void failApplicationWithInvalidMap() throws Exception { - mvc.perform(post(URIConstants.APPLICATIONS_URI) - .content("{" + - "\"name\":\"test\"," + - "\"jspTemplate\":\"test\"," + - "\"type\":\"I\"," + - "\"createdDate\":\"2020-01-01\"," + - "\"situationMap\":\"http://localhost/api/cartography-group/6\"" + - "}") - .with(user(Fixtures.admin())) - ) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); - } - - @Test - @DisplayName("PUT: situationMap must point to a CartographyPermission") - void failUpdateApplicationWithInvalidMap() throws Exception { - mvc.perform(put(URIConstants.APPLICATION_URI_SITUATION_MAP, 1) - .content("http://localhost/api/cartography-group/6") - .contentType("text/uri-list") - .with(user(Fixtures.admin())) - ) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); - } - @AfterEach public void cleanup() throws Exception { if (response != null) { @@ -144,6 +106,7 @@ public void cleanup() throws Exception { .with(user(Fixtures.admin())) ).andExpect(status().isNoContent()); } + response = null; } } } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryTest.java index 85f87275..2326ad1a 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationRepositoryTest.java @@ -4,6 +4,7 @@ import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.domain.application.background.ApplicationBackground; import org.sitmun.domain.application.parameter.ApplicationParameter; @@ -23,6 +24,8 @@ import org.springframework.core.task.TaskExecutor; import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.Date; import java.util.HashSet; @@ -30,6 +33,7 @@ @DataJpaTest +@DisplayName("Application Repository JPA test") class ApplicationRepositoryTest { @Autowired @@ -65,18 +69,17 @@ public void init() { .build(); application.getAvailableRoles().add(rol); - CartographyPermission backgroundMap; - backgroundMap = CartographyPermission.builder() - .name("Background map") - .build(); - cartographyPermissionRepository.save(backgroundMap); + CartographyPermission backgroundMap = CartographyPermission.builder() + .name("Background map") + .build(); + cartographyPermissionRepository.save(backgroundMap); Background background = new Background(); background.setActive(true); background.setDescription(null); background.setName("fondo"); background.setCartographyGroup(backgroundMap); - background.setCreatedDate(new Date()); + background.setCreatedDate(Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant())); backgroundRepository.save(background); ApplicationBackground applicationBackground = new ApplicationBackground(); @@ -94,6 +97,7 @@ public void init() { } @Test + @DisplayName("Create an application") void saveApplication() { assertThat(application.getId()).isNull(); applicationRepository.save(application); @@ -101,6 +105,7 @@ void saveApplication() { } @Test + @DisplayName("Find an application by id") void findOneApplicationById() { assertThat(application.getId()).isNull(); applicationRepository.save(application); @@ -116,6 +121,7 @@ void findOneApplicationById() { } @Test + @DisplayName("Delete an application by id") void deleteApplicationById() { assertThat(application.getId()).isNull(); applicationRepository.save(application); diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationResourceTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationResourceTest.java index 19070b45..1d4cc309 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationResourceTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/ApplicationResourceTest.java @@ -1,7 +1,9 @@ package org.sitmun.domain.application; +import lombok.extern.java.Log; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.domain.application.background.ApplicationBackground; import org.sitmun.domain.application.background.ApplicationBackgroundRepository; @@ -34,6 +36,7 @@ import org.springframework.test.web.servlet.MockMvc; import java.sql.Date; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.ArrayList; @@ -50,6 +53,8 @@ @SpringBootTest @AutoConfigureMockMvc +@Log +@DisplayName("Application Repository Data REST test") class ApplicationResourceTest { private static final String NON_PUBLIC_APPLICATION_NAME = "Non-public Application"; @@ -62,7 +67,6 @@ class ApplicationResourceTest { private static final String PUBLIC_SITUATION_MAP_NAME = "Public Situation Map Name"; private static final String PUBLIC_CARTOGRAPHY_NAME = "Public Cartography Name"; private static final String PUBLIC_TREE_NODE_NAME = "Tree Node Name"; - private static final String TREE_NODE_URI = "http://localhost/api/tree-nodes"; private static final String PUBLIC_SERVICE_NAME = "Public Service Name"; @Autowired ApplicationRepository applicationRepository; @@ -92,7 +96,6 @@ class ApplicationResourceTest { @Autowired private MockMvc mvc; - private Integer appId; private Integer backAppId; private ArrayList trees; private Set services; @@ -131,7 +134,7 @@ public void init() { Tree publicTree = new Tree(); publicTree.setName(PUBLIC_TREE_NAME); trees.add(publicTree); - this.treeRepository.saveAll(trees); + treeRepository.saveAll(trees); publicTree.setAvailableRoles(availableRoles); treeRepository.save(publicTree); @@ -164,7 +167,7 @@ public void init() { cartographies = new HashSet<>(); cartographies.add(publicCartography); - this.cartographyRepository.saveAll(cartographies); + cartographyRepository.saveAll(cartographies); publicCartography = cartographies.iterator().next(); //Cartography availabilities @@ -174,7 +177,7 @@ public void init() { cartographyAvailabilities = new HashSet<>(); cartographyAvailabilities.add(publicCartographyAvailability); - this.cartographyAvailabilityRepository.saveAll(cartographyAvailabilities); + cartographyAvailabilityRepository.saveAll(cartographyAvailabilities); // publicCartographyAvailability = cartographyAvailabilities.iterator().next(); //Tree nodes @@ -184,7 +187,7 @@ public void init() { publicTreeNode.setCartography(publicCartography); publicTreeNode.setTree(publicTree); treeNodes.add(publicTreeNode); - this.treeNodeRepository.saveAll(treeNodes); + treeNodeRepository.saveAll(treeNodes); // publicTreeNode = treeNodes.iterator().next(); //Cartography group @@ -216,12 +219,12 @@ public void init() { .type("I") .jspTemplate("") .build(); - SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM dd, yyyy HH:mm:ss a"); - String dateInString = "Friday, Jun 7, 2013 12:10:56 PM"; + SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM d, yyyy HH:mm:ss a"); try { + String dateInString = "Friday, Jun 7, 2013 12:10:56 PM"; application.setCreatedDate(formatter.parse(dateInString)); - } catch (Exception e) { - e.printStackTrace(); + } catch (ParseException e) { + log.warning("Error parsing date:" + e.getMessage()); } applications.add(application); @@ -251,14 +254,12 @@ public void init() { publicApplication.getTrees().addAll(trees); applicationRepository.save(publicApplication); - appId = applications.get(0).getId(); - //application backgrounds - Set applicationBackgrounds = new HashSet<>(); ApplicationBackground publicApplicationBackground = new ApplicationBackground(); publicApplicationBackground.setBackground(publicBackground); publicApplicationBackground.setApplication(publicApplication); publicApplicationBackground.setOrder(1); + Set applicationBackgrounds = new HashSet<>(); applicationBackgrounds.add(publicApplicationBackground); applicationBackgroundRepository.saveAll(applicationBackgrounds); @@ -303,14 +304,16 @@ public void cleanup() { } @Test + @DisplayName("GET: information about the backgrounds of an application") void getInformationAboutBackgrounds() throws Exception { - mvc.perform(get(URIConstants.APPLICATION_BACKGROUNDS_URI + "/" + backAppId) + mvc.perform(get(URIConstants.APPLICATION_BACKGROUNDS_URI + '/' + backAppId) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.order").value(1)); } @Test + @DisplayName("GET: information about the layers of an application") void getServiceLayersAsPublic() throws Exception { // TODO // ok is expected @@ -320,12 +323,13 @@ void getServiceLayersAsPublic() throws Exception { } @Test - void getApplicationsAsSitumunAdmin() throws Exception { + @DisplayName("GET: information as administrator") + void getApplicationsAsSitmunAdmin() throws Exception { // ok is expected mvc.perform(get(URIConstants.APPLICATIONS_URI) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.applications", hasSize(36))); + .andExpect(jsonPath("$._embedded.applications", hasSize(7))); } } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/parameter/ApplicationParameterRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/parameter/ApplicationParameterRepositoryDataRestTest.java index 5a39e5d7..946f334a 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/parameter/ApplicationParameterRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/application/parameter/ApplicationParameterRepositoryDataRestTest.java @@ -1,5 +1,6 @@ package org.sitmun.domain.application.parameter; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -11,22 +12,26 @@ import static org.hamcrest.Matchers.hasSize; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest @AutoConfigureMockMvc +@DisplayName("Application Parameter Repository Data rest test") class ApplicationParameterRepositoryDataRestTest { @Autowired private MockMvc mvc; @Test - void retrieveAll() throws Exception { - mvc.perform(get(URIConstants.APPLICATION_PARAMETERS_URI_FILTERED, 1, "type", "PRINT_TEMPLATE") + @DisplayName("GET: Retrieve filtered application parameters") + void filteredApplicationParameters() throws Exception { + mvc.perform(get(URIConstants.APPLICATION_PARAMETERS_URI, 1, "type", "PRINT_TEMPLATE") .with(user(Fixtures.admin())) ) + .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.application-parameters", hasSize(4))); } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/background/BackgroundRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/background/BackgroundRepositoryDataRestTest.java index c0f02e3f..c8bd16eb 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/background/BackgroundRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/background/BackgroundRepositoryDataRestTest.java @@ -1,17 +1,20 @@ package org.sitmun.domain.background; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.MockMvc; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import javax.annotation.Nullable; + import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -19,63 +22,53 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("Background Repository Data REST test") class BackgroundRepositoryDataRestTest { @Autowired private MockMvc mvc; + @Nullable + private MockHttpServletResponse response; + @Test - void backgroundIsNotDependentOfBackgroundMap() throws Exception { - String content = "{" + + @DisplayName("POST: minimum set of properties") + void createBackground() throws Exception { + String content = '{' + "\"name\":\"test\"," + "\"description\":\"test\"," + "\"active\":\"true\"" + - "}"; + '}'; - mvc.perform(post(URIConstants.BACKGROUNDS_URI) + response = mvc.perform(post(URIConstants.BACKGROUNDS_URI) .content(content) .with(user(Fixtures.admin())) ) .andExpect(status().isCreated()) - .andReturn(); + .andReturn().getResponse(); } - @Test - void createBackgroundWithMap() throws Exception { - String content = "{" + - "\"name\":\"test\"," + - "\"description\":\"test\"," + - "\"active\":\"true\"," + - "\"cartographyGroup\":\"http://localhost/api/cartography-group/129\"" + - "}"; - String location = mvc.perform(post(URIConstants.BACKGROUNDS_URI) - .content(content) - .with(user(Fixtures.admin())) - ) - .andDo(print()) - .andExpect(status().isCreated()) - .andReturn().getResponse().getHeader("Location"); - - assertNotNull(location); - } @Test + @DisplayName("POST: fail creation when cartography group has invalid background map") void failCreateBackgroundWithInvalidMap() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"description\":\"test\"," + "\"active\":\"true\"," + "\"cartographyGroup\":\"http://localhost/api/cartography-group/1\"" + - "}"; + '}'; mvc.perform(post(URIConstants.BACKGROUNDS_URI) .content(content) .with(user(Fixtures.admin())) ) + .andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); } @Test + @DisplayName("PUT: fail update of cartography group with invalid background map") void failUpdateBackgroundWithInvalidMap() throws Exception { String content = "http://localhost/api/cartography-group/1"; mvc.perform(put(URIConstants.BACKGROUND_URI_CARTOGRAPHY_GROUP, 1) @@ -86,4 +79,17 @@ void failUpdateBackgroundWithInvalidMap() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); } + + @AfterEach + public void cleanup() throws Exception { + if (response != null) { + String location = response.getHeader("Location"); + if (location != null) { + mvc.perform(delete(location) + .with(user(Fixtures.admin())) + ).andExpect(status().isNoContent()); + } + response = null; + } + } } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryDataRestTest.java index 4090387b..e7eb4dc7 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryDataRestTest.java @@ -22,6 +22,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.net.URI; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -105,7 +107,7 @@ public void init() { CartographyAvailability cartographyAvailability1 = new CartographyAvailability(); cartographyAvailability1.setCartography(cartographyWithAvailabilities); cartographyAvailability1.setTerritory(territory); - cartographyAvailability1.setCreatedDate(new Date()); + cartographyAvailability1.setCreatedDate(Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant())); availabilities.add(cartographyAvailability1); cartographyAvailabilityRepository.saveAll(availabilities); @@ -124,7 +126,6 @@ public void after() { @Test @DisplayName("POST: minimum set of properties") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void postCartography() throws Exception { String content = new JSONObject() @@ -181,7 +182,7 @@ void hasTreeNodeListProperty() throws Exception { @Test @DisplayName("GET: has cartography-groups property") void hasAccessToCartographyGroups() throws Exception { - mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI_PERMISSION_URI, 85) + mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI_PERMISSION_URI, 1) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.cartography-groups[*]", hasSize(1))); @@ -229,7 +230,7 @@ void checkIssueSitmunAdminApp41() throws Exception { "\"permissions\":{\"href\":\"https://sitmun-backend-core.herokuapp.com/api/cartographies/724/permissions\"}," + "\"styles\":{\"href\":\"https://sitmun-backend-core.herokuapp.com/api/cartographies/724/styles\"}," + "\"treeNodes\":{\"href\":\"https://sitmun-backend-core.herokuapp.com/api/cartographies/724/treeNodes{?projection}\",\"templated\":true}}" + - "}"; + '}'; mvc.perform(MockMvcRequestBuilders.put(URIConstants.CARTOGRAPHY_URI, 724) .contentType(MediaType.APPLICATION_JSON) .content(badRequest) @@ -244,35 +245,20 @@ void checkIssueSitmunAdminApp41() throws Exception { * @see Github */ @Test - @DisplayName("GET: for Cartography 724 applyFilterXXX are null") + @DisplayName("GET: filters are available in projections") void applyFilterTestDataIsNull() throws Exception { - mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI, 724) + mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI, 1) .contentType(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.applyFilterToGetFeatureInfo", is(true))) .andExpect(jsonPath("$.applyFilterToSpatialSelection", is(true))); - mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI_PROJECTION, 724) + mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHY_URI_PROJECTION, 1) .contentType(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.applyFilterToGetFeatureInfo", is(true))) .andExpect(jsonPath("$.applyFilterToSpatialSelection", is(true))); } - - @Test - @DisplayName("GET: Cartography available per application are different") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") - void getCartographiesAvailableForApplication() throws Exception { - mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHIES_AVAILABLE_URI, 1) - .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.cartographies", hasSize(449))); - - mvc.perform(MockMvcRequestBuilders.get(URIConstants.CARTOGRAPHIES_AVAILABLE_URI, 2) - .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.cartographies", hasSize(500))); - } } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryTest.java index 9cc3d138..4610b010 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/CartographyRepositoryTest.java @@ -1,6 +1,7 @@ package org.sitmun.domain.cartography; import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.infrastructure.persistence.config.LiquibaseConfig; import org.springframework.beans.factory.annotation.Autowired; @@ -12,16 +13,20 @@ import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.TaskExecutor; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.Date; @DataJpaTest +@DisplayName("Cartography Repository JPA test") class CartographyRepositoryTest { @Autowired private CartographyRepository cartographyRepository; @Test + @DisplayName("Save a Cartography") void saveCartography() { Cartography cartography = cartographyBuilder().build(); Assertions.assertThat(cartography.getId()).isNull(); @@ -30,6 +35,7 @@ void saveCartography() { } @Test + @DisplayName("Find a Cartography by id") void findOneCartographyById() { Cartography cartography = cartographyBuilder().build(); Assertions.assertThat(cartography.getId()).isNull(); @@ -39,10 +45,10 @@ void findOneCartographyById() { Assertions.assertThat(cartographyRepository.findById(cartography.getId())).isNotNull(); } - private Cartography.CartographyBuilder cartographyBuilder() { + private static Cartography.CartographyBuilder cartographyBuilder() { return Cartography.builder() .name("Test") - .createdDate(new Date()) + .createdDate(Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant())) .order(0) .queryableFeatureAvailable(true) .queryableFeatureEnabled(true) diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/filter/CartographyFiltersRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/filter/CartographyFiltersRepositoryDataRestTest.java index 0da82f43..9d22e686 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/filter/CartographyFiltersRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/filter/CartographyFiltersRepositoryDataRestTest.java @@ -1,6 +1,6 @@ package org.sitmun.domain.cartography.filter; -import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -18,20 +18,21 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("CartographyFilters Repository Data REST test") class CartographyFiltersRepositoryDataRestTest { @Autowired private MockMvc mvc; @Test - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") + @DisplayName("POST: Create a CartographyFilter") void newCartographyFilterCanBePosted() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"type\":\"C\"," + "\"required\":true," + - "\"cartography\":\"http://localhost/api/cartographies/1228\"" + - "}"; + "\"cartography\":\"http://localhost/api/cartographies/1\"" + + '}'; String location = mvc.perform( post(URIConstants.CARTOGRAPHY_FILTERS_URI) @@ -46,7 +47,7 @@ void newCartographyFilterCanBePosted() throws Exception { mvc.perform(get(location + "/cartography") .with(user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(1228)); + .andExpect(jsonPath("$.id").value(1)); mvc.perform(delete(location) .with(user(Fixtures.admin())) @@ -54,12 +55,13 @@ void newCartographyFilterCanBePosted() throws Exception { } @Test + @DisplayName("POST: No two default CartographyFilter can be created for the same Cartography") void newCartographyFilterRequiresCartographyLink() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"type\":\"C\"," + "\"required\":true" + - "}"; + '}'; mvc.perform( post(URIConstants.CARTOGRAPHY_FILTERS_URI + "?lang=EN") diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/parameter/CartographyParametersRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/parameter/CartographyParametersRepositoryDataRestTest.java index eabb0597..a7f94488 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/parameter/CartographyParametersRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/parameter/CartographyParametersRepositoryDataRestTest.java @@ -1,7 +1,7 @@ package org.sitmun.domain.cartography.parameter; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.springframework.beans.factory.annotation.Autowired; @@ -18,15 +18,16 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("CartographyParameters Repository Data REST test") class CartographyParametersRepositoryDataRestTest { @Autowired private MockMvc mvc; @Test - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") + @DisplayName("POST: Create a CartographyParameter") void newCartographyParametersCanBePosted() throws Exception { - String content = "{\"value\":\"test \",\"name\":\"test\",\"format\":\"I\",\"order\":null,\"type\":\"INFO\",\"status\":\"Pending creation\", \"cartography\":\"http://localhost/api/cartographies/0\"}"; + String content = "{\"value\":\"test \",\"name\":\"test\",\"format\":\"I\",\"order\":null,\"type\":\"INFO\",\"status\":\"Pending creation\", \"cartography\":\"http://localhost/api/cartographies/1\"}"; String location = mvc.perform( post("/api/cartography-parameters") @@ -42,7 +43,7 @@ void newCartographyParametersCanBePosted() throws Exception { mvc.perform(get("/api/cartography-parameters/{id}/cartography", id) .with(user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(0)); + .andExpect(jsonPath("$.id").value(1)); mvc.perform(delete("/api/cartography-parameters/{id}", id) .with(user(Fixtures.admin())) @@ -50,6 +51,7 @@ void newCartographyParametersCanBePosted() throws Exception { } @Test + @DisplayName("POST: new cartography parameter requires a cartography link") void newCartographyParameterRequiresCartographyLink() throws Exception { String content = "{\"value\":\"test \",\"name\":\"test\",\"format\":\"I\",\"order\":null,\"type\":\"INFO\",\"status\":\"Pending creation\"}"; diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestTest.java index 91ecd441..0eb739e9 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestTest.java @@ -1,6 +1,6 @@ package org.sitmun.domain.cartography.permission; -import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -20,12 +20,14 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("CartographyPermissions Repository Data REST test") class CartographyPermissionsRepositoryDataRestTest { @Autowired private MockMvc mvc; @Test + @DisplayName("GET: Retrieve CartographyPermissions by type") void filterType() throws Exception { mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_FILTER, CartographyPermission.TYPE_SITUATION_MAP) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) @@ -35,41 +37,43 @@ void filterType() throws Exception { mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_FILTER, CartographyPermission.TYPE_BACKGROUND_MAP) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.*.*", hasSize(6))) - .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == '" + CartographyPermission.TYPE_BACKGROUND_MAP + "')]", hasSize(6))); + .andExpect(jsonPath("$._embedded.*.*", hasSize(1))) + .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == '" + CartographyPermission.TYPE_BACKGROUND_MAP + "')]", hasSize(1))); mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_FILTER, "C") .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.*.*", hasSize(112))) - .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == 'C')]", hasSize(112))); + .andExpect(jsonPath("$._embedded.*.*", hasSize(1))) + .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == 'C')]", hasSize(1))); } @Test + @DisplayName("GET: Retrieve CartographyPermissions by type") void filterOrType() throws Exception { mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_OR_FILTER, CartographyPermission.TYPE_SITUATION_MAP, "C") .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.*.*", hasSize(113))) + .andExpect(jsonPath("$._embedded.*.*", hasSize(2))) .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == '" + CartographyPermission.TYPE_SITUATION_MAP + "')]", hasSize(1))) - .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == 'C')]", hasSize(112))); + .andExpect(jsonPath("$._embedded.cartography-groups[?(@.type == 'C')]", hasSize(1))); } @Test + @DisplayName("GET: Retrieve roles associated to CartographyPermissions") void rolesOfAPermissions() throws Exception { - mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 6) + mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) ) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.*.*", hasSize(9))); + .andExpect(jsonPath("$._embedded.*.*", hasSize(1))); } @Test - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") + @DisplayName("POST: Create a CartographyPermission") void createPermission() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"type\":\"C\"" + - "}"; + '}'; String location = mvc.perform(post(URIConstants.CARTOGRAPHY_PERMISSIONS_URI) .content(content) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) @@ -79,10 +83,10 @@ void createPermission() throws Exception { assertNotNull(location); - String changedContent = "{" + + String changedContent = '{' + "\"name\":\"test2\"," + "\"type\":\"M\"" + - "}"; + '}'; mvc.perform(put(location).content(changedContent) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) @@ -94,39 +98,43 @@ void createPermission() throws Exception { } @Test + @DisplayName("PUT: cartography permission type cannot be updated when it is a situation map") void cantChangeTypeWhenInUseAsSituationMap() throws Exception { - String changedContent = "{" + + String changedContent = '{' + "\"name\":\"test\"," + "\"type\":\"C\"" + - "}"; - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132).content(changedContent) + '}'; + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 3).content(changedContent) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) ).andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); } @Test + @DisplayName("PUT: cartography permission type cannot be updated when it is a background map") void cantChangeTypeWhenInUseAsBackgroundMap() throws Exception { - String changedContent = "{" + + String changedContent = '{' + "\"name\":\"test\"," + "\"type\":\"C\"" + - "}"; - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 129).content(changedContent) + '}'; + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 2).content(changedContent) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) ).andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors[0].invalidValue").value("C")); } @Test + @DisplayName("GET: Retrieve all background maps") void retrieveAllBackgroundMaps() throws Exception { mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_FILTER, CartographyPermission.TYPE_BACKGROUND_MAP) .with(user(Fixtures.admin()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.*.*", hasSize(6))) - .andExpect(jsonPath("$._embedded.cartography-groups", hasSize(6))); + .andExpect(jsonPath("$._embedded.*.*", hasSize(1))) + .andExpect(jsonPath("$._embedded.cartography-groups", hasSize(1))); } @Test + @DisplayName("GET: Retrieve all situation maps") void retrieveAllSituationMaps() throws Exception { mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSIONS_URI_FILTER, CartographyPermission.TYPE_SITUATION_MAP) .with(user(Fixtures.admin()))) diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestUpdateTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestUpdateTest.java index 7a4f4f72..18c46402 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestUpdateTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/permission/CartographyPermissionsRepositoryDataRestUpdateTest.java @@ -3,6 +3,7 @@ import com.jayway.jsonpath.JsonPath; import org.hamcrest.Matchers; import org.json.JSONObject; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -15,6 +16,7 @@ import java.util.stream.Collectors; import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -23,14 +25,16 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("CartographyPermissions Repository Data REST test") class CartographyPermissionsRepositoryDataRestUpdateTest { @Autowired private MockMvc mvc; @Test + @DisplayName("PUT: Update a CartographyPermission") void itemResourceUpdate() throws Exception { - String item = mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132) + String item = mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) @@ -40,12 +44,12 @@ void itemResourceUpdate() throws Exception { String oldName = json.getString("name"); json.put("name", "New name"); - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132).content(json.toString()) + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 1).content(json.toString()) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()); - mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132) + mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) @@ -53,12 +57,12 @@ void itemResourceUpdate() throws Exception { json.put("name", oldName); - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132).content(json.toString()) + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_URI, 1).content(json.toString()) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()); - mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 132) + mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) @@ -66,8 +70,9 @@ void itemResourceUpdate() throws Exception { } @Test + @DisplayName("PUT: Update a CartographyPermission association to roles") void associationResourceUpdate() throws Exception { - String item = mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 132) + String item = mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) @@ -75,14 +80,15 @@ void associationResourceUpdate() throws Exception { @SuppressWarnings("unchecked") List links = (List) JsonPath.parse(item).read("$._embedded.roles[*]._links.self.href", List.class); + assertEquals(1, links.size()); String update = links.stream().skip(1).collect(Collectors.joining("\n")); - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 132).content(update).contentType("text/uri-list") + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1).content(update).contentType("text/uri-list") .with(user(Fixtures.admin())) ); - mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 132) + mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) @@ -90,11 +96,11 @@ void associationResourceUpdate() throws Exception { update = String.join("\n", links); - mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 132).content(update).contentType("text/uri-list") + mvc.perform(put(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1).content(update).contentType("text/uri-list") .with(user(Fixtures.admin())) ); - mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 132) + mvc.perform(get(URIConstants.CARTOGRAPHY_PERMISSION_ROLES_URI, 1) .with(user(Fixtures.admin())) ) .andExpect(status().isOk()) diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/style/CartographyStylesRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/style/CartographyStylesRepositoryDataRestTest.java index 9873d750..e8a7e0cb 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/style/CartographyStylesRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/cartography/style/CartographyStylesRepositoryDataRestTest.java @@ -1,6 +1,5 @@ package org.sitmun.domain.cartography.style; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; @@ -28,13 +27,12 @@ class CartographyStylesRepositoryDataRestTest { @Test @DisplayName("POST: Create a CartographyStyle") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void newCartographyStyleCanBePosted() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"defaultStyle\":false," + - "\"cartography\":\"http://localhost/api/cartographies/1228\"" + - "}"; + "\"cartography\":\"http://localhost/api/cartographies/1\"" + + '}'; String location = mvc.perform( post(URIConstants.CARTOGRAPHY_STYLES_URI) @@ -53,15 +51,14 @@ void newCartographyStyleCanBePosted() throws Exception { @Test @DisplayName("POST: No two default CartographyStyle can be created for the same Cartography") - @Disabled("Potential freeze of active connections. @Transactional may be required in REST controllers.") void twoDefaultStylesCannotBePosted() throws Exception { - String content = "{" + + String content = '{' + "\"name\":\"test\"," + "\"defaultStyle\":true," + - "\"cartography\":\"http://localhost/api/cartographies/1228\"" + - "}"; + "\"cartography\":\"http://localhost/api/cartographies/1\"" + + '}'; - String location = mvc.perform( + String location1 = mvc.perform( post(URIConstants.CARTOGRAPHY_STYLES_URI) .content(content) .with(user(Fixtures.admin())) @@ -69,7 +66,7 @@ void twoDefaultStylesCannotBePosted() throws Exception { .andExpect(jsonPath("$.name").value("test")) .andReturn().getResponse().getHeader("Location"); - assertNotNull(location); + assertNotNull(location1); mvc.perform( post(URIConstants.CARTOGRAPHY_STYLES_URI) @@ -79,7 +76,7 @@ void twoDefaultStylesCannotBePosted() throws Exception { .andExpect(jsonPath("$.errors[0].property").value("defaultStyle")) .andExpect(jsonPath("$.errors[0].message").value("Already a default style exists for the cartography.")); - mvc.perform(delete(location) + mvc.perform(delete(location1) .with(user(Fixtures.admin())) ).andExpect(status().isNoContent()); } diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/configuration/ConfigurationParameterRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/configuration/ConfigurationParameterRepositoryDataRestTest.java index 9aa22a8d..6a761960 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/configuration/ConfigurationParameterRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/configuration/ConfigurationParameterRepositoryDataRestTest.java @@ -1,5 +1,6 @@ package org.sitmun.domain.configuration; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -16,12 +17,14 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("ConfigurationParameter Repository Data REST test") class ConfigurationParameterRepositoryDataRestTest { @Autowired private MockMvc mvc; @Test + @DisplayName("GET: Retrieve all ConfigurationParameters") void retrieveAll() throws Exception { mvc.perform(get(URIConstants.CONFIGURATION_PARAMETERS_URI) .with(SecurityMockMvcRequestPostProcessors.user(Fixtures.admin())) diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryDataRestTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryDataRestTest.java index 4afc70d4..4829397f 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryDataRestTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryDataRestTest.java @@ -1,5 +1,6 @@ package org.sitmun.domain.database; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.test.Fixtures; import org.sitmun.test.URIConstants; @@ -23,6 +24,7 @@ @SpringBootTest @AutoConfigureMockMvc +@DisplayName("DatabaseConnection Repository Data REST test") class DatabaseConnectionRepositoryDataRestTest { @Autowired @@ -32,25 +34,19 @@ class DatabaseConnectionRepositoryDataRestTest { private MockMvc mvc; @Test + @DisplayName("GET: List DatabaseConnection") void tasksLinksExist() throws Exception { mvc.perform(get(URIConstants.CONNECTIONS_URI) .with(user(Fixtures.admin()))) .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.connections.*", hasSize(1))) - .andExpect(jsonPath("$._embedded.connections[*]._links.tasks", hasSize(1))); - } - - @Test - void cartographiesLinksExist() throws Exception { - mvc.perform(get(URIConstants.CONNECTIONS_URI) - .with(user(Fixtures.admin()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.connections.*", hasSize(1))) + .andExpect(jsonPath("$._embedded.connections[*]._links.tasks", hasSize(1))) .andExpect(jsonPath("$._embedded.connections[*]._links.cartographies", hasSize(1))); } @Test + @DisplayName("POST: Create a DatabaseConnection and then update the password") void updateUserPassword() throws Exception { String uri = mvc.perform(post(URIConstants.CONNECTIONS_URI) .contentType(MediaType.APPLICATION_JSON) @@ -92,6 +88,7 @@ void updateUserPassword() throws Exception { } @Test + @DisplayName("POST: Create a DatabaseConnection and then keep the password") void keepUserPassword() throws Exception { String uri = mvc.perform(post(URIConstants.CONNECTIONS_URI) .contentType(MediaType.APPLICATION_JSON) @@ -133,6 +130,7 @@ void keepUserPassword() throws Exception { } @Test + @DisplayName("POST: Create a DatabaseConnection and then clear the password") void clearUserPassword() throws Exception { String uri = mvc.perform(post(URIConstants.CONNECTIONS_URI) .contentType(MediaType.APPLICATION_JSON) diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryIntegrationTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryIntegrationTest.java index 22a9e066..c848db35 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryIntegrationTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/domain/database/DatabaseConnectionRepositoryIntegrationTest.java @@ -7,6 +7,7 @@ import org.json.JSONObject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.sitmun.authentication.dto.AuthenticationResponse; import org.sitmun.authentication.dto.UserPasswordAuthenticationRequest; @@ -34,6 +35,7 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@DisplayName("DatabaseConnection Repository Integration test") class DatabaseConnectionRepositoryIntegrationTest { @Autowired @@ -77,6 +79,7 @@ void cleanup() { } @Test + @DisplayName("GET: List DatabaseConnection") void requestConnections() { HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.AUTHORIZATION, TestUtils.requestAuthorization(restTemplate, port)); @@ -97,41 +100,40 @@ void requestConnections() { @Test void updateConnection() throws JSONException { - JSONObject updatedValueJson = getConnection(2); - assertThat(updatedValueJson.get("user")).isEqualTo("User2"); + JSONObject updatedValueJson = getConnection(1); + assertThat(updatedValueJson.get("user")).isEqualTo("User1"); String auth = getAuthorization(); updatedValueJson.put("user", "User3"); - updatedValueJson.put("user", "User3"); - updateConnection(2, updatedValueJson, auth); + updateConnection(1, updatedValueJson, auth); - assertThat(getConnection(2).get("user")).isEqualTo("User3"); + assertThat(getConnection(1).get("user")).isEqualTo("User3"); - updatedValueJson.put("user", "User2"); - updateConnection(2, updatedValueJson, auth); + updatedValueJson.put("user", "User1"); + updateConnection(1, updatedValueJson, auth); - assertThat(getConnection(2).get("user")).isEqualTo("User2"); + assertThat(getConnection(1).get("user")).isEqualTo("User1"); } @SuppressWarnings({"rawtypes", "unchecked"}) @Test void putCannotUpdateConnectionCartographies() throws JSONException { - JSONObject oldValueJson = getConnectionCartographies(2); + JSONObject oldValueJson = getConnectionCartographies(1); List oldList = getListOfCartographies(oldValueJson); String auth = getAuthorization(); - List newList = Arrays.asList("http://localhost:" + port + "/api/cartographies/1255", - "http://localhost:" + port + "/api/cartographies/1055", - "http://localhost:" + port + "/api/cartographies/1086", - "http://localhost:" + port + "/api/cartographies/1043", - "http://localhost:" + port + "/api/cartographies/1254", - "http://localhost:" + port + "/api/cartographies/154"); + List newList = Arrays.asList("http://localhost:" + port + "/api/cartographies/1", + "http://localhost:" + port + "/api/cartographies/2", + "http://localhost:" + port + "/api/cartographies/3", + "http://localhost:" + port + "/api/cartographies/4", + "http://localhost:" + port + "/api/cartographies/5", + "http://localhost:" + port + "/api/cartographies/6"); - updateConnectionCartograhies(2, newList, auth); + updateConnectionCartograhies(1, newList, auth); - oldValueJson = getConnectionCartographies(2); + oldValueJson = getConnectionCartographies(1); List updatedList = getListOfCartographies(oldValueJson); assertThat(updatedList).containsExactlyInAnyOrderElementsOf(oldList); diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/test/URIConstants.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/test/URIConstants.java index 456a8890..a5f50f11 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/test/URIConstants.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/test/URIConstants.java @@ -8,7 +8,9 @@ public class URIConstants { public static final String APPLICATION_URI = APPLICATIONS_URI + "/{0}"; - public static final String APPLICATION_PARAMETERS_URI_FILTERED = APPLICATION_URI + "/parameters?{1}={2}"; + public static final String APPLICATION_PARAMETERS_URI = APPLICATION_URI + "/parameters"; + + public static final String APPLICATION_PARAMETERS_URI_FILTERED = APPLICATION_PARAMETERS_URI + "?{1}={2}"; public static final String APPLICATION_PROJECTION_VIEW = APPLICATION_URI + "?projection=view"; diff --git a/legacy/build.gradle b/legacy/build.gradle index 5c92c1a4..9b104ac9 100644 --- a/legacy/build.gradle +++ b/legacy/build.gradle @@ -26,7 +26,7 @@ dependencies { jacocoTestReport { reports { - xml.enabled true + xml.required.set(true) } }