Search in sources :

Example 56 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class PortfolioMapDocument method getContent.

private static String getContent(PortfolioStructure map, SearchResourceContext resourceContext, StringBuilder sb, Filter filter) {
    sb.append(' ').append(map.getTitle());
    if (StringHelper.containsNonWhitespace(map.getDescription())) {
        sb.append(' ').append(filter.filter(map.getDescription()));
    }
    for (PortfolioStructure child : ePFMgr.loadStructureChildren(map)) {
        getContent(child, resourceContext, sb, filter);
    }
    for (AbstractArtefact artefact : ePFMgr.getArtefacts(map)) {
        String reflexion = artefact.getReflexion();
        if (StringHelper.containsNonWhitespace(reflexion)) {
            sb.append(' ').append(filter.filter(reflexion));
        }
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(AbstractArtefact.class.getSimpleName(), artefact.getKey());
        EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(artefact.getResourceableTypeName());
        SearchResourceContext artefactResourceContext = new SearchResourceContext(resourceContext);
        artefactResourceContext.setBusinessControlFor(ores);
        OlatDocument doc = handler.getIndexerDocument(artefactResourceContext, artefact, ePFMgr);
        sb.append(' ').append(doc.getContent());
    }
    return sb.toString();
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) OLATResourceable(org.olat.core.id.OLATResourceable) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Example 57 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class AbstractHierarchicalIndexer method checkAccess.

/**
 * @param businessControl
 * @param identity
 * @param roles
 * @return
 */
public boolean checkAccess(BusinessControl businessControl, Identity identity, Roles roles) {
    boolean debug = isLogDebugEnabled();
    if (debug)
        logDebug("checkAccess for businessControl=" + businessControl + "  identity=" + identity + "  roles=" + roles);
    ContextEntry contextEntry = businessControl.popLauncherContextEntry();
    if (contextEntry != null) {
        // there is an other context-entry => go further
        OLATResourceable ores = contextEntry.getOLATResourceable();
        String type = ores.getResourceableTypeName();
        List<Indexer> indexers = getIndexerByType(type);
        if (indexers.isEmpty()) {
            // loop in child-indexers to check access for businesspath not stacked as on index-run
            for (Indexer childIndexer : childIndexers) {
                List<Indexer> foundSubChildIndexers = childIndexer instanceof AbstractHierarchicalIndexer ? ((AbstractHierarchicalIndexer) childIndexer).getIndexerByType(type) : null;
                if (foundSubChildIndexers != null) {
                    if (debug)
                        logDebug("took a childindexer for ores= " + ores + " not directly linked (means businesspath is not the same stack as indexer -> childindexer). type= " + type + " . indexer parent-type not on businesspath=" + childIndexer.getSupportedTypeName());
                    for (Indexer foundSubChildIndexer : foundSubChildIndexers) {
                        boolean allow = foundSubChildIndexer.checkAccess(contextEntry, businessControl, identity, roles) && super.checkAccess(contextEntry, businessControl, identity, roles);
                        if (allow) {
                            return true;
                        }
                    }
                }
            }
            if (debug)
                logDebug("could not find an indexer for type=" + type + " businessControl=" + businessControl + " identity=" + identity, null);
        } else {
            for (Indexer indexer : indexers) {
                boolean allow = indexer.checkAccess(contextEntry, businessControl, identity, roles) && super.checkAccess(contextEntry, businessControl, identity, roles);
                if (allow) {
                    return true;
                }
            }
        }
        return false;
    } else {
        // rearch the end context entry list
        return super.checkAccess(contextEntry, businessControl, identity, roles);
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 58 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class CheckboxManagerTest method createCheckBox.

@Test
public void createCheckBox() {
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-1", 2345l);
    String resSubPath = UUID.randomUUID().toString();
    String checkboxId = UUID.randomUUID().toString();
    DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
    dbInstance.commit();
    Assert.assertNotNull(checkbox);
    Assert.assertNotNull(checkbox.getKey());
    Assert.assertNotNull(checkbox.getCreationDate());
    Assert.assertEquals(checkboxId, checkbox.getCheckboxId());
    Assert.assertEquals("checkbox-1", checkbox.getResName());
    Assert.assertEquals(new Long(2345l), checkbox.getResId());
    Assert.assertEquals(resSubPath, checkbox.getResSubPath());
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 59 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class CheckboxManagerTest method loadCheck.

@Test
public void loadCheck() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-2");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-6", 2350l);
    String resSubPath = UUID.randomUUID().toString();
    String checkboxId = UUID.randomUUID().toString();
    DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
    // create a check
    DBCheck check = checkboxManager.createCheck(checkbox, id, new Float(1.0), Boolean.TRUE);
    dbInstance.commitAndCloseSession();
    // load the check
    DBCheck loadedCheck = checkboxManager.loadCheck(checkbox, id);
    // paranoia check
    Assert.assertNotNull(loadedCheck);
    Assert.assertEquals(check, loadedCheck);
    Assert.assertEquals(id, loadedCheck.getIdentity());
    Assert.assertEquals(checkbox, loadedCheck.getCheckbox());
    Assert.assertEquals(Boolean.TRUE, loadedCheck.getChecked());
    Assert.assertEquals(1.0f, loadedCheck.getScore().floatValue(), 0.00001);
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 60 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class InstantMessageDAOTest method testLoadMessage_byId.

@Test
public void testLoadMessage_byId() {
    // create a message
    OLATResourceable chatResources = OresHelper.createOLATResourceableInstance("unit-test-2-" + UUID.randomUUID().toString(), System.currentTimeMillis());
    Identity id = JunitTestHelper.createAndPersistIdentityAsAdmin("im-2-" + UUID.randomUUID().toString());
    InstantMessage msg = imDao.createMessage(id, id.getName(), false, "Hello load by id", chatResources);
    Assert.assertNotNull(msg);
    dbInstance.commitAndCloseSession();
    // load the message
    InstantMessage reloadedMsg = imDao.loadMessageById(msg.getKey());
    Assert.assertNotNull(reloadedMsg);
    Assert.assertEquals(msg.getKey(), reloadedMsg.getKey());
    Assert.assertEquals("Hello load by id", reloadedMsg.getBody());
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

OLATResourceable (org.olat.core.id.OLATResourceable)924 WindowControl (org.olat.core.gui.control.WindowControl)304 Test (org.junit.Test)158 Identity (org.olat.core.id.Identity)154 RepositoryEntry (org.olat.repository.RepositoryEntry)130 ContextEntry (org.olat.core.id.context.ContextEntry)82 ArrayList (java.util.ArrayList)68 OLATResource (org.olat.resource.OLATResource)60 Controller (org.olat.core.gui.control.Controller)48 Date (java.util.Date)46 AssertException (org.olat.core.logging.AssertException)32 StateSite (org.olat.core.id.context.StateSite)30 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)30 ICourse (org.olat.course.ICourse)30 CourseNode (org.olat.course.nodes.CourseNode)28 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)28 BusinessControl (org.olat.core.id.context.BusinessControl)24 BusinessGroup (org.olat.group.BusinessGroup)24 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)22 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)22