Skip to content

Commit

Permalink
feat: added productName (#31)
Browse files Browse the repository at this point in the history
* feat: added productName

* fix: reduced mapping params

* feat: improved internal api
  • Loading branch information
JordenReuter authored Apr 26, 2024
1 parent 5b741f1 commit 8645f82
Show file tree
Hide file tree
Showing 25 changed files with 298 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ApplicationParameterHistorySearchCriteria {
*/
private String applicationId;

/**
* The product name
*/
private String productName;

/**
* The application parameter key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ApplicationParameterSearchCriteria {
*/
private String applicationId;

/**
* The product name
*/
private String productName;

/**
* The application parameter key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public class KeysSearchCriteria {

private String applicationId;

private String productName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ public List<ApplicationParameter> findByApplicationIdAndParameterKeys(String app
}
}

public Map<String, String> findAllByApplicationId(String applicationId) {
public Map<String, String> findAllByProductNameAndApplicationId(String productName, String applicationId) {
try {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<ApplicationParameter> cq = cb.createQuery(ApplicationParameter.class);
Root<ApplicationParameter> 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)),
Expand All @@ -102,6 +103,10 @@ public PageResult<ApplicationParameter> searchByCriteria(ApplicationParameterSea
Root<ApplicationParameter> root = cq.from(ApplicationParameter.class);
List<Predicate> 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())));
Expand Down Expand Up @@ -131,6 +136,10 @@ public PageResult<String> searchAllKeys(KeysSearchCriteria criteria) {
Root<ApplicationParameter> 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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public PageResult<ApplicationParameterHistory> searchByCriteria(ApplicationParam
Root<ApplicationParameterHistory> root = cq.from(ApplicationParameterHistory.class);
List<Predicate> 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())));
Expand Down Expand Up @@ -78,6 +84,10 @@ public PageResult<ApplicationParameterHistory> searchOnlyLatestByCriteria(
List<Predicate> 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()));
Expand Down Expand Up @@ -106,6 +116,11 @@ public List<ParameterHistoryCountTuple> searchCountsByCriteria(ApplicationParame
root.get(ApplicationParameterHistory_.COUNT)));
List<Predicate> 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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,23 +32,21 @@ public class ParameterRestControllerV3 implements ExternalApi {
@Inject
ApplicationParameterHistoryMapper mapper;

@Inject
ExceptionMapper exceptionMapper;

@Override
public Response getApplicationParameters(String appId) {
Map<String, String> applicationParameters = applicationParameterDAO.findAllByApplicationId(appId);
public Response getApplicationParameters(String productName, String appId) {
Map<String, String> 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<ApplicationParameterHistory> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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<String> 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<String> 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();
}
Expand All @@ -55,9 +49,8 @@ public Response getApplicationParametersHistoryById(String id) {
}

@Override
public Response getCountsByCriteria(String applicationId, String key, Integer pageNumber, Integer pageSize,
List<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> page);
Expand All @@ -27,11 +27,14 @@ public interface ApplicationParameterInternalMapper {
ApplicationsPageResultDTO apps(PageResult<String> page);

@BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
ApplicationParameterHistorySearchCriteria map(String applicationId, String key, Integer pageNumber, Integer pageSize,
List<String> 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<String> type);

@Mapping(target = "removeStreamItem", ignore = true)
Expand Down
Loading

0 comments on commit 8645f82

Please sign in to comment.