@Test public void testSameLocale() { Locale locale = new Locale(LocaleCode.EN, "English"); DocumentContent docContent = new DocumentContent(ImmutableList.of( new TypeString("testing", MediaType.TEXT_HTML, "meta1")), "http: Response response = documentResource .translate(docContent, locale.getLocaleCode()); assertThat(response.getStatus()) .isEqualTo(Response.Status.OK.getStatusCode()); DocumentContent returnedDocContent = (DocumentContent) response.getEntity(); assertThat(returnedDocContent).isEqualTo(docContent); }
@Override public Response translate(DocumentContent docContent, @QueryParam("toLocaleCode") LocaleCode toLocaleCode) { Optional<APIResponse> errorResp = validateTranslateRequest(docContent, toLocaleCode); if (errorResp.isPresent()) { return Response.status(errorResp.get().getStatus()) .entity(errorResp.get()).build(); } final BackendID backendID = isDevMode ? BackendID.DEV : fromStringWithDefault(docContent.getBackendId(), defaultProvider); if (!availableProviders.contains(backendID)) { LOG.warn( "requested machine translation provider {} is not set up (no credential)", backendID); return Response.status(Response.Status.NOT_IMPLEMENTED) .entity(new APIResponse(Response.Status.NOT_IMPLEMENTED, "Error: backendId " + docContent.getBackendId() + " not available")).build(); } LocaleCode fromLocaleCode = new LocaleCode(docContent.getLocaleCode()); if (fromLocaleCode.equals(toLocaleCode)) { LOG.info( "Returning unchanged request, FROM and TO localeCode are the same {}", fromLocaleCode); return Response.ok().entity(docContent).build(); } if (LOG.isDebugEnabled()) { LOG.debug("Request translations: {} toLocaleCode {} backendId: {}", docContent, toLocaleCode, backendID.getId()); } Locale fromLocale = getLocale(fromLocaleCode); Locale toLocale = getLocale(toLocaleCode); Document doc = documentService .getOrCreateByUrl(docContent.getUrl(), fromLocale, toLocale); documentService.incrementDocRequestCount(doc); DocumentContent newDocContent = documentContentTranslatorService .translateDocument(doc, docContent, backendID); return Response.ok().entity(newDocContent).build(); }
DocumentResourceImpl implements DocumentResource { @Override public Response translate(DocumentContent docContent, @QueryParam("toLocaleCode") LocaleCode toLocaleCode) { Optional<APIResponse> errorResp = validateTranslateRequest(docContent, toLocaleCode); if (errorResp.isPresent()) { return Response.status(errorResp.get().getStatus()) .entity(errorResp.get()).build(); } final BackendID backendID = isDevMode ? BackendID.DEV : fromStringWithDefault(docContent.getBackendId(), defaultProvider); if (!availableProviders.contains(backendID)) { LOG.warn( "requested machine translation provider {} is not set up (no credential)", backendID); return Response.status(Response.Status.NOT_IMPLEMENTED) .entity(new APIResponse(Response.Status.NOT_IMPLEMENTED, "Error: backendId " + docContent.getBackendId() + " not available")).build(); } LocaleCode fromLocaleCode = new LocaleCode(docContent.getLocaleCode()); if (fromLocaleCode.equals(toLocaleCode)) { LOG.info( "Returning unchanged request, FROM and TO localeCode are the same {}", fromLocaleCode); return Response.ok().entity(docContent).build(); } if (LOG.isDebugEnabled()) { LOG.debug("Request translations: {} toLocaleCode {} backendId: {}", docContent, toLocaleCode, backendID.getId()); } Locale fromLocale = getLocale(fromLocaleCode); Locale toLocale = getLocale(toLocaleCode); Document doc = documentService .getOrCreateByUrl(docContent.getUrl(), fromLocale, toLocale); documentService.incrementDocRequestCount(doc); DocumentContent newDocContent = documentContentTranslatorService .translateDocument(doc, docContent, backendID); return Response.ok().entity(newDocContent).build(); } }
DocumentResourceImpl implements DocumentResource { @Override public Response translate(DocumentContent docContent, @QueryParam("toLocaleCode") LocaleCode toLocaleCode) { Optional<APIResponse> errorResp = validateTranslateRequest(docContent, toLocaleCode); if (errorResp.isPresent()) { return Response.status(errorResp.get().getStatus()) .entity(errorResp.get()).build(); } final BackendID backendID = isDevMode ? BackendID.DEV : fromStringWithDefault(docContent.getBackendId(), defaultProvider); if (!availableProviders.contains(backendID)) { LOG.warn( "requested machine translation provider {} is not set up (no credential)", backendID); return Response.status(Response.Status.NOT_IMPLEMENTED) .entity(new APIResponse(Response.Status.NOT_IMPLEMENTED, "Error: backendId " + docContent.getBackendId() + " not available")).build(); } LocaleCode fromLocaleCode = new LocaleCode(docContent.getLocaleCode()); if (fromLocaleCode.equals(toLocaleCode)) { LOG.info( "Returning unchanged request, FROM and TO localeCode are the same {}", fromLocaleCode); return Response.ok().entity(docContent).build(); } if (LOG.isDebugEnabled()) { LOG.debug("Request translations: {} toLocaleCode {} backendId: {}", docContent, toLocaleCode, backendID.getId()); } Locale fromLocale = getLocale(fromLocaleCode); Locale toLocale = getLocale(toLocaleCode); Document doc = documentService .getOrCreateByUrl(docContent.getUrl(), fromLocale, toLocale); documentService.incrementDocRequestCount(doc); DocumentContent newDocContent = documentContentTranslatorService .translateDocument(doc, docContent, backendID); return Response.ok().entity(newDocContent).build(); } @SuppressWarnings("unused")  DocumentResourceImpl(); @Inject  DocumentResourceImpl(
        DocumentContentTranslatorService documentContentTranslatorService,
        LocaleDAO localeDAO,
        DocumentService documentService,
        BackendResource backendResourceImpl,
        @DevMode boolean isDevMode,
        @DefaultProvider BackendID defaultProvider,
        @BackEndProviders Set<BackendID> availableProviders); }
DocumentResourceImpl implements DocumentResource { @Override public Response translate(DocumentContent docContent, @QueryParam("toLocaleCode") LocaleCode toLocaleCode) { Optional<APIResponse> errorResp = validateTranslateRequest(docContent, toLocaleCode); if (errorResp.isPresent()) { return Response.status(errorResp.get().getStatus()) .entity(errorResp.get()).build(); } final BackendID backendID = isDevMode ? BackendID.DEV : fromStringWithDefault(docContent.getBackendId(), defaultProvider); if (!availableProviders.contains(backendID)) { LOG.warn( "requested machine translation provider {} is not set up (no credential)", backendID); return Response.status(Response.Status.NOT_IMPLEMENTED) .entity(new APIResponse(Response.Status.NOT_IMPLEMENTED, "Error: backendId " + docContent.getBackendId() + " not available")).build(); } LocaleCode fromLocaleCode = new LocaleCode(docContent.getLocaleCode()); if (fromLocaleCode.equals(toLocaleCode)) { LOG.info( "Returning unchanged request, FROM and TO localeCode are the same {}", fromLocaleCode); return Response.ok().entity(docContent).build(); } if (LOG.isDebugEnabled()) { LOG.debug("Request translations: {} toLocaleCode {} backendId: {}", docContent, toLocaleCode, backendID.getId()); } Locale fromLocale = getLocale(fromLocaleCode); Locale toLocale = getLocale(toLocaleCode); Document doc = documentService .getOrCreateByUrl(docContent.getUrl(), fromLocale, toLocale); documentService.incrementDocRequestCount(doc); DocumentContent newDocContent = documentContentTranslatorService .translateDocument(doc, docContent, backendID); return Response.ok().entity(newDocContent).build(); } @SuppressWarnings("unused")  DocumentResourceImpl(); @Inject  DocumentResourceImpl(
        DocumentContentTranslatorService documentContentTranslatorService,
        LocaleDAO localeDAO,
        DocumentService documentService,
        BackendResource backendResourceImpl,
        @DevMode boolean isDevMode,
        @DefaultProvider BackendID defaultProvider,
        @BackEndProviders Set<BackendID> availableProviders); @Override Response getStatistics(@QueryParam("url") String url,
            @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode,
            @QueryParam("toLocaleCode") LocaleCode toLocaleCode,
            @QueryParam("dateRange") String dateRangeParam); @Override Response translate(DocumentContent docContent,
        @QueryParam("toLocaleCode") LocaleCode toLocaleCode); @Override Response translateFile(TranslateDocumentForm form,
        LocaleCode fromLocaleCode, LocaleCode toLocaleCode); }
DocumentResourceImpl implements DocumentResource { @Override public Response translate(DocumentContent docContent, @QueryParam("toLocaleCode") LocaleCode toLocaleCode) { Optional<APIResponse> errorResp = validateTranslateRequest(docContent, toLocaleCode); if (errorResp.isPresent()) { return Response.status(errorResp.get().getStatus()) .entity(errorResp.get()).build(); } final BackendID backendID = isDevMode ? BackendID.DEV : fromStringWithDefault(docContent.getBackendId(), defaultProvider); if (!availableProviders.contains(backendID)) { LOG.warn( "requested machine translation provider {} is not set up (no credential)", backendID); return Response.status(Response.Status.NOT_IMPLEMENTED) .entity(new APIResponse(Response.Status.NOT_IMPLEMENTED, "Error: backendId " + docContent.getBackendId() + " not available")).build(); } LocaleCode fromLocaleCode = new LocaleCode(docContent.getLocaleCode()); if (fromLocaleCode.equals(toLocaleCode)) { LOG.info( "Returning unchanged request, FROM and TO localeCode are the same {}", fromLocaleCode); return Response.ok().entity(docContent).build(); } if (LOG.isDebugEnabled()) { LOG.debug("Request translations: {} toLocaleCode {} backendId: {}", docContent, toLocaleCode, backendID.getId()); } Locale fromLocale = getLocale(fromLocaleCode); Locale toLocale = getLocale(toLocaleCode); Document doc = documentService .getOrCreateByUrl(docContent.getUrl(), fromLocale, toLocale); documentService.incrementDocRequestCount(doc); DocumentContent newDocContent = documentContentTranslatorService .translateDocument(doc, docContent, backendID); return Response.ok().entity(newDocContent).build(); } @SuppressWarnings("unused")  DocumentResourceImpl(); @Inject  DocumentResourceImpl(
        DocumentContentTranslatorService documentContentTranslatorService,
        LocaleDAO localeDAO,
        DocumentService documentService,
        BackendResource backendResourceImpl,
        @DevMode boolean isDevMode,
        @DefaultProvider BackendID defaultProvider,
        @BackEndProviders Set<BackendID> availableProviders); @Override Response getStatistics(@QueryParam("url") String url,
            @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode,
            @QueryParam("toLocaleCode") LocaleCode toLocaleCode,
            @QueryParam("dateRange") String dateRangeParam); @Override Response translate(DocumentContent docContent,
        @QueryParam("toLocaleCode") LocaleCode toLocaleCode); @Override Response translateFile(TranslateDocumentForm form,
        LocaleCode fromLocaleCode, LocaleCode toLocaleCode);  }