Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ea 3842 fix etranslation callback #57

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class ETranslationTranslationService extends AbstractTranslationService {
public static final String markupDelimiter="\ndeenPVsaOg\n";//base64 encoded string (as in generateRedisKey()) with new lines
public static final String markupDelimiterWithoutNewline="deenPVsaOg";
public static final String eTranslationErrorCallbackIndicator="eTranslationErrorCallback";
public static final String eTranslationCallbackRelativeUrl="/eTranslation/callback";
public static final String eTranslationErrorCallbackRelativeUrl="/eTranslation/error-callback";
public static final String eTranslationCallbackRelativeUrl="/etranslation/callback";
public static final String eTranslationErrorCallbackRelativeUrl="/etranslation/error-callback";

private String serviceId;
private final String baseUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -32,8 +34,8 @@ public void eTranslationCallbackPost(
@RequestParam(value = "target-language", required = false) String targetLanguage,
@RequestParam(value = "translated-text", required = true) String translatedTextSnippet,
@RequestParam(value = "request-id", required = true) String requestId,
@RequestParam(value = "external-reference", required = true) String externalReference,
@RequestBody(required = false) String body) {
@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));
Expand All @@ -45,18 +47,35 @@ public void eTranslationCallbackPost(

@Tag(description = "ETranslation callback endpoint", name = "eTranslationCallback")
@GetMapping(value = ETranslationTranslationService.eTranslationCallbackRelativeUrl)
public void eTranslationCallbackGet(
public ResponseEntity<String> eTranslationCallbackGet(
@RequestParam(value = "target-language", required = false) String targetLanguage,
@RequestParam(value = "translated-text", required = true) String translatedTextSnippet,
@RequestParam(value = "request-id", required = true) String requestId,
@RequestParam(value = "external-reference", required = true) String externalReference) {
@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());
}
}

if(LOGGER.isDebugEnabled()) {
LOGGER.debug("eTranslation callback has been received with the request-id: {}, and the"
+ " external-reference: {}", LoggingUtils.sanitizeUserInput(requestId), LoggingUtils.sanitizeUserInput(externalReference));
+ " external-reference: {}", LoggingUtils.sanitizeUserInput(""+ requestId), LoggingUtils.sanitizeUserInput(""+externalReference));
}
if(externalReference!=null && translatedTextSnippet!=null) {
redisTemplate.convertAndSend(externalReference, translatedTextSnippet);
}

return ResponseEntity.status(HttpStatus.ACCEPTED).build();


}

@Tag(description = "ETranslation error callback endpoint", name = "eTranslationErrorCallback")
Expand Down
Loading