@Test public void testStatisticsNullUrl() { LocaleCode fromLocaleCode = LocaleCode.EN_US; LocaleCode toLocaleCode = LocaleCode.DE; Response response = documentResource .getStatistics(null, fromLocaleCode, toLocaleCode, null); assertThat(response.getStatus()) .isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); }
@Override public Response getStatistics(@QueryParam("url") String url, @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode, @QueryParam("toLocaleCode") LocaleCode toLocaleCode, @QueryParam("dateRange") String dateRangeParam) { if (StringUtils.isBlank(url)) { APIResponse response = new APIResponse(Response.Status.BAD_REQUEST, "Empty url"); return Response.status(response.getStatus()).entity(response) .build(); } Optional<DateRange> dateParam = StringUtils.isBlank(dateRangeParam) ? Optional.empty() : Optional.of(DateRange.from(dateRangeParam)); List<Document> documents = documentService .getByUrl(url, Optional.ofNullable(fromLocaleCode), Optional.ofNullable(toLocaleCode), dateParam); DocumentStatistics statistics = new DocumentStatistics(url); for (Document document: documents) { int wordCount = getTotalWordCount(document, document.getFromLocale().getLocaleCode()); statistics.addRequestCount( document.getFromLocale().getLocaleCode().getId(), document.getToLocale().getLocaleCode().getId(), document.getCount(), wordCount); } return Response.ok().entity(statistics).build(); }
DocumentResourceImpl implements DocumentResource { @Override public Response getStatistics(@QueryParam("url") String url, @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode, @QueryParam("toLocaleCode") LocaleCode toLocaleCode, @QueryParam("dateRange") String dateRangeParam) { if (StringUtils.isBlank(url)) { APIResponse response = new APIResponse(Response.Status.BAD_REQUEST, "Empty url"); return Response.status(response.getStatus()).entity(response) .build(); } Optional<DateRange> dateParam = StringUtils.isBlank(dateRangeParam) ? Optional.empty() : Optional.of(DateRange.from(dateRangeParam)); List<Document> documents = documentService .getByUrl(url, Optional.ofNullable(fromLocaleCode), Optional.ofNullable(toLocaleCode), dateParam); DocumentStatistics statistics = new DocumentStatistics(url); for (Document document: documents) { int wordCount = getTotalWordCount(document, document.getFromLocale().getLocaleCode()); statistics.addRequestCount( document.getFromLocale().getLocaleCode().getId(), document.getToLocale().getLocaleCode().getId(), document.getCount(), wordCount); } return Response.ok().entity(statistics).build(); } }
DocumentResourceImpl implements DocumentResource { @Override public Response getStatistics(@QueryParam("url") String url, @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode, @QueryParam("toLocaleCode") LocaleCode toLocaleCode, @QueryParam("dateRange") String dateRangeParam) { if (StringUtils.isBlank(url)) { APIResponse response = new APIResponse(Response.Status.BAD_REQUEST, "Empty url"); return Response.status(response.getStatus()).entity(response) .build(); } Optional<DateRange> dateParam = StringUtils.isBlank(dateRangeParam) ? Optional.empty() : Optional.of(DateRange.from(dateRangeParam)); List<Document> documents = documentService .getByUrl(url, Optional.ofNullable(fromLocaleCode), Optional.ofNullable(toLocaleCode), dateParam); DocumentStatistics statistics = new DocumentStatistics(url); for (Document document: documents) { int wordCount = getTotalWordCount(document, document.getFromLocale().getLocaleCode()); statistics.addRequestCount( document.getFromLocale().getLocaleCode().getId(), document.getToLocale().getLocaleCode().getId(), document.getCount(), wordCount); } return Response.ok().entity(statistics).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 getStatistics(@QueryParam("url") String url, @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode, @QueryParam("toLocaleCode") LocaleCode toLocaleCode, @QueryParam("dateRange") String dateRangeParam) { if (StringUtils.isBlank(url)) { APIResponse response = new APIResponse(Response.Status.BAD_REQUEST, "Empty url"); return Response.status(response.getStatus()).entity(response) .build(); } Optional<DateRange> dateParam = StringUtils.isBlank(dateRangeParam) ? Optional.empty() : Optional.of(DateRange.from(dateRangeParam)); List<Document> documents = documentService .getByUrl(url, Optional.ofNullable(fromLocaleCode), Optional.ofNullable(toLocaleCode), dateParam); DocumentStatistics statistics = new DocumentStatistics(url); for (Document document: documents) { int wordCount = getTotalWordCount(document, document.getFromLocale().getLocaleCode()); statistics.addRequestCount( document.getFromLocale().getLocaleCode().getId(), document.getToLocale().getLocaleCode().getId(), document.getCount(), wordCount); } return Response.ok().entity(statistics).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 getStatistics(@QueryParam("url") String url, @QueryParam("fromLocaleCode") LocaleCode fromLocaleCode, @QueryParam("toLocaleCode") LocaleCode toLocaleCode, @QueryParam("dateRange") String dateRangeParam) { if (StringUtils.isBlank(url)) { APIResponse response = new APIResponse(Response.Status.BAD_REQUEST, "Empty url"); return Response.status(response.getStatus()).entity(response) .build(); } Optional<DateRange> dateParam = StringUtils.isBlank(dateRangeParam) ? Optional.empty() : Optional.of(DateRange.from(dateRangeParam)); List<Document> documents = documentService .getByUrl(url, Optional.ofNullable(fromLocaleCode), Optional.ofNullable(toLocaleCode), dateParam); DocumentStatistics statistics = new DocumentStatistics(url); for (Document document: documents) { int wordCount = getTotalWordCount(document, document.getFromLocale().getLocaleCode()); statistics.addRequestCount( document.getFromLocale().getLocaleCode().getId(), document.getToLocale().getLocaleCode().getId(), document.getCount(), wordCount); } return Response.ok().entity(statistics).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);  }