diff --git a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterHistorySearchCriteria.java b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterHistorySearchCriteria.java index 1adf981..acddea5 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterHistorySearchCriteria.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterHistorySearchCriteria.java @@ -17,6 +17,11 @@ public class ApplicationParameterHistorySearchCriteria { */ private String applicationId; + /** + * The product name + */ + private String productName; + /** * The application parameter key. */ diff --git a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterSearchCriteria.java b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterSearchCriteria.java index 871d2ec..2316f49 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterSearchCriteria.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ApplicationParameterSearchCriteria.java @@ -17,6 +17,11 @@ public class ApplicationParameterSearchCriteria { */ private String applicationId; + /** + * The product name + */ + private String productName; + /** * The application parameter key. */ diff --git a/src/main/java/org/tkit/onecx/parameters/domain/criteria/KeysSearchCriteria.java b/src/main/java/org/tkit/onecx/parameters/domain/criteria/KeysSearchCriteria.java index 382c13e..a5a2fd0 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/criteria/KeysSearchCriteria.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/criteria/KeysSearchCriteria.java @@ -9,4 +9,6 @@ public class KeysSearchCriteria { private String applicationId; + private String productName; + } diff --git a/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAO.java b/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAO.java index 1fdb6fd..a456e3c 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAO.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAO.java @@ -74,12 +74,13 @@ public List findByApplicationIdAndParameterKeys(String app } } - public Map findAllByApplicationId(String applicationId) { + public Map findAllByProductNameAndApplicationId(String productName, String applicationId) { try { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ApplicationParameter.class); Root root = cq.from(ApplicationParameter.class); cq.where(cb.and( + cb.equal(root.get(ApplicationParameter_.PRODUCT_NAME), productName), cb.equal(root.get(ApplicationParameter_.APPLICATION_ID), applicationId), cb.or( cb.isNotNull(root.get(ApplicationParameter_.SET_VALUE)), @@ -102,6 +103,10 @@ public PageResult searchByCriteria(ApplicationParameterSea Root root = cq.from(ApplicationParameter.class); List predicates = new ArrayList<>(); CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.PRODUCT_NAME)), + stringPattern(criteria.getProductName()))); + } if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.APPLICATION_ID)), stringPattern(criteria.getApplicationId()))); @@ -131,6 +136,10 @@ public PageResult searchAllKeys(KeysSearchCriteria criteria) { Root root = cq.from(ApplicationParameter.class); cq.select(root.get(ApplicationParameter_.KEY)).distinct(true); + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + cq.where(cb.equal(root.get(ApplicationParameter_.PRODUCT_NAME), criteria.getProductName())); + } + if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { cq.where(cb.equal(root.get(ApplicationParameter_.APPLICATION_ID), criteria.getApplicationId())); } diff --git a/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterHistoryDAO.java b/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterHistoryDAO.java index 9615b76..1295178 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterHistoryDAO.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterHistoryDAO.java @@ -43,6 +43,12 @@ public PageResult searchByCriteria(ApplicationParam Root root = cq.from(ApplicationParameterHistory.class); List predicates = new ArrayList<>(); CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); + + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.PRODUCT_NAME)), + stringPattern(criteria.getProductName()))); + } + if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.APPLICATION_ID)), stringPattern(criteria.getApplicationId()))); @@ -78,6 +84,10 @@ public PageResult searchOnlyLatestByCriteria( List predicates = new ArrayList<>(); predicates.add(root.get(AbstractTraceableEntity_.CREATION_DATE).in(maxDateSubquery)); + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + predicates.add(cb.equal(cb.lower(root.get(ApplicationParameter_.PRODUCT_NAME)), + criteria.getProductName().toLowerCase())); + } if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { predicates.add(cb.equal(cb.lower(root.get(ApplicationParameter_.APPLICATION_ID)), criteria.getApplicationId().toLowerCase())); @@ -106,6 +116,11 @@ public List searchCountsByCriteria(ApplicationParame root.get(ApplicationParameterHistory_.COUNT))); List predicates = new ArrayList<>(); + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.PRODUCT_NAME)), + stringPattern(criteria.getProductName()))); + } + if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { predicates.add(cb.like(cb.lower(root.get(ApplicationParameter_.APPLICATION_ID)), stringPattern(criteria.getApplicationId()))); diff --git a/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameter.java b/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameter.java index 86f0a27..6a03957 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameter.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameter.java @@ -15,7 +15,7 @@ @Setter @Entity @Table(name = "APM_APP_PARAM", uniqueConstraints = { - @UniqueConstraint(columnNames = { "APPLICATION_ID", "PARAM_KEY", "TENANT_ID" }) }) + @UniqueConstraint(columnNames = { "APPLICATION_ID", "PRODUCT_NAME", "PARAM_KEY", "TENANT_ID" }) }) @SuppressWarnings("java:S2160") public class ApplicationParameter extends TraceableEntity { @@ -53,6 +53,12 @@ public class ApplicationParameter extends TraceableEntity { @Column(name = "APPLICATION_ID") private String applicationId; + /** + * The product + */ + @Column(name = "PRODUCT_NAME") + private String productName; + /** * The application parameter set value. */ diff --git a/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameterHistory.java b/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameterHistory.java index 0195f9f..4bd4982 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameterHistory.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/models/ApplicationParameterHistory.java @@ -34,6 +34,12 @@ public class ApplicationParameterHistory extends TraceableEntity { @Column(name = "APPLICATION_ID") private String applicationId; + /** + * The product + */ + @Column(name = "PRODUCT_NAME") + private String productName; + /** * The application parameter type. */ diff --git a/src/main/java/org/tkit/onecx/parameters/rs/external/v3/controllers/ParameterRestControllerV3.java b/src/main/java/org/tkit/onecx/parameters/rs/external/v3/controllers/ParameterRestControllerV3.java index 5c4539c..64d6a99 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/external/v3/controllers/ParameterRestControllerV3.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/external/v3/controllers/ParameterRestControllerV3.java @@ -13,7 +13,6 @@ import org.tkit.onecx.parameters.domain.daos.ApplicationParameterHistoryDAO; import org.tkit.onecx.parameters.domain.models.ApplicationParameterHistory; import org.tkit.onecx.parameters.rs.external.v3.mappers.ApplicationParameterHistoryMapper; -import org.tkit.onecx.parameters.rs.internal.mappers.ExceptionMapper; import org.tkit.quarkus.log.cdi.LogService; import gen.org.tkit.onecx.parameters.rs.v3.ExternalApi; @@ -33,23 +32,21 @@ public class ParameterRestControllerV3 implements ExternalApi { @Inject ApplicationParameterHistoryMapper mapper; - @Inject - ExceptionMapper exceptionMapper; - @Override - public Response getApplicationParameters(String appId) { - Map applicationParameters = applicationParameterDAO.findAllByApplicationId(appId); + public Response getApplicationParameters(String productName, String appId) { + Map applicationParameters = applicationParameterDAO.findAllByProductNameAndApplicationId(productName, + appId); return Response.ok(applicationParameters).build(); } @Override - public Response bucketRequest(String appId, ParametersBucketDTOV3 dto) { + public Response bucketRequest(String productName, String appId, ParametersBucketDTOV3 dto) { if (dto == null || dto.getParameters().isEmpty()) { return Response.status(Response.Status.OK).build(); } List items = new ArrayList<>(); dto.getParameters().forEach((key, value) -> items - .add(mapper.mapItem(value, key, dto.getStart(), dto.getEnd(), dto.getInstanceId(), appId, + .add(mapper.mapItem(value, key, dto, productName, appId, value.getCurrentValue()))); historyDAO.create(items); return Response.status(Response.Status.OK).build(); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java b/src/main/java/org/tkit/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java index b293321..fcdcf30 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java @@ -1,7 +1,5 @@ package org.tkit.onecx.parameters.rs.external.v3.mappers; -import java.time.OffsetDateTime; - import org.mapstruct.Mapper; import org.mapstruct.MapperConfig; import org.mapstruct.Mapping; @@ -10,6 +8,7 @@ import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import gen.org.tkit.onecx.parameters.rs.v3.model.ParameterInfoDTOV3; +import gen.org.tkit.onecx.parameters.rs.v3.model.ParametersBucketDTOV3; @Mapper(uses = OffsetDateTimeMapper.class) @MapperConfig(unmappedTargetPolicy = ReportingPolicy.ERROR) @@ -23,6 +22,7 @@ public interface ApplicationParameterHistoryMapper { @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) @Mapping(target = "id", ignore = true) - ApplicationParameterHistory mapItem(ParameterInfoDTOV3 dto, String key, OffsetDateTime start, - OffsetDateTime end, String instanceId, String applicationId, String usedValue); + ApplicationParameterHistory mapItem(ParameterInfoDTOV3 dto, String key, ParametersBucketDTOV3 bucketDTO, String productName, + String applicationId, String usedValue); + } diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterHistoryRestController.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterHistoryRestController.java index e42e830..6466997 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterHistoryRestController.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterHistoryRestController.java @@ -1,7 +1,5 @@ package org.tkit.onecx.parameters.rs.internal.controllers; -import java.util.List; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; @@ -10,9 +8,10 @@ import org.tkit.onecx.parameters.domain.daos.ApplicationParameterHistoryDAO; import org.tkit.onecx.parameters.domain.models.ApplicationParameterHistory; import org.tkit.onecx.parameters.rs.internal.mappers.ApplicationParameterInternalMapper; -import org.tkit.onecx.parameters.rs.internal.mappers.ExceptionMapper; import org.tkit.quarkus.log.cdi.LogService; +import gen.org.tki.onecx.parameters.rs.internal.model.ApplicationParameterHistoryCriteriaDTO; +import gen.org.tki.onecx.parameters.rs.internal.model.ParameterHistoryCountCriteriaDTO; import gen.org.tkit.onecx.parameters.rs.internal.HistoriesApi; @LogService @@ -26,21 +25,16 @@ public class ApplicationParameterHistoryRestController implements HistoriesApi { @Inject ApplicationParameterHistoryDAO historyDAO; - @Inject - ExceptionMapper exceptionMapper; - @Override - public Response getAllApplicationParametersHistoryLatest(String applicationId, String key, Integer pageNumber, - Integer pageSize, List type) { - var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); + public Response getAllApplicationParametersHistoryLatest(ApplicationParameterHistoryCriteriaDTO criteriaDTO) { + var criteria = applicationParameterInternalMapper.map(criteriaDTO); var parametersHistories = historyDAO.searchOnlyLatestByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); } @Override - public Response getAllApplicationParametersHistory(String applicationId, String key, Integer pageNumber, Integer pageSize, - List type) { - var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); + public Response getAllApplicationParametersHistory(ApplicationParameterHistoryCriteriaDTO criteriaDTO) { + var criteria = applicationParameterInternalMapper.map(criteriaDTO); var parametersHistories = historyDAO.searchByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); } @@ -55,9 +49,8 @@ public Response getApplicationParametersHistoryById(String id) { } @Override - public Response getCountsByCriteria(String applicationId, String key, Integer pageNumber, Integer pageSize, - List type) { - var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); + public Response getCountsByCriteria(ParameterHistoryCountCriteriaDTO criteriaDTO) { + var criteria = applicationParameterInternalMapper.map(criteriaDTO); var counts = historyDAO.searchCountsByCriteria(criteria); var results = applicationParameterInternalMapper.mapCountList(counts); return Response.ok(results).build(); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterRestController.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterRestController.java index 480e0d2..d9bf993 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterRestController.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/ApplicationParameterRestController.java @@ -56,17 +56,19 @@ public Response getAllApplications() { } @Override - public Response getAllKeys(String applicationId) { - var criteria = applicationParameterInternalMapper.map(applicationId); + public Response getAllKeys(String applicationId, String productName) { + var criteria = applicationParameterInternalMapper.map(productName, applicationId); var keys = applicationParameterDAO.searchAllKeys(criteria); return Response.ok(applicationParameterInternalMapper.keys(keys)).build(); } @Override - public Response getAllApplicationParameters(String applicationId, String key, String name, Integer pageNumber, + public Response getAllApplicationParameters(String applicationId, String productName, String key, String name, + Integer pageNumber, Integer pageSize, List type) { - var criteria = applicationParameterInternalMapper.map(applicationId, key, name, pageNumber, pageSize, type); + var criteria = applicationParameterInternalMapper.map(productName, applicationId, key, name, pageNumber, pageSize, + type); var parameters = applicationParameterDAO.searchByCriteria(criteria); ApplicationParameterPageResultDTO results = applicationParameterInternalMapper.map(parameters); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java index 7dcd70b..b705c82 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java @@ -59,6 +59,7 @@ default ApplicationParameterData create(ApplicationParameterCreateDTO dto, Strin return entity; } + @Mapping(target = "productName", ignore = true) @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) @Mapping(target = "creationUser", ignore = true) diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java index fc82150..0c4bd59 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java @@ -18,7 +18,7 @@ public interface ApplicationParameterInternalMapper { @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) - KeysSearchCriteria map(String applicationId); + KeysSearchCriteria map(String productName, String applicationId); @Mapping(target = "removeStreamItem", ignore = true) KeysPageResultDTO keys(PageResult page); @@ -27,11 +27,14 @@ public interface ApplicationParameterInternalMapper { ApplicationsPageResultDTO apps(PageResult page); @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) - ApplicationParameterHistorySearchCriteria map(String applicationId, String key, Integer pageNumber, Integer pageSize, - List type); + ApplicationParameterHistorySearchCriteria map(ApplicationParameterHistoryCriteriaDTO criteriaDTO); + + @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) + ApplicationParameterHistorySearchCriteria map(ParameterHistoryCountCriteriaDTO criteriaDTO); @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) - ApplicationParameterSearchCriteria map(String applicationId, String key, String name, Integer pageNumber, Integer pageSize, + ApplicationParameterSearchCriteria map(String productName, String applicationId, String key, String name, + Integer pageNumber, Integer pageSize, List type); @Mapping(target = "removeStreamItem", ignore = true) diff --git a/src/main/openapi/openapi-internal.yaml b/src/main/openapi/openapi-internal.yaml index bb6ea59..70257a0 100644 --- a/src/main/openapi/openapi-internal.yaml +++ b/src/main/openapi/openapi-internal.yaml @@ -11,43 +11,16 @@ tags: - name: parameters paths: /histories: - get: + post: tags: - histories description: Find all parameters history operationId: getAllApplicationParametersHistory - parameters: - - name: applicationId - in: query - schema: - description: The application parameter id. - type: string - - name: key - in: query - schema: - description: The application parameter key. - type: string - - name: pageNumber - in: query - schema: - format: int32 - description: The number of page. - default: 0 - type: integer - - name: pageSize - in: query - schema: - format: int32 - description: The size of page - default: 100 - type: integer - - name: type - in: query - schema: - description: The application parameter type. - type: array - items: - type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ApplicationParameterHistoryCriteria' responses: "200": description: OK @@ -56,43 +29,16 @@ paths: schema: $ref: '#/components/schemas/ApplicationParameterHistoryPageResult' /histories/counts: - get: + post: tags: - histories description: Get creation dates and counts by criteria operationId: getCountsByCriteria - parameters: - - name: applicationId - in: query - schema: - description: The application parameter id. - type: string - - name: key - in: query - schema: - description: The application parameter key. - type: string - - name: pageNumber - in: query - schema: - format: int32 - description: The number of page. - default: 0 - type: integer - - name: pageSize - in: query - schema: - format: int32 - description: The size of page - default: 100 - type: integer - - name: type - in: query - schema: - description: The application parameter type. - type: array - items: - type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ParameterHistoryCountCriteria' responses: "200": description: OK @@ -103,43 +49,16 @@ paths: items: $ref: '#/components/schemas/ParameterHistoryCount' /histories/latest: - get: + post: tags: - histories description: Find all parameters history latest operationId: getAllApplicationParametersHistoryLatest - parameters: - - name: applicationId - in: query - schema: - description: The application parameter id. - type: string - - name: key - in: query - schema: - description: The application parameter key. - type: string - - name: pageNumber - in: query - schema: - format: int32 - description: The number of page. - default: 0 - type: integer - - name: pageSize - in: query - schema: - format: int32 - description: The size of page - default: 100 - type: integer - - name: type - in: query - schema: - description: The application parameter type. - type: array - items: - type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ApplicationParameterHistoryCriteria' responses: "200": description: OK @@ -180,6 +99,11 @@ paths: schema: description: The application parameter id. type: string + - name: productName + in: query + schema: + description: The product name. + type: string - name: key in: query schema: @@ -269,6 +193,11 @@ paths: schema: description: The application parameter id. type: string + - name: productName + in: query + schema: + description: The product name. + type: string responses: "200": description: OK @@ -358,6 +287,8 @@ components: type: string applicationId: type: string + productName: + type: string value: type: string type: @@ -398,6 +329,8 @@ components: type: string applicationId: type: string + productName: + type: string key: type: string setValue: @@ -436,6 +369,8 @@ components: type: string applicationId: type: string + productName: + type: string key: type: string usedValue: @@ -446,6 +381,27 @@ components: type: string instanceId: type: string + ApplicationParameterHistoryCriteria: + type: object + properties: + applicationId: + type: string + productName: + type: string + key: + type: string + pageNumber: + type: integer + format: int32 + default: 0 + pageSize: + type: integer + format: int32 + default: 100 + type: + type: array + items: + type: string ApplicationParameterHistoryPageResult: type: object properties: @@ -540,6 +496,27 @@ components: type: array items: type: string + ParameterHistoryCountCriteria: + type: object + properties: + applicationId: + type: string + productName: + type: string + key: + type: string + pageNumber: + format: int32 + default: 0 + type: integer + pageSize: + format: int32 + default: 100 + type: integer + type: + type: array + items: + type: string ParameterHistoryCount: type: object properties: diff --git a/src/main/openapi/openapi-v3.yaml b/src/main/openapi/openapi-v3.yaml index 38176a6..5ff4c74 100644 --- a/src/main/openapi/openapi-v3.yaml +++ b/src/main/openapi/openapi-v3.yaml @@ -9,13 +9,18 @@ servers: tags: - name: external paths: - /v3/{appId}/history: + /v3/{productName}/{appId}/history: post: tags: - external description: Create Bucket request operationId: bucketRequest parameters: + - name: productName + in: path + required: true + schema: + type: string - name: appId in: path required: true @@ -35,13 +40,18 @@ paths: $ref: '#/components/schemas/ParametersBucket' "404": description: Not Found - /v3/{appId}/parameters: + /v3/{productName}/{appId}/parameters: get: tags: - external description: Get parameters by application id operationId: getApplicationParameters parameters: + - name: productName + in: path + required: true + schema: + type: string - name: appId in: path required: true diff --git a/src/main/resources/db/24-04-2024-multi-tenancy.xml b/src/main/resources/db/24-04-2024-multi-tenancy.xml index b1f5312..d936f90 100644 --- a/src/main/resources/db/24-04-2024-multi-tenancy.xml +++ b/src/main/resources/db/24-04-2024-multi-tenancy.xml @@ -11,5 +11,13 @@ + + + + + + + + diff --git a/src/test/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAOExceptionTest.java b/src/test/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAOExceptionTest.java index 90516d8..a34e2a5 100644 --- a/src/test/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAOExceptionTest.java +++ b/src/test/java/org/tkit/onecx/parameters/domain/daos/ApplicationParameterDAOExceptionTest.java @@ -51,7 +51,7 @@ void findByApplicationIdAndParameterKeysTest() { @Test void findAllByApplicationIdTest() { - var exc = Assertions.assertThrows(DAOException.class, () -> dao.findAllByApplicationId(null)); + var exc = Assertions.assertThrows(DAOException.class, () -> dao.findAllByProductNameAndApplicationId(null, null)); Assertions.assertEquals(ApplicationParameterDAO.ErrorKeys.FIND_ALL_PARAMETERS_BY_APPLICATION_ID_FAILED, exc.key); } diff --git a/src/test/java/org/tkit/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java b/src/test/java/org/tkit/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java index 469476a..37747ef 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java @@ -27,6 +27,7 @@ class ParameterRestControllerV3Test extends AbstractTest { void shouldNotFindParametersWithGivenApplicationId() { Map applicationParameters = given() .when() + .pathParam("productName", "not-exist") .pathParam("appId", "not-exist") .get("parameters") .then() @@ -43,6 +44,7 @@ void shouldReturnImportValueParameter() { Map applicationParameters = given() .when() .contentType(APPLICATION_JSON) + .pathParam("productName", "import-product") .pathParam("appId", "import-app") .get("parameters") .then() @@ -59,6 +61,7 @@ void shouldReturnImportValueParameter() { void shouldReturnParameter() { Map applicationParameters = given() .when() + .pathParam("productName", "access-mgmt-product") .pathParam("appId", "access-mgmt") .get("parameters") .then() @@ -75,6 +78,7 @@ void shouldReturnParameter() { void shouldNotReturnParameterWithNullSetValue() { JsonPath applicationParameters = given() .when() + .pathParam("productName", "access-mgmt-product") .pathParam("appId", "access-mgmt") .get("parameters") .then() @@ -99,12 +103,14 @@ void shouldCreateNewParameter() { given() .contentType(APPLICATION_JSON) .body(parametersBucketDTO) + .pathParam("productName", "new-product") .pathParam("appId", "new-application") .post("history") .then() .statusCode(Response.Status.OK.getStatusCode()); Map applicationParameters = given() .when() + .pathParam("productName", "new-product") .pathParam("appId", "new-application") .get("parameters") .then() @@ -128,6 +134,7 @@ void shouldUpdateParameters() { given() .contentType(APPLICATION_JSON) .body(parametersBucketDTO) + .pathParam("productName", "access-mgmt-product") .pathParam("appId", "access-mgmt") .post("history") .then() @@ -138,6 +145,7 @@ void shouldUpdateParameters() { void bucketRequestEmptyDTO() { given() .contentType(APPLICATION_JSON) + .pathParam("productName", "test") .pathParam("appId", "test") .post("history") .then() @@ -150,6 +158,7 @@ void bucketRequestNoParametersDTO() { given() .contentType(APPLICATION_JSON) .body(parametersBucketDTO) + .pathParam("productName", "test") .pathParam("appId", "test") .post("history") .then() diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java index e99530e..3889e74 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java @@ -3,7 +3,7 @@ import static io.restassured.RestAssured.given; import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; -import java.util.Map; +import java.util.List; import java.util.stream.Stream; import jakarta.ws.rs.core.Response; @@ -17,8 +17,10 @@ import org.tkit.onecx.parameters.test.AbstractTest; import org.tkit.quarkus.test.WithDBData; +import gen.org.tki.onecx.parameters.rs.internal.model.ApplicationParameterHistoryCriteriaDTO; import gen.org.tki.onecx.parameters.rs.internal.model.ApplicationParameterHistoryDTO; import gen.org.tki.onecx.parameters.rs.internal.model.ApplicationParameterHistoryPageResultDTO; +import gen.org.tki.onecx.parameters.rs.internal.model.ParameterHistoryCountCriteriaDTO; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; @@ -30,7 +32,9 @@ class ApplicationParameterHistoryRestControllerTest extends AbstractTest { @Test void shouldFindAllParametersHistoryWithoutCriteria() { var pageResultDTO = given() - .get() + .body(new ApplicationParameterHistoryCriteriaDTO()) + .contentType(APPLICATION_JSON) + .post() .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -43,22 +47,26 @@ void shouldFindAllParametersHistoryWithoutCriteria() { static Stream findByCriteriaTestData() { return Stream.of( - Arguments.of(Map.of(), 6), - Arguments.of(Map.of("applicationId", "", "key", "", "type", ""), 0), - Arguments.of(Map.of("applicationId", "app0", "key", "key0", "type", "type0"), 0), - Arguments.of(Map.of("applicationId", "access-mgmt"), 2), - Arguments.of(Map.of("applicationId", "app0"), 0), - Arguments.of(Map.of("applicationId", "app1"), 1), - Arguments.of(Map.of("applicationId", "app2"), 3)); + Arguments.of(new ApplicationParameterHistoryCriteriaDTO(), 6), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("").productName("").key("") + .type(List.of("")), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app0").productName("p0").key("key0") + .type(List.of("type0")), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("access-mgmt") + .productName("access-mgmt-product"), 2), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app1").productName("p1"), 1), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app2").productName("p2"), 3)); } @ParameterizedTest @MethodSource("findByCriteriaTestData") - void shouldFindParametersHistoryByCriteria(Map queryParams, Integer expectedArraySize) { + void shouldFindParametersHistoryByCriteria(ApplicationParameterHistoryCriteriaDTO criteriaDTO, Integer expectedArraySize) { var pageResultDTO = given() .when() - .queryParams(queryParams) - .get() + .body(criteriaDTO) + .contentType(APPLICATION_JSON) + .post() .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -69,23 +77,26 @@ void shouldFindParametersHistoryByCriteria(Map queryParams, Inte static Stream findByCriteriaTestDataQueryLatest() { return Stream.of( - Arguments.of(Map.of(), 0), - Arguments.of(Map.of("applicationId", "access-mgmt"), 0), - Arguments.of(Map.of("applicationId", "", "key", ""), 0), - Arguments.of(Map.of("applicationId", "", "key", "key1"), 0), - Arguments.of(Map.of("applicationId", ""), 0), - Arguments.of(Map.of("applicationId", "app0"), 0), - Arguments.of(Map.of("applicationId", "app1"), 0), - Arguments.of(Map.of("applicationId", "app2"), 0)); + Arguments.of(new ApplicationParameterHistoryCriteriaDTO(), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("access-mgmt") + .productName("access-mgmt-product"), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("").productName("").key(""), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("").productName("").key("key1"), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("").productName(""), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app1").productName("p1"), 0), + Arguments.of(new ApplicationParameterHistoryCriteriaDTO().applicationId("app2").productName("p2"), 0)); } @ParameterizedTest @MethodSource("findByCriteriaTestDataQueryLatest") - void shouldFindParametersHistoryByCriteriaQueryLatest(Map queryParams, Integer expectedArraySize) { + void shouldFindParametersHistoryByCriteriaQueryLatest(ApplicationParameterHistoryCriteriaDTO criteriaDTO, + Integer expectedArraySize) { var pageResultDTO = given() .when() - .queryParams(queryParams) - .get("latest") + .body(criteriaDTO) + .contentType(APPLICATION_JSON) + .post("latest") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -106,15 +117,15 @@ void getApplicationParametersHistoryByIdNoFoundTest() { static Stream getApplicationParametersHistoryByIds() { return Stream.of( - Arguments.of("1", "access-mgmt"), - Arguments.of("2", "access-mgmt"), - Arguments.of("h1", "app1"), - Arguments.of("h2", "app2")); + Arguments.of("1", "access-mgmt", "access-mgmt-product"), + Arguments.of("2", "access-mgmt", "access-mgmt-product"), + Arguments.of("h1", "app1", "p1"), + Arguments.of("h2", "app2", "p2")); } @ParameterizedTest @MethodSource("getApplicationParametersHistoryByIds") - void getApplicationParametersHistoryById(String id, String applicationId) { + void getApplicationParametersHistoryById(String id, String applicationId, String productName) { var result = given() .when() .pathParam("id", id) @@ -127,26 +138,31 @@ void getApplicationParametersHistoryById(String id, String applicationId) { Assertions.assertNotNull(result); Assertions.assertEquals(id, result.getId()); Assertions.assertEquals(applicationId, result.getApplicationId()); + Assertions.assertEquals(productName, result.getProductName()); + } static Stream findCountByCriteriaTestData() { return Stream.of( - Arguments.of(Map.of(), 6), - Arguments.of(Map.of("applicationId", "", "key", ""), 6), - Arguments.of(Map.of("applicationId", "", "key", "key1"), 1), - Arguments.of(Map.of("applicationId", "access-mgmt"), 2), - Arguments.of(Map.of("applicationId", "app0"), 0), - Arguments.of(Map.of("applicationId", "app1"), 1), - Arguments.of(Map.of("applicationId", "app2"), 3)); + Arguments.of(new ParameterHistoryCountCriteriaDTO(), 6), + Arguments.of(new ParameterHistoryCountCriteriaDTO().applicationId("").productName("").key(""), 6), + Arguments.of(new ParameterHistoryCountCriteriaDTO().applicationId("").productName("").key("key1"), 1), + Arguments.of( + new ParameterHistoryCountCriteriaDTO().applicationId("access-mgmt").productName("access-mgmt-product"), + 2), + Arguments.of(new ParameterHistoryCountCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new ParameterHistoryCountCriteriaDTO().applicationId("app1").productName("p1"), 1), + Arguments.of(new ParameterHistoryCountCriteriaDTO().applicationId("app2").productName("p2"), 3)); } @ParameterizedTest @MethodSource("findCountByCriteriaTestData") - void getCountsByCriteriaTest(Map queryParams, Integer expectedArraySize) { + void getCountsByCriteriaTest(ParameterHistoryCountCriteriaDTO criteria, Integer expectedArraySize) { var tmp = given() .when() - .queryParams(queryParams) - .get("counts") + .body(criteria) + .contentType(APPLICATION_JSON) + .post("counts") .then() .statusCode(Response.Status.OK.getStatusCode()) .extract().jsonPath(); diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java index a97e381..912d4f6 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java @@ -60,8 +60,8 @@ void searchAllApplicationsTest() { static Stream findAllKeys() { return Stream.of( Arguments.of(Map.of(), 9), - Arguments.of(Map.of("applicationId", ""), 9), - Arguments.of(Map.of("applicationId", "app1"), 5)); + Arguments.of(Map.of("applicationId", "", "productName", ""), 9), + Arguments.of(Map.of("applicationId", "app1", "productName", "p1"), 5)); } @ParameterizedTest @@ -82,10 +82,11 @@ void searchAllKeysTest(Map queryParams, int expectedArraySize) { static Stream findByCriteriaTestData() { return Stream.of( - Arguments.of(Map.of("applicationId", ""), 9), - Arguments.of(Map.of("applicationId", "access-mgmt"), 2), - Arguments.of(Map.of("applicationId", "incorrect_app"), 0), - Arguments.of(Map.of("applicationId", "incorrect_app", "key", "", "type", "", "name", ""), 0), + Arguments.of(Map.of("applicationId", "", "productName", ""), 9), + Arguments.of(Map.of("applicationId", "access-mgmt", "productName", "access-mgmt-product"), 2), + Arguments.of(Map.of("applicationId", "incorrect_app", "productName", "incorrect-product"), 0), + Arguments.of(Map.of("applicationId", "incorrect_app", "productName", "incorrect-product", "key", "", "type", "", + "name", ""), 0), Arguments.of(Map.of("type", "custom,custom2", "name", "custom"), 0), Arguments.of(Map.of("key", "ENGINE"), 1), Arguments.of(Map.of("key", "incorrect_key"), 0)); @@ -121,6 +122,7 @@ void shouldFindParameterById() { .body().as(ApplicationParameterDTO.class); Assertions.assertNotNull(applicationParameterDTO); Assertions.assertEquals("access-mgmt", applicationParameterDTO.getApplicationId()); + Assertions.assertEquals("access-mgmt-product", applicationParameterDTO.getProductName()); Assertions.assertEquals("ENGINE", applicationParameterDTO.getKey()); Assertions.assertEquals("KOGITO", applicationParameterDTO.getSetValue()); Assertions.assertEquals("Engine", applicationParameterDTO.getName()); @@ -328,25 +330,27 @@ void shouldNotUpdateBooleanParameterWithIncorrectValue(String id, Object wrongVa static Stream createParameterTestInput() { return Stream.of( - Arguments.of("app_10", "description", "key_10", "value_10", null, null, null, null), - Arguments.of("app_10", "description", "key_11", "value_10", "", null, null, null), - Arguments.of("app_10", "description", "key_12", "value_10", " ", null, null, null), - Arguments.of("app_10", "description", "key_13", "value_10", "DAYS", null, null, "DAYS"), - Arguments.of("app_10", "description", "key_14", "value_10", "DAYS", 0, null, "DAYS"), - Arguments.of("app_10", "description", "key_15", "value_10", "DAYS", null, 100, "DAYS"), - Arguments.of("app_10", "description", "key_16", "value_10", "DAYS", 0, 100, "DAYS"), - Arguments.of("app_10", "description", "key_17", "value_10", null, 0, null, null), - Arguments.of("app_10", "description", "key_18", "value_10", null, null, 100, null), - Arguments.of("app_10", "description", "key_19", "value_10", null, 0, 100, null)); + Arguments.of("app_10", "p10", "description", "key_10", "value_10", null, null, null, null), + Arguments.of("app_10", "p10", "description", "key_11", "value_10", "", null, null, null), + Arguments.of("app_10", "p10", "description", "key_12", "value_10", " ", null, null, null), + Arguments.of("app_10", "p10", "description", "key_13", "value_10", "DAYS", null, null, "DAYS"), + Arguments.of("app_10", "p10", "description", "key_14", "value_10", "DAYS", 0, null, "DAYS"), + Arguments.of("app_10", "p10", "description", "key_15", "value_10", "DAYS", null, 100, "DAYS"), + Arguments.of("app_10", "p10", "description", "key_16", "value_10", "DAYS", 0, 100, "DAYS"), + Arguments.of("app_10", "p10", "description", "key_17", "value_10", null, 0, null, null), + Arguments.of("app_10", "p10", "description", "key_18", "value_10", null, null, 100, null), + Arguments.of("app_10", "p10", "description", "key_19", "value_10", null, 0, 100, null)); } @ParameterizedTest @MethodSource("createParameterTestInput") @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) - void createParameterTest(String appId, String desc, String key, String value, String unit, Integer from, Integer to, + void createParameterTest(String appId, String productName, String desc, String key, String value, String unit, Integer from, + Integer to, String checkUnit) { ApplicationParameterCreateDTO dto = new ApplicationParameterCreateDTO(); dto.setApplicationId(appId); + dto.setProductName(productName); dto.setDescription(desc); dto.setKey(key); dto.setValue(value); @@ -372,6 +376,7 @@ void createParameterTest(String appId, String desc, String key, String value, St Assertions.assertNotNull(dto2); Assertions.assertEquals(dto.getApplicationId(), dto2.getApplicationId()); + Assertions.assertEquals(dto.getProductName(), dto2.getProductName()); Assertions.assertEquals(dto.getDescription(), dto2.getDescription()); Assertions.assertEquals(dto.getKey(), dto2.getKey()); Assertions.assertEquals(dto.getValue(), dto2.getSetValue()); @@ -385,6 +390,7 @@ void createParameterTest(String appId, String desc, String key, String value, St void createTwice_Bad_Request_Test() { ApplicationParameterCreateDTO dto = new ApplicationParameterCreateDTO(); dto.setApplicationId("app1"); + dto.setProductName("productName1"); dto.setKey("key1"); given() .body(dto) diff --git a/src/test/resources/data/history-testdata.xml b/src/test/resources/data/history-testdata.xml index 3694b03..3ed7c0b 100644 --- a/src/test/resources/data/history-testdata.xml +++ b/src/test/resources/data/history-testdata.xml @@ -1,14 +1,14 @@ - - - - - - - - + + + + + + + + - - + + \ No newline at end of file diff --git a/src/test/resources/data/parameters-dao-testdata.xml b/src/test/resources/data/parameters-dao-testdata.xml index 02786e2..ef6b5f4 100644 --- a/src/test/resources/data/parameters-dao-testdata.xml +++ b/src/test/resources/data/parameters-dao-testdata.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/src/test/resources/data/parameters-importdata.xml b/src/test/resources/data/parameters-importdata.xml index 9f9e7f5..d05d695 100644 --- a/src/test/resources/data/parameters-importdata.xml +++ b/src/test/resources/data/parameters-importdata.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/src/test/resources/data/parameters-testdata-v2.xml b/src/test/resources/data/parameters-testdata-v2.xml index ff99ee0..f8abf5b 100644 --- a/src/test/resources/data/parameters-testdata-v2.xml +++ b/src/test/resources/data/parameters-testdata-v2.xml @@ -1,9 +1,9 @@ - - - - - + + + + + \ No newline at end of file diff --git a/src/test/resources/data/parameters-testdata.xml b/src/test/resources/data/parameters-testdata.xml index adcedca..cd46969 100644 --- a/src/test/resources/data/parameters-testdata.xml +++ b/src/test/resources/data/parameters-testdata.xml @@ -1,25 +1,25 @@ - - - - - + + + + + - + - - + + - - - + + + - - - - + + + +