diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/TranslationController.java b/translation-web/src/main/java/eu/europeana/api/translation/web/TranslationController.java index f6021ea7..1c9f6c97 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/TranslationController.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/TranslationController.java @@ -1,6 +1,8 @@ package eu.europeana.api.translation.web; import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -10,7 +12,6 @@ import eu.europeana.api.commons.web.exception.ParamValidationException; import eu.europeana.api.commons.web.http.HttpHeaders; import eu.europeana.api.commons.web.model.vocabulary.Operations; -import eu.europeana.api.translation.config.I18nConstants; import eu.europeana.api.translation.definitions.language.LanguagePair; import eu.europeana.api.translation.definitions.vocabulary.TranslationAppConstants; import eu.europeana.api.translation.model.TranslationRequest; @@ -18,8 +19,11 @@ import eu.europeana.api.translation.web.service.TranslationWebService; import io.swagger.v3.oas.annotations.tags.Tag; +import static eu.europeana.api.translation.config.I18nConstants.EMPTY_PARAM_MANDATORY; +import static eu.europeana.api.translation.config.I18nConstants.INVALID_SERVICE_PARAM; + @RestController -@Tag(name = "Translation endoint", description = "Perform text translation") +@Tag(name = "Translation endpoint", description = "Perform text translation") public class TranslationController extends BaseRest { private final TranslationWebService translationService; @@ -49,23 +53,19 @@ public ResponseEntity translate(@RequestBody TranslationRequest translRe private void validateRequest(TranslationRequest translationRequest) throws ParamValidationException { // validate mandatory params if (translationRequest.getText() == null) { - throw new ParamValidationException( I18nConstants.EMPTY_PARAM_MANDATORY, I18nConstants.EMPTY_PARAM_MANDATORY, + throw new ParamValidationException( EMPTY_PARAM_MANDATORY, EMPTY_PARAM_MANDATORY, new String[] {TranslationAppConstants.TEXT}); } - //source is optional -// if (translRequest.getSource() == null) { -// throw new ParamValidationException( I18nConstants.EMPTY_PARAM_MANDATORY, I18nConstants.EMPTY_PARAM_MANDATORY, -// new String[] {TranslationAppConstants.SOURCE_LANG}); -// } - if (translationRequest.getTarget() == I18nConstants.EMPTY_PARAM_MANDATORY) { - throw new ParamValidationException(I18nConstants.EMPTY_PARAM_MANDATORY, I18nConstants.EMPTY_PARAM_MANDATORY, + + if (StringUtils.equals(translationRequest.getTarget(), EMPTY_PARAM_MANDATORY)) { + throw new ParamValidationException(EMPTY_PARAM_MANDATORY, EMPTY_PARAM_MANDATORY, new String[] {TranslationAppConstants.TARGET_LANG}); } //validate language pair final LanguagePair languagePair = new LanguagePair(translationRequest.getSource(), translationRequest.getTarget()); if(!translationService.isTranslationSupported(languagePair)) { - throw new ParamValidationException(null, I18nConstants.INVALID_SERVICE_PARAM, new String[] {languagePair.toString()}); + throw new ParamValidationException(null, INVALID_SERVICE_PARAM, new String[] {languagePair.toString()}); } }