diff --git a/docs/modules/onecx-welcome-svc/pages/onecx-welcome-svc-extensions.adoc b/docs/modules/onecx-welcome-svc/pages/onecx-welcome-svc-extensions.adoc index d5d4a87..2397be8 100644 --- a/docs/modules/onecx-welcome-svc/pages/onecx-welcome-svc-extensions.adoc +++ b/docs/modules/onecx-welcome-svc/pages/onecx-welcome-svc-extensions.adoc @@ -41,8 +41,8 @@ h| Version | onecx-tenant | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-tenant.html[Link] -| https://github.com/onecx/onecx-quarkus/blob/0.17.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] -| 0.17.0 +| https://github.com/onecx/onecx-quarkus/blob/0.18.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] +| 0.18.0 | tkit-quarkus-jpa-tenant @@ -60,79 +60,79 @@ h| Version | https://quarkus.io/guides/cdi-reference[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-liquibase | https://quarkus.io/guides/liquibase[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-liquibase.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-smallrye-health | https://quarkus.io/guides/smallrye-health[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-micrometer-registry-prometheus | https://quarkus.io/guides/telemetry-micrometer[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-hibernate-orm | https://quarkus.io/guides/hibernate-orm[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-orm.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-rest | https://quarkus.io/guides/rest[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-rest-jackson | https://quarkus.io/guides/rest-json[Link] | -| 3.9.3 +| 3.9.4 | quarkus-jdbc-postgresql | https://quarkus.io/guides/datasource[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-jdbc-postgresql.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-smallrye-openapi | https://quarkus.io/guides/openapi-swaggerui[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-openapi.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-hibernate-validator | https://quarkus.io/guides/validation[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-validator.adoc[Link] -| 3.9.3 +| 3.9.4 | quarkus-opentelemetry | https://quarkus.io/guides/opentelemetry[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link] -| 3.9.3 +| 3.9.4 | onecx-core | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.17.0 +| 0.18.0 | quarkus-container-image-docker | https://quarkus.io/guides/container-image[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link] -| 3.9.3 +| 3.9.4 diff --git a/src/main/java/org/tkit/onecx/welcome/domain/daos/ImageDAO.java b/src/main/java/org/tkit/onecx/welcome/domain/daos/ImageDAO.java index b18c20e..0e7433e 100644 --- a/src/main/java/org/tkit/onecx/welcome/domain/daos/ImageDAO.java +++ b/src/main/java/org/tkit/onecx/welcome/domain/daos/ImageDAO.java @@ -1,10 +1,45 @@ package org.tkit.onecx.welcome.domain.daos; +import static org.tkit.quarkus.jpa.utils.QueryCriteriaUtil.addSearchStringPredicate; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + import jakarta.enterprise.context.ApplicationScoped; +import jakarta.persistence.criteria.Predicate; +import jakarta.transaction.Transactional; import org.tkit.onecx.welcome.domain.models.Image; +import org.tkit.onecx.welcome.domain.models.Image_; import org.tkit.quarkus.jpa.daos.AbstractDAO; +import org.tkit.quarkus.jpa.exceptions.DAOException; +import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; @ApplicationScoped public class ImageDAO extends AbstractDAO { + + @Transactional(Transactional.TxType.NOT_SUPPORTED) + public Stream findAllByWorkspaceName(String workspaceName) { + try { + var cb = this.getEntityManager().getCriteriaBuilder(); + var cq = cb.createQuery(Image.class); + var root = cq.from(Image.class); + + List predicates = new ArrayList<>(); + addSearchStringPredicate(predicates, cb, root.get(Image_.WORKSPACE_NAME), workspaceName); + + cq.where(predicates.toArray(new Predicate[] {})); + + cq.orderBy(cb.desc(root.get(AbstractTraceableEntity_.modificationDate))); + + return this.getEntityManager().createQuery(cq).getResultStream(); + } catch (Exception ex) { + throw new DAOException(ErrorKeys.ERROR_FIND_IMAGE_INFO_BY_WORKSPACE, ex); + } + } + + enum ErrorKeys { + ERROR_FIND_IMAGE_INFO_BY_WORKSPACE + } } diff --git a/src/main/java/org/tkit/onecx/welcome/domain/models/Image.java b/src/main/java/org/tkit/onecx/welcome/domain/models/Image.java index 1d5a82d..55ddbc5 100644 --- a/src/main/java/org/tkit/onecx/welcome/domain/models/Image.java +++ b/src/main/java/org/tkit/onecx/welcome/domain/models/Image.java @@ -19,6 +19,9 @@ public class Image extends TraceableEntity { @Column(name = "TENANT_ID") private String tenantId; + @Column(name = "WORKSPACE_NAME", nullable = false, columnDefinition = "VARCHAR(255) default 'undefined'") + private String workspaceName; + @Column(name = "POSITION") private Integer position; diff --git a/src/main/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestController.java b/src/main/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestController.java index 0628927..75c081c 100644 --- a/src/main/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestController.java +++ b/src/main/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestController.java @@ -82,9 +82,9 @@ public Response deleteImageInfoById(String id) { } @Override - public Response getAllImageInfos() { + public Response getAllImageInfosByWorkspaceName(String workspaceName) { List imageInfos; - imageInfos = imageMapper.mapInfoList(imageInfoDAO.findAll().toList()); + imageInfos = imageMapper.mapInfoList(imageInfoDAO.findAllByWorkspaceName(workspaceName).toList()); return Response.ok().entity(imageInfos).build(); } diff --git a/src/main/openapi/onecx-welcome-internal-openapi.yaml b/src/main/openapi/onecx-welcome-internal-openapi.yaml index b0a532b..9b81717 100644 --- a/src/main/openapi/onecx-welcome-internal-openapi.yaml +++ b/src/main/openapi/onecx-welcome-internal-openapi.yaml @@ -88,11 +88,18 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' + /internal/images/{workspaceName}/info: get: tags: - imagesInternal description: get all existing image-infos - operationId: getAllImageInfos + operationId: getAllImageInfosByWorkspaceName + parameters: + - in: path + name: workspaceName + schema: + type: string + required: true responses: "200": description: OK @@ -211,6 +218,8 @@ components: modificationUser: type: string ImageInfo: + required: + - workspaceName type: object properties: position: @@ -234,6 +243,8 @@ components: $ref: '#/components/schemas/OffsetDateTime' modificationUser: type: string + workspaceName: + type: string OffsetDateTime: format: date-time type: string diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml index 2487e35..b5613dc 100644 --- a/src/main/resources/db/changeLog.xml +++ b/src/main/resources/db/changeLog.xml @@ -4,5 +4,6 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> + \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-05-29-add-workspace-name.xml b/src/main/resources/db/v1/2024-05-29-add-workspace-name.xml new file mode 100644 index 0000000..8f34f67 --- /dev/null +++ b/src/main/resources/db/v1/2024-05-29-add-workspace-name.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/test/java/org/tkit/onecx/welcome/domain/daos/AbstractDAOTest.java b/src/test/java/org/tkit/onecx/welcome/domain/daos/AbstractDAOTest.java new file mode 100644 index 0000000..a771b37 --- /dev/null +++ b/src/test/java/org/tkit/onecx/welcome/domain/daos/AbstractDAOTest.java @@ -0,0 +1,28 @@ +package org.tkit.onecx.welcome.domain.daos; + +import jakarta.persistence.EntityManager; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.function.Executable; +import org.mockito.Mockito; +import org.tkit.onecx.welcome.test.AbstractTest; +import org.tkit.quarkus.jpa.exceptions.DAOException; + +import io.quarkus.test.InjectMock; + +abstract class AbstractDAOTest extends AbstractTest { + + @InjectMock + EntityManager em; + + @BeforeEach + void beforeAll() { + Mockito.when(em.getCriteriaBuilder()).thenThrow(new RuntimeException("Test technical error exception")); + } + + void methodExceptionTests(Executable fn, Enum key) { + var exc = Assertions.assertThrows(DAOException.class, fn); + Assertions.assertEquals(key, exc.key); + } +} diff --git a/src/test/java/org/tkit/onecx/welcome/domain/daos/ImageDAOTest.java b/src/test/java/org/tkit/onecx/welcome/domain/daos/ImageDAOTest.java new file mode 100644 index 0000000..805e9b0 --- /dev/null +++ b/src/test/java/org/tkit/onecx/welcome/domain/daos/ImageDAOTest.java @@ -0,0 +1,21 @@ +package org.tkit.onecx.welcome.domain.daos; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class ImageDAOTest extends AbstractDAOTest { + + @Inject + ImageDAO dao; + + @Test + @SuppressWarnings("java:S2699") + void methodExceptionTests() { + methodExceptionTests(() -> dao.findAllByWorkspaceName(null), + ImageDAO.ErrorKeys.ERROR_FIND_IMAGE_INFO_BY_WORKSPACE); + } +} diff --git a/src/test/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestControllerTest.java b/src/test/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestControllerTest.java index cc49c25..29f1099 100644 --- a/src/test/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/welcome/rs/internal/controllers/ImageInternalRestControllerTest.java @@ -100,7 +100,7 @@ void createImageInfoTest() { .body().as(ImageDataResponseDTO.class); ImageInfoDTO body = new ImageInfoDTO(); - body.imageId(imageData.getImageId()).position("2").visible(true); + body.imageId(imageData.getImageId()).position("2").visible(true).workspaceName("w1"); given() .when() @@ -114,7 +114,7 @@ void createImageInfoTest() { @Test void createImageInfoExternalURLTest() { ImageInfoDTO body = new ImageInfoDTO(); - body.url("randomURl").position("2").visible(true); + body.url("randomURl").position("2").visible(true).workspaceName("w1"); given() .when() .body(body) @@ -180,6 +180,7 @@ void updateImageInfoByIdTest() { var updateBody = new ImageInfoDTO(); updateBody.url("updated-url"); updateBody.modificationCount(0); + updateBody.workspaceName("w1"); var updatedInfo = given() .contentType(APPLICATION_JSON) @@ -231,6 +232,7 @@ void updateImageInfoAssignedImageDataByIdTest() { var updateBody = new ImageInfoDTO(); updateBody.imageId(data.getImageId()); updateBody.modificationCount(0); + updateBody.workspaceName("w1"); var updatedInfo = given() .contentType(APPLICATION_JSON) @@ -284,9 +286,10 @@ void deleteImageInfoByIdTest() { } @Test - void getAllImageInfosTest() { + void getAllImageInfosByWorkspaceNameTest() { var output = given() - .get("/info") + .pathParam("workspaceName", "w1") + .get("/{workspaceName}/info") .then() .contentType(APPLICATION_JSON) .extract().as(ImageInfoDTO[].class); diff --git a/src/test/resources/data/testdata-internal.xml b/src/test/resources/data/testdata-internal.xml index 2217dc8..adccb0f 100644 --- a/src/test/resources/data/testdata-internal.xml +++ b/src/test/resources/data/testdata-internal.xml @@ -5,6 +5,6 @@ - - + + \ No newline at end of file