Skip to content

Commit

Permalink
feat: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Dec 6, 2024
1 parent 27333b4 commit 43f04d6
Show file tree
Hide file tree
Showing 39 changed files with 571 additions and 1,138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ quarkus.http.auth.permission.health.paths=/q/*
quarkus.http.auth.permission.health.policy=permit
quarkus.http.auth.permission.default.paths=/*
quarkus.http.auth.permission.default.policy=authenticated
quarkus.banner.enabled=false
quarkus.hibernate-orm.database.generation=validate
quarkus.hibernate-orm.multitenant=DISCRIMINATOR
quarkus.liquibase.migrate-at-start=true
Expand Down Expand Up @@ -65,3 +64,7 @@ app:
----

pes: [ ocx-tn:read ]

----
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ h| Documentation
h| Configuration
h| Version

| tkit-quarkus-data-import

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-data-import.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.36.0

| tkit-quarkus-jpa

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link]
Expand Down Expand Up @@ -166,4 +160,22 @@ h| Version
| 3.15.1
|===ps://quarkus.io/guides/container-image[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link]
| 3.15.1
| onecx-security
|
|
| 0.34.0
| quarkus-scheduler
|
|
| 3.15.1
|===
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<dependencies>

<!-- 1000kit -->
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-data-import</artifactId>
</dependency>
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-jpa</artifactId>
Expand Down Expand Up @@ -187,19 +183,6 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<id>di-v1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/di-v1.yaml</inputSpec>
<apiPackage>gen.org.tkit.onecx.parameters.di.v1</apiPackage>
<modelPackage>gen.org.tkit.onecx.parameters.di.v1.model</modelPackage>
<modelNameSuffix>DTOV1</modelNameSuffix>
<skipValidateSpec>true</skipValidateSpec>
</configuration>
</execution>
<execution>
<id>internal</id>
<goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.tkit.onecx.parameters.domain.timer;
package org.tkit.onecx.parameters.domain.config;

import io.quarkus.runtime.annotations.ConfigDocFilename;
import io.quarkus.runtime.annotations.ConfigPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
@Getter
@Setter
public class ApplicationParameterHistorySearchCriteria {
public class ParameterHistorySearchCriteria {

/**
* The application ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
@Getter
@Setter
public class ApplicationParameterSearchCriteria {
public class ParameterSearchCriteria {

/**
* The application ID.
Expand Down

This file was deleted.

123 changes: 123 additions & 0 deletions src/main/java/org/tkit/onecx/parameters/domain/daos/ParameterDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.tkit.onecx.parameters.domain.daos;

import java.util.*;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.persistence.criteria.*;
import jakarta.transaction.Transactional;

import org.tkit.onecx.parameters.domain.criteria.KeysSearchCriteria;
import org.tkit.onecx.parameters.domain.criteria.ParameterSearchCriteria;
import org.tkit.onecx.parameters.domain.models.*;
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;

@ApplicationScoped
@Transactional(value = Transactional.TxType.NOT_SUPPORTED, rollbackOn = DAOException.class)
public class ParameterDAO extends AbstractDAO<Parameter> {

public Map<String, String> findAllByProductNameAndApplicationId(String productName, String applicationId) {
try {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Parameter> cq = cb.createQuery(Parameter.class);
Root<Parameter> root = cq.from(Parameter.class);
cq.where(cb.and(
cb.equal(root.get(Parameter_.PRODUCT_NAME), productName),
cb.equal(root.get(Parameter_.APPLICATION_ID), applicationId),
cb.or(
cb.isNotNull(root.get(Parameter_.VALUE)),
cb.isNotNull(root.get(Parameter_.IMPORT_VALUE)))));

return getEntityManager()
.createQuery(cq)
.getResultStream()
.collect(Collectors.toMap(Parameter::getKey,
p -> p.getValue() != null ? p.getValue() : p.getImportValue()));

} catch (Exception e) {
throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_BY_APPLICATION_ID_FAILED, e);
}
}

public PageResult<Parameter> searchByCriteria(ParameterSearchCriteria criteria) {
try {
CriteriaQuery<Parameter> cq = criteriaQuery();
Root<Parameter> root = cq.from(Parameter.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(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())));
}
if (!predicates.isEmpty()) {
cq.where(cb.and(predicates.toArray(new Predicate[0])));
}
return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult();
} catch (Exception exception) {
throw new DAOException(ErrorKeys.FIND_ALL_PARAMETERS_FAILED, exception);
}
}

public PageResult<String> searchAllKeys(KeysSearchCriteria criteria) {
try {
var cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Parameter> root = cq.from(Parameter.class);
cq.select(root.get(Parameter_.KEY)).distinct(true);

if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) {
cq.where(cb.equal(root.get(Parameter_.PRODUCT_NAME), criteria.getProductName()));
}

if (criteria.getApplicationId() != null && !criteria.getApplicationId().isEmpty()) {
cq.where(cb.equal(root.get(Parameter_.APPLICATION_ID), criteria.getApplicationId()));
}

var results = getEntityManager().createQuery(cq).getResultList();
return new PageResult<>(results.size(), results.stream(), Page.of(0, 1));
} catch (Exception exception) {
throw new DAOException(ErrorKeys.FIND_ALL_KEYS_FAILED, exception);
}
}

public List<ApplicationTuple> searchAllProductNamesAndApplicationIds() {
try {
var cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<ApplicationTuple> cq = cb.createQuery(ApplicationTuple.class);
Root<Parameter> root = cq.from(Parameter.class);
cq.select(
cb.construct(ApplicationTuple.class, root.get(Parameter_.PRODUCT_NAME),
root.get(Parameter_.APPLICATION_ID)))
.distinct(true);
return getEntityManager().createQuery(cq).getResultList();
} catch (Exception exception) {
throw new DAOException(ErrorKeys.FIND_ALL_APPLICATIONS_FAILED, exception);
}
}

private static String stringPattern(String value) {
return (value.toLowerCase() + "%");
}

public enum ErrorKeys {

FIND_ALL_PARAMETERS_BY_APPLICATION_ID_FAILED,
FIND_ALL_APPLICATIONS_FAILED,

FIND_ALL_KEYS_FAILED,
FIND_ALL_PARAMETERS_FAILED;
}
}
Loading

0 comments on commit 43f04d6

Please sign in to comment.