use of org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification in project haikudepotserver by haiku.
the class PkgController method getAllAsJson.
/**
* <p>This streams back a redirect to report data that contains a JSON stream gzip-compressed
* that describes all of the packages for a repository source. This is used by clients to get
* deep(ish) data on all pkgs without having to query each one.</p>
*
* <p>The primary client for this is the Haiku desktop application "Haiku Depot".
* This API deprecates and older JSON-RPC API for obtaining bulk data.</p>
*/
// TODO; observe the natural language code
@RequestMapping(value = "/all-{repositorySourceCode}-{naturalLanguageCode}.json.gz", method = RequestMethod.GET)
public void getAllAsJson(HttpServletResponse response, @PathVariable(value = KEY_NATURALLANGUAGECODE) String naturalLanguageCode, @PathVariable(value = KEY_REPOSITORYSOURCECODE) String repositorySourceCode, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) String ifModifiedSinceHeader) throws IOException {
ObjectContext objectContext = serverRuntime.newContext();
Optional<RepositorySource> repositorySourceOptional = RepositorySource.tryGetByCode(objectContext, repositorySourceCode);
if (!repositorySourceOptional.isPresent()) {
LOGGER.info("repository source [" + repositorySourceCode + "] not found");
response.setStatus(HttpStatus.NOT_FOUND.value());
} else {
Date lastModifiedTimestamp = pkgService.getLastModifyTimestampSecondAccuracy(objectContext, repositorySourceOptional.get());
PkgDumpExportJobSpecification specification = new PkgDumpExportJobSpecification();
specification.setNaturalLanguageCode(naturalLanguageCode);
specification.setRepositorySourceCode(repositorySourceCode);
JobController.handleRedirectToJobData(response, jobService, ifModifiedSinceHeader, lastModifiedTimestamp, specification);
}
}
use of org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification in project haikudepotserver by haiku.
the class PkgDumpExportJobRunnerIT method testRun.
/**
* <p>Uses the sample data and checks that the output from the report matches a captured, sensible-looking
* previous run.</p>
*/
@Test
public void testRun() throws IOException {
long now = DateTimeHelper.secondAccuracyDate(new Date()).getTime();
integrationTestSupportService.createStandardTestData();
PkgDumpExportJobSpecification specification = new PkgDumpExportJobSpecification();
specification.setRepositorySourceCode("testreposrc_xyz");
specification.setNaturalLanguageCode("es");
// ------------------------------------
String guid = jobService.submit(specification, JobSnapshot.COALESCE_STATUSES_NONE);
// ------------------------------------
jobService.awaitJobFinishedUninterruptibly(guid, 10000);
Optional<? extends JobSnapshot> snapshotOptional = jobService.tryGetJob(guid);
Assertions.assertThat(snapshotOptional.get().getStatus()).isEqualTo(JobSnapshot.Status.FINISHED);
// pull in the ZIP file now and extract the data
String dataGuid = snapshotOptional.get().getGeneratedDataGuids().iterator().next();
JobDataWithByteSource jobSource = jobService.tryObtainData(dataGuid).get();
try (final InputStream inputStream = jobSource.getByteSource().openBufferedStream();
final GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream)) {
JsonNode rootNode = objectMapper.readTree(gzipInputStream);
JsonNode dataModifiedTimestampNode = rootNode.at("/info/dataModifiedTimestamp");
Assertions.assertThat(dataModifiedTimestampNode.asLong()).isGreaterThanOrEqualTo(now);
JsonNode repositoryCode = rootNode.at("/items/0/name");
Assertions.assertThat(repositoryCode.asText()).isEqualTo("pkg1");
JsonNode derivedRating = rootNode.at("/items/0/derivedRating");
Assertions.assertThat(derivedRating.asText()).isEqualTo("3.5");
JsonNode pkgScreenshots = rootNode.at("/items/0/pkgScreenshots/0/length");
Assertions.assertThat(pkgScreenshots.asLong()).isEqualTo(41296L);
JsonNode pkgCategories = rootNode.at("/items/0/pkgCategories/0/code");
Assertions.assertThat(pkgCategories.asText()).isEqualTo("graphics");
JsonNode pv0Summary = rootNode.at("/items/0/pkgVersions/0/summary");
Assertions.assertThat(pv0Summary.asText()).isEqualTo("pkg1Version2SummarySpanish_feijoa");
}
}
Aggregations