Search in sources :

Example 1 with PkgDumpExportJobSpecification

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 &quot;Haiku Depot&quot;.
 * 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);
    }
}
Also used : RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) ObjectContext(org.apache.cayenne.ObjectContext) PkgDumpExportJobSpecification(org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PkgDumpExportJobSpecification

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");
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JobDataWithByteSource(org.haiku.haikudepotserver.job.model.JobDataWithByteSource) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) PkgDumpExportJobSpecification(org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification) Date(java.util.Date) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Date (java.util.Date)2 PkgDumpExportJobSpecification (org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)1 JobDataWithByteSource (org.haiku.haikudepotserver.job.model.JobDataWithByteSource)1 Test (org.junit.jupiter.api.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1