diff --git a/pom.xml b/pom.xml index e48c5be..b3d8c5e 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,91 @@ + + + + org.openapitools + openapi-generator-maven-plugin + 6.6.0 + + + di-v1 + + generate + + + src/main/openapi/di-v1.yaml + gen.io.github.onecx.parameters.di.v1 + gen.io.github.onecx.parameters.di.v1.model + DTOV1 + true + + + + internal + + generate + + + src/main/openapi/openapi-internal.yaml + gen.io.github.onecx.parameters.rs.internal + gen.io.github.onecx.parameters.rs.internal.model + + + + v2 + + generate + + + src/main/openapi/openapi-v2.yaml + gen.io.github.onecx.parameters.rs.v2 + gen.io.github.onecx.parameters.rs.v2.model + DTOV2 + + + + v3 + + generate + + + src/main/openapi/openapi-v3.yaml + gen.io.github.onecx.parameters.rs.v3 + gen.io.github.onecx.parameters.rs.v3.model + DTOV3 + + + + + jaxrs-spec + DTO + false + false + false + false + false + true + quarkus + + / + false + true + true + true + true + true + java8 + true + true + false + true + + + + + + openapi diff --git a/src/main/java/io/github/onecx/parameters/domain/daos/JobDAO.java b/src/main/java/io/github/onecx/parameters/domain/daos/JobDAO.java index 2d75e27..76dddbd 100644 --- a/src/main/java/io/github/onecx/parameters/domain/daos/JobDAO.java +++ b/src/main/java/io/github/onecx/parameters/domain/daos/JobDAO.java @@ -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 { diff --git a/src/main/java/io/github/onecx/parameters/domain/di/models/ApplicationParameterDataImport.java b/src/main/java/io/github/onecx/parameters/domain/di/models/ApplicationParameterDataImport.java deleted file mode 100644 index 4303788..0000000 --- a/src/main/java/io/github/onecx/parameters/domain/di/models/ApplicationParameterDataImport.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.onecx.parameters.domain.di.models; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class ApplicationParameterDataImport { - - private String description; - - private String name; - - private String value; -} diff --git a/src/main/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportService.java b/src/main/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportService.java similarity index 75% rename from src/main/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportService.java rename to src/main/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportService.java index 6d88d9a..168800b 100644 --- a/src/main/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportService.java +++ b/src/main/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportService.java @@ -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; @@ -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 + * + *
  * {
- * "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"
+ *     }
+ *   }
  * }
+ * 
+ * + *
  * operation:
  * - CLEAN_INSERT - delete all data and import new set
  * - UPDATE - update existing data from file or create new parameters
