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());
}
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;
}
Aggregations