use of org.olat.repository.model.RepositoryEntryToGroupRelation in project openolat by klemens.
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;
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation in project openolat by klemens.
the class GTAReminderRuleTest method addEnrollmentDate.
private void addEnrollmentDate(RepositoryEntry entry, Identity id, GroupRoles role, int amount, int field) {
RepositoryEntryToGroupRelation rel = entry.getGroups().iterator().next();
rel.getGroup();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(field, amount);
GroupMembershipImpl membership = new GroupMembershipImpl();
membership.setCreationDate(cal.getTime());
membership.setLastModified(cal.getTime());
membership.setGroup(rel.getGroup());
membership.setIdentity(id);
membership.setRole(role.name());
dbInstance.getCurrentEntityManager().persist(membership);
dbInstance.commit();
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation in project openolat by klemens.
the class BusinessGroupServiceImpl method addResourcesTo.
@Override
public void addResourcesTo(List<BusinessGroup> groups, List<RepositoryEntry> resources) {
if (groups == null || groups.isEmpty())
return;
if (resources == null || resources.isEmpty())
return;
List<Group> baseGroupKeys = new ArrayList<Group>();
for (BusinessGroup group : groups) {
baseGroupKeys.add(group.getBaseGroup());
}
// check for duplicate entries
List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(baseGroupKeys);
for (BusinessGroup group : groups) {
// reload the base group to prevent lazy loading exception
Group baseGroup = businessGroupRelationDAO.getGroup(group);
if (baseGroup == null) {
continue;
}
for (RepositoryEntry re : resources) {
boolean found = false;
for (RepositoryEntryToGroupRelation relation : relations) {
if (relation.getGroup().equals(baseGroup) && relation.getEntry().equals(re)) {
found = true;
}
}
if (!found) {
repositoryEntryRelationDao.createRelation(baseGroup, re);
}
}
}
}
Aggregations