Search in sources :

Example 91 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPPerformanceTest method internalTestCreateManyMaps.

private void internalTestCreateManyMaps(int mapAmount) {
    long start = System.currentTimeMillis();
    // prepare some artefacts to link to maps later
    ArrayList<AbstractArtefact> artefacts = new ArrayList<AbstractArtefact>(10);
    for (int i = 1; i < 11; i++) {
        artefacts.add(createAndFillArtefact(i));
    }
    for (int k = 1; k < mapAmount; k++) {
        PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "a test map number " + k, LOREM_STRING_512);
        // attach sites and structures to it
        ArrayList<PortfolioStructure> structs = new ArrayList<PortfolioStructure>();
        PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "test page1 for map " + k, LOREM_STRING_512);
        structs.add(page1);
        PortfolioStructure struct11 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "struct1 in page1 for map" + k, LOREM_STRING_512);
        structs.add(struct11);
        PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "struct2 in page1 for map" + k, LOREM_STRING_512);
        structs.add(struct12);
        PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(map, "test page2 for map " + k, LOREM_STRING_512);
        structs.add(page2);
        PortfolioStructure struct21 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "struct1 in page2 for map" + k, LOREM_STRING_512);
        structs.add(struct21);
        PortfolioStructure struct22 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "struct2 in page2 for map" + k, LOREM_STRING_512);
        structs.add(struct22);
        // attach different artefacts to several places in map
        int l = 1;
        for (Iterator<PortfolioStructure> iterator = structs.iterator(); iterator.hasNext(); ) {
            PortfolioStructure portfolioStructure = iterator.next();
            epFrontendManager.addArtefactToStructure(ident1, artefacts.get(l), portfolioStructure);
            // add two artefacts
            if (l % 2 == 0) {
                epFrontendManager.addArtefactToStructure(ident1, artefacts.get(l + 1), portfolioStructure);
            }
            l++;
        }
        // for attach
        // share the map with all users
        EPMapPolicy userPolicy = new EPMapPolicy();
        userPolicy.setType(Type.allusers);
        epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
        dbInstance.commitAndCloseSession();
    }
    // for maps
    long now = System.currentTimeMillis();
    logger.info("created " + mapAmount + " maps, attached artefacts and shared maps to public in: " + (now - start) + " ms.");
    // load all maps
    start = System.currentTimeMillis();
    List<PortfolioStructure> publicMaps = epFrontendManager.getStructureElementsFromOthers(ident2, null, ElementType.STRUCTURED_MAP, ElementType.DEFAULT_MAP);
    now = System.currentTimeMillis();
    logger.info("got all public maps in: " + (now - start) + " ms.");
    // simulate queries done in EPMultipleMapController for all public maps:
    start = System.currentTimeMillis();
    long sharedQ = 0;
    long countArtefactQ = 0;
    long countChildQ = 0;
    long qstart = 0;
    int j = 0;
    Runtime r = Runtime.getRuntime();
    for (PortfolioStructure map : publicMaps) {
        j++;
        qstart = System.currentTimeMillis();
        epFrontendManager.isMapShared((PortfolioStructureMap) map);
        sharedQ += System.currentTimeMillis() - qstart;
        qstart = System.currentTimeMillis();
        epFrontendManager.countArtefactsInMap((PortfolioStructureMap) map);
        countArtefactQ += System.currentTimeMillis() - qstart;
        // lookup structured maps: if received from a template, would also do a lookup on repository entry!
        // EPTargetResource resource = structMap.getTargetResource();
        // RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(resource.getOLATResourceable(), false);
        qstart = System.currentTimeMillis();
        epFrontendManager.countStructureChildren(map);
        countChildQ += System.currentTimeMillis() - qstart;
        if (j % 100 == 0) {
            showStatsForStep(j, start, sharedQ, countArtefactQ, countChildQ, r);
        }
    }
    logger.info("============= get overall stats ==============");
    showStatsForStep(mapAmount, start, sharedQ, countArtefactQ, countChildQ, r);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) ArrayList(java.util.ArrayList) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy)

Example 92 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPFrontendManagerTest method deleteMap_pageAndArtefact.

/**
 * Create a map with a page and an artefact. Delete it.
 */
