Skip to content

Commit

Permalink
fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
GordeaS authored and GordeaS committed Oct 18, 2023
1 parent fa549e7 commit 9946a08
Showing 1 changed file with 0 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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()});
}
}
}

0 comments on commit 9946a08

Please sign in to comment.