From a828de3990c64045e110002e189fc7112052db89 Mon Sep 17 00:00:00 2001 From: PAVEL PALMA Date: Wed, 7 Jan 2026 22:31:56 -0600 Subject: [PATCH] Revert "Correccion error 500" This reverts commit 24cebae2e3533923d756bfc1140f54359515ec77 --- Dockerfile | 22 ++++---- .../ConversationMessageMapper.java | 10 +--- .../ConversationManagerService.java | 23 ++++---- src/main/resources/application-dev.properties | 55 +++++++++---------- .../resources/application-prod.properties | 8 +-- src/main/resources/application-qa.properties | 8 +-- src/main/resources/application.properties | 2 +- 7 files changed, 57 insertions(+), 71 deletions(-) diff --git a/Dockerfile b/Dockerfile index df646be..3711dc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ -# Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose. -# Your use of it is subject to your agreement with Google. - # Java 21.0.6 # 'jammy' refers to Ubuntu 22.04 LTS, which is a stable and widely used base. -FROM maven:3.9.6-eclipse-temurin-21 AS builder -WORKDIR /app -COPY pom.xml . -COPY src ./src -RUN mvn -B clean install -DskipTests -Dmaven.javadoc.skip=true -FROM registry.access.redhat.com/ubi9/openjdk-21-runtime -COPY --from=builder /app/target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar +# FROM maven:3.9.6-eclipse-temurin-21 AS builder +# FROM quay.ocp.banorte.com/base/openjdk-21:maven_3.8 AS builder +# WORKDIR /app +# COPY pom.xml . +# COPY src ./src +# RUN mvn -B clean install -DskipTests -Dmaven.javadoc.skip=true +# FROM eclipse-temurin:21.0.3_9-jre-jammy +FROM quay.ocp.banorte.com/golden/openjdk-21:latest +# COPY --from=builder /app/target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar +COPY target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar EXPOSE 8080 -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java b/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java index ec167c1..38c37bb 100644 --- a/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java +++ b/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java @@ -4,7 +4,6 @@ */ package com.example.mapper.conversation; -import com.google.cloud.Timestamp; import com.example.dto.dialogflow.conversation.ConversationMessageDTO; import com.example.dto.dialogflow.conversation.MessageType; @@ -32,16 +31,9 @@ public class ConversationMessageMapper { } public ConversationMessageDTO fromMap(Map map) { - Object timeObject = map.get("tiempo"); - Instant timestamp = null; - if (timeObject instanceof Timestamp) { - timestamp = ((Timestamp) timeObject).toDate().toInstant(); - } else if (timeObject instanceof Instant) { - timestamp = (Instant) timeObject; - } return new ConversationMessageDTO( MessageType.valueOf((String) map.get("entidad")), - timestamp, + (Instant) map.get("tiempo"), (String) map.get("mensaje"), (Map) map.get("parametros"), (String) map.get("canal") diff --git a/src/main/java/com/example/service/conversation/ConversationManagerService.java b/src/main/java/com/example/service/conversation/ConversationManagerService.java index d2a5d80..cd646b5 100644 --- a/src/main/java/com/example/service/conversation/ConversationManagerService.java +++ b/src/main/java/com/example/service/conversation/ConversationManagerService.java @@ -239,25 +239,22 @@ public class ConversationManagerService { DetectIntentRequestDTO request, ConversationSessionDTO session) { Instant now = Instant.now(); if (Duration.between(session.lastModified(), now).toMinutes() < SESSION_RESET_THRESHOLD_MINUTES) { - logger.info("Recent Session Found: Session {} is within the 30-minute threshold. Proceeding to Dialogflow.", + logger.info("Recent Session Found: Session {} is within the 10-minute threshold. Proceeding to Dialogflow.", session.sessionId()); return processDialogflowRequest(session, request, context.userId(), context.userMessageText(), context.primaryPhoneNumber(), false); } else { logger.info( - "Old Session Found: Session {} is older than the 30-minute threshold. Fetching history and continuing with same session.", + "Old Session Found: Session {} is older than the threshold. Fetching history and continuing with same session.", session.sessionId()); - return memoryStoreConversationService.getMessages(session.sessionId()) - .collectList() - // Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages - .map(messages -> conversationContextMapper.toTextWithLimits(session, messages)) - .defaultIfEmpty("") - .flatMap(conversationHistory -> { - // Inject historial (max 60 msgs / 30 días / 50KB) - DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory); - return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(), - context.primaryPhoneNumber(), false); - }); + return memoryStoreConversationService.getMessages(session.sessionId()).collectList() + .map(conversationContextMapper::toTextFromMessages) + .defaultIfEmpty("") + .flatMap(conversationHistory -> { + DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory); + return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(), + context.primaryPhoneNumber(), false); + }); } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 896c348..513f673 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -17,65 +17,62 @@ # ========================================================= # Orchestrator general Configuration # ========================================================= -spring.cloud.gcp.project-id=app-jovenes +spring.cloud.gcp.project-id=${GCP_PROJECT_ID} # ========================================================= # Google Firestore Configuration # ========================================================= -spring.cloud.gcp.firestore.project-id=app-jovenes -spring.cloud.gcp.firestore.database-id=app-jovenes-cache-database -spring.cloud.gcp.firestore.host=firestore.googleapis.com -spring.cloud.gcp.firestore.port=443 +spring.cloud.gcp.firestore.project-id=${GCP_PROJECT_ID} +spring.cloud.gcp.firestore.database-id=${GCP_FIRESTORE_DATABASE_ID} +spring.cloud.gcp.firestore.host=${GCP_FIRESTORE_HOST} +spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} # ========================================================= # Google Memorystore(Redis) Configuration # ========================================================= -spring.data.redis.host=10.241.0.11 -spring.data.redis.port=6379 -#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a +spring.data.redis.host=${REDIS_HOST} +spring.data.redis.port=${REDIS_PORT} +#spring.data.redis.password=${REDIS_PWD} #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=your-keystore-password +# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} # ========================================================= # Google Conversational Agents Configuration -# beto-singlerag-contexto # ========================================================= -dialogflow.cx.project-id=app-jovenes -dialogflow.cx.location=us-central1 -dialogflow.cx.agent-id=d55333d2-9543-4f9c-bd7a-d0ee3b3573ac -dialogflow.default-language-code=es +dialogflow.cx.project-id=${DIALOGFLOW_CX_PROJECT_ID} +dialogflow.cx.location=${DIALOGFLOW_CX_LOCATION} +dialogflow.cx.agent-id=${DIALOGFLOW_CX_AGENT_ID} +dialogflow.default-language-code=${DIALOGFLOW_DEFAULT_LANGUAGE_CODE} # ========================================================= # Google Generative AI (Gemini) Configuration # ========================================================= -google.cloud.project=app-jovenes -google.cloud.location=us-central1 -gemini.model.name=gemini-2.5-flash +google.cloud.project=${GCP_PROJECT_ID} +google.cloud.location=${GCP_LOCATION} +gemini.model.name=${GEMINI_MODEL_NAME} # ========================================================= # (Gemini) MessageFilter Configuration # ========================================================= -messagefilter.geminimodel=gemini-2.5-flash -messagefilter.temperature=0.1f -messagefilter.maxOutputTokens=800 -messagefilter.topP= 0.1f +messagefilter.geminimodel=${MESSAGE_FILTER_GEMINI_MODEL} +messagefilter.temperature=${MESSAGE_FILTER_TEMPERATURE} +messagefilter.maxOutputTokens=${MESSAGE_FILTER_MAX_OUTPUT_TOKENS} +messagefilter.topP=${MESSAGE_FILTER_TOP_P} messagefilter.prompt=prompts/message_filter_prompt.txt # ========================================================= # (DLP) Configuration # ========================================================= -google.cloud.dlp.dlpTemplateCompleteFlow=BNET_INSPECT +google.cloud.dlp.dlpTemplateCompleteFlow=${DLP_TEMPLATE_COMPLETE_FLOW} # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=false +firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} # ========================================================= # LOGGING Configuration # ========================================================= -logging.level.root=INFO -logging.level.com.example=INFO +logging.level.root=${LOGGING_LEVEL_ROOT:INFO} +logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} # ========================================================= # ConversationContext Configuration # ========================================================= -conversation.context.message.limit=60 -conversation.context.days.limit=30 -# logs for dev inspection -logging.file.name=logs/orchestrator.log +conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} +conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 130ef3e..dea84f3 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -30,13 +30,13 @@ spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} # ========================================================= spring.data.redis.host=${REDIS_HOST} spring.data.redis.port=${REDIS_PORT} -#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a +#spring.data.redis.password=${REDIS_PWD} #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=your-keystore-password +# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} # ========================================================= # Google Conversational Agents Configuration # ========================================================= @@ -66,7 +66,7 @@ google.cloud.dlp.dlpTemplatePersistFlow=${DLP_TEMPLATE_PERSIST_FLOW} # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=true +firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} # ========================================================= # LOGGING Configuration # ========================================================= @@ -76,4 +76,4 @@ logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} # ConversationContext Configuration # ========================================================= conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} -conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} +conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file diff --git a/src/main/resources/application-qa.properties b/src/main/resources/application-qa.properties index 130ef3e..dea84f3 100644 --- a/src/main/resources/application-qa.properties +++ b/src/main/resources/application-qa.properties @@ -30,13 +30,13 @@ spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} # ========================================================= spring.data.redis.host=${REDIS_HOST} spring.data.redis.port=${REDIS_PORT} -#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a +#spring.data.redis.password=${REDIS_PWD} #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=your-keystore-password +# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} # ========================================================= # Google Conversational Agents Configuration # ========================================================= @@ -66,7 +66,7 @@ google.cloud.dlp.dlpTemplatePersistFlow=${DLP_TEMPLATE_PERSIST_FLOW} # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=true +firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} # ========================================================= # LOGGING Configuration # ========================================================= @@ -76,4 +76,4 @@ logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} # ConversationContext Configuration # ========================================================= conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} -conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} +conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 257b306..404a33d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=${SPRING_PROFILE} \ No newline at end of file