use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ACFrontendManager method isAccessible.
/**
* The rule to access a business group:<br/>
* -No offer, access is free<br/>
* -Owners have always access to the resource<br/>
* -Tutors have access to the resource<br/>
* -Participants have access to the resource<br/>
* @param group
* @param forId
* @return
*/
@Override
public AccessResult isAccessible(BusinessGroup group, Identity forId, boolean allowNonInteractiveAccess) {
if (!accessModule.isEnabled()) {
return new AccessResult(true);
}
List<String> roles = businessGroupRelationDao.getRoles(forId, group);
if (roles.contains(GroupRoles.coach.name())) {
return new AccessResult(true);
}
if (roles.contains(GroupRoles.participant.name())) {
return new AccessResult(true);
}
Date now = dateNow();
OLATResource resource = OLATResourceManager.getInstance().findResourceable(group);
List<Offer> offers = accessManager.findOfferByResource(resource, true, now);
if (offers.isEmpty()) {
if (methodManager.isValidMethodAvailable(resource, null)) {
// not open for the moment: no valid offer at this date but some methods are defined
return new AccessResult(false);
} else {
return new AccessResult(true);
}
}
return isAccessible(forId, offers, allowNonInteractiveAccess);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ACMethodDAO method getAccessMethodForResources.
public List<OLATResourceAccess> getAccessMethodForResources(Collection<Long> resourceKeys, String resourceType, String excludedResourceType, boolean valid, Date atDate) {
// quicker to filter in java, numerous keys in "in" are slow
final int maxResourcesEntries = 250;
StringBuilder sb = new StringBuilder();
sb.append("select access.method, resource, offer.price from acofferaccess access, ").append(OLATResourceImpl.class.getName()).append(" resource").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=").append(valid).append(" and offer.valid=").append(valid).append(" and resource.key=oResource.key");
if (resourceKeys != null && !resourceKeys.isEmpty()) {
if (resourceKeys.size() < maxResourcesEntries) {
sb.append(" and resource.key in (:resourceKeys) ");
}
sb.append(" and oResource.key=resource.key");
}
if (StringHelper.containsNonWhitespace(resourceType)) {
sb.append(" and oResource.resName =:resourceType ");
}
if (StringHelper.containsNonWhitespace(excludedResourceType)) {
sb.append(" and not(oResource.resName=:excludedResourceType)");
}
if (atDate != null) {
sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)").append(" and (offer.validTo is null or offer.validTo>=:atDate)");
}
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
if (atDate != null) {
query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
}
Set<Long> resourceKeysSet = null;
if (resourceKeys != null && !resourceKeys.isEmpty()) {
if (resourceKeys.size() < maxResourcesEntries) {
query.setParameter("resourceKeys", resourceKeys);
} else {
resourceKeysSet = new HashSet<Long>(resourceKeys);
}
}
if (StringHelper.containsNonWhitespace(resourceType)) {
query.setParameter("resourceType", resourceType);
}
if (StringHelper.containsNonWhitespace(excludedResourceType)) {
query.setParameter("excludedResourceType", excludedResourceType);
}
List<Object[]> rawResults = query.getResultList();
Map<Long, OLATResourceAccess> rawResultsMap = new HashMap<Long, OLATResourceAccess>();
for (Object[] rawResult : rawResults) {
AccessMethod method = (AccessMethod) rawResult[0];
OLATResource resource = (OLATResource) rawResult[1];
if (resourceKeysSet != null && !resourceKeysSet.contains(resource.getKey())) {
continue;
}
if (!method.isVisibleInGui()) {
continue;
}
Price price = (Price) rawResult[2];
if (rawResultsMap.containsKey(resource.getKey())) {
rawResultsMap.get(resource.getKey()).addBundle(price, method);
} else {
rawResultsMap.put(resource.getKey(), new OLATResourceAccess(resource, price, method));
}
}
return new ArrayList<OLATResourceAccess>(rawResultsMap.values());
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class RepositoryManagerTest method createRepositoryEntry.
private RepositoryEntry createRepositoryEntry(final String type, Identity owner, long i) {
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(type, new Long(i));
OLATResource r = resourceManager.createOLATResourceInstance(resourceable);
dbInstance.saveObject(r);
// now make a repository entry for this course
final RepositoryEntry re = repositoryService.create(owner, null, "Lernen mit OLAT " + i, "JunitTest_RepositoryEntry_" + i, "yo man description bla bla + i", r, RepositoryEntry.ACC_OWNERS_AUTHORS);
return re;
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class RepositoryEntryDAOTest method loadRepositoryEntryResource.
@Test
public void loadRepositoryEntryResource() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(re);
Assert.assertNotNull(re.getSoftkey());
Assert.assertNotNull(re.getOlatResource());
OLATResource loadedResource = repositoryEntryDao.loadRepositoryEntryResource(re.getKey());
Assert.assertNotNull(loadedResource);
Assert.assertEquals(re.getOlatResource(), loadedResource);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class PortfolioServiceTest method createTemplate.
private RepositoryEntry createTemplate(Identity initialAuthor, String displayname, String description) {
OLATResource resource = portfolioService.createBinderTemplateResource();
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
portfolioService.createAndPersistBinderTemplate(initialAuthor, re, Locale.ENGLISH);
return re;
}
Aggregations