@Test
public void deleteMap_pageAndArtefact() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-4");
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
    PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
    assertNotNull(page);
    dbInstance.commitAndCloseSession();
    // create artefact
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
    dbInstance.commitAndCloseSession();
    // create the link
    epFrontendManager.addArtefactToStructure(id, artefact, page);
    dbInstance.commitAndCloseSession();
    // reload and check
    PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    Assert.assertNotNull(reloadedMap);
    Assert.assertEquals(map, reloadedMap);
    List<PortfolioStructure> reloadedPages = epFrontendManager.loadStructureChildren(reloadedMap);
    Assert.assertNotNull(reloadedPages);
    Assert.assertEquals(1, reloadedPages.size());
    PortfolioStructure reloadedPage = reloadedPages.get(0);
    Assert.assertEquals(page, reloadedPage);
    List<AbstractArtefact> reloadedArtefacts = epFrontendManager.getArtefacts(reloadedPage);
    Assert.assertNotNull(reloadedArtefacts);
    Assert.assertEquals(1, reloadedArtefacts.size());
    AbstractArtefact reloadedArtefact = reloadedArtefacts.get(0);
    Assert.assertEquals(artefact, reloadedArtefact);
    dbInstance.commitAndCloseSession();
    // delete the map
    epFrontendManager.deletePortfolioStructure(reloadedMap);
    dbInstance.commit();
    // what is deleted?
    AbstractArtefact notDeletedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
    Assert.assertNotNull(notDeletedArtefact);
    PortfolioStructure deletedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    Assert.assertNull(deletedMap);
    PortfolioStructure deletedPage = epFrontendManager.loadPortfolioStructureByKey(page.getKey());
    Assert.assertNull(deletedPage);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 93 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPPageViewController method init.

