diff --git a/translation-web/src/main/java/eu/europeana/api/translation/web/LangDetectionController.java b/translation-web/src/main/java/eu/europeana/api/translation/web/LangDetectionController.java index a089c158..fae5c9a4 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/web/LangDetectionController.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/web/LangDetectionController.java @@ -63,71 +63,4 @@ private void validateRequest(LangDetectRequest langDetectRequest) new String[] {TranslationAppConstants.LANG, langDetectRequest.getLang()}); } } -} -======= -package eu.europeana.api.translation.web; - -import javax.servlet.http.HttpServletRequest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -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.definitions.vocabulary.TranslationAppConstants; -import eu.europeana.api.translation.model.LangDetectRequest; -import eu.europeana.api.translation.model.LangDetectResponse; -import eu.europeana.api.translation.web.service.LangDetectionWebService; -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 = "Language Detection endpoints", description = "Perform language detection") -public class LangDetectionController extends BaseRest { - - private final LangDetectionWebService langDetectionService; - - public LangDetectionController(@Autowired LangDetectionWebService langDetectionService) { - this.langDetectionService = langDetectionService; - } - - @Tag(description = "Language detection", name = "detectLang") - @PostMapping(value = {"/detect"}, produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, MediaType.APPLICATION_JSON_VALUE}) - public ResponseEntity detectLang(@RequestBody LangDetectRequest langDetectRequest, - HttpServletRequest request) throws Exception { - - verifyWriteAccess(Operations.CREATE, request); - - validateRequest(langDetectRequest); - - LangDetectResponse result = langDetectionService.detectLang(langDetectRequest); - - String resultJson = serialize(result); - - return generateResponseEntity(request, resultJson); - } - - /** - * Validate the Language detection request. - * - * @param langDetectRequest detection request - * @throws ParamValidationException exception - */ - private void validateRequest(LangDetectRequest langDetectRequest) - throws ParamValidationException { - // validate mandatory params - if (langDetectRequest.getText() == null) { - throw new ParamValidationException(null, EMPTY_PARAM_MANDATORY, - new String[] {TranslationAppConstants.TEXT}); - } - //validate language hint if provided - if(langDetectRequest.getLang() != null && !langDetectionService.isLangDetectionSupported(langDetectRequest.getLang())) { - throw new ParamValidationException(null, INVALID_SERVICE_PARAM, - new String[] {TranslationAppConstants.LANG, langDetectRequest.getLang()}); - } - } } \ No newline at end of file