Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added workspaceName #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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



Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/tkit/onecx/welcome/domain/daos/ImageDAO.java
Original file line number Diff line number Diff line change
@@ -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<Image> {

@Transactional(Transactional.TxType.NOT_SUPPORTED)
public Stream<Image> findAllByWorkspaceName(String workspaceName) {
try {
var cb = this.getEntityManager().getCriteriaBuilder();
var cq = cb.createQuery(Image.class);
var root = cq.from(Image.class);

List<Predicate> 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
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/tkit/onecx/welcome/domain/models/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public Response deleteImageInfoById(String id) {
}

@Override
public Response getAllImageInfos() {
public Response getAllImageInfosByWorkspaceName(String workspaceName) {
List<ImageInfoDTO> imageInfos;
imageInfos = imageMapper.mapInfoList(imageInfoDAO.findAll().toList());
imageInfos = imageMapper.mapInfoList(imageInfoDAO.findAllByWorkspaceName(workspaceName).toList());
return Response.ok().entity(imageInfos).build();
}

Expand Down
13 changes: 12 additions & 1 deletion src/main/openapi/onecx-welcome-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,6 +218,8 @@ components:
modificationUser:
type: string
ImageInfo:
required:
- workspaceName
type: object
properties:
position:
Expand All @@ -234,6 +243,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
modificationUser:
type: string
workspaceName:
type: string
OffsetDateTime:
format: date-time
type: string
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<include relativeToChangelogFile="true" file="v1/2024-02-16-create-tables.xml"/>
<include relativeToChangelogFile="true" file="v1/2024-05-29-add-workspace-name.xml"/>

</databaseChangeLog>
14 changes: 14 additions & 0 deletions src/main/resources/db/v1/2024-05-29-add-workspace-name.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<changeSet author="dev (generated)" id="1716974694552-1">
<addColumn tableName="image">
<column name="workspace_name" type="varchar(255 BYTE)" defaultValue="undefined">
</column>
</addColumn>
<addNotNullConstraint tableName="image" columnName="workspace_name" constraintName="image_workspace_name_not_null" defaultNullValue="undefined"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -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);
}
}
21 changes: 21 additions & 0 deletions src/test/java/org/tkit/onecx/welcome/domain/daos/ImageDAOTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/data/testdata-internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<IMAGE_DATA guid="d-11-111" optlock="0" tenant_id="tenant-100" data_length="1049" mime_type="image/png" image_data="iVBORw0KGgoAAAANSUhEUgAAABEAAAAOCAMAAAD+MweGAAADAFBMVEUAAAAAAFUAAKoAAP8AJAAAJFUAJKoAJP8ASQAASVUASaoASf8AbQAAbVUAbaoAbf8AkgAAklUAkqoAkv8AtgAAtlUAtqoAtv8A2wAA21UA26oA2/8A/wAA/1UA/6oA//8kAAAkAFUkAKokAP8kJAAkJFUkJKokJP8kSQAkSVUkSaokSf8kbQAkbVUkbaokbf8kkgAkklUkkqokkv8ktgAktlUktqoktv8k2wAk21Uk26ok2/8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K5CYII="/>

<!-- IMAGE INFO -->
<IMAGE guid="11-111" optlock="0" visible="true" position="1" url="" tenant_id="tenant-100" image_data="d-11-111" />
<IMAGE guid="22-222" optlock="0" visible="true" position="2" url="http://onecx.de/test" tenant_id="tenant-100"/>
<IMAGE guid="11-111" optlock="0" visible="true" position="1" url="" tenant_id="tenant-100" image_data="d-11-111" workspace_name="w1" />
<IMAGE guid="22-222" optlock="0" visible="true" position="2" url="http://onecx.de/test" tenant_id="tenant-100" workspace_name="w1" />
</dataset>
Loading