From 8a59d89821d914b25db0686cd7012a4f3712a375 Mon Sep 17 00:00:00 2001 From: Mark Allen <3417310+maallen@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:14:37 +0000 Subject: [PATCH] Fixed issue with null object for delete request --- .../cli/command/AIRepositoryLocaleOverrideCommand.java | 9 +++++---- .../java/com/box/l10n/mojito/rest/ai/AIPromptWS.java | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java index 03d6dbc05a..448b21b2a8 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java @@ -4,12 +4,12 @@ import com.beust.jcommander.Parameters; import com.box.l10n.mojito.rest.client.AIServiceClient; import com.box.l10n.mojito.rest.entity.AITranslationLocalePromptOverridesRequest; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; @Component @Scope("prototype") @@ -38,8 +38,8 @@ public class AIRepositoryLocaleOverrideCommand extends Command { @Parameter( names = {"--locales", "-l"}, required = true, - description = "Locale BCP-47 tags") - Set locales; + description = "Locale BCP-47 tags provided in a comma separated list") + String locales; @Parameter( names = {"--disabled"}, @@ -57,7 +57,8 @@ public class AIRepositoryLocaleOverrideCommand extends Command { @Override protected void execute() throws CommandException { AITranslationLocalePromptOverridesRequest aiTranslationLocalePromptOverridesRequest = - new AITranslationLocalePromptOverridesRequest(repository, locales, aiPromptId, disabled); + new AITranslationLocalePromptOverridesRequest( + repository, StringUtils.commaDelimitedListToSet(locales), aiPromptId, disabled); if (isDelete) { aiServiceClient.deleteRepositoryLocalePromptOverrides( diff --git a/webapp/src/main/java/com/box/l10n/mojito/rest/ai/AIPromptWS.java b/webapp/src/main/java/com/box/l10n/mojito/rest/ai/AIPromptWS.java index 6adda2d227..33e55b36bb 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/rest/ai/AIPromptWS.java +++ b/webapp/src/main/java/com/box/l10n/mojito/rest/ai/AIPromptWS.java @@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -95,7 +97,7 @@ public void deletePromptMessage(@PathVariable("context_message_id") Long context value = "/api/ai/prompts/translation/locale/overrides", method = RequestMethod.POST) @Timed("AIWS.createOrUpdateRepositoryLocalePromptOverrides") - public void createOrUpdateRepositoryLocalePromptOverrides( + public ResponseEntity createOrUpdateRepositoryLocalePromptOverrides( @RequestBody AITranslationLocalePromptOverridesRequest request) { logger.debug("Received request to create or update repository locale prompt overrides"); promptService.createOrUpdateRepositoryLocaleTranslationPromptOverrides( @@ -103,17 +105,19 @@ public void createOrUpdateRepositoryLocalePromptOverrides( request.getLocales(), request.getAiPromptId(), request.isDisabled()); + return new ResponseEntity<>("Success", HttpStatus.CREATED); } @RequestMapping( value = "/api/ai/prompts/translation/locale/overrides", method = RequestMethod.DELETE) @Timed("AIWS.deleteRepositoryLocalePromptOverrides") - public void deleteRepositoryLocalePromptOverrides( - AITranslationLocalePromptOverridesRequest request) { + public ResponseEntity deleteRepositoryLocalePromptOverrides( + @RequestBody AITranslationLocalePromptOverridesRequest request) { logger.debug("Received request to delete repository locale prompt overrides"); promptService.deleteRepositoryLocaleTranslationPromptOverride( request.getRepositoryName(), request.getLocales()); + return new ResponseEntity<>("Delete success", HttpStatus.OK); } private static AIPrompt buildOpenAIPromptDTO(com.box.l10n.mojito.entity.AIPrompt prompt) {