Search in sources :

Example 11 with RepositoryEntryStatistics

use of org.olat.repository.model.RepositoryEntryStatistics in project OpenOLAT by OpenOLAT.

the class RepositoryEntryMyCourseQueries method searchViews.

public List<RepositoryEntryMyView> searchViews(SearchMyRepositoryEntryViewParams params, int firstResult, int maxResults) {
    if (params.getIdentity() == null) {
        log.error("No identity defined for query");
        return Collections.emptyList();
    }
    TypedQuery<Object[]> query = creatMyViewQuery(params, Object[].class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    // we don't need statistics when rating and comments are disabled unless
    // were searching for videos, there we want to see the launch counter
    // from the statistics
    boolean needStats = repositoryModule.isRatingEnabled() || repositoryModule.isCommentEnabled() || (params.getResourceTypes() != null && params.getResourceTypes().contains(VideoFileResource.TYPE_NAME));
    List<Long> effKeys = new ArrayList<>();
    List<Object[]> objects = query.getResultList();
    List<RepositoryEntryMyView> views = new ArrayList<>(objects.size());
    Map<OLATResource, RepositoryEntryMyCourseImpl> viewsMap = new HashMap<>();
    for (Object[] object : objects) {
        RepositoryEntry re = (RepositoryEntry) object[0];
        Number numOfMarks = (Number) object[1];
        boolean hasMarks = numOfMarks == null ? false : numOfMarks.longValue() > 0;
        Number numOffers = (Number) object[2];
        long offers = numOffers == null ? 0l : numOffers.longValue();
        Integer myRating = (Integer) object[3];
        RepositoryEntryStatistics stats;
        if (needStats) {
            stats = re.getStatistics();
        } else {
            stats = null;
        }
        RepositoryEntryMyCourseImpl view = new RepositoryEntryMyCourseImpl(re, stats, hasMarks, offers, myRating);
        views.add(view);
        viewsMap.put(re.getOlatResource(), view);
        Long effKey = (Long) object[4];
        if (effKey != null) {
            effKeys.add(effKey);
        }
    }
    if (effKeys.size() > 0) {
        List<UserEfficiencyStatementLight> efficiencyStatements = efficiencyStatementManager.findEfficiencyStatementsLight(effKeys);
        for (UserEfficiencyStatementLight efficiencyStatement : efficiencyStatements) {
            if (viewsMap.containsKey(efficiencyStatement.getResource())) {
                viewsMap.get(efficiencyStatement.getResource()).setEfficiencyStatement(efficiencyStatement);
            }
        }
    }
    return views;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) UserEfficiencyStatementLight(org.olat.course.assessment.model.UserEfficiencyStatementLight) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) RepositoryEntryMyCourseImpl(org.olat.repository.model.RepositoryEntryMyCourseImpl)

Example 12 with RepositoryEntryStatistics

use of org.olat.repository.model.RepositoryEntryStatistics in project OpenOLAT by OpenOLAT.

the class RepositoryEntryStatisticsDAO method loadStatisticsForUpdate.

private RepositoryEntryStatistics loadStatisticsForUpdate(OLATResourceable repositoryEntryRes) {
    if (repositoryEntryRes instanceof RepositoryEntry) {
        RepositoryEntry re = (RepositoryEntry) repositoryEntryRes;
        dbInstance.getCurrentEntityManager().detach(re);
        dbInstance.getCurrentEntityManager().detach(re.getStatistics());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select stats from ").append(RepositoryEntryStatistics.class.getName()).append(" as stats").append(" where stats.key in (select v.statistics.key from ").append(RepositoryEntry.class.getName()).append(" as v where v.key=:key)");
    return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryStatistics.class).setParameter("key", repositoryEntryRes.getResourceableId()).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult();
}
Also used : RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 13 with RepositoryEntryStatistics

use of org.olat.repository.model.RepositoryEntryStatistics in project OpenOLAT by OpenOLAT.

the class RepositoryEntryStatisticsDAO method update.

@Override
public boolean update(OLATResourceable ores, String resSubPath, double newAverageRating, long numOfRatings) {
    RepositoryEntryStatistics statistics = loadStatisticsForUpdate(ores);
    if (statistics != null) {
        statistics.setRating(newAverageRating);
        statistics.setNumOfRatings(numOfRatings);
        statistics.setLastModified(new Date());
        dbInstance.getCurrentEntityManager().merge(statistics);
        return true;
    }
    return false;
}
Also used : RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) Date(java.util.Date)

