Search in sources :

Example 1 with PkgLocalizationLookupService

use of org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService in project haikudepotserver by haiku.

the class PkgVersionTitleTag method getResolvedPkgVersionLocalization.

private ResolvedPkgVersionLocalization getResolvedPkgVersionLocalization() {
    ServerRuntime serverRuntime = ServerRuntime.class.cast(pageContext.getRequest().getAttribute(MultipageConstants.KEY_SERVERRUNTIME));
    PkgLocalizationLookupService lookupService = PkgLocalizationLookupService.class.cast(pageContext.getRequest().getAttribute(MultipageConstants.KEY_PKGLOCALIZATIONLOOKUPSERVICE));
    return lookupService.resolvePkgVersionLocalization(serverRuntime.newContext(), getPkgVersion(), null, getNaturalLanguage());
}
Also used : ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) PkgLocalizationLookupService(org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService)

Example 2 with PkgLocalizationLookupService

use of org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService in project haikudepotserver by haiku.

the class PkgDumpExportJobRunner method writePkgVersions.

private void writePkgVersions(JsonGenerator jsonGenerator, ObjectContext context, List<PkgVersion> pkgVersions, RepositorySource repositorySource, NaturalLanguage naturalLanguage) {
    final PkgLocalizationLookupService pkgLocalizationLookupService = new FixedPkgLocalizationLookupServiceImpl(context, pkgVersions, naturalLanguage);
    Map<String, List<PkgVersion>> pkgVersionsUnderCommonPkg = pkgVersions.stream().collect(Collectors.groupingBy((pv) -> pv.getPkg().getName()));
    pkgVersionsUnderCommonPkg.values().forEach((pvs) -> {
        try {
            objectMapper.writeValue(jsonGenerator, createDumpPkg(context, pvs, repositorySource, naturalLanguage, pkgLocalizationLookupService));
        } catch (IOException ioe) {
            throw new UncheckedIOException(ioe);
        }
    });
}
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) FixedPkgLocalizationLookupServiceImpl(org.haiku.haikudepotserver.pkg.FixedPkgLocalizationLookupServiceImpl) PkgLocalizationLookupService(org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService) List(java.util.List) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with PkgLocalizationLookupService

use of org.haiku.haikudepotserver.pkg.model.PkgLocalizationLookupService 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

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