Skip to content

Commit

Permalink
Chat-SVC Refactors (#5)
Browse files Browse the repository at this point in the history
* Chat-SVC Refactors

* adjusted liquibase script

* script adjustments

* add tests

* add native build

---------

Co-authored-by: Bartosz <[email protected]>
  • Loading branch information
bbrynski and Bartosz authored Dec 10, 2024
1 parent b58ea17 commit 5767e1d
Show file tree
Hide file tree
Showing 23 changed files with 500 additions and 285 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ on:
jobs:
branch:
uses: onecx-apps/ci-quarkus/.github/workflows/build-branch.yml@v2
secrets: inherit
secrets: inherit
with:
native: true
4 changes: 3 additions & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ on:
jobs:
pr:
uses: onecx-apps/ci-quarkus/.github/workflows/build-pr.yml@v2
secrets: inherit
secrets: inherit
with:
native: true
4 changes: 3 additions & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ on:
jobs:
release:
uses: onecx-apps/ci-quarkus/.github/workflows/build-release.yml@v2
secrets: inherit
secrets: inherit
with:
native: true
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
uses: onecx-apps/ci-quarkus/.github/workflows/build.yml@v2
secrets: inherit
with:
native: true
helmEventTargetRepository: onecx-apps/onecx-chat
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
QUARKUS_DATASOURCE_PASSWORD: onecx_chat
QUARKUS_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgresdb:5432/onecx-chat?sslmode=disable"
QUARKUS_REST_CLIENT_ONECX_AI_SVC_URL: "http://onecx-ai-svc:8080/internal/ai/"
QUARKUS_OIDC_AUTH_SERVER_URL: "http://keycloak-app:8080/realms/onecx"
ports:
- "8081:8080"
depends_on:
Expand Down
33 changes: 21 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.onecx</groupId>
<groupId>org.tkit.onecx</groupId>
<artifactId>onecx-quarkus3-parent</artifactId>
<version>0.26.0</version>
<version>0.72.0</version>
</parent>

<artifactId>onecx-chat-svc</artifactId>
<version>999-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>io.github.onecx.quarkus</groupId>
<groupId>org.tkit.onecx.quarkus</groupId>
<artifactId>onecx-core</artifactId>
</dependency>
<dependency>
<groupId>io.github.onecx.quarkus</groupId>
<groupId>org.tkit.onecx.quarkus</groupId>
<artifactId>onecx-tenant</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-oidc-filter</artifactId>
</dependency>

<!-- 1000kit -->
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
Expand All @@ -31,10 +40,6 @@
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-jpa-tenant</artifactId>
</dependency>
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-data-import</artifactId>
</dependency>
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-jpa</artifactId>
Expand Down Expand Up @@ -83,11 +88,11 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -119,7 +124,6 @@
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>

<dependency>
<groupId>io.quarkiverse.mockserver</groupId>
<artifactId>quarkus-mockserver</artifactId>
Expand Down Expand Up @@ -157,6 +161,11 @@
<artifactId>tkit-quarkus-test-db-import</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -209,7 +218,7 @@
<artifactId>download-maven-plugin</artifactId>
<executions>
<execution>
<id>user-profile-svc-internal</id>
<id>onecx-ai-svc</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
Expand Down
10 changes: 2 additions & 8 deletions src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
FROM registry.access.redhat.com/ubi9/openjdk-17:1.15

ENV LANGUAGE='en_US:en'
FROM ghcr.io/onecx/docker-quarkus-jvm:0.15.0

COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
USER 185
12 changes: 2 additions & 10 deletions src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.2
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root target/*-runner /work/application
FROM ghcr.io/onecx/docker-quarkus-native:0.10.0

EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
COPY --chown=1001:root target/*-runner /work/application
9 changes: 8 additions & 1 deletion src/main/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ app:
repository: "onecx-apps/onecx-chat-svc"
tag: 999-SNAPSHOT
db:
enabled: true
enabled: true
operator:
keycloak:
client:
enabled: true
spec:
kcConfig:
defaultClientScopes: [ ocx-tn:read ]
6 changes: 5 additions & 1 deletion src/main/java/io/github/onecx/chat/domain/models/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import jakarta.persistence.*;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.TenantId;
import org.tkit.quarkus.jpa.models.TraceableEntity;

Expand Down Expand Up @@ -35,17 +37,19 @@ public class Chat extends TraceableEntity {
@Column(name = "TOPIC")
private String topic;

@Column(name = "SUMMARY")
@Column(name = "SUMMARY", columnDefinition = "varchar(1000)")
private String summary;

@Column(name = "APP_ID")
private String appId;

@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "chat", orphanRemoval = true)
@OnDelete(action = OnDeleteAction.CASCADE)
@OrderBy("creationDate ASC")
private Set<Message> messages = new HashSet<>();

@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "chat", orphanRemoval = true)
@OnDelete(action = OnDeleteAction.CASCADE)
@OrderBy("creationDate ASC")
private Set<Participant> participants = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Message extends TraceableEntity {
@Column(name = "TENANT_ID")
private String tenantId;

@Column(name = "TEXT")
@Column(name = "TEXT", columnDefinition = "varchar(4000)")
private String text;

@Column(name = "TYPE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.ws.rs.core.UriInfo;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.quarkus.jpa.exceptions.ConstraintException;
Expand Down Expand Up @@ -66,7 +67,6 @@ public class ChatsRestController implements ChatsInternalApi {
@Override
@Transactional
public Response createChat(CreateChatDTO createChatDTO) {

var chat = mapper.create(createChatDTO);
chat = dao.create(chat);

Expand Down Expand Up @@ -150,14 +150,13 @@ public Response createChatMessage(String chatId, CreateMessageDTO createMessageD
ChatRequest chatRequest = new ChatRequest();
chatRequest.chatMessage(chatMessage);
chatRequest.conversation(conversation);
Response response = aiChatClient.chat(chatRequest);

var chatResponse = response.readEntity(ChatMessage.class);

var responseMessage = mapper.mapAiSvcMessage(chatResponse);
responseMessage.setChat(chat);
msgDao.create(responseMessage);

try (Response response = aiChatClient.chat(chatRequest)) {
var chatResponse = response.readEntity(ChatMessage.class);
var responseMessage = mapper.mapAiSvcMessage(chatResponse);
responseMessage.setChat(chat);
msgDao.create(responseMessage);
}
}

return Response
Expand All @@ -170,7 +169,7 @@ public Response createChatMessage(String chatId, CreateMessageDTO createMessageD
public Response getChatMessages(String chatId) {
var chat = dao.findById(chatId);

if (chat == null || chat.getMessages() == null) {
if (chat == null || chat.getMessages().isEmpty()) {
// Handle the case where chat or its messages are null
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand Down Expand Up @@ -205,7 +204,7 @@ public Response getChatParticipants(String chatId) {

var chat = dao.findById(chatId);

if (chat == null || chat.getParticipants() == null) {
if (chat == null || chat.getParticipants().isEmpty()) {
// Handle the case where chat or its messages are null
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand All @@ -226,6 +225,11 @@ public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationExce
return exceptionMapper.constraint(ex);
}

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> restException(ClientWebApplicationException ex) {
return exceptionMapper.clientException(ex);
}

enum ChatErrorKeys {
CHAT_DOES_NOT_EXIST
}
Expand Down
Loading

0 comments on commit 5767e1d

Please sign in to comment.