use of org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization in project haikudepotserver by haiku.
the class CreatedUserRatingSyndEntrySupplier method generate.
@Override
public List<SyndEntry> generate(final FeedSpecification specification) {
Preconditions.checkNotNull(specification);
if (specification.getSupplierTypes().contains(FeedSpecification.SupplierType.CREATEDUSERRATING)) {
if (null != specification.getPkgNames() && specification.getPkgNames().isEmpty()) {
return Collections.emptyList();
}
ObjectSelect<UserRating> objectSelect = ObjectSelect.query(UserRating.class).where(UserRating.ACTIVE.isTrue()).and(UserRating.PKG_VERSION.dot(PkgVersion.ACTIVE).isTrue()).and(UserRating.PKG_VERSION.dot(PkgVersion.PKG).dot(Pkg.ACTIVE).isTrue()).statementFetchSize(specification.getLimit()).orderBy(UserRating.CREATE_TIMESTAMP.desc());
if (null != specification.getPkgNames()) {
objectSelect.and(UserRating.PKG_VERSION.dot(PkgVersion.PKG).dot(Pkg.NAME).in(specification.getPkgNames()));
}
ObjectContext context = serverRuntime.newContext();
List<UserRating> userRatings = objectSelect.select(serverRuntime.newContext());
NaturalLanguage naturalLanguage = deriveNaturalLanguage(context, specification);
return userRatings.stream().map(ur -> {
SyndEntry entry = new SyndEntryImpl();
entry.setPublishedDate(ur.getCreateTimestamp());
entry.setUpdatedDate(ur.getModifyTimestamp());
entry.setAuthor(ur.getUser().getNickname());
entry.setUri(URI_PREFIX + Hashing.sha1().hashUnencodedChars(String.format("%s_::_%s_::_%s_::_%s", this.getClass().getCanonicalName(), ur.getPkgVersion().getPkg().getName(), ur.getPkgVersion().toVersionCoordinates().toString(), ur.getUser().getNickname())).toString());
entry.setLink(String.format("%s/#!/userrating/%s", baseUrl, ur.getCode()));
ResolvedPkgVersionLocalization resolvedPkgVersionLocalization = pkgLocalizationService.resolvePkgVersionLocalization(context, ur.getPkgVersion(), null, naturalLanguage);
entry.setTitle(messageSource.getMessage("feed.createdUserRating.atom.title", new Object[] { Optional.ofNullable(resolvedPkgVersionLocalization.getTitle()).orElse(ur.getPkgVersion().getPkg().getName()), ur.getUser().getNickname() }, new Locale(specification.getNaturalLanguageCode())));
String contentString = ur.getComment();
if (null != contentString && contentString.length() > CONTENT_LENGTH) {
contentString = contentString.substring(0, CONTENT_LENGTH) + "...";
}
if (null != ur.getRating()) {
contentString = buildRatingIndicator(ur.getRating()) + (Strings.isNullOrEmpty(contentString) ? "" : " -- " + contentString);
}
SyndContentImpl content = new SyndContentImpl();
content.setType(MediaType.PLAIN_TEXT_UTF_8.type());
content.setValue(contentString);
entry.setDescription(content);
return entry;
}).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization in project haikudepotserver by haiku.
the class FixedPkgLocalizationLookupServiceImpl method resolvePkgVersionLocalization.
@Override
public ResolvedPkgVersionLocalization resolvePkgVersionLocalization(ObjectContext context, PkgVersion pkgVersion, Pattern searchPattern, NaturalLanguage naturalLanguage) {
Preconditions.checkNotNull(pkgVersion, "the pkg version must be supplied");
Preconditions.checkArgument(null == searchPattern, "a search pattern is not supported");
Preconditions.checkArgument(null != naturalLanguage, "the natural language must be supplied");
Preconditions.checkArgument(naturalLanguage.getCode().equals(naturalLanguageCode), "mismatch between requested and originally specified natural language.");
ResolvedPkgVersionLocalization result = cachedResult.get(pkgVersion.getObjectId());
if (null == result) {
throw new IllegalStateException("the pkg version [" + pkgVersion + "] was queried, but was not in the initial set of package versions supplied");
}
return result;
}
use of org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization in project haikudepotserver by haiku.
the class PkgLocalizationServiceImpl method resolvePkgVersionLocalization.
@Override
public ResolvedPkgVersionLocalization resolvePkgVersionLocalization(ObjectContext context, PkgVersion pkgVersion, Pattern searchPattern, NaturalLanguage naturalLanguage) {
ResolvedPkgVersionLocalization result = new ResolvedPkgVersionLocalization();
fillResolvedPkgVersionLocalization(result, context, pkgVersion, searchPattern, naturalLanguage);
return result;
}
use of org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization in project haikudepotserver by haiku.
the class PkgDumpExportJobRunner method createDumpPkgVersion.
private DumpExportPkgVersion createDumpPkgVersion(ObjectContext context, PkgVersion pkgVersion, NaturalLanguage naturalLanguage, PkgLocalizationLookupService pkgLocalizationLookupService) {
DumpExportPkgVersion result = new DumpExportPkgVersion();
result.setCreateTimestamp(pkgVersion.getCreateTimestamp().getTime());
result.setModifyTimestamp(pkgVersion.getModifyTimestamp().getTime());
result.setMajor(pkgVersion.getMajor());
result.setMinor(pkgVersion.getMinor());
result.setMicro(pkgVersion.getMicro());
result.setPreRelease(pkgVersion.getPreRelease());
result.setRevision(null == pkgVersion.getRevision() ? null : pkgVersion.getRevision().longValue());
result.setArchitectureCode(pkgVersion.getArchitecture().getCode());
result.setPayloadLength(pkgVersion.getPayloadLength());
ResolvedPkgVersionLocalization resolvedPkgVersionLocalization = pkgLocalizationLookupService.resolvePkgVersionLocalization(context, pkgVersion, null, naturalLanguage);
result.setDescription(resolvedPkgVersionLocalization.getDescription());
result.setSummary(resolvedPkgVersionLocalization.getSummary());
result.setTitle(resolvedPkgVersionLocalization.getTitle());
return result;
}
use of org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization in project haikudepotserver by haiku.
the class CreatedPkgVersionSyndEntrySupplier method generate.
@Override
public List<SyndEntry> generate(final FeedSpecification specification) {
Preconditions.checkNotNull(specification);
if (specification.getSupplierTypes().contains(FeedSpecification.SupplierType.CREATEDPKGVERSION)) {
if (null != specification.getPkgNames() && specification.getPkgNames().isEmpty()) {
return Collections.emptyList();
}
ObjectSelect<PkgVersion> objectSelect = ObjectSelect.query(PkgVersion.class).where(PkgVersion.ACTIVE.isTrue()).and(PkgVersion.PKG.dot(Pkg.ACTIVE).isTrue()).and(ExpressionFactory.or(PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_DEBUGINFO), PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_DEVELOPMENT), PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_SOURCE)).notExp()).orderBy(PkgVersion.CREATE_TIMESTAMP.desc()).limit(specification.getLimit());
if (null != specification.getPkgNames()) {
objectSelect.and(PkgVersion.PKG.dot(Pkg.NAME).in(specification.getPkgNames()));
}
ObjectContext context = serverRuntime.newContext();
NaturalLanguage naturalLanguage = deriveNaturalLanguage(context, specification);
List<PkgVersion> pkgVersions = objectSelect.select(context);
return pkgVersions.stream().map(pv -> {
SyndEntry entry = new SyndEntryImpl();
entry.setPublishedDate(pv.getCreateTimestamp());
entry.setUpdatedDate(pv.getModifyTimestamp());
entry.setUri(URI_PREFIX + Hashing.sha1().hashUnencodedChars(String.format("%s_::_%s_::_%s", this.getClass().getCanonicalName(), pv.getPkg().getName(), pv.toVersionCoordinates().toString())).toString());
{
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl).pathSegment("#!", "pkg");
pv.appendPathSegments(builder);
entry.setLink(builder.build().toUriString());
}
ResolvedPkgVersionLocalization resolvedPkgVersionLocalization = pkgLocalizationService.resolvePkgVersionLocalization(context, pv, null, naturalLanguage);
entry.setTitle(messageSource.getMessage("feed.createdPkgVersion.atom.title", new Object[] { Optional.ofNullable(resolvedPkgVersionLocalization.getTitle()).orElse(pv.getPkg().getName()), pv.toVersionCoordinates().toString() }, new Locale(naturalLanguage.getCode())));
{
SyndContent content = new SyndContentImpl();
content.setType(MediaType.PLAIN_TEXT_UTF_8.type());
content.setValue(resolvedPkgVersionLocalization.getSummary());
entry.setDescription(content);
}
return entry;
}).collect(Collectors.toList());
}
return Collections.emptyList();
}
Aggregations