Example 14 with RepositoryEntryStatistics

use of org.olat.repository.model.RepositoryEntryStatistics in project OpenOLAT by OpenOLAT.

the class RepositoryEntryStatisticsDAO method update.

@Override
public boolean update(OLATResourceable ores, String resSubPath, int numOfComments) {
    RepositoryEntryStatistics statistics = loadStatisticsForUpdate(ores);
    if (statistics != null) {
        statistics.setNumOfComments(numOfComments);
        statistics.setLastModified(new Date());
        dbInstance.getCurrentEntityManager().merge(statistics);
        return true;
    }
    return false;
}
Also used : RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) Date(java.util.Date)

Example 15 with RepositoryEntryStatistics

use of org.olat.repository.model.RepositoryEntryStatistics in project OpenOLAT by OpenOLAT.

the class RepositoryServiceImpl method create.

private RepositoryEntry create(String initialAuthorName, Identity initialAuthor, String resourceName, String displayname, String description, OLATResource resource, int access) {
    Date now = new Date();
    RepositoryEntry re = new RepositoryEntry();
    if (StringHelper.containsNonWhitespace(initialAuthorName)) {
        re.setInitialAuthor(initialAuthorName);
    } else if (initialAuthor != null) {
        re.setInitialAuthor(initialAuthor.getName());
    } else {
        re.setInitialAuthor("-");
    }
    re.setCreationDate(now);
    re.setLastModified(now);
    re.setAccess(access);
    re.setCanDownload(false);
    re.setCanCopy(false);
    re.setCanReference(false);
    re.setCanLaunch(true);
    re.setDisplayname(displayname);
    re.setResourcename(StringHelper.containsNonWhitespace(resourceName) ? resourceName : "-");
    re.setDescription(description == null ? "" : description);
    re.setAllowToLeaveOption(repositoryModule.getAllowToLeaveDefaultOption());
    if (resource == null) {
        OLATResourceable ores = OresHelper.createOLATResourceableInstance("RepositoryEntry", CodeHelper.getForeverUniqueID());
        resource = resourceManager.createAndPersistOLATResourceInstance(ores);
    } else if (resource != null && resource.getKey() == null) {
        dbInstance.getCurrentEntityManager().persist(resource);
    }
    re.setOlatResource(resource);
    RepositoryEntryStatistics statistics = new RepositoryEntryStatistics();
    statistics.setLastUsage(now);
    statistics.setCreationDate(now);
    statistics.setLastModified(now);
    statistics.setDownloadCounter(0l);
    statistics.setLaunchCounter(0l);
    statistics.setNumOfRatings(0l);
    statistics.setNumOfComments(0l);
    dbInstance.getCurrentEntityManager().persist(statistics);
    re.setStatistics(statistics);
    Group group = groupDao.createGroup();
    RepositoryEntryToGroupRelation rel = new RepositoryEntryToGroupRelation();
    rel.setCreationDate(new Date());
    rel.setDefaultGroup(true);
    rel.setGroup(group);
    rel.setEntry(re);
    Set<RepositoryEntryToGroupRelation> rels = new HashSet<>(2);
    rels.add(rel);
    re.setGroups(rels);
    if (initialAuthor != null) {
        groupDao.addMembershipTwoWay(group, initialAuthor, GroupRoles.owner.name());
    }
    dbInstance.getCurrentEntityManager().persist(re);
    autoAccessManager.grantAccess(re);
    return re;
}
Also used : RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) Group(org.olat.basesecurity.Group) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) HashSet(java.util.HashSet)

Aggregations

RepositoryEntryStatistics (org.olat.repository.model.RepositoryEntryStatistics)18 RepositoryEntry (org.olat.repository.RepositoryEntry)14 Date (java.util.Date)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Identity (org.olat.core.id.Identity)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 OLATResource (org.olat.resource.OLATResource)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Group (org.olat.basesecurity.Group)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 License (org.olat.core.commons.services.license.License)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 ImageComponent (org.olat.core.gui.components.image.ImageComponent)2 RatingWithAverageFormItem (org.olat.core.gui.components.rating.RatingWithAverageFormItem)2 Roles (org.olat.core.id.Roles)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2