Search in sources :

Example 1 with DumpExportPkg

use of org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkg in project haikudepotserver by haiku.

the class PkgDumpExportJobRunner method createDumpPkg.

private DumpExportPkg createDumpPkg(ObjectContext context, List<PkgVersion> pkgVersionsUnderCommonPkg, RepositorySource repositorySource, NaturalLanguage naturalLanguage, PkgLocalizationLookupService pkgLocalizationLookupService) {
    Preconditions.checkArgument(null != pkgVersionsUnderCommonPkg && !pkgVersionsUnderCommonPkg.isEmpty());
    // any will do to get the pkg.
    Pkg pkg = pkgVersionsUnderCommonPkg.get(0).getPkg();
    DumpExportPkg dumpExportPkg = new DumpExportPkg();
    dumpExportPkg.setCreateTimestamp(pkg.getCreateTimestamp().getTime());
    dumpExportPkg.setModifyTimestamp(pkg.getModifyTimestamp().getTime());
    dumpExportPkg.setName(pkg.getName());
    dumpExportPkg.setHasChangelog(pkg.getPkgSupplement().getPkgChangelog().isPresent());
    dumpExportPkg.setProminenceOrdering(pkg.getPkgProminence(repositorySource.getRepository()).map((p) -> p.getProminence().getOrdering()).map(Long::new).orElse(null));
    dumpExportPkg.setDerivedRating(pkg.getPkgUserRatingAggregate(repositorySource.getRepository()).map((v) -> v.getDerivedRating().doubleValue()).orElse(null));
    dumpExportPkg.setPkgCategories(pkg.getPkgSupplement().getPkgPkgCategories().stream().map((ppc) -> {
        DumpExportPkgCategory dumpExportPkgCategory = new DumpExportPkgCategory();
        dumpExportPkgCategory.setCode(ppc.getPkgCategory().getCode());
        return dumpExportPkgCategory;
    }).collect(Collectors.toList()));
    dumpExportPkg.setPkgScreenshots(pkg.getPkgSupplement().getPkgScreenshots().stream().sorted().map((ps) -> {
        DumpExportPkgScreenshot dumpExportPkgScreenshot = new DumpExportPkgScreenshot();
        dumpExportPkgScreenshot.setCode(ps.getCode());
        dumpExportPkgScreenshot.setHeight(ps.getHeight().longValue());
        dumpExportPkgScreenshot.setWidth(ps.getWidth().longValue());
        dumpExportPkgScreenshot.setLength(ps.getLength().longValue());
        dumpExportPkgScreenshot.setOrdering(ps.getOrdering().longValue());
        return dumpExportPkgScreenshot;
    }).collect(Collectors.toList()));
    dumpExportPkg.setPkgVersions(pkgVersionsUnderCommonPkg.stream().sorted().map((pv) -> createDumpPkgVersion(context, pv, naturalLanguage, pkgLocalizationLookupService)).collect(Collectors.toList()));
    return dumpExportPkg;
}
Also used : PkgService(org.haiku.haikudepotserver.pkg.model.PkgService) ObjectContext(org.apache.cayenne.ObjectContext) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) DumpExportPkgScreenshot(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkgScreenshot) Date(java.util.Date) FixedPkgLocalizationLookupServiceImpl(org.haiku.haikudepotserver.pkg.FixedPkgLocalizationLookupServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArchiveInfo(org.haiku.haikudepotserver.support.ArchiveInfo) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobDataWithByteSink(org.haiku.haikudepotserver.job.model.JobDataWithByteSink) JobService(org.haiku.haikudepotserver.job.model.JobService) DumpExportPkg(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkg) DumpExportPkgVersion(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkgVersion) PkgDumpExportJobSpecification(org.haiku.haikudepotserver.pkg.model.PkgDumpExportJobSpecification) DateTimeHelper(org.haiku.haikudepotserver.support.DateTimeHelper) OutputStream(java.io.OutputStream) MediaType(com.google.common.net.MediaType) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedPkgVersionLocalization(org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization) DataRow(org.apache.cayenne.DataRow) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractJobRunner(org.haiku.haikudepotserver.job.AbstractJobRunner) RuntimeInformationService(org.haiku.haikudepotserver.support.RuntimeInformationService) IOException(java.io.IOException) PkgLocalizationLookupService(org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService) Collectors(java.util.stream.Collectors) org.haiku.haikudepotserver.dataobjects(org.haiku.haikudepotserver.dataobjects) UncheckedIOException(java.io.UncheckedIOException) SQLTemplate(org.apache.cayenne.query.SQLTemplate) Component(org.springframework.stereotype.Component) List(java.util.List) PrefetchTreeNode(org.apache.cayenne.query.PrefetchTreeNode) DumpExportPkgCategory(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkgCategory) Preconditions(com.google.common.base.Preconditions) ObjectSelect(org.apache.cayenne.query.ObjectSelect) GZIPOutputStream(java.util.zip.GZIPOutputStream) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) DumpExportPkgCategory(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkgCategory) DumpExportPkgScreenshot(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkgScreenshot) DumpExportPkg(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkg) DumpExportPkg(org.haiku.haikudepotserver.pkg.model.dumpexport.DumpExportPkg)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 MediaType (com.google.common.net.MediaType)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 DataRow (org.apache.cayenne.DataRow)1 ObjectContext (org.apache.cayenne.ObjectContext)1 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)1 ObjectSelect (org.apache.cayenne.query.ObjectSelect)1 PrefetchTreeNode (org.apache.cayenne.query.PrefetchTreeNode)1