Skip to content

Commit

Permalink
feat: rest interface refactoring (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Aug 23, 2023
1 parent f90e710 commit 2af353b
Show file tree
Hide file tree
Showing 46 changed files with 378 additions and 987 deletions.
85 changes: 85 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,91 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.6.0</version>
<executions>
<execution>
<id>di-v1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/di-v1.yaml</inputSpec>
<apiPackage>gen.io.github.onecx.parameters.di.v1</apiPackage>
<modelPackage>gen.io.github.onecx.parameters.di.v1.model</modelPackage>
<modelNameSuffix>DTOV1</modelNameSuffix>
<skipValidateSpec>true</skipValidateSpec>
</configuration>
</execution>
<execution>
<id>internal</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/openapi-internal.yaml</inputSpec>
<apiPackage>gen.io.github.onecx.parameters.rs.internal</apiPackage>
<modelPackage>gen.io.github.onecx.parameters.rs.internal.model</modelPackage>
</configuration>
</execution>
<execution>
<id>v2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/openapi-v2.yaml</inputSpec>
<apiPackage>gen.io.github.onecx.parameters.rs.v2</apiPackage>
<modelPackage>gen.io.github.onecx.parameters.rs.v2.model</modelPackage>
<modelNameSuffix>DTOV2</modelNameSuffix>
</configuration>
</execution>
<execution>
<id>v3</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/openapi-v3.yaml</inputSpec>
<apiPackage>gen.io.github.onecx.parameters.rs.v3</apiPackage>
<modelPackage>gen.io.github.onecx.parameters.rs.v3.model</modelPackage>
<modelNameSuffix>DTOV3</modelNameSuffix>
</configuration>
</execution>
</executions>
<configuration>
<generatorName>jaxrs-spec</generatorName>
<modelNameSuffix>DTO</modelNameSuffix>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<addCompileSourceRoot>true</addCompileSourceRoot>
<library>quarkus</library>
<configOptions>
<sourceFolder>/</sourceFolder>
<openApiNullable>false</openApiNullable>
<returnResponse>true</returnResponse>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<serializableModel>true</serializableModel>
<singleContentTypes>true</singleContentTypes>
<dateLibrary>java8</dateLibrary>
<useMicroProfileOpenAPIAnnotations>true</useMicroProfileOpenAPIAnnotations>
<useJakartaEe>true</useJakartaEe>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
<java17>true</java17>
</configOptions>
</configuration>
</plugin>

</plugins>
</build>
<profiles>
<profile>
<id>openapi</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.tkit.quarkus.jpa.exceptions.DAOException;
import org.tkit.quarkus.jpa.models.TraceableEntity_;

import io.github.onecx.parameters.domain.di.models.Job;
import io.github.onecx.parameters.domain.models.Job;

@ApplicationScoped
public class JobDAO extends AbstractDAO<Job> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.onecx.parameters.domain.di;
package io.github.onecx.parameters.domain.di.v1;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -15,37 +15,43 @@
import org.tkit.quarkus.dataimport.DataImportConfig;
import org.tkit.quarkus.dataimport.DataImportService;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import gen.io.github.onecx.parameters.di.v1.model.DataImportDTOV1;
import gen.io.github.onecx.parameters.di.v1.model.DataImportParamDTOV1;
import io.github.onecx.parameters.domain.daos.ApplicationParameterDAO;
import io.github.onecx.parameters.domain.di.models.ApplicationParameterDataImport;
import io.github.onecx.parameters.domain.models.ApplicationParameter;

/**
* Import format
* Import JSON format. Openapi: ./src/main/openapi/di-v1.yaml
*
* <pre>
* {
* "appId" : {
* "key1": {
* "description": "description_1",
* "name": "name_1",
* "value": "value_1"
* },
* "key2": {
* "description": "description_2",
* "name": "name_2",
* "value": "value_2"
* }
* }
* "appId" : {
* "key1": {
* "description": "description_1",
* "name": "name_1",
* "value": "value_1"
* },
* "key2": {
* "description": "description_2",
* "name": "name_2",
* "value": "value_2"
* }
* }
* }
* </pre>
*
* <pre>
* operation:
* - CLEAN_INSERT - delete all data and import new set
* - UPDATE - update existing data from file or create new parameters
* </pre>
*/
@DataImport("parameters")
public class ApplicationParameterDataImportService implements DataImportService {
public class ParameterDataImportService implements DataImportService {

private static final Logger log = LoggerFactory.getLogger(ApplicationParameterDataImportService.class);
private static final Logger log = LoggerFactory.getLogger(ParameterDataImportService.class);

public static final String KEY_SEPARATOR = "__";

Expand All @@ -62,7 +68,7 @@ public void importData(DataImportConfig config) {
try {
String operation = config.getMetadata().getOrDefault("operation", "NONE");

Consumer<Map<String, Map<String, ApplicationParameterDataImport>>> action = switch (operation) {
Consumer<DataImportDTOV1> action = switch (operation) {
case "CLEAN_INSERT" -> this::cleanInsert;
case "UPDATE" -> this::update;
default -> null;
Expand All @@ -78,9 +84,7 @@ public void importData(DataImportConfig config) {
return;
}

Map<String, Map<String, ApplicationParameterDataImport>> data = mapper.readValue(config.getData(),
new TypeReference<Map<String, Map<String, ApplicationParameterDataImport>>>() {
});
DataImportDTOV1 data = mapper.readValue(config.getData(), DataImportDTOV1.class);
if (data.isEmpty()) {
log.warn("Import configuration key {} does not contains any JSON data to import", config.getKey());
return;
Expand All @@ -97,7 +101,7 @@ public ErrorImportException(Exception ex) {
}
}

private void cleanInsert(Map<String, Map<String, ApplicationParameterDataImport>> data) {
private void cleanInsert(DataImportDTOV1 data) {

// convert import model to list of parameters
List<ApplicationParameter> params = new ArrayList<>();
Expand All @@ -114,11 +118,11 @@ private void cleanInsert(Map<String, Map<String, ApplicationParameterDataImport>
dao.create(params);
}

private void update(Map<String, Map<String, ApplicationParameterDataImport>> data) {
Map<String, ApplicationParameterDataImport> values = new HashMap<>();
data.forEach((app, keys) -> {
if (keys != null && !keys.isEmpty()) {
keys.forEach((key, value) -> values.put(id(app, key), value));
private void update(DataImportDTOV1 data) {
Map<String, DataImportParamDTOV1> values = new HashMap<>();
data.forEach((appId, app) -> {
if (app != null) {
app.forEach((paramId, param) -> values.put(id(appId, paramId), param));
}
});

Expand Down Expand Up @@ -148,7 +152,7 @@ private void update(Map<String, Map<String, ApplicationParameterDataImport>> dat
dao.create(created);
}

private ApplicationParameter update(ApplicationParameter param, ApplicationParameterDataImport value) {
private ApplicationParameter update(ApplicationParameter param, DataImportParamDTOV1 value) {
if (isValue(value.getName())) {
param.setName(value.getName());
}
Expand All @@ -161,7 +165,7 @@ private ApplicationParameter update(ApplicationParameter param, ApplicationParam
return param;
}

private ApplicationParameter create(String app, String key, ApplicationParameterDataImport value) {
private ApplicationParameter create(String app, String key, DataImportParamDTOV1 value) {
ApplicationParameter param = new ApplicationParameter();
param.setApplicationId(app);
param.setKey(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.onecx.parameters.domain.di.models;
package io.github.onecx.parameters.domain.models;

import jakarta.persistence.Entity;
import jakarta.persistence.Table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import io.github.onecx.parameters.domain.daos.ApplicationParameterHistoryDAO;
import io.github.onecx.parameters.domain.daos.JobDAO;
import io.github.onecx.parameters.domain.di.models.Job;
import io.github.onecx.parameters.domain.models.Job;
import io.quarkus.scheduler.Scheduled;
import lombok.extern.slf4j.Slf4j;

Expand Down
Loading

0 comments on commit 2af353b

Please sign in to comment.