Search in sources :

Example 66 with OLATResource

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);
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) AccessResult(org.olat.resource.accesscontrol.AccessResult) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 67 with OLATResource

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceImpl(org.olat.resource.OLATResourceImpl) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) Price(org.olat.resource.accesscontrol.Price)

Example 68 with OLATResource

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;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource)

Example 69 with OLATResource

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);
}
Also used : OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 70 with OLATResource

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;
}
Also used : OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26