Search in sources :

Example 1 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class PortfolioRepositoryIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext resourceContext, Object object, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    if (isLogDebugEnabled())
        logDebug("Index portfolio templates...");
    RepositoryEntry repositoryEntry = (RepositoryEntry) object;
    OLATResource ores = repositoryEntry.getOlatResource();
    PortfolioStructure element = structureManager.loadPortfolioStructure(ores);
    // only index templates
    if (element instanceof EPStructuredMapTemplate) {
        resourceContext.setDocumentType(TYPE);
        resourceContext.setParentContextType(TYPE);
        resourceContext.setParentContextName(repositoryEntry.getDisplayname());
        resourceContext.setFilePath(element.getKey().toString());
        Document document = PortfolioMapDocument.createDocument(resourceContext, element);
        indexWriter.addDocument(document);
    }
}
Also used : EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document)

Example 2 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPFrontendManagerTest method testSyncMapTemplateToUserMap.

@Test
public void testSyncMapTemplateToUserMap() {
    // create a template
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // create a repository entry
    RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "Template in user", "Template in use", resource, RepositoryEntry.ACC_OWNERS);
    // create the template owned by ident1
    PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    // create five pages
    List<PortfolioStructure> pageRefs = new ArrayList<PortfolioStructure>();
    List<PortfolioStructure> elementRefs = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 5; i++) {
        PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(templateEl, "sync-template-page-" + i, "sync-template-page-" + i);
        pageRefs.add(page);
        for (int j = 0; j < 5; j++) {
            PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(page, "template-structure-" + i + "." + j, "template-structure-" + i + "." + j);
            epStructureManager.addCollectRestriction(struct, "Forum", "minimum", 2);
            epStructureManager.savePortfolioStructure(struct);
            elementRefs.add(struct);
        }
    }
    // save the template
    dbInstance.commitAndCloseSession();
    // end create template
    // ////////////////////
    // make the copy
    PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(map);
    // ////////////////////////////////
    // shuffle the pages and delete one
    PortfolioStructure retrievedTemplateEl = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedTemplateEl);
    epStructureManager.moveUp(retrievedTemplateEl, pages.get(1));
    epStructureManager.moveDown(retrievedTemplateEl, pages.get(2));
    epStructureManager.removeStructure(retrievedTemplateEl, pages.get(3));
    epStructureManager.savePortfolioStructure(retrievedTemplateEl);
    // shuffle a page
    List<PortfolioStructure> page1Children = epFrontendManager.loadStructureChildren(pages.get(1));
    epStructureManager.moveUp(pages.get(1), page1Children.get(3));
    epStructureManager.moveUp(pages.get(1), page1Children.get(2));
    epStructureManager.moveUp(pages.get(1), page1Children.get(4));
    // and add an element and sub-elements
    PortfolioStructure newStruct = epFrontendManager.createAndPersistPortfolioStructureElement(pages.get(1), "new-template-structure-1.6", "template-structure-1.6");
    epStructureManager.addCollectRestriction(pages.get(1), "Forum", "minimum", 2);
    epStructureManager.savePortfolioStructure(newStruct);
    epStructureManager.savePortfolioStructure(pages.get(1));
    for (int k = 0; k < 5; k++) {
        PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(newStruct, "new-template-structure-2." + k, "template-structure-2." + k);
        epStructureManager.addCollectRestriction(struct, "bc", "minimum", 2);
        epStructureManager.savePortfolioStructure(struct);
        elementRefs.add(struct);
    }
    dbInstance.commitAndCloseSession();
    // end shuffle the pages
    // ////////////////////////////////
    // //////////////////
    // check the template
    PortfolioStructure retrievedTemplate2El = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    assertNotNull(retrievedTemplate2El);
    assertTrue(retrievedTemplate2El instanceof EPStructuredMapTemplate);
    List<PortfolioStructure> retrievedPages2 = epFrontendManager.loadStructureChildren(retrievedTemplate2El);
    assertEquals(4, retrievedPages2.size());
    assertEquals(4, ((EPStructuredMapTemplate) retrievedTemplate2El).getInternalChildren().size());
    // check the shuffled pages
    assertEquals(pageRefs.get(1).getKey(), retrievedPages2.get(0).getKey());
    assertEquals(pageRefs.get(0).getKey(), retrievedPages2.get(1).getKey());
    assertEquals(pageRefs.get(2).getKey(), retrievedPages2.get(2).getKey());
    assertEquals(pageRefs.get(4).getKey(), retrievedPages2.get(3).getKey());
    // check added element
    List<PortfolioStructure> retrievedChildren2 = epFrontendManager.loadStructureChildren(retrievedPages2.get(0));
    assertEquals(6, retrievedChildren2.size());
    dbInstance.commitAndCloseSession();
    // check the template
    // //////////////////
    // sync the map
    epFrontendManager.synchronizeStructuredMapToUserCopy(map);
    dbInstance.commitAndCloseSession();
    // ///////////////
    // check the sync
    PortfolioStructure synchedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    assertNotNull(synchedMap);
    assertTrue(synchedMap instanceof EPStructuredMap);
    List<PortfolioStructure> synchedPages = epFrontendManager.loadStructureChildren(synchedMap);
    assertNotNull(synchedPages);
    assertEquals(4, synchedPages.size());
    assertEquals(((EPStructureElement) pageRefs.get(1)).getTitle(), ((EPStructureElement) synchedPages.get(0)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getTitle(), ((EPStructureElement) synchedPages.get(1)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getTitle(), ((EPStructureElement) synchedPages.get(2)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getTitle(), ((EPStructureElement) synchedPages.get(3)).getTitle());
    // check synched key
    assertEquals(((EPStructureElement) pageRefs.get(1)).getKey(), ((EPStructureElement) synchedPages.get(0)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getKey(), ((EPStructureElement) synchedPages.get(1)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getKey(), ((EPStructureElement) synchedPages.get(2)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getKey(), ((EPStructureElement) synchedPages.get(3)).getStructureElSource());
    // check the new elements
    List<PortfolioStructure> retrievedPage1Children = epFrontendManager.loadStructureChildren(synchedPages.get(0));
    assertEquals(6, retrievedPage1Children.size());
    PortfolioStructure retrievedNewStruct = retrievedPage1Children.get(5);
    assertEquals("new-template-structure-1.6", ((EPStructureElement) retrievedNewStruct).getTitle());
    List<PortfolioStructure> retrievedNewStructChildren = epFrontendManager.loadStructureChildren(retrievedNewStruct);
    assertNotNull(retrievedNewStructChildren);
    assertEquals(5, retrievedNewStructChildren.size());
    for (int k = 0; k < 5; k++) {
        assertEquals("new-template-structure-2." + k, ((EPStructureElement) retrievedNewStructChildren.get(k)).getTitle());
    }
// end check the sync
// //////////////////
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 3 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureManager method removeStructureRecursively.

public void removeStructureRecursively(PortfolioStructure struct) {
    List<PortfolioStructure> children = loadStructureChildren(struct);
    for (PortfolioStructure childstruct : children) {
        removeStructureRecursively(childstruct);
    }
    // remove artefact-links
    List<AbstractArtefact> thisStructsArtefacts = getArtefacts(struct);
    for (AbstractArtefact artefact : thisStructsArtefacts) {
        removeArtefactFromStructure(artefact, struct, false);
    }
    // remove from parent
    PortfolioStructure parent = loadStructureParent(struct);
    if (parent == null && struct.getRoot() != null)
        parent = struct.getRoot();
    removeStructure(parent, struct);
    // remove collect restriction
    struct.getCollectRestrictions().clear();
    // remove sharings
    if (struct instanceof EPAbstractMap) {
        ((EPAbstractMap) struct).getGroups().clear();
    }
    // remove comments and ratings
    CommentAndRatingService commentAndRatingService = CoreSpringFactory.getImpl(CommentAndRatingService.class);
    commentAndRatingService.deleteAllIgnoringSubPath(struct.getOlatResource());
    // FXOLAT-431 remove subscriptions if the current struct is a map
    if (struct instanceof EPAbstractMap) {
        SubscriptionContext subsContext = new SubscriptionContext(EPNotificationsHandler.TYPENNAME, struct.getResourceableId(), EPNotificationsHandler.TYPENNAME);
        NotificationsManager.getInstance().delete(subsContext);
    }
    // remove structure itself
    struct = (EPStructureElement) dbInstance.loadObject((EPStructureElement) struct);
    dbInstance.deleteObject(struct);
    if (struct instanceof EPAbstractMap) {
        removeBaseGroup((EPAbstractMap) struct);
    }
    // which need the resource
    if (!(struct instanceof EPStructuredMapTemplate)) {
        resourceManager.deleteOLATResourceable(struct);
    }
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CommentAndRatingService(org.olat.core.commons.services.commentAndRating.CommentAndRatingService) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 4 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureManager method createAndPersistPortfolioMapTemplateFromEntry.

/**
 * Create a template map with the given repsoitory entry and olat resource (in the repository entry).
 * The repository entry must already be persisted.
 * @param identity
 * @param entry
 * @return
 */
public PortfolioStructureMap createAndPersistPortfolioMapTemplateFromEntry(Identity identity, RepositoryEntry entry) {
    EPStructuredMapTemplate el = (EPStructuredMapTemplate) loadPortfolioStructure(entry.getOlatResource());
    if (el == null) {
        el = new EPStructuredMapTemplate();
    }
    el.setTitle(entry.getDisplayname());
    el.setDescription(entry.getDescription());
    el.setOlatResource(entry.getOlatResource());
    // create security group
    Group group = repositoryEntyRelationDao.getDefaultGroup(entry);
    if (group == null) {
        group = groupDao.createGroup();
        groupDao.addMembershipTwoWay(group, identity, GroupRoles.owner.name());
    }
    EPStructureElementToGroupRelation relation = createBaseRelation(el, group);
    Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
    relations.add(relation);
    el.setGroups(relations);
    dbInstance.saveObject(el);
    return el;
}
Also used : Group(org.olat.basesecurity.Group) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) HashSet(java.util.HashSet)

Example 5 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureDetailsController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(final UserRequest ureq) {
    editStructure = ePFMgr.reloadPortfolioStructure(editStructure);
    editStructure.setTitle(titleEl.getValue());
    editStructure.setDescription(descriptionEl.getValue());
    editStructure.setArtefactRepresentationMode(viewRadio.getSelectedKey());
    if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
        clearErrors();
        editStructure.getCollectRestrictions().clear();
        setCollectRestrictions();
        for (final SingleSelection restrictionElement : restrictionElements) {
            final CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
            if (restriction.isValid()) {
                final CollectRestriction cr = new CollectRestriction(restriction);
                editStructure.getCollectRestrictions().add(cr);
            }
        }
    }
    ePFMgr.savePortfolioStructure(editStructure);
    fireEvent(ureq, new EPStructureEvent(EPStructureEvent.CHANGE, editStructure));
}
Also used : EPStructureEvent(org.olat.portfolio.ui.structel.EPStructureEvent) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Aggregations

EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)28 RepositoryEntry (org.olat.repository.RepositoryEntry)10 ArrayList (java.util.ArrayList)8 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)8 HashSet (java.util.HashSet)6 Group (org.olat.basesecurity.Group)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)6 EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)6 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 Document (org.apache.lucene.document.Document)2 Test (org.junit.Test)2 CommentAndRatingService (org.olat.core.commons.services.commentAndRating.CommentAndRatingService)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2