diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java b/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java index 2c66254..1946463 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/ETranslationCallbackController.java @@ -15,12 +15,13 @@ import eu.europeana.api.translation.service.etranslation.ETranslationTranslationService; import eu.europeana.api.translation.web.model.CachedTranslation; import io.swagger.v3.oas.annotations.tags.Tag; + @RestController @Tag(name = "ETranslation callback controller", description = "Receives the eTranslation response") public class ETranslationCallbackController { private static final Logger LOGGER = LogManager.getLogger(ETranslationCallbackController.class); - + RedisTemplate redisTemplate; @Autowired @@ -35,16 +36,19 @@ public void eTranslationCallbackPost( @RequestParam(value = "translated-text", required = true) String translatedTextSnippet, @RequestParam(value = "request-id", required = true) String requestId, @RequestParam(value = "external-reference", required = true) String externalReference) { - - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("eTranslation callback has been received with the request-id: {}, and the" - + " external-reference: {}", LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference)); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "eTranslation callback has been received with the request-id: {}, and the" + + " external-reference: {}", + LoggingUtils.sanitizeUserInput(requestId), + LoggingUtils.sanitizeUserInput(externalReference)); } - if(externalReference!=null && translatedTextSnippet!=null) { + if (externalReference != null && translatedTextSnippet != null) { redisTemplate.convertAndSend(externalReference, translatedTextSnippet); } - } - + } + @Tag(description = "ETranslation callback endpoint", name = "eTranslationCallback") @GetMapping(value = ETranslationTranslationService.eTranslationCallbackRelativeUrl) public ResponseEntity eTranslationCallbackGet( @@ -52,31 +56,30 @@ public ResponseEntity eTranslationCallbackGet( @RequestParam(value = "translated-text", required = false) String translatedTextSnippet, @RequestParam(value = "request-id", required = false) String requestId, @RequestParam(value = "external-reference", required = false) String externalReference, - @RequestParam(value = "timeout", required = false) int timeout, - @RequestBody(required = false) String body) { - if(timeout > 0) { - try { - //for simulation purposes, wait for $timeout seconds - Thread.sleep(timeout * 1000); - return ResponseEntity.status(HttpStatus.ACCEPTED).build(); - } catch (InterruptedException e) { - //should not happen - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.toString()); - } - } + @RequestParam(value = "timeout", required = false) Integer timeout, + @RequestBody(required = false) String body) throws InterruptedException { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("eTranslation callback has been received with the request-id: {}, and the" - + " external-reference: {}", LoggingUtils.sanitizeUserInput(""+ requestId), LoggingUtils.sanitizeUserInput(""+externalReference)); + if (timeout != null && timeout > 0) { + // for simulation purposes, wait for $timeout seconds + Thread.sleep(timeout * 1000); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); + } + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "eTranslation callback has been received with the request-id: {}, and the" + + " external-reference: {}", + LoggingUtils.sanitizeUserInput("" + requestId), + LoggingUtils.sanitizeUserInput("" + externalReference)); } - if(externalReference!=null && translatedTextSnippet!=null) { + if (externalReference != null && translatedTextSnippet != null) { redisTemplate.convertAndSend(externalReference, translatedTextSnippet); } - + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); - - } + + } @Tag(description = "ETranslation error callback endpoint", name = "eTranslationErrorCallback") @PostMapping(value = ETranslationTranslationService.eTranslationErrorCallbackRelativeUrl) @@ -87,17 +90,22 @@ public void eTranslationErrorCallbackPost( @RequestParam(value = "request-id", required = false) String requestId, @RequestParam(value = "external-reference", required = false) String externalReference, @RequestBody(required = false) String body) { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("eTranslation error callback has been received with the following parameters: error-code: {}," - + "error-message: {}, request-id: {}, external-reference: {}", LoggingUtils.sanitizeUserInput(errorCode), - LoggingUtils.sanitizeUserInput(errorMessage), LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "eTranslation error callback has been received with the following parameters: error-code: {}," + + "error-message: {}, request-id: {}, external-reference: {}", + LoggingUtils.sanitizeUserInput(errorCode), LoggingUtils.sanitizeUserInput(errorMessage), + LoggingUtils.sanitizeUserInput(requestId), + LoggingUtils.sanitizeUserInput(externalReference)); } - if(externalReference!=null) { - redisTemplate.convertAndSend(externalReference, String.format("%s: error-code=%s, error-message=%s", - ETranslationTranslationService.eTranslationErrorCallbackIndicator, errorCode, errorMessage)); + if (externalReference != null) { + redisTemplate.convertAndSend(externalReference, + String.format("%s: error-code=%s, error-message=%s", + ETranslationTranslationService.eTranslationErrorCallbackIndicator, errorCode, + errorMessage)); } - } - + } + @Tag(description = "ETranslation error callback endpoint", name = "eTranslationErrorCallback") @GetMapping(value = ETranslationTranslationService.eTranslationErrorCallbackRelativeUrl) public void eTranslationErrorCallbackGet( @@ -107,16 +115,21 @@ public void eTranslationErrorCallbackGet( @RequestParam(value = "request-id", required = false) String requestId, @RequestParam(value = "external-reference", required = false) String externalReference, @RequestBody(required = false) String body) { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("eTranslation error callback has been received with the following parameters: error-code: {}," - + "error-message: {}, request-id: {}, external-reference: {}", LoggingUtils.sanitizeUserInput(errorCode), - LoggingUtils.sanitizeUserInput(errorMessage), LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "eTranslation error callback has been received with the following parameters: error-code: {}," + + "error-message: {}, request-id: {}, external-reference: {}", + LoggingUtils.sanitizeUserInput(errorCode), LoggingUtils.sanitizeUserInput(errorMessage), + LoggingUtils.sanitizeUserInput(requestId), + LoggingUtils.sanitizeUserInput(externalReference)); } - if(externalReference!=null) { - redisTemplate.convertAndSend(externalReference, String.format("%s: error-code=%s, error-message=%s", - ETranslationTranslationService.eTranslationErrorCallbackIndicator, errorCode, errorMessage)); + if (externalReference != null) { + redisTemplate.convertAndSend(externalReference, + String.format("%s: error-code=%s, error-message=%s", + ETranslationTranslationService.eTranslationErrorCallbackIndicator, errorCode, + errorMessage)); } - } + } }