diff --git a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterHistorySearchCriteria.java b/src/main/java/org/tkit/onecx/parameters/domain/criteria/HistorySearchCriteria.java similarity index 80% rename from src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterHistorySearchCriteria.java rename to src/main/java/org/tkit/onecx/parameters/domain/criteria/HistorySearchCriteria.java index 84720e1..81fd2ef 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterHistorySearchCriteria.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/criteria/HistorySearchCriteria.java @@ -10,7 +10,7 @@ */ @Getter @Setter -public class ParameterHistorySearchCriteria { +public class HistorySearchCriteria { /** * The application ID. @@ -23,9 +23,9 @@ public class ParameterHistorySearchCriteria { private String productName; /** - * The application parameter key. + * The parameter name. */ - private String key; + private String name; private List type; diff --git a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterSearchCriteria.java b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterSearchCriteria.java index 9924d6f..808c655 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterSearchCriteria.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/criteria/ParameterSearchCriteria.java @@ -4,7 +4,7 @@ import lombok.Setter; /** - * The application parameter search criteria. + * The parameter search criteria. */ @Getter @Setter @@ -21,12 +21,12 @@ public class ParameterSearchCriteria { private String productName; /** - * The application parameter key. + * The parameter key. */ - private String key; - private String name; + private String displayName; + private Integer pageNumber; private Integer pageSize; diff --git a/src/main/java/org/tkit/onecx/parameters/domain/daos/HistoryDAO.java b/src/main/java/org/tkit/onecx/parameters/domain/daos/HistoryDAO.java new file mode 100644 index 0000000..000575c --- /dev/null +++ b/src/main/java/org/tkit/onecx/parameters/domain/daos/HistoryDAO.java @@ -0,0 +1,121 @@ +package org.tkit.onecx.parameters.domain.daos; + +import static org.tkit.quarkus.jpa.utils.QueryCriteriaUtil.addSearchStringPredicate; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.persistence.criteria.*; +import jakarta.transaction.Transactional; + +import org.tkit.onecx.parameters.domain.criteria.HistorySearchCriteria; +import org.tkit.onecx.parameters.domain.models.History; +import org.tkit.onecx.parameters.domain.models.HistoryCountTuple; +import org.tkit.onecx.parameters.domain.models.History_; +import org.tkit.quarkus.jpa.daos.AbstractDAO; +import org.tkit.quarkus.jpa.daos.Page; +import org.tkit.quarkus.jpa.daos.PageResult; +import org.tkit.quarkus.jpa.exceptions.DAOException; +import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; +import org.tkit.quarkus.jpa.models.TraceableEntity_; + +@ApplicationScoped +@Transactional(value = Transactional.TxType.NOT_SUPPORTED, rollbackOn = DAOException.class) +public class HistoryDAO extends AbstractDAO { + + @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = DAOException.class) + public void deleteApplicationHistoryOlderThan(LocalDateTime date) { + try { + CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); + CriteriaDelete cd = deleteQuery(); + Root root = cd.from(History.class); + cd.where(cb.lessThanOrEqualTo(root.get(AbstractTraceableEntity_.CREATION_DATE), date)); + getEntityManager().createQuery(cd).executeUpdate(); + } catch (Exception e) { + throw new DAOException(ErrorKeys.DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, e); + } + } + + public PageResult searchByCriteria(HistorySearchCriteria criteria) { + try { + CriteriaQuery cq = criteriaQuery(); + Root root = cq.from(History.class); + List predicates = new ArrayList<>(); + CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); + + addSearchStringPredicate(predicates, cb, root.get(History_.PRODUCT_NAME), criteria.getProductName()); + addSearchStringPredicate(predicates, cb, root.get(History_.APPLICATION_ID), criteria.getApplicationId()); + addSearchStringPredicate(predicates, cb, root.get(History_.NAME), criteria.getName()); + + if (!criteria.getType().isEmpty()) { + var items = criteria.getType().stream().map(String::toLowerCase).toList(); + predicates.add(cb.lower(root.get(History_.TYPE)).in(items)); + } + if (!predicates.isEmpty()) { + cq.where(cb.and(predicates.toArray(new Predicate[0]))); + } + cq.orderBy(cb.asc(root.get(AbstractTraceableEntity_.CREATION_DATE))); + return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); + } catch (Exception exception) { + throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); + } + } + + public PageResult searchOnlyLatestByCriteria( + HistorySearchCriteria criteria) { + try { + CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(History.class); + Root root = cq.from(History.class); + + Subquery maxDateSubquery = cq.subquery(Number.class); + Root maxDateSubqueryRoot = maxDateSubquery.from(History.class); + maxDateSubquery.select(cb.max(maxDateSubqueryRoot.get(AbstractTraceableEntity_.CREATION_DATE))) + .groupBy(maxDateSubqueryRoot.get(History_.INSTANCE_ID)); + + List predicates = new ArrayList<>(); + predicates.add(root.get(AbstractTraceableEntity_.CREATION_DATE).in(maxDateSubquery)); + addSearchStringPredicate(predicates, cb, root.get(History_.PRODUCT_NAME), criteria.getProductName()); + addSearchStringPredicate(predicates, cb, root.get(History_.APPLICATION_ID), criteria.getApplicationId()); + addSearchStringPredicate(predicates, cb, root.get(History_.NAME), criteria.getName()); + + cq.select(root) + .where(cb.and(predicates.toArray(new Predicate[0]))) + .groupBy(root.get(History_.INSTANCE_ID), root.get(TraceableEntity_.ID)); + + return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); + } catch (Exception exception) { + throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); + } + } + + public List searchCountsByCriteria(HistorySearchCriteria criteria) { + try { + var cb = getEntityManager().getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(HistoryCountTuple.class); + Root root = cq.from(History.class); + cq.select( + cb.construct(HistoryCountTuple.class, root.get(AbstractTraceableEntity_.CREATION_DATE), + root.get(History_.COUNT))); + List predicates = new ArrayList<>(); + + addSearchStringPredicate(predicates, cb, root.get(History_.PRODUCT_NAME), criteria.getProductName()); + addSearchStringPredicate(predicates, cb, root.get(History_.APPLICATION_ID), criteria.getApplicationId()); + addSearchStringPredicate(predicates, cb, root.get(History_.NAME), criteria.getName()); + + if (!predicates.isEmpty()) { + cq.where(cb.and(predicates.toArray(new Predicate[0]))); + } + return em.createQuery(cq).getResultList(); + } catch (Exception exception) { + throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); + } + } + + public enum ErrorKeys { + DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, + FIND_ALL_PARAMETERS_HISTORY_FAILED; + } +} diff --git a/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterDAO.java b/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterDAO.java index 8d3fb1c..7f1e8e3 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterDAO.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterDAO.java @@ -1,5 +1,7 @@ package org.tkit.onecx.parameters.domain.daos; +import static org.tkit.quarkus.jpa.utils.QueryCriteriaUtil.addSearchStringPredicate; + import java.util.*; import java.util.stream.Collectors; @@ -34,7 +36,7 @@ public Map findAllByProductNameAndApplicationId(String productNa return getEntityManager() .createQuery(cq) .getResultStream() - .collect(Collectors.toMap(Parameter::getKey, + .collect(Collectors.toMap(Parameter::getName, p -> p.getValue() != null ? p.getValue() : p.getImportValue())); } catch (Exception e) { @@ -46,22 +48,14 @@ public PageResult searchByCriteria(ParameterSearchCriteria criteria) try { CriteriaQuery cq = criteriaQuery(); Root root = cq.from(Parameter.class); - List predicates = new ArrayList<>(); CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); - if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.PRODUCT_NAME)), - stringPattern(criteria.getProductName()))); - } - if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.APPLICATION_ID)), - stringPattern(criteria.getApplicationId()))); - } - if (criteria.getKey() != null && !criteria.getKey().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.KEY)), stringPattern(criteria.getKey()))); - } - if (criteria.getName() != null && !criteria.getName().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.NAME)), stringPattern(criteria.getName()))); - } + + List predicates = new ArrayList<>(); + addSearchStringPredicate(predicates, cb, root.get(Parameter_.PRODUCT_NAME), criteria.getProductName()); + addSearchStringPredicate(predicates, cb, root.get(Parameter_.APPLICATION_ID), criteria.getApplicationId()); + addSearchStringPredicate(predicates, cb, root.get(Parameter_.NAME), criteria.getName()); + addSearchStringPredicate(predicates, cb, root.get(Parameter_.DISPLAY_NAME), criteria.getDisplayName()); + if (!predicates.isEmpty()) { cq.where(cb.and(predicates.toArray(new Predicate[0]))); } @@ -76,7 +70,7 @@ public PageResult searchAllKeys(KeysSearchCriteria criteria) { var cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(String.class); Root root = cq.from(Parameter.class); - cq.select(root.get(Parameter_.KEY)).distinct(true); + cq.select(root.get(Parameter_.NAME)).distinct(true); if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { cq.where(cb.equal(root.get(Parameter_.PRODUCT_NAME), criteria.getProductName())); @@ -108,10 +102,6 @@ public List searchAllProductNamesAndApplicationIds() { } } - private static String stringPattern(String value) { - return (value.toLowerCase() + "%"); - } - public enum ErrorKeys { FIND_ALL_PARAMETERS_BY_APPLICATION_ID_FAILED, diff --git a/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAO.java b/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAO.java deleted file mode 100644 index efa6fac..0000000 --- a/src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAO.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.tkit.onecx.parameters.domain.daos; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.persistence.criteria.*; -import jakarta.transaction.Transactional; - -import org.tkit.onecx.parameters.domain.criteria.ParameterHistorySearchCriteria; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; -import org.tkit.onecx.parameters.domain.models.ParameterHistoryCountTuple; -import org.tkit.onecx.parameters.domain.models.ParameterHistory_; -import org.tkit.onecx.parameters.domain.models.Parameter_; -import org.tkit.quarkus.jpa.daos.AbstractDAO; -import org.tkit.quarkus.jpa.daos.Page; -import org.tkit.quarkus.jpa.daos.PageResult; -import org.tkit.quarkus.jpa.exceptions.DAOException; -import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; -import org.tkit.quarkus.jpa.models.TraceableEntity_; - -@ApplicationScoped -@Transactional(value = Transactional.TxType.NOT_SUPPORTED, rollbackOn = DAOException.class) -public class ParameterHistoryDAO extends AbstractDAO { - - @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = DAOException.class) - public void deleteApplicationHistoryOlderThan(LocalDateTime date) { - try { - CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); - CriteriaDelete cd = deleteQuery(); - Root root = cd.from(ParameterHistory.class); - cd.where(cb.lessThanOrEqualTo(root.get(AbstractTraceableEntity_.CREATION_DATE), date)); - getEntityManager().createQuery(cd).executeUpdate(); - } catch (Exception e) { - throw new DAOException(ErrorKeys.DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, e); - } - } - - public PageResult searchByCriteria(ParameterHistorySearchCriteria criteria) { - try { - CriteriaQuery cq = criteriaQuery(); - Root root = cq.from(ParameterHistory.class); - List predicates = new ArrayList<>(); - CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); - - if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.PRODUCT_NAME)), - stringPattern(criteria.getProductName()))); - } - - if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.APPLICATION_ID)), - stringPattern(criteria.getApplicationId()))); - } - if (criteria.getKey() != null && !criteria.getKey().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(ParameterHistory_.KEY)), stringPattern(criteria.getKey()))); - } - if (!criteria.getType().isEmpty()) { - predicates.add(cb.lower(root.get(ParameterHistory_.TYPE)).in(toLowerCase(criteria.getType()))); - } - if (!predicates.isEmpty()) { - cq.where(cb.and(predicates.toArray(new Predicate[0]))); - } - cq.orderBy(cb.asc(root.get(AbstractTraceableEntity_.CREATION_DATE))); - return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); - } catch (Exception exception) { - throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); - } - } - - public PageResult searchOnlyLatestByCriteria( - ParameterHistorySearchCriteria criteria) { - try { - CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(ParameterHistory.class); - Root root = cq.from(ParameterHistory.class); - - Subquery maxDateSubquery = cq.subquery(Number.class); - Root maxDateSubqueryRoot = maxDateSubquery.from(ParameterHistory.class); - maxDateSubquery.select(cb.max(maxDateSubqueryRoot.get(AbstractTraceableEntity_.CREATION_DATE))) - .groupBy(maxDateSubqueryRoot.get(ParameterHistory_.INSTANCE_ID)); - - 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(Parameter_.PRODUCT_NAME)), - criteria.getProductName().toLowerCase())); - } - if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { - predicates.add(cb.equal(cb.lower(root.get(Parameter_.APPLICATION_ID)), - criteria.getApplicationId().toLowerCase())); - } - if (criteria.getKey() != null && !criteria.getKey().isEmpty()) { - predicates.add(cb.equal(cb.lower(root.get(ParameterHistory_.KEY)), criteria.getKey().toLowerCase())); - } - - cq.select(root) - .where(cb.and(predicates.toArray(new Predicate[0]))) - .groupBy(root.get(ParameterHistory_.INSTANCE_ID), root.get(TraceableEntity_.ID)); - - return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); - } catch (Exception exception) { - throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); - } - } - - public List searchCountsByCriteria(ParameterHistorySearchCriteria criteria) { - try { - var cb = getEntityManager().getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(ParameterHistoryCountTuple.class); - Root root = cq.from(ParameterHistory.class); - cq.select( - cb.construct(ParameterHistoryCountTuple.class, root.get(AbstractTraceableEntity_.CREATION_DATE), - root.get(ParameterHistory_.COUNT))); - List predicates = new ArrayList<>(); - - if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.PRODUCT_NAME)), - stringPattern(criteria.getProductName()))); - } - - if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(Parameter_.APPLICATION_ID)), - stringPattern(criteria.getApplicationId()))); - } - if (criteria.getKey() != null && !criteria.getKey().isEmpty()) { - predicates.add(cb.like(cb.lower(root.get(ParameterHistory_.KEY)), stringPattern(criteria.getKey()))); - } - if (!predicates.isEmpty()) { - cq.where(cb.and(predicates.toArray(new Predicate[0]))); - } - return em.createQuery(cq).getResultList(); - } catch (Exception exception) { - throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exception); - } - } - - private static String stringPattern(String value) { - return (value.toLowerCase() + "%"); - } - - private static List toLowerCase(List value) { - return value.stream().map(String::toLowerCase).toList(); - } - - public enum ErrorKeys { - DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, - FIND_ALL_PARAMETERS_HISTORY_FAILED; - } -} diff --git a/src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistory.java b/src/main/java/org/tkit/onecx/parameters/domain/models/History.java similarity index 72% rename from src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistory.java rename to src/main/java/org/tkit/onecx/parameters/domain/models/History.java index fa3a0de..fb66153 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistory.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/models/History.java @@ -15,48 +15,48 @@ @Getter @Setter @Entity -@Table(name = "PARAMETER_HISTORY") +@Table(name = "HISTORY") @SuppressWarnings("java:S2160") -public class ParameterHistory extends TraceableEntity { +public class History extends TraceableEntity { @TenantId - @Column(name = "TENANT_ID") + @Column(name = "TENANT_ID", nullable = false) private String tenantId; /** - * The application parameter key. + * The parameter key. */ - @Column(name = "KEY") - private String key; + @Column(name = "NAME", nullable = false) + private String name; /** * The application. */ - @Column(name = "APPLICATION_ID") + @Column(name = "APP_ID", nullable = false) private String applicationId; /** * The product */ - @Column(name = "PRODUCT_NAME") + @Column(name = "PRODUCT_NAME", nullable = false) private String productName; /** - * The application parameter type. + * The parameter type. */ @Column(name = "VALUE_TYPE") private String type; /** - * The application parameter used value. + * The parameter used value. */ - @Column(name = "USED_VALUE", columnDefinition = "varchar(1000)") + @Column(name = "USED_VALUE", columnDefinition = "varchar(5000)") private String usedValue; /** - * The application parameter used value. + * The parameter used value. */ - @Column(name = "DEFAULT_VALUE", columnDefinition = "varchar(1000)") + @Column(name = "DEFAULT_VALUE", columnDefinition = "varchar(5000)") private String defaultValue; /** diff --git a/src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistoryCountTuple.java b/src/main/java/org/tkit/onecx/parameters/domain/models/HistoryCountTuple.java similarity index 75% rename from src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistoryCountTuple.java rename to src/main/java/org/tkit/onecx/parameters/domain/models/HistoryCountTuple.java index 8132c43..d04e9bf 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/models/ParameterHistoryCountTuple.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/models/HistoryCountTuple.java @@ -9,13 +9,13 @@ @Getter @Setter @RegisterForReflection -public class ParameterHistoryCountTuple { +public class HistoryCountTuple { private LocalDateTime creationDate; private Long count; - public ParameterHistoryCountTuple(LocalDateTime creationDate, Long count) { + public HistoryCountTuple(LocalDateTime creationDate, Long count) { this.creationDate = creationDate; this.count = count; } diff --git a/src/main/java/org/tkit/onecx/parameters/domain/models/Parameter.java b/src/main/java/org/tkit/onecx/parameters/domain/models/Parameter.java index b9209fc..7680669 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/models/Parameter.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/models/Parameter.java @@ -12,26 +12,26 @@ @Setter @Entity @Table(name = "PARAMETER", uniqueConstraints = { - @UniqueConstraint(name = "PARAMETER_CONSTRAINT", columnNames = { "KEY", "APPLICATION_ID", "PRODUCT_NAME", + @UniqueConstraint(name = "PARAMETER_CONSTRAINT", columnNames = { "NAME", "APP_ID", "PRODUCT_NAME", "TENANT_ID" }) }) @SuppressWarnings("java:S2160") public class Parameter extends TraceableEntity { @TenantId - @Column(name = "TENANT_ID") + @Column(name = "TENANT_ID", nullable = false) private String tenantId; /** - * The application parameter key. + * The parameter key. */ - @Column(name = "KEY") - private String key; + @Column(name = "NAME", nullable = false) + private String name; /** - * The application parameter name. + * The display parameter name. */ - @Column(name = "NAME") - private String name; + @Column(name = "DISPLAY_NAME") + private String displayName; /** * The name of the parameter as it appears in functional specifications @@ -43,13 +43,13 @@ public class Parameter extends TraceableEntity { /** * The application. */ - @Column(name = "APPLICATION_ID") + @Column(name = "APP_ID", nullable = false) private String applicationId; /** * The product */ - @Column(name = "PRODUCT_NAME") + @Column(name = "PRODUCT_NAME", nullable = false) private String productName; /** diff --git a/src/main/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryService.java b/src/main/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryService.java index a3f3afc..aca5ac9 100644 --- a/src/main/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryService.java +++ b/src/main/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryService.java @@ -7,8 +7,8 @@ import jakarta.transaction.Transactional; import org.tkit.onecx.parameters.domain.config.ParameterConfig; +import org.tkit.onecx.parameters.domain.daos.HistoryDAO; import org.tkit.onecx.parameters.domain.daos.JobDAO; -import org.tkit.onecx.parameters.domain.daos.ParameterHistoryDAO; import org.tkit.onecx.parameters.domain.models.Job; import org.tkit.quarkus.jpa.exceptions.DAOException; @@ -24,7 +24,7 @@ public class MaintenanceHistoryService { ParameterConfig parameterConfig; @Inject - ParameterHistoryDAO dao; + HistoryDAO dao; @Inject JobDAO jobDAO; diff --git a/src/main/java/org/tkit/onecx/parameters/rs/external/v1/controllers/ParameterRestControllerV1.java b/src/main/java/org/tkit/onecx/parameters/rs/external/v1/controllers/ParameterRestControllerV1.java index 8a1838d..df28a5c 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/external/v1/controllers/ParameterRestControllerV1.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/external/v1/controllers/ParameterRestControllerV1.java @@ -12,9 +12,9 @@ import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.server.ServerExceptionMapper; +import org.tkit.onecx.parameters.domain.daos.HistoryDAO; import org.tkit.onecx.parameters.domain.daos.ParameterDAO; -import org.tkit.onecx.parameters.domain.daos.ParameterHistoryDAO; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; +import org.tkit.onecx.parameters.domain.models.History; import org.tkit.onecx.parameters.rs.external.v1.mappers.ExceptionMapperV1; import org.tkit.onecx.parameters.rs.external.v1.mappers.ParameterMapperV1; import org.tkit.quarkus.log.cdi.LogService; @@ -32,7 +32,7 @@ public class ParameterRestControllerV1 implements ParameterApi { ParameterDAO applicationParameterDAO; @Inject - ParameterHistoryDAO historyDAO; + HistoryDAO historyDAO; @Inject ParameterMapperV1 mapper; @@ -55,9 +55,9 @@ public Response bucketRequest(String productName, String appId, ParametersBucket if (dto.getParameters() == null || dto.getParameters().isEmpty()) { return Response.status(Response.Status.NO_CONTENT).build(); } - List items = new ArrayList<>(); - dto.getParameters().forEach((key, value) -> items - .add(mapper.mapItem(value, key, dto, productName, appId, + List items = new ArrayList<>(); + dto.getParameters().forEach((name, value) -> items + .add(mapper.mapItem(value, name, dto, productName, appId, value.getCurrentValue()))); historyDAO.create(items); return Response.status(Response.Status.NO_CONTENT).build(); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/external/v1/mappers/ParameterMapperV1.java b/src/main/java/org/tkit/onecx/parameters/rs/external/v1/mappers/ParameterMapperV1.java index de5d47b..646853d 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/external/v1/mappers/ParameterMapperV1.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/external/v1/mappers/ParameterMapperV1.java @@ -7,7 +7,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; +import org.tkit.onecx.parameters.domain.models.History; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,7 +46,7 @@ public Map mapParameters(Map parameters) { @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) @Mapping(target = "id", ignore = true) - public abstract ParameterHistory mapItem(ParameterInfoDTOV1 dto, String key, ParametersBucketDTOV1 bucketDTO, + public abstract History mapItem(ParameterInfoDTOV1 dto, String name, ParametersBucketDTOV1 bucketDTO, String productName, String applicationId, String usedValue); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/HistoryRestController.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/HistoryRestController.java index 4cfaaa4..2514364 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/HistoryRestController.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/controllers/HistoryRestController.java @@ -5,14 +5,14 @@ import jakarta.transaction.Transactional; import jakarta.ws.rs.core.Response; -import org.tkit.onecx.parameters.domain.daos.ParameterHistoryDAO; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; +import org.tkit.onecx.parameters.domain.daos.HistoryDAO; +import org.tkit.onecx.parameters.domain.models.History; import org.tkit.onecx.parameters.rs.internal.mappers.ParameterMapper; import org.tkit.quarkus.log.cdi.LogService; import gen.org.tkit.onecx.parameters.rs.internal.HistoriesApi; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryCountCriteriaDTO; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryCriteriaDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryCountCriteriaDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryCriteriaDTO; @LogService @ApplicationScoped @@ -23,17 +23,17 @@ public class HistoryRestController implements HistoriesApi { ParameterMapper applicationParameterInternalMapper; @Inject - ParameterHistoryDAO historyDAO; + HistoryDAO historyDAO; @Override - public Response getAllParametersHistoryLatest(ParameterHistoryCriteriaDTO criteriaDTO) { + public Response getAllParametersHistoryLatest(HistoryCriteriaDTO criteriaDTO) { var criteria = applicationParameterInternalMapper.map(criteriaDTO); var parametersHistories = historyDAO.searchOnlyLatestByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); } @Override - public Response getAllParametersHistory(ParameterHistoryCriteriaDTO criteriaDTO) { + public Response getAllParametersHistory(HistoryCriteriaDTO criteriaDTO) { var criteria = applicationParameterInternalMapper.map(criteriaDTO); var parametersHistories = historyDAO.searchByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); @@ -41,7 +41,7 @@ public Response getAllParametersHistory(ParameterHistoryCriteriaDTO criteriaDTO) @Override public Response getParametersHistoryById(String id) { - ParameterHistory parameter = historyDAO.findById(id); + History parameter = historyDAO.findById(id); if (parameter == null) { return Response.status(Response.Status.NOT_FOUND).build(); } @@ -49,7 +49,7 @@ public Response getParametersHistoryById(String id) { } @Override - public Response getCountsByCriteria(ParameterHistoryCountCriteriaDTO criteriaDTO) { + public Response getCountsByCriteria(HistoryCountCriteriaDTO criteriaDTO) { var criteria = applicationParameterInternalMapper.map(criteriaDTO); var counts = historyDAO.searchCountsByCriteria(criteria); var results = applicationParameterInternalMapper.mapCountList(counts); diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/log/ParameterLogParam.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/log/ParameterLogParam.java index 5e79041..37e3031 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/log/ParameterLogParam.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/log/ParameterLogParam.java @@ -14,15 +14,15 @@ public class ParameterLogParam implements LogParam { @Override public List getClasses() { return List.of( - item(10, ParameterHistoryCriteriaDTO.class, x -> { - ParameterHistoryCriteriaDTO d = (ParameterHistoryCriteriaDTO) x; - return ParameterHistoryCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + item(10, HistoryCriteriaDTO.class, x -> { + HistoryCriteriaDTO d = (HistoryCriteriaDTO) x; + return HistoryCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize() + "]"; }), - item(10, ParameterHistoryCountCriteriaDTO.class, x -> { - ParameterHistoryCountCriteriaDTO d = (ParameterHistoryCountCriteriaDTO) x; - return ParameterHistoryCountCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + item(10, HistoryCountCriteriaDTO.class, x -> { + HistoryCountCriteriaDTO d = (HistoryCountCriteriaDTO) x; + return HistoryCountCriteriaDTO.class.getSimpleName() + "[" + d.getPageNumber() + "," + d.getPageSize() + "]"; }), @@ -32,7 +32,7 @@ public List getClasses() { + "]"; }), item(10, ParameterCreateDTO.class, - x -> x.getClass().getSimpleName() + ":" + ((ParameterCreateDTO) x).getKey()), + x -> x.getClass().getSimpleName() + ":" + ((ParameterCreateDTO) x).getName()), item(10, ParameterUpdateDTO.class, x -> x.getClass().getSimpleName())); } diff --git a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ParameterMapper.java b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ParameterMapper.java index d5448fd..ddef0b2 100644 --- a/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ParameterMapper.java +++ b/src/main/java/org/tkit/onecx/parameters/rs/internal/mappers/ParameterMapper.java @@ -8,13 +8,13 @@ import jakarta.inject.Inject; import org.mapstruct.*; +import org.tkit.onecx.parameters.domain.criteria.HistorySearchCriteria; import org.tkit.onecx.parameters.domain.criteria.KeysSearchCriteria; -import org.tkit.onecx.parameters.domain.criteria.ParameterHistorySearchCriteria; import org.tkit.onecx.parameters.domain.criteria.ParameterSearchCriteria; import org.tkit.onecx.parameters.domain.models.ApplicationTuple; +import org.tkit.onecx.parameters.domain.models.History; +import org.tkit.onecx.parameters.domain.models.HistoryCountTuple; import org.tkit.onecx.parameters.domain.models.Parameter; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; -import org.tkit.onecx.parameters.domain.models.ParameterHistoryCountTuple; import org.tkit.quarkus.jpa.daos.PageResult; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; @@ -52,20 +52,20 @@ public List apps(List applicationTuple) { } @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) - public abstract ParameterHistorySearchCriteria map(ParameterHistoryCriteriaDTO criteriaDTO); + public abstract HistorySearchCriteria map(HistoryCriteriaDTO criteriaDTO); @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) - public abstract ParameterHistorySearchCriteria map(ParameterHistoryCountCriteriaDTO criteriaDTO); + public abstract HistorySearchCriteria map(HistoryCountCriteriaDTO criteriaDTO); @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) public abstract ParameterSearchCriteria map(ParameterSearchCriteriaDTO criteriaDTO); @Mapping(target = "removeStreamItem", ignore = true) - public abstract ParameterHistoryPageResultDTO mapHistory(PageResult page); + public abstract HistoryPageResultDTO mapHistory(PageResult page); - public abstract ParameterHistoryDTO mapHistory(ParameterHistory parameterHistory); + public abstract HistoryDTO mapHistory(History parameterHistory); - public abstract List mapCountList(List count); + public abstract List mapCountList(List count); @Mapping(target = "removeStreamItem", ignore = true) public abstract ParameterPageResultDTO map(PageResult page); @@ -101,7 +101,6 @@ public String o2s(Object value) { @Mapping(target = "tenantId", ignore = true) @Mapping(target = "value", source = "value", qualifiedByName = "o2s") @Mapping(target = "persisted", ignore = true) - @Mapping(target = "name", ignore = true) @Mapping(target = "modificationUser", ignore = true) @Mapping(target = "modificationDate", ignore = true) @Mapping(target = "modificationCount", ignore = true) @@ -110,7 +109,7 @@ public String o2s(Object value) { @Mapping(target = "creationUser", ignore = true) @Mapping(target = "creationDate", ignore = true) @Mapping(target = "controlTraceabilityManual", ignore = true) - @Mapping(target = "key", ignore = true) + @Mapping(target = "name", ignore = true) @Mapping(target = "applicationId", ignore = true) @Mapping(target = "productName", ignore = true) public abstract void update(ParameterUpdateDTO dto, @MappingTarget Parameter parameter); @@ -118,7 +117,6 @@ public String o2s(Object value) { @Mapping(target = "tenantId", ignore = true) @Mapping(target = "value", source = "value", qualifiedByName = "o2s") @Mapping(target = "persisted", ignore = true) - @Mapping(target = "name", ignore = true) @Mapping(target = "modificationUser", ignore = true) @Mapping(target = "modificationDate", ignore = true) @Mapping(target = "modificationCount", ignore = true) diff --git a/src/main/openapi/openapi-internal.yaml b/src/main/openapi/openapi-internal.yaml index e99cde5..b3f37c6 100644 --- a/src/main/openapi/openapi-internal.yaml +++ b/src/main/openapi/openapi-internal.yaml @@ -22,14 +22,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ParameterHistoryCriteria' + $ref: '#/components/schemas/HistoryCriteria' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ParameterHistoryPageResult' + $ref: '#/components/schemas/HistoryPageResult' /histories/counts: post: security: @@ -42,7 +42,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ParameterHistoryCountCriteria' + $ref: '#/components/schemas/HistoryCountCriteria' responses: "200": description: OK @@ -51,7 +51,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/ParameterHistoryCount' + $ref: '#/components/schemas/HistoryCount' /histories/latest: post: security: @@ -64,14 +64,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ParameterHistoryCriteria' + $ref: '#/components/schemas/HistoryCriteria' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ParameterHistoryPageResult' + $ref: '#/components/schemas/HistoryPageResult' /histories/{id}: get: security: @@ -92,7 +92,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ParameterHistory' + $ref: '#/components/schemas/History' "404": description: Not Found /parameters/search: @@ -287,7 +287,9 @@ components: ParameterCreate: type: object properties: - key: + name: + type: string + displayName: type: string applicationId: type: string @@ -317,7 +319,7 @@ components: example: 2022-03-10T12:15:50-04:00 modificationUser: type: string - name: + displayName: type: string description: type: string @@ -325,13 +327,13 @@ components: type: string productName: type: string - key: + name: type: string value: type: object importValue: type: object - ParameterHistory: + History: type: object properties: id: @@ -355,7 +357,7 @@ components: type: string productName: type: string - key: + name: type: string usedValue: type: object @@ -365,14 +367,14 @@ components: type: string instanceId: type: string - ParameterHistoryCriteria: + HistoryCriteria: type: object properties: applicationId: type: string productName: type: string - key: + name: type: string pageNumber: type: integer @@ -386,7 +388,7 @@ components: type: array items: type: string - ParameterHistoryPageResult: + HistoryPageResult: type: object properties: totalElements: @@ -405,7 +407,7 @@ components: stream: type: array items: - $ref: '#/components/schemas/ParameterHistory' + $ref: '#/components/schemas/History' ParameterPageResult: type: object properties: @@ -431,6 +433,8 @@ components: properties: value: type: object + displayName: + type: string description: type: string Product: @@ -462,14 +466,14 @@ components: type: array items: type: string - ParameterHistoryCountCriteria: + HistoryCountCriteria: type: object properties: applicationId: type: string productName: type: string - key: + name: type: string pageNumber: format: int32 @@ -483,7 +487,7 @@ components: type: array items: type: string - ParameterHistoryCount: + HistoryCount: type: object properties: creationDate: @@ -500,10 +504,10 @@ components: type: string productName: type: string - key: - type: string name: type: string + displayName: + type: string pageNumber: format: int32 description: The number of page diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml index 44e6ce3..54d37af 100644 --- a/src/main/resources/db/changeLog.xml +++ b/src/main/resources/db/changeLog.xml @@ -4,5 +4,5 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> - + diff --git a/src/main/resources/db/v1/2024-12-13-create-tables.xml b/src/main/resources/db/v1/2024-12-16-create-tables.xml similarity index 69% rename from src/main/resources/db/v1/2024-12-13-create-tables.xml rename to src/main/resources/db/v1/2024-12-16-create-tables.xml index ff25c06..31ba7af 100644 --- a/src/main/resources/db/v1/2024-12-13-create-tables.xml +++ b/src/main/resources/db/v1/2024-12-16-create-tables.xml @@ -4,22 +4,61 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - - - + + + + + + + @@ -28,10 +67,10 @@ - - + + - + @@ -49,31 +88,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAOExceptionTest.java b/src/test/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAOExceptionTest.java index 1c9d3af..7c97b7e 100644 --- a/src/test/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAOExceptionTest.java +++ b/src/test/java/org/tkit/onecx/parameters/domain/daos/ParameterHistoryDAOExceptionTest.java @@ -16,7 +16,7 @@ class ParameterHistoryDAOExceptionTest { @Inject - ParameterHistoryDAO dao; + HistoryDAO dao; @InjectMock EntityManager em; @@ -29,21 +29,21 @@ void beforeAll() { @Test void searchByCriteriaTest() { var exc = Assertions.assertThrows(DAOException.class, () -> dao.searchByCriteria(null)); - Assertions.assertEquals(ParameterHistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, + Assertions.assertEquals(HistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exc.key); } @Test void searchOnlyLatestByCriteriaTest() { var exc = Assertions.assertThrows(DAOException.class, () -> dao.searchOnlyLatestByCriteria(null)); - Assertions.assertEquals(ParameterHistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, + Assertions.assertEquals(HistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exc.key); } @Test void searchCountsByCriteriaTest() { var exc = Assertions.assertThrows(DAOException.class, () -> dao.searchCountsByCriteria(null)); - Assertions.assertEquals(ParameterHistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, + Assertions.assertEquals(HistoryDAO.ErrorKeys.FIND_ALL_PARAMETERS_HISTORY_FAILED, exc.key); } } diff --git a/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java b/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java index 1ab73e8..2b33569 100644 --- a/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java +++ b/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java @@ -9,8 +9,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import org.tkit.onecx.parameters.domain.daos.HistoryDAO; import org.tkit.onecx.parameters.domain.daos.JobDAO; -import org.tkit.onecx.parameters.domain.daos.ParameterHistoryDAO; import org.tkit.onecx.parameters.domain.models.Job; import org.tkit.quarkus.jpa.exceptions.DAOException; @@ -42,7 +42,7 @@ void testDaoException() { service.maintenanceHistoryData(); }); var de = Assertions.assertInstanceOf(DAOException.class, exc); - Assertions.assertEquals(ParameterHistoryDAO.ErrorKeys.DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, de.key); + Assertions.assertEquals(HistoryDAO.ErrorKeys.DELETE_PARAMETER_HISTORY_OLDER_THAN_FAILED, de.key); } } diff --git a/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceTest.java b/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceTest.java index 3ae5c63..5b97377 100644 --- a/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceTest.java +++ b/src/test/java/org/tkit/onecx/parameters/domain/timer/MaintenanceHistoryServiceTest.java @@ -7,9 +7,9 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.tkit.onecx.parameters.domain.daos.HistoryDAO; import org.tkit.onecx.parameters.domain.daos.JobDAO; -import org.tkit.onecx.parameters.domain.daos.ParameterHistoryDAO; -import org.tkit.onecx.parameters.domain.models.ParameterHistory; +import org.tkit.onecx.parameters.domain.models.History; import org.tkit.quarkus.test.WithDBData; import io.quarkus.test.junit.QuarkusTest; @@ -22,7 +22,7 @@ class MaintenanceHistoryServiceTest { MaintenanceHistoryService service; @Inject - ParameterHistoryDAO dao; + HistoryDAO dao; @Inject JobDAO jobDAO; @@ -31,7 +31,7 @@ class MaintenanceHistoryServiceTest { @Order(1) void maintenanceHistoryDataTest() { service.maintenanceHistoryData(); - List result = dao.findAll().toList(); + List result = dao.findAll().toList(); Assertions.assertNotNull(result); Assertions.assertEquals(2, result.size()); } diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTestIT.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerIT.java similarity index 61% rename from src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTestIT.java rename to src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerIT.java index f83818e..873d133 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTestIT.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerIT.java @@ -3,5 +3,5 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest -public class ParameterRestControllerTestIT extends ParameterRestControllerTest { +class HistoryRestControllerIT extends HistoryRestControllerTest { } diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerTest.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerTest.java similarity index 73% rename from src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerTest.java rename to src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerTest.java index 6c3bfec..3bec88a 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/HistoryRestControllerTest.java @@ -26,10 +26,10 @@ import org.tkit.quarkus.security.test.GenerateKeycloakClient; import org.tkit.quarkus.test.WithDBData; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryCountCriteriaDTO; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryCriteriaDTO; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryDTO; -import gen.org.tkit.onecx.parameters.rs.internal.model.ParameterHistoryPageResultDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryCountCriteriaDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryCriteriaDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryDTO; +import gen.org.tkit.onecx.parameters.rs.internal.model.HistoryPageResultDTO; import gen.org.tkit.onecx.tenant.client.model.TenantId; import io.quarkiverse.mockserver.test.InjectMockServerClient; import io.quarkus.test.common.http.TestHTTPEndpoint; @@ -39,7 +39,7 @@ @TestHTTPEndpoint(HistoryRestController.class) @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) @GenerateKeycloakClient(clientName = "testClient", scopes = { "ocx-pa:read", "ocx-pa:write", "ocx-pa:delete", "ocx-pa:all" }) -class ParameterHistoryRestControllerTest extends AbstractTest { +class HistoryRestControllerTest extends AbstractTest { @InjectMockServerClient MockServerClient mockServerClient; @@ -61,13 +61,13 @@ void shouldFindAllParametersHistoryWithoutCriteria() { var pageResultDTO = given() .auth().oauth2(getKeycloakClientToken("testClient")) .header(HEADER_APM_TOKEN, apm) - .body(new ParameterHistoryCriteriaDTO()) + .body(new HistoryCriteriaDTO()) .contentType(APPLICATION_JSON) .post() .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) - .extract().body().as(ParameterHistoryPageResultDTO.class); + .extract().body().as(HistoryPageResultDTO.class); Assertions.assertEquals(6, pageResultDTO.getStream().size()); Assertions.assertEquals(Long.valueOf(6), pageResultDTO.getTotalElements()); @@ -76,21 +76,21 @@ void shouldFindAllParametersHistoryWithoutCriteria() { static Stream findByCriteriaTestData() { return Stream.of( - Arguments.of(new ParameterHistoryCriteriaDTO(), 6), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("").productName("").key("") + Arguments.of(new HistoryCriteriaDTO(), 6), + Arguments.of(new HistoryCriteriaDTO().applicationId("").productName("").name("") .type(List.of("")), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app0").productName("p0").key("key0") + Arguments.of(new HistoryCriteriaDTO().applicationId("app0").productName("p0").name("key0") .type(List.of("type0")), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("access-mgmt") + Arguments.of(new HistoryCriteriaDTO().applicationId("access-mgmt") .productName("access-mgmt-product"), 2), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app1").productName("p1"), 1), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app2").productName("p2"), 3)); + Arguments.of(new HistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("app1").productName("p1"), 1), + Arguments.of(new HistoryCriteriaDTO().applicationId("app2").productName("p2"), 3)); } @ParameterizedTest @MethodSource("findByCriteriaTestData") - void shouldFindParametersHistoryByCriteria(ParameterHistoryCriteriaDTO criteriaDTO, Integer expectedArraySize) { + void shouldFindParametersHistoryByCriteria(HistoryCriteriaDTO criteriaDTO, Integer expectedArraySize) { var apm = createToken("org1"); addExpectation(mockServerClient @@ -110,26 +110,26 @@ void shouldFindParametersHistoryByCriteria(ParameterHistoryCriteriaDTO criteriaD .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(ParameterHistoryPageResultDTO.class); + .body().as(HistoryPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); } static Stream findByCriteriaTestDataQueryLatest() { return Stream.of( - Arguments.of(new ParameterHistoryCriteriaDTO(), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("access-mgmt") + Arguments.of(new HistoryCriteriaDTO(), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("access-mgmt") .productName("access-mgmt-product"), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("").productName("").key(""), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("").productName("").key("key1"), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("").productName(""), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app1").productName("p1"), 0), - Arguments.of(new ParameterHistoryCriteriaDTO().applicationId("app2").productName("p2"), 0)); + Arguments.of(new HistoryCriteriaDTO().applicationId("").productName("").name(""), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("").productName("").name("key1"), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("").productName(""), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("app1").productName("p1"), 0), + Arguments.of(new HistoryCriteriaDTO().applicationId("app2").productName("p2"), 0)); } @ParameterizedTest @MethodSource("findByCriteriaTestDataQueryLatest") - void shouldFindParametersHistoryByCriteriaQueryLatest(ParameterHistoryCriteriaDTO criteriaDTO, + void shouldFindParametersHistoryByCriteriaQueryLatest(HistoryCriteriaDTO criteriaDTO, Integer expectedArraySize) { var apm = createToken("org1"); @@ -150,7 +150,7 @@ void shouldFindParametersHistoryByCriteriaQueryLatest(ParameterHistoryCriteriaDT .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(ParameterHistoryPageResultDTO.class); + .body().as(HistoryPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); } @@ -201,7 +201,7 @@ void getParametersHistoryById(String id, String applicationId, String productNam .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(ParameterHistoryDTO.class); + .body().as(HistoryDTO.class); Assertions.assertNotNull(result); Assertions.assertEquals(id, result.getId()); Assertions.assertEquals(applicationId, result.getApplicationId()); @@ -211,20 +211,20 @@ void getParametersHistoryById(String id, String applicationId, String productNam static Stream findCountByCriteriaTestData() { return Stream.of( - 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 HistoryCountCriteriaDTO(), 6), + Arguments.of(new HistoryCountCriteriaDTO().applicationId("").productName("").name(""), 6), + Arguments.of(new HistoryCountCriteriaDTO().applicationId("").productName("").name("key1"), 1), Arguments.of( - new ParameterHistoryCountCriteriaDTO().applicationId("access-mgmt").productName("access-mgmt-product"), + new HistoryCountCriteriaDTO().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)); + Arguments.of(new HistoryCountCriteriaDTO().applicationId("app0").productName("p0"), 0), + Arguments.of(new HistoryCountCriteriaDTO().applicationId("app1").productName("p1"), 1), + Arguments.of(new HistoryCountCriteriaDTO().applicationId("app2").productName("p2"), 3)); } @ParameterizedTest @MethodSource("findCountByCriteriaTestData") - void getCountsByCriteriaTest(ParameterHistoryCountCriteriaDTO criteria, Integer expectedArraySize) { + void getCountsByCriteriaTest(HistoryCountCriteriaDTO criteria, Integer expectedArraySize) { var apm = createToken("org1"); addExpectation(mockServerClient .when(request().withPath("/v1/tenant").withMethod(HttpMethod.GET).withHeader("apm-principal-token", apm)) diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerIT.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerIT.java similarity index 60% rename from src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerIT.java rename to src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerIT.java index 7008613..37c9284 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterHistoryRestControllerIT.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerIT.java @@ -3,5 +3,5 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest -class ParameterHistoryRestControllerIT extends ParameterHistoryRestControllerTest { +public class ParameterRestControllerIT extends ParameterRestControllerTest { } diff --git a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTest.java b/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTest.java index ad93169..f9eabc8 100644 --- a/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/parameters/rs/internal/ParameterRestControllerTest.java @@ -137,10 +137,10 @@ static Stream findByCriteriaTestData() { Arguments.of(new ParameterSearchCriteriaDTO().applicationId("incorrect_app").productName("incorrect-product"), 0), Arguments.of(new ParameterSearchCriteriaDTO().applicationId("incorrect_app").productName("incorrect-product") - .key("").name(""), 0), - Arguments.of(new ParameterSearchCriteriaDTO().name("custom"), 0), - Arguments.of(new ParameterSearchCriteriaDTO().key("ENGINE"), 1), - Arguments.of(new ParameterSearchCriteriaDTO().key("incorrect_key"), 0)); + .name("").displayName(""), 0), + Arguments.of(new ParameterSearchCriteriaDTO().displayName("custom"), 0), + Arguments.of(new ParameterSearchCriteriaDTO().name("ENGINE"), 1), + Arguments.of(new ParameterSearchCriteriaDTO().name("incorrect_key"), 0)); } @ParameterizedTest @@ -193,9 +193,9 @@ void shouldFindParameterById() { Assertions.assertNotNull(applicationParameterDTO); Assertions.assertEquals("access-mgmt", applicationParameterDTO.getApplicationId()); Assertions.assertEquals("access-mgmt-product", applicationParameterDTO.getProductName()); - Assertions.assertEquals("ENGINE", applicationParameterDTO.getKey()); + Assertions.assertEquals("ENGINE", applicationParameterDTO.getName()); Assertions.assertEquals("KOGITO", applicationParameterDTO.getValue()); - Assertions.assertEquals("Engine", applicationParameterDTO.getName()); + Assertions.assertEquals("Engine", applicationParameterDTO.getDisplayName()); Assertions.assertNull(applicationParameterDTO.getDescription()); } @@ -339,7 +339,7 @@ void createParameterTest(String appId, String productName, String desc, String k dto.setApplicationId(appId); dto.setProductName(productName); dto.setDescription(desc); - dto.setKey(key); + dto.setName(key); dto.setValue(value); String uri = given() @@ -366,7 +366,7 @@ void createParameterTest(String appId, String productName, String desc, String k 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.getName(), dto2.getName()); Assertions.assertEquals(dto.getValue(), dto2.getValue()); } @@ -383,7 +383,7 @@ void createTwice_Bad_Request_Test() { ParameterCreateDTO dto = new ParameterCreateDTO(); dto.setApplicationId("app1"); dto.setProductName("productName1"); - dto.setKey("key1"); + dto.setName("key1"); given() .auth().oauth2(getKeycloakClientToken("testClient")) .header(HEADER_APM_TOKEN, apm) diff --git a/src/test/resources/data/history-testdata.xml b/src/test/resources/data/history-testdata.xml index 0090935..5fc4ba8 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 3b4e1f3..5eb6bae 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 273ce6a..7aab7f4 100644 --- a/src/test/resources/data/parameters-importdata.xml +++ b/src/test/resources/data/parameters-importdata.xml @@ -1,6 +1,6 @@ - - - + + + \ 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 198e5f2..6f04b21 100644 --- a/src/test/resources/data/parameters-testdata.xml +++ b/src/test/resources/data/parameters-testdata.xml @@ -1,23 +1,23 @@ - - - - - + + + + + - + - - + + - - - + + + - - - - + + + + \ No newline at end of file