+ * 
*/ @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 = "__"; @@ -62,7 +68,7 @@ public void importData(DataImportConfig config) { try { String operation = config.getMetadata().getOrDefault("operation", "NONE"); - Consumer>> action = switch (operation) { + Consumer action = switch (operation) { case "CLEAN_INSERT" -> this::cleanInsert; case "UPDATE" -> this::update; default -> null; @@ -78,9 +84,7 @@ public void importData(DataImportConfig config) { return; } - Map> data = mapper.readValue(config.getData(), - new TypeReference>>() { - }); + 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; @@ -97,7 +101,7 @@ public ErrorImportException(Exception ex) { } } - private void cleanInsert(Map> data) { + private void cleanInsert(DataImportDTOV1 data) { // convert import model to list of parameters List params = new ArrayList<>(); @@ -114,11 +118,11 @@ private void cleanInsert(Map dao.create(params); } - private void update(Map> data) { - Map 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 values = new HashMap<>(); + data.forEach((appId, app) -> { + if (app != null) { + app.forEach((paramId, param) -> values.put(id(appId, paramId), param)); } }); @@ -148,7 +152,7 @@ private void update(Map> 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()); } @@ -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); diff --git a/src/main/java/io/github/onecx/parameters/domain/di/models/Job.java b/src/main/java/io/github/onecx/parameters/domain/models/Job.java similarity index 83% rename from src/main/java/io/github/onecx/parameters/domain/di/models/Job.java rename to src/main/java/io/github/onecx/parameters/domain/models/Job.java index f0714f9..bf39e1b 100644 --- a/src/main/java/io/github/onecx/parameters/domain/di/models/Job.java +++ b/src/main/java/io/github/onecx/parameters/domain/models/Job.java @@ -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; diff --git a/src/main/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryService.java b/src/main/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryService.java index 11a6d75..d7b0df5 100644 --- a/src/main/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryService.java +++ b/src/main/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryService.java @@ -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; diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/ParameterRestControllerV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/ParameterRestControllerV2.java index 9eb63fc..dcc8ce9 100644 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/ParameterRestControllerV2.java +++ b/src/main/java/io/github/onecx/parameters/rs/external/v2/ParameterRestControllerV2.java @@ -7,34 +7,21 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import org.eclipse.microprofile.openapi.annotations.Operation; -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.tags.Tag; - +import gen.io.github.onecx.parameters.rs.v2.ExternalApi; +import gen.io.github.onecx.parameters.rs.v2.model.ApplicationParameterDTOV2; +import gen.io.github.onecx.parameters.rs.v2.model.ApplicationParameterTypeDTOV2; import io.github.onecx.parameters.domain.daos.ApplicationParameterDAO; import io.github.onecx.parameters.domain.daos.ApplicationParameterDataDAO; import io.github.onecx.parameters.domain.models.ApplicationParameter; import io.github.onecx.parameters.domain.models.ApplicationParameterData; -import io.github.onecx.parameters.rs.external.v2.dtos.AbstractEntityDTOV2; -import io.github.onecx.parameters.rs.external.v2.dtos.ApplicationParameterDTOV2; -import io.github.onecx.parameters.rs.external.v2.dtos.enums.ApplicationParameterTypeDTOV2; import io.github.onecx.parameters.rs.external.v2.mappers.ApplicationParameterDataMapperV2; import io.github.onecx.parameters.rs.external.v2.mappers.ApplicationParameterMapperV2; @ApplicationScoped -@Path("/v2") -@Tag(name = "external") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) @Transactional(value = Transactional.TxType.NOT_SUPPORTED) -public class ParameterRestControllerV2 { +public class ParameterRestControllerV2 implements ExternalApi { @Inject ApplicationParameterDAO applicationParameterService; @@ -48,15 +35,9 @@ public class ParameterRestControllerV2 { @Inject ApplicationParameterDataMapperV2 applicationParameterDataMapperV2; - @GET - @Path("/parameters") - @Operation(operationId = "getParameter", description = "Get application parameter by application id and parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterDTOV2.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getParameter(@QueryParam("applicationId") String applicationId, - @QueryParam("parameterKey") String parameterKey) { + @Override + public Response getParameter(String applicationId, String parameterKey) { + System.out.println("########## " + applicationId + " ## " + parameterKey); if (applicationId == null || applicationId.isEmpty() || parameterKey == null || parameterKey.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST).entity("ApplicationId and parameterKey are mandatory.").build(); } @@ -66,14 +47,8 @@ public Response getParameter(@QueryParam("applicationId") String applicationId, return getAllParameters(applicationParameterList); } - @POST - @Path("/parameters") - @Operation(operationId = "getAllParameters", description = "Get all application parameters by application id and/or parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterDTOV2.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getAllParameters(@QueryParam("applicationId") String applicationId, List parametersKeys) { + @Override + public Response getAllParameters(String applicationId, List parametersKeys) { if (applicationId == null || applicationId.isEmpty() || parametersKeys == null || parametersKeys.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST).entity("ApplicationId and parametersKeys are mandatory.") .build(); @@ -91,7 +66,7 @@ Response getAllParameters(List applicationParameterList) { // map ApplicationParameterData to ApplicationParameter due to backward compatibility var parametersData = applicationParameterDataDAO - .findByParameterIds(results.stream().map(AbstractEntityDTOV2::getId).toList()) + .findByParameterIds(results.stream().map(ApplicationParameterDTOV2::getId).toList()) .stream() .collect(Collectors.toMap(ApplicationParameterData::getApplicationParameterGuid, d -> d)); @@ -102,51 +77,23 @@ Response getAllParameters(List applicationParameterList) { return Response.status(Response.Status.NOT_FOUND).build(); } - @GET - @Path("/stringParameters") - @Operation(operationId = "getString", description = "Get application parameter as String by application id and parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = String.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getString(@QueryParam("applicationId") String applicationId, - @QueryParam("parameterKey") String parameterKey) { + @Override + public Response getString(String applicationId, String parameterKey) { return getValue(applicationId, parameterKey, ApplicationParameterTypeDTOV2.STRING, s -> s); } - @GET - @Path("/longParameters") - @Operation(operationId = "getLong", description = "Get application parameter as Long by application id and parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Long.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getLong(@QueryParam("applicationId") String applicationId, - @QueryParam("parameterKey") String parameterKey) { + @Override + public Response getLong(String applicationId, String parameterKey) { return getValue(applicationId, parameterKey, ApplicationParameterTypeDTOV2.NUMBER, Long::valueOf); } - @GET - @Path("/integerParameters") - @Operation(operationId = "getInteger", description = "Get application parameter as Integer by application id and parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Integer.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getInteger(@QueryParam("applicationId") String applicationId, - @QueryParam("parameterKey") String parameterKey) { + @Override + public Response getInteger(String applicationId, String parameterKey) { return getValue(applicationId, parameterKey, ApplicationParameterTypeDTOV2.NUMBER, Integer::valueOf); } - @GET - @Path("/booleanParameters") - @Operation(operationId = "getBoolean", description = "Get application parameter as Boolean by application id and parameter key") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Boolean.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getBoolean(@QueryParam("applicationId") String applicationId, - @QueryParam("parameterKey") String parameterKey) { + @Override + public Response getBoolean(String applicationId, String parameterKey) { return getValue(applicationId, parameterKey, ApplicationParameterTypeDTOV2.BOOLEAN, Boolean::valueOf); } diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/AbstractEntityDTOV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/AbstractEntityDTOV2.java deleted file mode 100644 index 067ce78..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/AbstractEntityDTOV2.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.onecx.parameters.rs.external.v2.dtos; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class AbstractEntityDTOV2 { - - /** - * The persisted flag. - */ - private boolean persisted; - - /** - * The ID. - */ - @EqualsAndHashCode.Include - private String id; - - /** - * The optimistic lock version - */ - private Integer version; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/ApplicationParameterDTOV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/ApplicationParameterDTOV2.java deleted file mode 100644 index 62da5ff..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/ApplicationParameterDTOV2.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.onecx.parameters.rs.external.v2.dtos; - -import io.github.onecx.parameters.rs.external.v2.dtos.enums.ApplicationParameterRoleTypeDTOV2; -import io.github.onecx.parameters.rs.external.v2.dtos.enums.ApplicationParameterTypeDTOV2; -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection - -public class ApplicationParameterDTOV2 extends AbstractEntityDTOV2 { - - private String key; - private String name; - private String value; - private String description; - private ApplicationParameterTypeDTOV2 type; - private String applicationId; - private ApplicationParameterRoleTypeDTOV2 roleType; - private String unit; - private Integer valueRangeFrom; - private Integer valueRangeTo; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterRoleTypeDTOV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterRoleTypeDTOV2.java deleted file mode 100644 index e3f577b..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterRoleTypeDTOV2.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.onecx.parameters.rs.external.v2.dtos.enums; - -public enum ApplicationParameterRoleTypeDTOV2 { - - /** - * The business. - */ - BUSINESS, - /** - * The system. - */ - SYSTEM; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterTypeDTOV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterTypeDTOV2.java deleted file mode 100644 index ea38d39..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/dtos/enums/ApplicationParameterTypeDTOV2.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.onecx.parameters.rs.external.v2.dtos.enums; - -public enum ApplicationParameterTypeDTOV2 { - - /** - * The number. - */ - NUMBER, - /** - * The string. - */ - STRING, - /** - * The boolean. - */ - BOOLEAN, - /** - * The password. - */ - TEXT_PASSWORD, - /** - * The date. - */ - DATE - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterDataMapperV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterDataMapperV2.java index 6e48564..f979ae6 100644 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterDataMapperV2.java +++ b/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterDataMapperV2.java @@ -1,14 +1,13 @@ package io.github.onecx.parameters.rs.external.v2.mappers; -import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; +import gen.io.github.onecx.parameters.rs.v2.model.ApplicationParameterDTOV2; import io.github.onecx.parameters.domain.models.ApplicationParameterData; -import io.github.onecx.parameters.rs.external.v2.dtos.ApplicationParameterDTOV2; -@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@Mapper public interface ApplicationParameterDataMapperV2 { @Mapping(target = "id", ignore = true) diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterMapperV2.java b/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterMapperV2.java index dc607d3..378ae00 100644 --- a/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterMapperV2.java +++ b/src/main/java/io/github/onecx/parameters/rs/external/v2/mappers/ApplicationParameterMapperV2.java @@ -2,13 +2,10 @@ import java.util.List; -import org.mapstruct.Mapper; -import org.mapstruct.MapperConfig; -import org.mapstruct.Mapping; -import org.mapstruct.ReportingPolicy; +import org.mapstruct.*; +import gen.io.github.onecx.parameters.rs.v2.model.ApplicationParameterDTOV2; import io.github.onecx.parameters.domain.models.ApplicationParameter; -import io.github.onecx.parameters.rs.external.v2.dtos.ApplicationParameterDTOV2; @Mapper @MapperConfig(unmappedTargetPolicy = ReportingPolicy.ERROR) diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3.java b/src/main/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3.java index 8a0a8ae..c2b1b22 100644 --- a/src/main/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3.java +++ b/src/main/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3.java @@ -7,31 +7,20 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import org.eclipse.microprofile.openapi.annotations.Operation; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.tags.Tag; - +import gen.io.github.onecx.parameters.rs.v3.ExternalApi; +import gen.io.github.onecx.parameters.rs.v3.model.ParametersBucketDTOV3; import io.github.onecx.parameters.domain.daos.ApplicationParameterDAO; import io.github.onecx.parameters.domain.daos.ApplicationParameterHistoryDAO; import io.github.onecx.parameters.domain.models.ApplicationParameterHistory; import io.github.onecx.parameters.rs.external.v3.mappers.ApplicationParameterHistoryMapper; -import io.github.onecx.parameters.rs.external.v3.models.ParametersBucketDTO; import lombok.extern.slf4j.Slf4j; @Slf4j @ApplicationScoped -@Path("/v3") -@Tag(name = "external") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) @Transactional(value = Transactional.TxType.NOT_SUPPORTED) -public class ParameterRestControllerV3 { +public class ParameterRestControllerV3 implements ExternalApi { @Inject ApplicationParameterDAO applicationParameterDAO; @@ -42,26 +31,14 @@ public class ParameterRestControllerV3 { @Inject ApplicationParameterHistoryMapper mapper; - @GET - @Path("/{appId}/parameters") - @Operation(operationId = "getApplicationParameters", description = "Get parameters by application id") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Object.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getApplicationParameters(@PathParam(value = "appId") String appId) { + @Override + public Response getApplicationParameters(String appId) { Map applicationParameters = applicationParameterDAO.findAllByApplicationId(appId); return Response.ok(applicationParameters).build(); } - @POST - @Path("/{appId}/history") - @Operation(operationId = "createOrUpdateParameters", description = "Update or create parameters for specific application") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ParametersBucketDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response bucketRequest(@PathParam(value = "appId") String appId, ParametersBucketDTO dto) { + @Override + public Response bucketRequest(String appId, ParametersBucketDTOV3 dto) { if (dto == null || dto.getParameters().isEmpty()) { return Response.status(Response.Status.OK).build(); } diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java b/src/main/java/io/github/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java index c901521..e239065 100644 --- a/src/main/java/io/github/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java +++ b/src/main/java/io/github/onecx/parameters/rs/external/v3/mappers/ApplicationParameterHistoryMapper.java @@ -7,13 +7,13 @@ import org.mapstruct.ReportingPolicy; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; +import gen.io.github.onecx.parameters.rs.v3.model.ParameterInfoDTOV3; import io.github.onecx.parameters.domain.models.ApplicationParameterHistory; -import io.github.onecx.parameters.rs.external.v3.models.ParameterInfoDTO; @Mapper(uses = OffsetDateTimeMapper.class) @MapperConfig(unmappedTargetPolicy = ReportingPolicy.ERROR) public interface ApplicationParameterHistoryMapper { - ApplicationParameterHistory mapItem(ParameterInfoDTO dto, String key, OffsetDateTime start, + ApplicationParameterHistory mapItem(ParameterInfoDTOV3 dto, String key, OffsetDateTime start, OffsetDateTime end, String instanceId, String applicationId, String usedValue); } diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParameterInfoDTO.java b/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParameterInfoDTO.java deleted file mode 100644 index 1827f2a..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParameterInfoDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.onecx.parameters.rs.external.v3.models; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection -public class ParameterInfoDTO { - - private Long count; - - private String type; - - private String defaultValue; - - private String currentValue; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParametersBucketDTO.java b/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParametersBucketDTO.java deleted file mode 100644 index 7454ee4..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/external/v3/models/ParametersBucketDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.onecx.parameters.rs.external.v3.models; - -import java.time.OffsetDateTime; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection -public class ParametersBucketDTO { - - private Map parameters = new ConcurrentHashMap<>(); - - private String instanceId; - - private OffsetDateTime start; - - private OffsetDateTime end; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestController.java b/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestController.java index 0b97e55..c294920 100644 --- a/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestController.java +++ b/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestController.java @@ -1,35 +1,20 @@ package io.github.onecx.parameters.rs.internal; +import java.util.List; + import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import org.eclipse.microprofile.openapi.annotations.Operation; -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.tags.Tag; - -import io.github.onecx.parameters.domain.criteria.ApplicationParameterHistorySearchCriteria; +import gen.io.github.onecx.parameters.rs.internal.HistoriesApi; import io.github.onecx.parameters.domain.daos.ApplicationParameterHistoryDAO; import io.github.onecx.parameters.domain.models.ApplicationParameterHistory; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterHistoryDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterHistoryPageResultDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterHistorySearchCriteriaDTO; -import io.github.onecx.parameters.rs.internal.dtos.ParameterHistoryCountDTO; import io.github.onecx.parameters.rs.internal.mappers.ApplicationParameterInternalMapper; @ApplicationScoped -@Tag(name = "internal") -@Path("/histories") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) @Transactional(value = Transactional.TxType.NOT_SUPPORTED) -public class ApplicationParameterHistoryRestController { +public class ApplicationParameterHistoryRestController implements HistoriesApi { @Inject ApplicationParameterInternalMapper applicationParameterInternalMapper; @@ -37,37 +22,24 @@ public class ApplicationParameterHistoryRestController { @Inject ApplicationParameterHistoryDAO historyDAO; - @GET - @Path("latest") - @Operation(operationId = "getAllApplicationParametersHistoryLatest", description = "Find all parameters history latest") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterHistoryPageResultDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getAllApplicationParametersHistoryLatest(@BeanParam ApplicationParameterHistorySearchCriteriaDTO dto) { - var criteria = applicationParameterInternalMapper.map(dto); + @Override + public Response getAllApplicationParametersHistoryLatest(String applicationId, String key, Integer pageNumber, + Integer pageSize, List type) { + var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); var parametersHistories = historyDAO.searchOnlyLatestByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); } - @GET - @Operation(operationId = "getAllApplicationParametersHistory", description = "Find all parameters history") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterHistoryPageResultDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getAllApplicationParametersHistory(@BeanParam ApplicationParameterHistorySearchCriteriaDTO dto) { - var criteria = applicationParameterInternalMapper.map(dto); + @Override + public Response getAllApplicationParametersHistory(String applicationId, String key, Integer pageNumber, Integer pageSize, + List type) { + var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); var parametersHistories = historyDAO.searchByCriteria(criteria); return Response.ok(applicationParameterInternalMapper.mapHistory(parametersHistories)).build(); } - @GET - @Path("/{id}") - @Operation(operationId = "getApplicationParametersHistoryById", description = "Find parameters history by Id") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterHistoryDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getApplicationParametersHistoryById(@PathParam("id") String id) { + @Override + public Response getApplicationParametersHistoryById(String id) { ApplicationParameterHistory parameter = historyDAO.findById(id); if (parameter == null) { return Response.status(Response.Status.NOT_FOUND).build(); @@ -75,14 +47,10 @@ public Response getApplicationParametersHistoryById(@PathParam("id") String id) return Response.ok(applicationParameterInternalMapper.mapHistory(parameter)).build(); } - @GET - @Path("/counts") - @Operation(operationId = "getCountsByCriteria", description = "Get creation dates and counts by criteria") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ParameterHistoryCountDTO.class, type = SchemaType.ARRAY))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getCountsByCriteria(@BeanParam ApplicationParameterHistorySearchCriteriaDTO dto) { - ApplicationParameterHistorySearchCriteria criteria = applicationParameterInternalMapper.map(dto); + @Override + public Response getCountsByCriteria(String applicationId, String key, Integer pageNumber, Integer pageSize, + List type) { + var criteria = applicationParameterInternalMapper.map(applicationId, key, pageNumber, pageSize, type); var counts = historyDAO.searchCountsByCriteria(criteria); var results = applicationParameterInternalMapper.mapCountList(counts); return Response.ok(results).build(); diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestController.java b/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestController.java index dda2d00..6941300 100644 --- a/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestController.java +++ b/src/main/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestController.java @@ -6,35 +6,27 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; -import jakarta.ws.rs.*; import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.UriInfo; -import org.eclipse.microprofile.openapi.annotations.Operation; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.tags.Tag; - +import gen.io.github.onecx.parameters.rs.internal.ParametersApi; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterCreateDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterPageResultDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterUpdateDTO; import io.github.onecx.parameters.domain.daos.ApplicationParameterDAO; import io.github.onecx.parameters.domain.daos.ApplicationParameterDataDAO; import io.github.onecx.parameters.domain.models.ApplicationParameter; import io.github.onecx.parameters.domain.models.ApplicationParameterData; -import io.github.onecx.parameters.rs.internal.dtos.*; import io.github.onecx.parameters.rs.internal.mappers.ApplicationParameterDataMapper; import io.github.onecx.parameters.rs.internal.mappers.ApplicationParameterInternalMapper; import lombok.extern.slf4j.Slf4j; -@ApplicationScoped @Slf4j -@Tag(name = "internal") -@Path("/parameters") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) +@ApplicationScoped @Transactional(value = Transactional.TxType.NOT_SUPPORTED) -public class ApplicationParameterRestController { +public class ApplicationParameterRestController implements ParametersApi { @Inject ApplicationParameterDAO applicationParameterDAO; @@ -48,43 +40,35 @@ public class ApplicationParameterRestController { @Inject ApplicationParameterDataMapper applicationParameterDataMapper; - @GET() - @Path("applications") - @Operation(operationId = "getAllApplications", description = "Find all parameters") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationsPageResultDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") + @Context + UriInfo uriInfo; + + @Override public Response getAllApplications() { var apps = applicationParameterDAO.searchAllApplications(); return Response.ok(applicationParameterInternalMapper.apps(apps)).build(); } - @GET() - @Path("keys") - @Operation(operationId = "getAllKeys", description = "Find all parameters") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = KeysPageResultDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getAllKeys(@BeanParam KeysSearchCriteriaDTO dto) { - var criteria = applicationParameterInternalMapper.map(dto); + @Override + public Response getAllKeys(String applicationId) { + var criteria = applicationParameterInternalMapper.map(applicationId); var keys = applicationParameterDAO.searchAllKeys(criteria); - return Response.ok(applicationParameterInternalMapper.apps(keys)).build(); + return Response.ok(applicationParameterInternalMapper.keys(keys)).build(); } - @GET - @Operation(operationId = "getAllApplicationParameters", description = "Find all parameters") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterPageResultDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getAllApplicationParameters(@BeanParam ApplicationParameterSearchCriteriaDTO dto) { - var criteria = applicationParameterInternalMapper.map(dto); + @Override + public Response getAllApplicationParameters(String applicationId, String key, String name, Integer pageNumber, + Integer pageSize, List type) { + + var criteria = applicationParameterInternalMapper.map(applicationId, key, name, pageNumber, pageSize, type); var parameters = applicationParameterDAO.searchByCriteria(criteria); ApplicationParameterPageResultDTO results = applicationParameterInternalMapper.map(parameters); // map ApplicationParameterData to ApplicationParameter due to backward compatibility if (!results.getStream().isEmpty()) { List data = results.getStream(); - var parametersData = applicationParameterDataDAO.findByParameterIds(data.stream().map(TraceableDTO::getId).toList()) + var parametersData = applicationParameterDataDAO + .findByParameterIds(data.stream().map(ApplicationParameterDTO::getId).toList()) .stream() .collect(Collectors.toMap(ApplicationParameterData::getApplicationParameterGuid, d -> d)); @@ -96,14 +80,8 @@ public Response getAllApplicationParameters(@BeanParam ApplicationParameterSearc return Response.ok(results).build(); } - @GET - @Path("/{id}") - @Operation(operationId = "getParameterById", description = "Find parameter by id") - @APIResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ApplicationParameterDTO.class))) - @APIResponse(responseCode = "400", description = "Bad request") - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response getParameterById(@PathParam("id") String id) { + @Override + public Response getParameterById(String id) { ApplicationParameter param = applicationParameterDAO.findById(id); if (param == null) { return Response.status(Response.Status.NOT_FOUND) @@ -120,15 +98,9 @@ public Response getParameterById(@PathParam("id") String id) { return Response.ok(parameterDTO).build(); } - @PUT - @Path("/{id}") + @Override @Transactional - @Operation(operationId = "updateParameterValue", description = "Update parameter") - @APIResponse(responseCode = "204", description = "No Content") - @APIResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = RestExceptionDTO.class))) - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response updateParameterValue(@PathParam("id") String id, + public Response updateParameterValue(String id, ApplicationParameterUpdateDTO applicationParameterUpdateDTO) { ApplicationParameter applicationParameter = applicationParameterDAO.findById(id); if (applicationParameter == null) { @@ -160,20 +132,11 @@ public Response updateParameterValue(@PathParam("id") String id, return Response.status(Response.Status.NO_CONTENT.getStatusCode()).build(); } - @POST + @Override @Transactional - @Operation(operationId = "createParameterValue", description = "Create parameter") - @APIResponse(responseCode = "204", description = "No Content") - @APIResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = RestExceptionDTO.class))) - @APIResponse(responseCode = "404", description = "Not Found") - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response createParameterValue(ApplicationParameterCreateDTO request, @Context UriInfo uriInfo) { - ApplicationParameter param = new ApplicationParameter(); - param.setApplicationId(request.getApplicationId()); - param.setKey(request.getKey()); - param.setType(request.getType()); - param.setDescription(request.getDescription()); - param.setSetValue(request.getValue()); + public Response createParameterValue(ApplicationParameterCreateDTO request) { + + ApplicationParameter param = applicationParameterDataMapper.create(request); param = applicationParameterDAO.create(param); // ApplicationParameterData creation due to backward compatibility @@ -189,14 +152,9 @@ public Response createParameterValue(ApplicationParameterCreateDTO request, @Con .build(); } - @DELETE - @Path("/{id}") + @Override @Transactional - @Operation(operationId = "deleteParameter", description = "Delete parameter") - @APIResponse(responseCode = "204", description = "No Content") - @APIResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = RestExceptionDTO.class))) - @APIResponse(responseCode = "500", description = "Internal Server Error") - public Response deleteParameter(@PathParam("id") String id) { + public Response deleteParameter(String id) { ApplicationParameter parameter = applicationParameterDAO.findById(id); if (parameter != null) { applicationParameterDAO.delete(parameter); diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterCreateDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterCreateDTO.java deleted file mode 100644 index 255693e..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterCreateDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@RegisterForReflection -public class ApplicationParameterCreateDTO { - - private String key; - - private String applicationId; - - private String value; - - private String type; - - private String description; - - private String unit; - - private Integer rangeFrom; - - private Integer rangeTo; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterDTO.java deleted file mode 100644 index be5066f..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterDTO.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@RegisterForReflection -@SuppressWarnings("java:S2160") -public class ApplicationParameterDTO extends TraceableDTO { - - private String name; - - private String description; - - private String applicationId; - - private String key; - - private String setValue; - - private String importValue; - - private String type; - - private String unit; - - private Integer rangeFrom; - - private Integer rangeTo; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryDTO.java deleted file mode 100644 index ef37f0a..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@RegisterForReflection -@SuppressWarnings("java:S2160") -public class ApplicationParameterHistoryDTO extends TraceableDTO { - - private String applicationId; - - private String key; - - private String usedValue; - - private String defaultValue; - - private String type; - - private String instanceId; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryPageResultDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryPageResultDTO.java deleted file mode 100644 index 762e7f5..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistoryPageResultDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection -public class ApplicationParameterHistoryPageResultDTO extends PageResultDTO { -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistorySearchCriteriaDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistorySearchCriteriaDTO.java deleted file mode 100644 index 31c127c..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterHistorySearchCriteriaDTO.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.util.List; - -import jakarta.ws.rs.DefaultValue; -import jakarta.ws.rs.QueryParam; - -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Schema; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class ApplicationParameterHistorySearchCriteriaDTO { - - @QueryParam("applicationId") - @Schema(description = "The application parameter id.") - private String applicationId; - - @QueryParam("key") - @Schema(description = "The application parameter key.") - private String key; - - @QueryParam("type") - @Schema(description = "The application parameter type.", implementation = String.class, type = SchemaType.ARRAY) - private List type; - - @DefaultValue("0") - @QueryParam("pageNumber") - @Schema(description = "The number of page.") - private Integer pageNumber = 0; - - @DefaultValue("100") - @QueryParam("pageSize") - @Schema(description = "The size of page") - private Integer pageSize = 100; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterPageResultDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterPageResultDTO.java deleted file mode 100644 index e665b36..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterPageResultDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection -public class ApplicationParameterPageResultDTO extends PageResultDTO { - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterSearchCriteriaDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterSearchCriteriaDTO.java deleted file mode 100644 index a471681..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterSearchCriteriaDTO.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.util.List; - -import jakarta.ws.rs.DefaultValue; -import jakarta.ws.rs.QueryParam; - -import org.eclipse.microprofile.openapi.annotations.media.Schema; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class ApplicationParameterSearchCriteriaDTO { - - @QueryParam("applicationId") - @Schema(description = "The application parameter id.") - private String applicationId; - - @QueryParam("key") - @Schema(description = "The application parameter key.") - private String key; - - @QueryParam("name") - @Schema(description = "The application parameter name.") - private String name; - - @QueryParam("type") - @Schema(description = "The application parameter type.") - private List type; - - @DefaultValue("0") - @QueryParam("pageNumber") - @Schema(description = "The number of page.") - private Integer pageNumber = 0; - - @DefaultValue("100") - @QueryParam("pageSize") - @Schema(description = "The size of page") - private Integer pageSize = 100; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterUpdateDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterUpdateDTO.java deleted file mode 100644 index 6f67f21..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationParameterUpdateDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@RegisterForReflection -public class ApplicationParameterUpdateDTO { - - private Object value; - - private String description; - - private String unit; - - private Integer rangeFrom; - - private Integer rangeTo; -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationsPageResultDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationsPageResultDTO.java deleted file mode 100644 index 153abca..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ApplicationsPageResultDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection -public class ApplicationsPageResultDTO extends PageResultDTO { -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysPageResultDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysPageResultDTO.java deleted file mode 100644 index b3bb145..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysPageResultDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection -public class KeysPageResultDTO extends PageResultDTO { -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysSearchCriteriaDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysSearchCriteriaDTO.java deleted file mode 100644 index cba0b35..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/KeysSearchCriteriaDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import jakarta.ws.rs.QueryParam; - -import org.eclipse.microprofile.openapi.annotations.media.Schema; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class KeysSearchCriteriaDTO { - - @QueryParam("applicationId") - @Schema(description = "The application parameter id.") - private String applicationId; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/PageResultDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/PageResultDTO.java deleted file mode 100644 index 7d0a242..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/PageResultDTO.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.util.List; - -import org.eclipse.microprofile.openapi.annotations.media.Schema; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection -public class PageResultDTO { - - /** - * The total elements in the database. - */ - @Schema(description = "The total elements in the resource.") - private long totalElements; - - /** - * The page index. - */ - private int number; - - /** - * The page size. - */ - private int size; - - /** - * The number of pages. - */ - private long totalPages; - - /** - * The data stream. - */ - private List stream; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ParameterHistoryCountDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ParameterHistoryCountDTO.java deleted file mode 100644 index 86147e7..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/ParameterHistoryCountDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.time.LocalDateTime; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@RegisterForReflection -public class ParameterHistoryCountDTO { - - private LocalDateTime creationDate; - - private Long count; - -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/RestExceptionDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/RestExceptionDTO.java deleted file mode 100644 index bcb6b03..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/RestExceptionDTO.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection -public class RestExceptionDTO { - - /** - * The error code. - */ - private String errorCode; - - /** - * The message. - */ - private String message; - - /** - * The error parameters. - */ - private List parameters; - - /** - * The named parameters. - */ - private Map namedParameters = new HashMap<>(); -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/TraceableDTO.java b/src/main/java/io/github/onecx/parameters/rs/internal/dtos/TraceableDTO.java deleted file mode 100644 index 1ccd729..0000000 --- a/src/main/java/io/github/onecx/parameters/rs/internal/dtos/TraceableDTO.java +++ /dev/null @@ -1,95 +0,0 @@ -package io.github.onecx.parameters.rs.internal.dtos; - -import java.time.OffsetDateTime; -import java.util.Objects; -import java.util.UUID; - -import io.quarkus.runtime.annotations.RegisterForReflection; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@RegisterForReflection -public class TraceableDTO { - - /** - * The ID. - */ - private String id = UUID.randomUUID().toString(); - - /** - * Optimistic lock version - */ - private Integer modificationCount; - - /** - * The creation date. - */ - private OffsetDateTime creationDate; - /** - * The creation user. - */ - private String creationUser; - /** - * The modification date. - */ - private OffsetDateTime modificationDate; - /** - * The modification user. - */ - private String modificationUser; - - /** - * Overwrite the {@code toString} method for the logger. - * - * @return the className:ID - */ - @Override - public String toString() { - return this.getClass().getSimpleName() + ":" + getId(); - } - - /** - * {@inheritDoc } - * - * @see Object#equals(Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - TraceableDTO other = (TraceableDTO) obj; - Object guid = getId(); - Object otherGuid = other.getId(); - - if (guid == null) { - if (otherGuid != null) { - return false; - } else { - return super.equals(obj); - } - } else - return guid.equals(otherGuid); - } - - /** - * {@inheritDoc } - * - * @see Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Objects.hashCode(getId()); - return result; - } -} diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java b/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java index ed616a4..59a4a83 100644 --- a/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java +++ b/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterDataMapper.java @@ -1,17 +1,17 @@ package io.github.onecx.parameters.rs.internal.mappers; import org.apache.commons.lang3.StringUtils; -import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterCreateDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterUpdateDTO; +import io.github.onecx.parameters.domain.models.ApplicationParameter; import io.github.onecx.parameters.domain.models.ApplicationParameterData; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterCreateDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterUpdateDTO; -@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@Mapper public interface ApplicationParameterDataMapper { default ApplicationParameterData update(ApplicationParameterUpdateDTO dto, ApplicationParameterData entity) { @@ -27,6 +27,9 @@ default ApplicationParameterData update(ApplicationParameterUpdateDTO dto, Appli return entity; } + @Mapping(target = "setValue", source = "value") + ApplicationParameter create(ApplicationParameterCreateDTO dto); + default ApplicationParameterData create(ApplicationParameterUpdateDTO dto, String applicationParameterId) { ApplicationParameterData entity = new ApplicationParameterData(); entity.setApplicationParameterGuid(applicationParameterId); diff --git a/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java b/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java index b7b055c..8307dac 100644 --- a/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java +++ b/src/main/java/io/github/onecx/parameters/rs/internal/mappers/ApplicationParameterInternalMapper.java @@ -6,26 +6,31 @@ import org.tkit.quarkus.jpa.daos.PageResult; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; +import gen.io.github.onecx.parameters.rs.internal.model.*; import io.github.onecx.parameters.domain.criteria.ApplicationParameterHistorySearchCriteria; import io.github.onecx.parameters.domain.criteria.ApplicationParameterSearchCriteria; import io.github.onecx.parameters.domain.criteria.KeysSearchCriteria; import io.github.onecx.parameters.domain.models.ApplicationParameter; import io.github.onecx.parameters.domain.models.ApplicationParameterHistory; import io.github.onecx.parameters.domain.models.ParameterHistoryCountTuple; -import io.github.onecx.parameters.rs.internal.dtos.*; -@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, uses = { OffsetDateTimeMapper.class }) +@Mapper(uses = { OffsetDateTimeMapper.class }) public interface ApplicationParameterInternalMapper { - KeysSearchCriteria map(KeysSearchCriteriaDTO dto); + @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) + KeysSearchCriteria map(String applicationId); KeysPageResultDTO keys(PageResult page); ApplicationsPageResultDTO apps(PageResult page); - ApplicationParameterHistorySearchCriteria map(ApplicationParameterHistorySearchCriteriaDTO dto); + @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) + ApplicationParameterHistorySearchCriteria map(String applicationId, String key, Integer pageNumber, Integer pageSize, + List type); - ApplicationParameterSearchCriteria map(ApplicationParameterSearchCriteriaDTO dto); + @BeanMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) + ApplicationParameterSearchCriteria map(String applicationId, String key, String name, Integer pageNumber, Integer pageSize, + List type); ApplicationParameterHistoryPageResultDTO mapHistory(PageResult page); diff --git a/src/main/openapi/di-v1.yaml b/src/main/openapi/di-v1.yaml new file mode 100644 index 0000000..ec19443 --- /dev/null +++ b/src/main/openapi/di-v1.yaml @@ -0,0 +1,28 @@ +--- +openapi: 3.0.3 +paths: +components: + schemas: + DataImport: + type: object + properties: + default: + type: string + additionalProperties: + $ref: '#/components/schemas/DataImportApp' + DataImportApp: + type: object + properties: + default: + type: string + additionalProperties: + $ref: '#/components/schemas/DataImportParam' + DataImportParam: + type: object + properties: + description: + type: string + name: + type: string + value: + type: string diff --git a/openapi/openapi-internal.yaml b/src/main/openapi/openapi-internal.yaml similarity index 91% rename from openapi/openapi-internal.yaml rename to src/main/openapi/openapi-internal.yaml index a73ec8f..9559593 100644 --- a/openapi/openapi-internal.yaml +++ b/src/main/openapi/openapi-internal.yaml @@ -7,12 +7,13 @@ info: servers: - url: http://onecx-parameters-svc:8080/ tags: -- name: internal +- name: histories +- name: parameters paths: /histories: get: tags: - - internal + - histories description: Find all parameters history operationId: getAllApplicationParametersHistory parameters: @@ -31,14 +32,14 @@ paths: schema: format: int32 description: The number of page. - default: "0" + default: 0 type: integer - name: pageSize in: query schema: format: int32 description: The size of page - default: "100" + default: 100 type: integer - name: type in: query @@ -53,7 +54,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterHistoryPageResultDTO' + $ref: '#/components/schemas/ApplicationParameterHistoryPageResult' "400": description: Bad request "500": @@ -61,7 +62,7 @@ paths: /histories/counts: get: tags: - - internal + - histories description: Get creation dates and counts by criteria operationId: getCountsByCriteria parameters: @@ -80,14 +81,14 @@ paths: schema: format: int32 description: The number of page. - default: "0" + default: 0 type: integer - name: pageSize in: query schema: format: int32 description: The size of page - default: "100" + default: 100 type: integer - name: type in: query @@ -104,7 +105,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/ParameterHistoryCountDTO' + $ref: '#/components/schemas/ParameterHistoryCount' "400": description: Bad request "500": @@ -112,7 +113,7 @@ paths: /histories/latest: get: tags: - - internal + - histories description: Find all parameters history latest operationId: getAllApplicationParametersHistoryLatest parameters: @@ -131,14 +132,14 @@ paths: schema: format: int32 description: The number of page. - default: "0" + default: 0 type: integer - name: pageSize in: query schema: format: int32 description: The size of page - default: "100" + default: 100 type: integer - name: type in: query @@ -153,7 +154,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterHistoryPageResultDTO' + $ref: '#/components/schemas/ApplicationParameterHistoryPageResult' "400": description: Bad request "500": @@ -161,7 +162,7 @@ paths: /histories/{id}: get: tags: - - internal + - histories description: Find parameters history by Id operationId: getApplicationParametersHistoryById parameters: @@ -176,7 +177,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterHistoryDTO' + $ref: '#/components/schemas/ApplicationParameterHistory' "400": description: Bad request "404": @@ -186,7 +187,7 @@ paths: /parameters: get: tags: - - internal + - parameters description: Find all parameters operationId: getAllApplicationParameters parameters: @@ -210,41 +211,43 @@ paths: schema: format: int32 description: The number of page. - default: "0" + default: 0 type: integer - name: pageSize in: query schema: format: int32 description: The size of page - default: "100" + default: 100 type: integer - name: type in: query schema: description: The application parameter type. - type: object + type: array + items: + type: string responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterPageResultDTO' + $ref: '#/components/schemas/ApplicationParameterPageResult' "400": description: Bad request "500": description: Internal Server Error post: tags: - - internal + - parameters description: Create parameter operationId: createParameterValue requestBody: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterCreateDTO' + $ref: '#/components/schemas/ApplicationParameterCreate' responses: "204": description: No Content @@ -253,7 +256,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/RestExceptionDTO' + $ref: '#/components/schemas/RestException' "404": description: Not Found "500": @@ -261,7 +264,7 @@ paths: /parameters/applications: get: tags: - - internal + - parameters description: Find all parameters operationId: getAllApplications responses: @@ -270,7 +273,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationsPageResultDTO' + $ref: '#/components/schemas/ApplicationsPageResult' "400": description: Bad request "500": @@ -278,7 +281,7 @@ paths: /parameters/keys: get: tags: - - internal + - parameters description: Find all parameters operationId: getAllKeys parameters: @@ -293,7 +296,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/KeysPageResultDTO' + $ref: '#/components/schemas/KeysPageResult' "400": description: Bad request "500": @@ -301,7 +304,7 @@ paths: /parameters/{id}: get: tags: - - internal + - parameters description: Find parameter by id operationId: getParameterById parameters: @@ -316,7 +319,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterDTO' + $ref: '#/components/schemas/ApplicationParameter' "400": description: Bad request "404": @@ -325,7 +328,7 @@ paths: description: Internal Server Error put: tags: - - internal + - parameters description: Update parameter operationId: updateParameterValue parameters: @@ -338,7 +341,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterUpdateDTO' + $ref: '#/components/schemas/ApplicationParameterUpdate' responses: "204": description: No Content @@ -347,14 +350,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/RestExceptionDTO' + $ref: '#/components/schemas/RestException' "404": description: Not Found "500": description: Internal Server Error delete: tags: - - internal + - parameters description: Delete parameter operationId: deleteParameter parameters: @@ -371,12 +374,12 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/RestExceptionDTO' + $ref: '#/components/schemas/RestException' "500": description: Internal Server Error components: schemas: - ApplicationParameterCreateDTO: + ApplicationParameterCreate: type: object properties: key: @@ -397,7 +400,7 @@ components: rangeTo: format: int32 type: integer - ApplicationParameterDTO: + ApplicationParameter: type: object properties: id: @@ -439,7 +442,7 @@ components: rangeTo: format: int32 type: integer - ApplicationParameterHistoryDTO: + ApplicationParameterHistory: type: object properties: id: @@ -471,7 +474,7 @@ components: type: string instanceId: type: string - ApplicationParameterHistoryPageResultDTO: + ApplicationParameterHistoryPageResult: type: object properties: totalElements: @@ -490,8 +493,8 @@ components: stream: type: array items: - $ref: '#/components/schemas/ApplicationParameterHistoryDTO' - ApplicationParameterPageResultDTO: + $ref: '#/components/schemas/ApplicationParameterHistory' + ApplicationParameterPageResult: type: object properties: totalElements: @@ -510,8 +513,8 @@ components: stream: type: array items: - $ref: '#/components/schemas/ApplicationParameterDTO' - ApplicationParameterUpdateDTO: + $ref: '#/components/schemas/ApplicationParameter' + ApplicationParameterUpdate: type: object properties: value: {} @@ -525,7 +528,7 @@ components: rangeTo: format: int32 type: integer - ApplicationsPageResultDTO: + ApplicationsPageResult: type: object properties: totalElements: @@ -545,7 +548,7 @@ components: type: array items: type: string - KeysPageResultDTO: + KeysPageResult: type: object properties: totalElements: @@ -565,7 +568,7 @@ components: type: array items: type: string - ParameterHistoryCountDTO: + ParameterHistoryCount: type: object properties: creationDate: @@ -575,7 +578,7 @@ components: count: format: int64 type: integer - RestExceptionDTO: + RestException: type: object properties: errorCode: diff --git a/openapi/openapi-v2.yaml b/src/main/openapi/openapi-v2.yaml similarity index 96% rename from openapi/openapi-v2.yaml rename to src/main/openapi/openapi-v2.yaml index 2501391..437d79e 100644 --- a/openapi/openapi-v2.yaml +++ b/src/main/openapi/openapi-v2.yaml @@ -125,7 +125,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ApplicationParameterDTOV2' + $ref: '#/components/schemas/ApplicationParameter' "400": description: Bad request "404": @@ -158,7 +158,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/ApplicationParameterDTOV2' + $ref: '#/components/schemas/ApplicationParameter' "400": description: Bad request "404": @@ -198,7 +198,7 @@ paths: description: Internal Server Error components: schemas: - ApplicationParameterDTOV2: + ApplicationParameter: type: object properties: persisted: @@ -217,11 +217,11 @@ components: description: type: string type: - $ref: '#/components/schemas/ApplicationParameterTypeDTOV2' + $ref: '#/components/schemas/ApplicationParameterType' applicationId: type: string roleType: - $ref: '#/components/schemas/ApplicationParameterRoleTypeDTOV2' + $ref: '#/components/schemas/ApplicationParameterRoleType' unit: type: string valueRangeFrom: @@ -230,12 +230,12 @@ components: valueRangeTo: format: int32 type: integer - ApplicationParameterRoleTypeDTOV2: + ApplicationParameterRoleType: enum: - BUSINESS - SYSTEM type: string - ApplicationParameterTypeDTOV2: + ApplicationParameterType: enum: - NUMBER - STRING diff --git a/openapi/openapi-v3.yaml b/src/main/openapi/openapi-v3.yaml similarity index 84% rename from openapi/openapi-v3.yaml rename to src/main/openapi/openapi-v3.yaml index 0109162..296d2d1 100644 --- a/openapi/openapi-v3.yaml +++ b/src/main/openapi/openapi-v3.yaml @@ -13,8 +13,8 @@ paths: post: tags: - external - description: Update or create parameters for specific application - operationId: createOrUpdateParameters + description: Create Bucket request + operationId: bucketRequest parameters: - name: appId in: path @@ -25,14 +25,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ParametersBucketDTO' + $ref: '#/components/schemas/ParametersBucket' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ParametersBucketDTO' + $ref: '#/components/schemas/ParametersBucket' "400": description: Bad request "404": @@ -65,7 +65,7 @@ paths: description: Internal Server Error components: schemas: - ParameterInfoDTO: + ParameterInfo: type: object properties: count: @@ -77,13 +77,13 @@ components: type: string currentValue: type: string - ParametersBucketDTO: + ParametersBucket: type: object properties: parameters: type: object additionalProperties: - $ref: '#/components/schemas/ParameterInfoDTO' + $ref: '#/components/schemas/ParameterInfo' instanceId: type: string start: diff --git a/src/test/java/io/github/onecx/parameters/domain/daos/ApplicationParameterDAOTest.java b/src/test/java/io/github/onecx/parameters/domain/daos/ApplicationParameterDAOTest.java index e4671a9..dd55c7c 100644 --- a/src/test/java/io/github/onecx/parameters/domain/daos/ApplicationParameterDAOTest.java +++ b/src/test/java/io/github/onecx/parameters/domain/daos/ApplicationParameterDAOTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import org.tkit.quarkus.test.WithDBData; -import io.github.onecx.parameters.domain.di.ApplicationParameterDataImportService; +import io.github.onecx.parameters.domain.di.v1.ParameterDataImportService; import io.github.onecx.parameters.domain.models.ApplicationParameter; import io.quarkus.test.junit.QuarkusTest; @@ -24,7 +24,7 @@ class ApplicationParameterDAOTest { void findApplicationParametersByKeysTest() { Set data = Set.of("app1__param", "app1__integer_param"); Map result = dao.findApplicationParametersByKeys(data, - ApplicationParameterDataImportService.KEY_SEPARATOR); + ParameterDataImportService.KEY_SEPARATOR); Assertions.assertNotNull(result); Assertions.assertEquals(2, result.size()); } @@ -34,7 +34,7 @@ void findApplicationParametersByKeysTest() { void findApplicationParametersByKeysNoResultTest() { Set data = Set.of("appx__paramx"); Map result = dao.findApplicationParametersByKeys(data, - ApplicationParameterDataImportService.KEY_SEPARATOR); + ParameterDataImportService.KEY_SEPARATOR); Assertions.assertNotNull(result); Assertions.assertEquals(0, result.size()); } diff --git a/src/test/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportServiceTest.java b/src/test/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportServiceTest.java similarity index 82% rename from src/test/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportServiceTest.java rename to src/test/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportServiceTest.java index 69639c5..886f1af 100644 --- a/src/test/java/io/github/onecx/parameters/domain/di/ApplicationParameterDataImportServiceTest.java +++ b/src/test/java/io/github/onecx/parameters/domain/di/v1/ParameterDataImportServiceTest.java @@ -1,4 +1,4 @@ -package io.github.onecx.parameters.domain.di; +package io.github.onecx.parameters.domain.di.v1; import java.util.HashMap; import java.util.List; @@ -14,18 +14,20 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import gen.io.github.onecx.parameters.di.v1.model.DataImportAppDTOV1; +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 io.github.onecx.parameters.test.AbstractTest; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) -class ApplicationParameterDataImportServiceTest extends AbstractTest { +class ParameterDataImportServiceTest extends AbstractTest { @Inject - ApplicationParameterDataImportService service; + ParameterDataImportService service; @Inject ApplicationParameterDAO dao; @@ -59,13 +61,16 @@ public Map getMetadata() { @Test void importCleanInsertTest() { - ApplicationParameterDataImport param = new ApplicationParameterDataImport(); - param.setDescription("desc"); - param.setName("name-of-name"); + DataImportParamDTOV1 k1 = new DataImportParamDTOV1(); + k1.setDescription("desc"); + k1.setName("name-of-name"); + + DataImportAppDTOV1 a1 = new DataImportAppDTOV1(); + a1.put("key1", k1); - var data = new HashMap>(); - data.put("app1", Map.of("key1", param)); - data.put("empty", Map.of()); + DataImportDTOV1 data = new DataImportDTOV1(); + data.put("app1", a1); + data.put("empty", new DataImportAppDTOV1()); data.put("null", null); service.importData(new DataImportConfig() { @@ -93,24 +98,28 @@ public byte[] getData() { @Test void importUpdateTest() { - ApplicationParameterDataImport param = new ApplicationParameterDataImport(); + DataImportParamDTOV1 param = new DataImportParamDTOV1(); param.setDescription("desc"); param.setName("name-of-name"); param.setValue("123"); - ApplicationParameterDataImport emptyValueParam = new ApplicationParameterDataImport(); + DataImportParamDTOV1 emptyValueParam = new DataImportParamDTOV1(); emptyValueParam.setDescription(""); emptyValueParam.setName(""); emptyValueParam.setValue(""); - var data = new HashMap>(); - data.put("app1", - Map.of( - "param", param, - "integer_param", new ApplicationParameterDataImport(), - "boolean_param", emptyValueParam)); - data.put("app_new", Map.of("key_new", param)); - data.put("empty", Map.of()); + DataImportAppDTOV1 appNew = new DataImportAppDTOV1(); + appNew.put("key_new", param); + + DataImportAppDTOV1 app1 = new DataImportAppDTOV1(); + app1.put("param", param); + app1.put("integer_param", new DataImportParamDTOV1()); + app1.put("boolean_param", emptyValueParam); + + DataImportDTOV1 data = new DataImportDTOV1(); + data.put("app1", app1); + data.put("app_new", appNew); + data.put("empty", new DataImportAppDTOV1()); data.put("null", null); service.importData(new DataImportConfig() { @@ -149,8 +158,8 @@ public byte[] getData() { @Test void importUpdateNoDataToUpdateTest() { - var data = new HashMap>(); - data.put("empty", Map.of()); + DataImportDTOV1 data = new DataImportDTOV1(); + data.put("empty", new DataImportAppDTOV1()); data.put("null", null); service.importData(new DataImportConfig() { diff --git a/src/test/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java b/src/test/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java index 0e9961d..1d0397b 100644 --- a/src/test/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java +++ b/src/test/java/io/github/onecx/parameters/domain/timer/MaintenanceHistoryServiceExceptionTest.java @@ -13,7 +13,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.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; diff --git a/src/test/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java b/src/test/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java index bf317dc..8017b42 100644 --- a/src/test/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java +++ b/src/test/java/io/github/onecx/parameters/rs/external/v3/ParameterRestControllerV3Test.java @@ -11,15 +11,16 @@ import org.junit.jupiter.api.Test; import org.tkit.quarkus.test.WithDBData; -import io.github.onecx.parameters.rs.external.v3.models.ParameterInfoDTO; -import io.github.onecx.parameters.rs.external.v3.models.ParametersBucketDTO; +import gen.io.github.onecx.parameters.rs.v3.ExternalApi; +import gen.io.github.onecx.parameters.rs.v3.model.ParameterInfoDTOV3; +import gen.io.github.onecx.parameters.rs.v3.model.ParametersBucketDTOV3; import io.github.onecx.parameters.test.AbstractTest; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.json.JsonPath; @QuarkusTest -@TestHTTPEndpoint(ParameterRestControllerV3.class) +@TestHTTPEndpoint(ExternalApi.class) class ParameterRestControllerV3Test extends AbstractTest { @Test @@ -27,7 +28,7 @@ void shouldNotFindParametersWithGivenApplicationId() { Map applicationParameters = given() .when() .pathParam("appId", "not-exist") - .get("{appId}/parameters") + .get("parameters") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -43,7 +44,7 @@ void shouldReturnImportValueParameter() { .when() .contentType(APPLICATION_JSON) .pathParam("appId", "import-app") - .get("{appId}/parameters") + .get("parameters") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -59,7 +60,7 @@ void shouldReturnParameter() { Map applicationParameters = given() .when() .pathParam("appId", "access-mgmt") - .get("{appId}/parameters") + .get("parameters") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -75,7 +76,7 @@ void shouldNotReturnParameterWithNullSetValue() { JsonPath applicationParameters = given() .when() .pathParam("appId", "access-mgmt") - .get("{appId}/parameters") + .get("parameters") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -88,8 +89,8 @@ void shouldNotReturnParameterWithNullSetValue() { @Test @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) void shouldCreateNewParameter() { - ParametersBucketDTO parametersBucketDTO = new ParametersBucketDTO(); - ParameterInfoDTO parameterInfoDTO1 = new ParameterInfoDTO(); + ParametersBucketDTOV3 parametersBucketDTO = new ParametersBucketDTOV3(); + ParameterInfoDTOV3 parameterInfoDTO1 = new ParameterInfoDTOV3(); parameterInfoDTO1.setCount(1L); parameterInfoDTO1.setCurrentValue("DefaultValue"); parameterInfoDTO1.setDefaultValue("DefaultValue"); @@ -99,13 +100,13 @@ void shouldCreateNewParameter() { .contentType(APPLICATION_JSON) .body(parametersBucketDTO) .pathParam("appId", "new-application") - .post("{appId}/history") + .post("history") .then() .statusCode(Response.Status.OK.getStatusCode()); Map applicationParameters = given() .when() .pathParam("appId", "new-application") - .get("{appId}/parameters") + .get("parameters") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) @@ -117,8 +118,8 @@ void shouldCreateNewParameter() { @Test @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) void shouldUpdateParameters() { - ParametersBucketDTO parametersBucketDTO = new ParametersBucketDTO(); - ParameterInfoDTO parameterInfoDTO1 = new ParameterInfoDTO(); + ParametersBucketDTOV3 parametersBucketDTO = new ParametersBucketDTOV3(); + ParameterInfoDTOV3 parameterInfoDTO1 = new ParameterInfoDTOV3(); parameterInfoDTO1.setCount(2L); parameterInfoDTO1.setCurrentValue("10"); parameterInfoDTO1.setDefaultValue("10"); @@ -128,7 +129,7 @@ void shouldUpdateParameters() { .contentType(APPLICATION_JSON) .body(parametersBucketDTO) .pathParam("appId", "access-mgmt") - .post("{appId}/history") + .post("history") .then() .statusCode(Response.Status.OK.getStatusCode()); } @@ -138,19 +139,19 @@ void bucketRequestEmptyDTO() { given() .contentType(APPLICATION_JSON) .pathParam("appId", "test") - .post("{appId}/history") + .post("history") .then() .statusCode(Response.Status.OK.getStatusCode()); } @Test void bucketRequestNoParametersDTO() { - ParametersBucketDTO parametersBucketDTO = new ParametersBucketDTO(); + ParametersBucketDTOV3 parametersBucketDTO = new ParametersBucketDTOV3(); given() .contentType(APPLICATION_JSON) .body(parametersBucketDTO) .pathParam("appId", "test") - .post("{appId}/history") + .post("history") .then() .statusCode(Response.Status.OK.getStatusCode()); } diff --git a/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java b/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java index f154a98..1186320 100644 --- a/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java +++ b/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterHistoryRestControllerTest.java @@ -15,8 +15,8 @@ import org.junit.jupiter.params.provider.MethodSource; import org.tkit.quarkus.test.WithDBData; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterHistoryDTO; -import io.github.onecx.parameters.rs.internal.dtos.PageResultDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterHistoryDTO; +import gen.io.github.onecx.parameters.rs.internal.model.ApplicationParameterHistoryPageResultDTO; import io.github.onecx.parameters.test.AbstractTest; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; @@ -33,7 +33,7 @@ void shouldFindAllParametersHistoryWithoutCriteria() { .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) - .extract().body().as(PageResultDTO.class); + .extract().body().as(ApplicationParameterHistoryPageResultDTO.class); Assertions.assertEquals(6, pageResultDTO.getStream().size()); Assertions.assertEquals(Long.valueOf(6), pageResultDTO.getTotalElements()); @@ -62,7 +62,7 @@ void shouldFindParametersHistoryByCriteria(Map queryParams, Inte .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(PageResultDTO.class); + .body().as(ApplicationParameterHistoryPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); } @@ -89,7 +89,7 @@ void shouldFindParametersHistoryByCriteriaQueryLatest(Map queryP .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(PageResultDTO.class); + .body().as(ApplicationParameterHistoryPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); } diff --git a/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java b/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java index 6d139e9..049fc51 100644 --- a/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java +++ b/src/test/java/io/github/onecx/parameters/rs/internal/ApplicationParameterRestControllerTest.java @@ -17,10 +17,7 @@ import org.junit.jupiter.params.provider.MethodSource; import org.tkit.quarkus.test.WithDBData; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterCreateDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterDTO; -import io.github.onecx.parameters.rs.internal.dtos.ApplicationParameterUpdateDTO; -import io.github.onecx.parameters.rs.internal.dtos.PageResultDTO; +import gen.io.github.onecx.parameters.rs.internal.model.*; import io.github.onecx.parameters.test.AbstractTest; import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; @@ -35,11 +32,11 @@ class ApplicationParameterRestControllerTest extends AbstractTest { @Test @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) void shouldFindAllParametersWithoutCriteria() { - PageResultDTO pageResultDTO = given() + ApplicationParameterPageResultDTO pageResultDTO = given() .get() .then() .statusCode(Response.Status.OK.getStatusCode()) - .extract().body().as(PageResultDTO.class); + .extract().body().as(ApplicationParameterPageResultDTO.class); Assertions.assertEquals(9, pageResultDTO.getStream().size()); Assertions.assertEquals(Long.valueOf(9), pageResultDTO.getTotalElements()); @@ -49,14 +46,14 @@ void shouldFindAllParametersWithoutCriteria() { @Test @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) void searchAllApplicationsTest() { - PageResultDTO pageResultDTO = given() + ApplicationsPageResultDTO pageResultDTO = given() .when() .get("applications") .then() .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(PageResultDTO.class); + .body().as(ApplicationsPageResultDTO.class); Assertions.assertEquals(4, pageResultDTO.getStream().size()); } @@ -79,7 +76,7 @@ void searchAllKeysTest(Map queryParams, int expectedArraySize) { .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(PageResultDTO.class); + .body().as(KeysPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); } @@ -98,7 +95,7 @@ static Stream findByCriteriaTestData() { @MethodSource("findByCriteriaTestData") @WithDBData(value = { "data/parameters-testdata.xml" }, deleteBeforeInsert = true, rinseAndRepeat = true) void shouldFindParametersByCriteria(Map queryParams, Integer expectedArraySize) { - PageResultDTO pageResultDTO = given() + ApplicationParameterPageResultDTO pageResultDTO = given() .when() .queryParams(queryParams) .get() @@ -106,7 +103,7 @@ void shouldFindParametersByCriteria(Map queryParams, Integer exp .statusCode(Response.Status.OK.getStatusCode()) .contentType(APPLICATION_JSON) .extract() - .body().as(PageResultDTO.class); + .body().as(ApplicationParameterPageResultDTO.class); Assertions.assertEquals(expectedArraySize, pageResultDTO.getStream().size()); }