private void init(UserRequest ureq) {
    vC.contextPut("page", page);
    PortfolioStructureMap parentOfPage = (PortfolioStructureMap) ePFMgr.loadStructureParent(page);
    boolean parentMapClosed = StructureStatusEnum.CLOSED.equals(parentOfPage.getStatus());
    vC.remove(vC.getComponent("checkResults"));
    if (secCallback.isRestrictionsEnabled()) {
        removeAsListenerAndDispose(resultCtrl);
        List<CollectRestriction> restrictions = page.getCollectRestrictions();
        if (!restrictions.isEmpty()) {
            boolean check = ePFMgr.checkCollectRestriction(page);
            resultCtrl = new EPCollectRestrictionResultController(ureq, getWindowControl());
            resultCtrl.setMessage(restrictions, check);
            vC.put("checkResults", resultCtrl.getInitialComponent());
            listenTo(resultCtrl);
        }
    }
    vC.remove(vC.getComponent("artefacts"));
    List<AbstractArtefact> artefacts = ePFMgr.getArtefacts(page);
    if (artefacts.size() != 0) {
        EPMultiArtefactsController artefactCtrl = EPUIFactory.getConfigDependentArtefactsControllerForStructure(ureq, getWindowControl(), artefacts, page, secCallback);
        vC.put("artefacts", artefactCtrl.getInitialComponent());
        listenTo(artefactCtrl);
    }
    vC.remove(vC.getComponent("structElements"));
    List<PortfolioStructure> structElements = ePFMgr.loadStructureChildren(page);
    if (structElements.size() != 0) {
        EPStructureElementsController structElCtrl = new EPStructureElementsController(ureq, getWindowControl(), structElements, secCallback, parentMapClosed);
        vC.put("structElements", structElCtrl.getInitialComponent());
        listenTo(structElCtrl);
    }
    vC.remove(vC.getComponent("addButton"));
    if (!parentMapClosed && (secCallback.canAddArtefact() || secCallback.canAddStructure())) {
        addButtonCtrl = new EPAddElementsController(ureq, getWindowControl(), page);
        listenTo(addButtonCtrl);
        if (secCallback.canAddArtefact()) {
            addButtonCtrl.setShowLink(EPAddElementsController.ADD_ARTEFACT);
        }
        if (secCallback.canAddStructure()) {
            addButtonCtrl.setShowLink(EPAddElementsController.ADD_STRUCTUREELEMENT);
        }
        vC.put("addButton", addButtonCtrl.getInitialComponent());
    }
    vC.remove(vC.getComponent("commentCtrl"));
    if (secCallback.canCommentAndRate()) {
        removeAsListenerAndDispose(commentsAndRatingCtr);
        boolean anonym = ureq.getUserSession().getRoles().isGuestOnly();
        CommentAndRatingSecurityCallback ratingSecCallback = new CommentAndRatingDefaultSecurityCallback(getIdentity(), false, anonym);
        commentsAndRatingCtr = new UserCommentsAndRatingsController(ureq, getWindowControl(), map.getOlatResource(), page.getKey().toString(), ratingSecCallback, true, true, true);
        listenTo(commentsAndRatingCtr);
        vC.put("commentCtrl", commentsAndRatingCtr.getInitialComponent());
    }
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPCollectRestrictionResultController(org.olat.portfolio.ui.structel.edit.EPCollectRestrictionResultController) CommentAndRatingSecurityCallback(org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback) EPMultiArtefactsController(org.olat.portfolio.ui.artefacts.view.EPMultiArtefactsController) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CommentAndRatingDefaultSecurityCallback(org.olat.core.commons.services.commentAndRating.CommentAndRatingDefaultSecurityCallback) UserCommentsAndRatingsController(org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 94 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPStructureElementsController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
protected void initForm(UserRequest ureq) {
    flc.contextPut("structElements", structElements);
    tableCtrls = new ArrayList<Controller>();
    addBtnCtrls = new ArrayList<Controller>();
    int i = 1;
    removeComponents();
    for (PortfolioStructure portStruct : structElements) {
        if (secCallback.isRestrictionsEnabled()) {
            List<CollectRestriction> restrictions = portStruct.getCollectRestrictions();
            if (!restrictions.isEmpty()) {
                boolean check = ePFMgr.checkCollectRestriction(portStruct);
                EPCollectRestrictionResultController resultCtrl = new EPCollectRestrictionResultController(ureq, getWindowControl());
                resultCtrl.setMessage(portStruct.getCollectRestrictions(), check);
                flc.put("checkResults" + i, resultCtrl.getInitialComponent());
                listenTo(resultCtrl);
            }
        }
        // get artefacts for this structure
        List<AbstractArtefact> artefacts = ePFMgr.getArtefacts(portStruct);
        if (artefacts.size() != 0) {
            EPMultiArtefactsController artefactCtrl = EPUIFactory.getConfigDependentArtefactsControllerForStructure(ureq, getWindowControl(), artefacts, portStruct, secCallback);
            flc.put("artefacts" + i, artefactCtrl.getInitialComponent());
            listenTo(artefactCtrl);
            tableCtrls.add(artefactCtrl);
        }
        if (!parentMapClosed && secCallback.canAddArtefact()) {
            // get an addElement-button for each structure
            EPAddElementsController addButton = new EPAddElementsController(ureq, getWindowControl(), portStruct);
            listenTo(addButton);
            addButton.setShowLink(EPAddElementsController.ADD_ARTEFACT);
            flc.put("addButton" + i, addButton.getInitialComponent());
            addBtnCtrls.add(addButton);
        }
        i++;
    }
    if (i != maxStructAmount)
        maxStructAmount = i;
}
Also used : EPCollectRestrictionResultController(org.olat.portfolio.ui.structel.edit.EPCollectRestrictionResultController) EPMultiArtefactsController(org.olat.portfolio.ui.artefacts.view.EPMultiArtefactsController) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction) Controller(org.olat.core.gui.control.Controller) EPMultiArtefactsController(org.olat.portfolio.ui.artefacts.view.EPMultiArtefactsController) BasicController(org.olat.core.gui.control.controller.BasicController) EPCollectRestrictionResultController(org.olat.portfolio.ui.structel.edit.EPCollectRestrictionResultController)

Example 95 with AbstractArtefact

use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.

the class EPTOCController method doSelectTreeElement.

private void doSelectTreeElement(UserRequest ureq, TreeEvent te) {
    TreeNode selectedNode = treeCtr.getTreeModel().getNodeById(te.getNodeId());
    Object userObj = selectedNode.getUserObject();
    if (userObj instanceof PortfolioStructure) {
        // structure clicked
        structureClicked = (PortfolioStructure) userObj;
        refreshAddElements(ureq, structureClicked);
        delButton.setVisible(true);
        // send event to load this page
        fireEvent(ureq, new EPStructureChangeEvent(EPStructureChangeEvent.SELECTED, structureClicked));
    } else if (userObj instanceof AbstractArtefact) {
        // artefact clicked
        Object parentObj = ((TreeNode) selectedNode.getParent()).getUserObject();
        if (parentObj instanceof PortfolioStructure) {
            artefactClicked = (AbstractArtefact) userObj;
            PortfolioStructure structure = (PortfolioStructure) parentObj;
            refreshAddElements(ureq, null);
            delButton.setVisible(true);
            fireEvent(ureq, new EPArtefactClicked(ARTEFACT_NODE_CLICKED, structure));
        }
    } else {
        // root tree node clicked, no add/delete link
        delButton.setVisible(false);
        refreshAddElements(ureq, null);
        fireEvent(ureq, new Event(ARTEFACT_NODE_CLICKED));
    }
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) TreeEvent(org.olat.core.gui.components.tree.TreeEvent) TreeDropEvent(org.olat.core.gui.components.tree.TreeDropEvent) Event(org.olat.core.gui.control.Event) EPStructureChangeEvent(org.olat.portfolio.ui.structel.EPStructureChangeEvent) EPStructureChangeEvent(org.olat.portfolio.ui.structel.EPStructureChangeEvent) EPArtefactClicked(org.olat.portfolio.ui.structel.EPArtefactClicked)

Aggregations

AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)164 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)70 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)36 Date (java.util.Date)20 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)18 DBQuery (org.olat.core.commons.persistence.DBQuery)10 Link (org.olat.core.gui.components.link.Link)10 Identity (org.olat.core.id.Identity)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)10 List (java.util.List)8 EPFilterSettings (org.olat.portfolio.model.EPFilterSettings)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Step (org.olat.core.gui.control.generic.wizard.Step)6 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)6 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)6 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)6