Search in sources :

Example 1 with GenerateFeedUrlRequest

use of org.haiku.haikudepotserver.api1.model.miscellaneous.GenerateFeedUrlRequest in project haikudepotserver by haiku.

the class MiscelaneousApiIT method testGenerateFeedUrl.

@Test
public void testGenerateFeedUrl() throws MalformedURLException {
    IntegrationTestSupportService.StandardTestData data = integrationTestSupportService.createStandardTestData();
    GenerateFeedUrlRequest request = new GenerateFeedUrlRequest();
    request.limit = 55;
    request.naturalLanguageCode = NaturalLanguage.CODE_GERMAN;
    request.pkgNames = ImmutableList.of(data.pkg1.getName(), data.pkg2.getName());
    request.supplierTypes = ImmutableList.of(GenerateFeedUrlRequest.SupplierType.CREATEDPKGVERSION);
    // ------------------------------------
    String urlString = miscellaneousApi.generateFeedUrl(request).url;
    // ------------------------------------
    URL url = new URL(urlString);
    Assertions.assertThat(url.getPath()).endsWith("/__feed/pkg.atom");
    // this is a bit rough, but will do for assertion...
    Map<String, String> queryParams = Splitter.on('&').trimResults().withKeyValueSeparator('=').split(url.getQuery());
    Assertions.assertThat(queryParams.get(FeedService.KEY_LIMIT)).isEqualTo("55");
    Assertions.assertThat(queryParams.get(FeedService.KEY_NATURALLANGUAGECODE)).isEqualTo(NaturalLanguage.CODE_GERMAN);
    Assertions.assertThat(queryParams.get(FeedService.KEY_PKGNAMES)).isEqualTo(String.join("-", data.pkg1.getName(), data.pkg2.getName()));
    Assertions.assertThat(queryParams.get(FeedService.KEY_TYPES)).isEqualTo(GenerateFeedUrlRequest.SupplierType.CREATEDPKGVERSION.name());
}
Also used : GenerateFeedUrlRequest(org.haiku.haikudepotserver.api1.model.miscellaneous.GenerateFeedUrlRequest) IntegrationTestSupportService(org.haiku.haikudepotserver.IntegrationTestSupportService) URL(java.net.URL) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with GenerateFeedUrlRequest

use of org.haiku.haikudepotserver.api1.model.miscellaneous.GenerateFeedUrlRequest in project haikudepotserver by haiku.

the class MiscellaneousApiImpl method generateFeedUrl.

@Override
public GenerateFeedUrlResult generateFeedUrl(final GenerateFeedUrlRequest request) {
    Preconditions.checkNotNull(request);
    final ObjectContext context = serverRuntime.newContext();
    FeedSpecification specification = new FeedSpecification();
    specification.setFeedType(FeedSpecification.FeedType.ATOM);
    specification.setLimit(request.limit);
    if (null != request.supplierTypes) {
        specification.setSupplierTypes(request.supplierTypes.stream().map(st -> FeedSpecification.SupplierType.valueOf(st.name())).collect(Collectors.toList()));
    }
    if (null != request.naturalLanguageCode) {
        specification.setNaturalLanguageCode(getNaturalLanguage(context, request.naturalLanguageCode).getCode());
    }
    if (null != request.pkgNames) {
        List<String> checkedPkgNames = new ArrayList<>();
        for (String pkgName : request.pkgNames) {
            Optional<Pkg> pkgOptional = Pkg.tryGetByName(context, pkgName);
            if (pkgOptional.isEmpty()) {
                throw new ObjectNotFoundException(Pkg.class.getSimpleName(), pkgName);
            }
            checkedPkgNames.add(pkgOptional.get().getName());
        }
        specification.setPkgNames(checkedPkgNames);
    }
    GenerateFeedUrlResult result = new GenerateFeedUrlResult();
    result.url = feedService.generateUrl(specification);
    return result;
}
Also used : ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

URL (java.net.URL)1 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 IntegrationTestSupportService (org.haiku.haikudepotserver.IntegrationTestSupportService)1 GenerateFeedUrlRequest (org.haiku.haikudepotserver.api1.model.miscellaneous.GenerateFeedUrlRequest)1 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 FeedSpecification (org.haiku.haikudepotserver.feed.model.FeedSpecification)1 Test (org.junit.jupiter.api.Test)1