use of org.haiku.haikudepotserver.dataobjects.UserRating 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.dataobjects.UserRating in project haikudepotserver by haiku.
the class UserRatingApiIT method testSearchUserRatings.
/**
* <p>This will just do a very basic search test; can add others later if/when problems arise.</p>
*/
@Test
public void testSearchUserRatings() {
integrationTestSupportService.createStandardTestData();
integrationTestSupportService.createUserRatings();
SearchUserRatingsRequest request = new SearchUserRatingsRequest();
request.pkgName = "pkg3";
request.offset = 0;
request.repositoryCode = "testrepo";
request.limit = Integer.MAX_VALUE;
request.daysSinceCreated = 10;
// ------------------------------------
SearchUserRatingsResult result = userRatingApi.searchUserRatings(request);
// ------------------------------------
// there are three user ratings, but one is disabled so we will not see that one.
Assertions.assertThat(result.items.size()).isEqualTo(2);
{
SearchUserRatingsResult.UserRating userRating = result.items.stream().filter(i -> i.code.equals("ABCDEF")).collect(SingleCollector.single());
Assertions.assertThat(userRating.active).isTrue();
Assertions.assertThat(userRating.comment).isEqualTo("Southern hemisphere winter");
Assertions.assertThat(userRating.createTimestamp).isNotNull();
Assertions.assertThat(userRating.modifyTimestamp).isNotNull();
Assertions.assertThat(userRating.naturalLanguageCode).isEqualTo(NaturalLanguage.CODE_ENGLISH);
Assertions.assertThat(userRating.pkgVersion.pkg.name).isEqualTo("pkg3");
Assertions.assertThat(userRating.pkgVersion.repositoryCode).isEqualTo("testrepo");
Assertions.assertThat(userRating.pkgVersion.architectureCode).isEqualTo("x86_64");
Assertions.assertThat(userRating.pkgVersion.major).isEqualTo("1");
Assertions.assertThat(userRating.pkgVersion.micro).isEqualTo("2");
Assertions.assertThat(userRating.pkgVersion.revision).isEqualTo(3);
Assertions.assertThat(userRating.pkgVersion.minor).isEqualTo("1");
Assertions.assertThat(userRating.pkgVersion.preRelease).isNull();
Assertions.assertThat(userRating.rating).isEqualTo((short) 5);
Assertions.assertThat(userRating.user.nickname).isEqualTo("urtest1");
Assertions.assertThat(userRating.userRatingStabilityCode).isNull();
}
{
SearchUserRatingsResult.UserRating userRating = result.items.stream().filter(i -> i.code.equals("GHIJKL")).collect(SingleCollector.single());
Assertions.assertThat(userRating.active).isTrue();
Assertions.assertThat(userRating.comment).isEqualTo("Winter banana apples");
Assertions.assertThat(userRating.user.nickname).isEqualTo("urtest2");
Assertions.assertThat(userRating.userRatingStabilityCode).isEqualTo(UserRatingStability.CODE_UNSTABLEBUTUSABLE);
}
}
use of org.haiku.haikudepotserver.dataobjects.UserRating in project haikudepotserver by haiku.
the class UserRatingApiIT method createTestUserAndSampleUserRating.
private String createTestUserAndSampleUserRating() {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "password");
integrationTestSupportService.agreeToUserUsageConditions(context, user);
UserRating userRating = context.newObject(UserRating.class);
userRating.setNaturalLanguage(NaturalLanguage.getByCode(context, NaturalLanguage.CODE_SPANISH));
userRating.setComment("How now brown cow");
userRating.setPkgVersion(pkgService.getLatestPkgVersionForPkg(context, Pkg.tryGetByName(context, "pkg1").get(), Repository.tryGetByCode(context, "testrepo").get(), Collections.singletonList(Architecture.tryGetByCode(context, "x86_64").get())).get());
userRating.setRating((short) 3);
userRating.setUserRatingStability(UserRatingStability.getByCode(context, UserRatingStability.CODE_VERYUNSTABLE).get());
userRating.setUser(user);
context.commitChanges();
return userRating.getCode();
}
use of org.haiku.haikudepotserver.dataobjects.UserRating in project haikudepotserver by haiku.
the class UserRatingDerivationTriggerListener method derivePkgName.
private String derivePkgName(Object entity) {
Preconditions.checkNotNull(entity);
UserRating userRating = (UserRating) entity;
return userRating.getPkgVersion().getPkg().getName();
}
use of org.haiku.haikudepotserver.dataobjects.UserRating in project haikudepotserver by haiku.
the class UserRatingOrchestrationServiceIT method createUserRating.
// -------------------
// SETUP
private UserRating createUserRating(ObjectContext context, PkgVersion pkgVersion, User user, Short rating) {
UserRating userRating = context.newObject(UserRating.class);
userRating.setUser(user);
userRating.setPkgVersion(pkgVersion);
userRating.setNaturalLanguage(NaturalLanguage.getByCode(context, NaturalLanguage.CODE_ENGLISH));
userRating.setRating(rating);
return userRating;
}
Aggregations