Search in sources :

Example 1 with UserRating

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();
}
Also used : UserRating(org.haiku.haikudepotserver.dataobjects.UserRating) ObjectContext(org.apache.cayenne.ObjectContext) Hashing(com.google.common.hash.Hashing) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) StringUtils(org.apache.commons.lang3.StringUtils) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) Locale(java.util.Locale) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) MessageSource(org.springframework.context.MessageSource) MediaType(com.google.common.net.MediaType) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) ResolvedPkgVersionLocalization(org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) NaturalLanguage(org.haiku.haikudepotserver.dataobjects.NaturalLanguage) UserRating(org.haiku.haikudepotserver.dataobjects.UserRating) SyndEntrySupplier(org.haiku.haikudepotserver.feed.model.SyndEntrySupplier) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ObjectSelect(org.apache.cayenne.query.ObjectSelect) PkgLocalizationService(org.haiku.haikudepotserver.pkg.model.PkgLocalizationService) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) Collections(java.util.Collections) Locale(java.util.Locale) ResolvedPkgVersionLocalization(org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ObjectContext(org.apache.cayenne.ObjectContext) NaturalLanguage(org.haiku.haikudepotserver.dataobjects.NaturalLanguage)

Example 2 with UserRating

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);
    }
}
Also used : SearchUserRatingsRequest(org.haiku.haikudepotserver.api1.model.userrating.SearchUserRatingsRequest) UserRating(org.haiku.haikudepotserver.dataobjects.UserRating) SearchUserRatingsResult(org.haiku.haikudepotserver.api1.model.userrating.SearchUserRatingsResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with UserRating

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();
}
Also used : UserRating(org.haiku.haikudepotserver.dataobjects.UserRating) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext)

Example 4 with UserRating

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();
}
Also used : UserRating(org.haiku.haikudepotserver.dataobjects.UserRating)

Example 5 with UserRating

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;
}
Also used : UserRating(org.haiku.haikudepotserver.dataobjects.UserRating)

Aggregations

UserRating (org.haiku.haikudepotserver.dataobjects.UserRating)5 ObjectContext (org.apache.cayenne.ObjectContext)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Hashing (com.google.common.hash.Hashing)1 MediaType (com.google.common.net.MediaType)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)1 ObjectSelect (org.apache.cayenne.query.ObjectSelect)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 SearchUserRatingsRequest (org.haiku.haikudepotserver.api1.model.userrating.SearchUserRatingsRequest)1 SearchUserRatingsResult (org.haiku.haikudepotserver.api1.model.userrating.SearchUserRatingsResult)1