UPDATE 28-Oct
This commit is contained in:
@@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.example.controller;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.example.service.base.SessionPurgeService;
|
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/v1/session-purge")
|
|
||||||
public class SessionPurgeController {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SessionPurgeController.class);
|
|
||||||
private final SessionPurgeService sessionPurgeService;
|
|
||||||
|
|
||||||
public SessionPurgeController(SessionPurgeService sessionPurgeService) {
|
|
||||||
this.sessionPurgeService = sessionPurgeService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/conversation/session/{sessionId}")
|
|
||||||
public Mono<Void> deleteSession(@PathVariable String sessionId) {
|
|
||||||
return sessionPurgeService.deleteSession(sessionId)
|
|
||||||
.doOnSuccess(voidResult -> logger.info("Successfully deleted session with id: {}", sessionId))
|
|
||||||
.doOnError(error -> logger.error("Error deleting session with id: {}", sessionId, error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -119,6 +119,7 @@ public class MessageEntryFilter {
|
|||||||
yield CATEGORY_UNKNOWN;
|
yield CATEGORY_UNKNOWN;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
resultCategory = CATEGORY_CONVERSATION;
|
||||||
return resultCategory;
|
return resultCategory;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("An error occurred during Gemini content generation for message classification.", e);
|
logger.error("An error occurred during Gemini content generation for message classification.", e);
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.example.service.base;
|
|
||||||
|
|
||||||
import com.example.dto.dialogflow.conversation.ConversationSessionDTO;
|
|
||||||
import com.example.service.conversation.FirestoreConversationService;
|
|
||||||
import com.example.service.conversation.MemoryStoreConversationService;
|
|
||||||
import com.example.service.notification.FirestoreNotificationService;
|
|
||||||
import com.example.service.notification.MemoryStoreNotificationService;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SessionPurgeService {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SessionPurgeService.class);
|
|
||||||
private static final String SESSION_KEY_PREFIX = "conversation:session:";
|
|
||||||
|
|
||||||
private final ReactiveRedisTemplate<String, ConversationSessionDTO> redisTemplate;
|
|
||||||
private final MemoryStoreConversationService memoryStoreConversationService;
|
|
||||||
private final FirestoreConversationService firestoreConversationService;
|
|
||||||
private final MemoryStoreNotificationService memoryStoreNotificationService;
|
|
||||||
private final FirestoreNotificationService firestoreNotificationService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SessionPurgeService(
|
|
||||||
ReactiveRedisTemplate<String, ConversationSessionDTO> redisTemplate,
|
|
||||||
MemoryStoreConversationService memoryStoreConversationService,
|
|
||||||
FirestoreConversationService firestoreConversationService,
|
|
||||||
MemoryStoreNotificationService memoryStoreNotificationService,
|
|
||||||
FirestoreNotificationService firestoreNotificationService) {
|
|
||||||
this.redisTemplate = redisTemplate;
|
|
||||||
this.memoryStoreConversationService = memoryStoreConversationService;
|
|
||||||
this.firestoreConversationService = firestoreConversationService;
|
|
||||||
this.memoryStoreNotificationService = memoryStoreNotificationService;
|
|
||||||
this.firestoreNotificationService = firestoreNotificationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Void> deleteSession(String sessionId) {
|
|
||||||
String sessionKey = SESSION_KEY_PREFIX + sessionId;
|
|
||||||
logger.info("Deleting session {} from all stores.", sessionId);
|
|
||||||
|
|
||||||
return redisTemplate.opsForValue().get(sessionKey)
|
|
||||||
.flatMap(session -> {
|
|
||||||
if (session != null && session.telefono() != null) {
|
|
||||||
return memoryStoreConversationService.deleteSession(sessionId)
|
|
||||||
.then(firestoreConversationService.deleteSession(sessionId))
|
|
||||||
.then(memoryStoreNotificationService.deleteNotificationSession(session.telefono()))
|
|
||||||
.then(firestoreNotificationService.deleteNotification(session.telefono()));
|
|
||||||
} else {
|
|
||||||
return memoryStoreConversationService.deleteSession(sessionId)
|
|
||||||
.then(firestoreConversationService.deleteSession(sessionId));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user