Search in sources :

Example 1 with EPStructureElement

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

the class EPStructureManager method removeArtefactFromStructure.

private PortfolioStructure removeArtefactFromStructure(AbstractArtefact artefact, PortfolioStructure structure, boolean updateFirst) {
    if (artefact == null || structure == null)
        throw new NullPointerException();
    // not persisted
    if (artefact.getKey() == null)
        return null;
    if (structure instanceof EPStructureElement) {
        // save eventual changes
        if (updateFirst) {
            dbInstance.updateObject(structure);
        }
        // reconnect to the session
        EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
        EPStructureToArtefactLink linkToDelete = null;
        for (Iterator<EPStructureToArtefactLink> linkIt = structureEl.getInternalArtefacts().iterator(); linkIt.hasNext(); ) {
            EPStructureToArtefactLink link = linkIt.next();
            if (link.getArtefact().getKey().equals(artefact.getKey())) {
                linkIt.remove();
                linkToDelete = link;
                break;
            }
        }
        // I have not set the cascade all delete
        if (linkToDelete != null) {
            dbInstance.updateObject(structureEl);
            dbInstance.deleteObject(linkToDelete);
        }
        return structureEl;
    }
    return null;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink)

Example 2 with EPStructureElement

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

the class EPStructureManager method addStructureToStructure.

/**
 * Add a child structure to the parent structure.
 * @param parentStructure
 * @param childStructure
 * @param destinationPos set to -1 to append at the end!
 */
public void addStructureToStructure(PortfolioStructure parentStructure, PortfolioStructure childStructure, int destinationPos) {
    if (parentStructure == null || childStructure == null)
        throw new NullPointerException();
    if (childStructure instanceof EPStructureElement) {
        // save eventual changes
        dbInstance.updateObject(parentStructure);
        // reconnect to the session (why reconnect? you update it already)
        // parentStructure = (EPStructureElement)dbInstance.loadObject((EPStructureElement)parentStructure);
        EPStructureToStructureLink link = new EPStructureToStructureLink();
        link.setParent(parentStructure);
        link.setChild(childStructure);
        // refresh internal link to its root element
        ((EPStructureElement) childStructure).setRoot((EPStructureElement) parentStructure);
        List<EPStructureToStructureLink> internalChildren = ((EPStructureElement) parentStructure).getInternalChildren();
        if (destinationPos == -1) {
            internalChildren.add(link);
        } else if (destinationPos <= internalChildren.size()) {
            internalChildren.add(destinationPos, link);
        } else {
            internalChildren.add(link);
        }
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 3 with EPStructureElement

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

the class EPStructureManager method instantiateClone.

private EPStructureElement instantiateClone(PortfolioStructure source) {
    EPStructureElement targetEl = null;
    // don't forget the inheritence
    if (source instanceof EPPage) {
        targetEl = new EPPage();
        targetEl.setTitle(((EPPage) source).getTitle());
        targetEl.setDescription(((EPPage) source).getDescription());
    } else if (source instanceof EPStructureElement) {
        targetEl = new EPStructureElement();
        targetEl.setTitle(((EPStructureElement) source).getTitle());
        targetEl.setDescription(((EPStructureElement) source).getDescription());
    }
    return targetEl;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPPage(org.olat.portfolio.model.structel.EPPage)

Example 4 with EPStructureElement

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

the class EPStructureManager method copy.

/**
 * Copy/Import structure elements recursively
 * @param refLink
 * @param targetEl
 * @param withArtefacts Copy the artefacts
 * @param importEl Don't load elements from the DB
 * @param cloneRestrictions should the collect-restrictions be applied? you could also do this manually by copyCollectRestriction()
 */
private void copy(EPStructureToStructureLink refLink, EPStructureElement targetEl, boolean withArtefacts, boolean importEl, boolean cloneRestrictions) {
    EPStructureElement childSourceEl = (EPStructureElement) refLink.getChild();
    EPStructureElement clonedChildEl = instantiateClone(refLink.getChild());
    if (clonedChildEl == null) {
        log.warn("Attempt to clone an unsupported structure type: " + refLink.getChild(), null);
    } else {
        OLATResource resource = resourceManager.createOLATResourceInstance(clonedChildEl.getClass());
        clonedChildEl.setOlatResource(resource);
        // set root
        if (targetEl.getRoot() == null) {
            // it's the root element
            clonedChildEl.setRoot(targetEl);
        } else {
            clonedChildEl.setRoot(targetEl.getRoot());
        }
        if (targetEl.getRootMap() == null && targetEl instanceof PortfolioStructureMap) {
            clonedChildEl.setRootMap((PortfolioStructureMap) targetEl);
        } else {
            clonedChildEl.setRootMap(targetEl.getRootMap());
        }
        if (!importEl)
            clonedChildEl.setStructureElSource(childSourceEl.getKey());
        if (cloneRestrictions)
            copyOrUpdateCollectRestriction(childSourceEl, clonedChildEl, true);
        if (importEl) {
            importEPStructureElementRecursively(childSourceEl, clonedChildEl);
        } else {
            copyEPStructureElementRecursively(childSourceEl, clonedChildEl, withArtefacts, cloneRestrictions);
        }
        EPStructureToStructureLink link = new EPStructureToStructureLink();
        link.setParent(targetEl);
        link.setChild(clonedChildEl);
        targetEl.getInternalChildren().add(link);
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) OLATResource(org.olat.resource.OLATResource) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 5 with EPStructureElement

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

the class EPStructureManager method importEPStructureElementRecursively.

private void importEPStructureElementRecursively(EPStructureElement sourceEl, EPStructureElement targetEl) {
    // clone the links
    List<EPStructureToStructureLink> childLinks = sourceEl.getInternalChildren();
    for (EPStructureToStructureLink childLink : childLinks) {
        EPStructureElement childSourceEl = (EPStructureElement) childLink.getChild();
        // remove source-info on imports.
        childSourceEl.setStructureElSource(null);
        copy(childLink, targetEl, false, true, true);
    }
    savePortfolioStructure(targetEl);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Aggregations

EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)66 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)18 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)16 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 EPPage (org.olat.portfolio.model.structel.EPPage)8 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)6 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)6 Identity (org.olat.core.id.Identity)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2