Search in sources :

Example 11 with EPStructureToStructureLink

use of org.olat.portfolio.model.structel.EPStructureToStructureLink in project openolat by klemens.

the class EPStructureManager method removeStructure.

/**
 * Remove a child structure from its parent structure.
 * @param parentStructure
 * @param childStructure
 */
// this has to be done recursively for pages, structs also!
// also remove the artefacts from each!
public void removeStructure(PortfolioStructure parentStructure, PortfolioStructure childStructure) {
    if (childStructure == null)
        throw new NullPointerException();
    // child not persisted
    if (childStructure.getKey() == null)
        return;
    // cannot remove with no parent!
    if (parentStructure == null)
        return;
    if (childStructure instanceof EPStructureElement) {
        // save eventual changes
        dbInstance.updateObject(parentStructure);
        // reconnect to the session
        EPStructureToStructureLink linkToDelete = null;
        EPStructureElement parentStructureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) parentStructure);
        for (Iterator<EPStructureToStructureLink> linkIt = parentStructureEl.getInternalChildren().iterator(); linkIt.hasNext(); ) {
            EPStructureToStructureLink link = linkIt.next();
            if (link.getChild().getKey().equals(childStructure.getKey())) {
                linkIt.remove();
                linkToDelete = link;
                break;
            }
        }
        // I have not set the cascade all delete
        if (linkToDelete != null) {
            dbInstance.updateObject(parentStructureEl);
            dbInstance.deleteObject(linkToDelete);
        }
    }
    if (parentStructure == childStructure) {
        deleteRootStructure(childStructure);
        return;
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 12 with EPStructureToStructureLink

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

the class EPStructureManager method copyEPStructureElementRecursively.

private void copyEPStructureElementRecursively(EPStructureElement sourceEl, EPStructureElement targetEl, boolean withArtefacts, boolean cloneRestrictions) {
    // needed if the sourceEl come from a link. Hibernate doesn't initialize the list properly
    sourceEl = (EPStructureElement) dbInstance.loadObject(sourceEl);
    if (withArtefacts) {
        List<EPStructureToArtefactLink> artefactLinks = sourceEl.getInternalArtefacts();
        for (EPStructureToArtefactLink artefactLink : artefactLinks) {
            EPStructureToArtefactLink link = instantiateClone(artefactLink);
            // make the pseudo
            link.setStructureElement(targetEl);
            // bidirectional relations
            targetEl.getInternalArtefacts().add(link);
        }
    }
    // clone the links
    List<EPStructureToStructureLink> childLinks = sourceEl.getInternalChildren();
    for (EPStructureToStructureLink childLink : childLinks) {
        copy(childLink, targetEl, withArtefacts, false, cloneRestrictions);
    }
    savePortfolioStructure(targetEl);
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 13 with EPStructureToStructureLink

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

the class EPStructureManager method syncEPStructureElementRecursively.

/**
 * This sync method syncs the structure of the tree, collect restriction, title, description, representation-mode (table/miniview)
 *
 * @param sourceEl
 * @param targetEl
 * @param withArtefacts
 */
private void syncEPStructureElementRecursively(EPStructureElement sourceEl, EPStructureElement targetEl, boolean withArtefacts) {
    List<EPStructureToStructureLink> sourceRefLinks = new ArrayList<EPStructureToStructureLink>(sourceEl.getInternalChildren());
    List<EPStructureToStructureLink> targetRefLinks = new ArrayList<EPStructureToStructureLink>(targetEl.getInternalChildren());
    Comparator<EPStructureToStructureLink> COMPARATOR = new KeyStructureToStructureLinkComparator();
    // remove deleted elements
    for (Iterator<EPStructureToStructureLink> targetIt = targetEl.getInternalChildren().iterator(); targetIt.hasNext(); ) {
        EPStructureToStructureLink targetLink = targetIt.next();
        int index = indexOf(sourceRefLinks, targetLink, COMPARATOR);
        if (index < 0) {
            targetIt.remove();
            removeStructureRecursively(targetLink.getChild());
        }
    }
    // add new element
    for (EPStructureToStructureLink sourceRefLink : sourceRefLinks) {
        int index = indexOf(targetRefLinks, sourceRefLink, COMPARATOR);
        if (index < 0) {
            // create a new structure element, dont clone restriction!
            copy(sourceRefLink, targetEl, withArtefacts, false, false);
        }
    }
    // sync attributes, representation and collect restrictions
    copyOrUpdateCollectRestriction(sourceEl, targetEl, true);
    targetEl.setArtefactRepresentationMode(sourceEl.getArtefactRepresentationMode());
    targetEl.setStyle(sourceEl.getStyle());
    targetEl.setTitle(sourceEl.getTitle());
    targetEl.setDescription(sourceEl.getDescription());
    // at this point, we must have the same content in the two list
    // but with perhaps other ordering: reorder
    List<EPStructureToStructureLink> targetLinks = targetEl.getInternalChildren();
    for (int i = 0; i < sourceRefLinks.size(); i++) {
        EPStructureToStructureLink sourceRefLink = sourceRefLinks.get(i);
        int index = indexOf(targetLinks, sourceRefLink, COMPARATOR);
        if (index == i) {
        // great, right at its position
        } else if (index > i) {
            Collections.swap(targetLinks, i, index);
        } else {
        // not possible
        }
        // sync recursively
        if (index >= 0) {
            EPStructureElement subSourceEl = (EPStructureElement) sourceRefLink.getChild();
            EPStructureElement subTargetEl = (EPStructureElement) targetLinks.get(i).getChild();
            syncEPStructureElementRecursively(subSourceEl, subTargetEl, withArtefacts);
        }
    }
    targetEl = dbInstance.getCurrentEntityManager().merge(targetEl);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) ArrayList(java.util.ArrayList) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 14 with EPStructureToStructureLink

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

the class EPStructureManager method move.

private void move(PortfolioStructure parentStructure, PortfolioStructure childStructure, boolean up) {
    if (childStructure == null || parentStructure == null)
        throw new NullPointerException();
    if (parentStructure instanceof EPStructureElement) {
        // save eventual changes
        dbInstance.updateObject(parentStructure);
        // reconnect to the session
        EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) parentStructure);
        List<EPStructureToStructureLink> structureLinks = structureEl.getInternalChildren();
        int index = indexOf(structureLinks, childStructure);
        if (up && index > 0) {
            // swap the link with the previous link in the list
            Collections.swap(structureLinks, index, index - 1);
            dbInstance.updateObject(structureEl);
        } else if (!up && (index >= 0 && index < (structureLinks.size() - 1))) {
            // swap the link with the next link in the list
            Collections.swap(structureLinks, index, index + 1);
            dbInstance.updateObject(structureEl);
        }
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Example 15 with EPStructureToStructureLink

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

the class EPStructureManager method removeStructure.

/**
 * Remove a child structure from its parent structure.
 * @param parentStructure
 * @param childStructure
 */
// this has to be done recursively for pages, structs also!
// also remove the artefacts from each!
public void removeStructure(PortfolioStructure parentStructure, PortfolioStructure childStructure) {
    if (childStructure == null)
        throw new NullPointerException();
    // child not persisted
    if (childStructure.getKey() == null)
        return;
    // cannot remove with no parent!
    if (parentStructure == null)
        return;
    if (childStructure instanceof EPStructureElement) {
        // save eventual changes
        dbInstance.updateObject(parentStructure);
        // reconnect to the session
        EPStructureToStructureLink linkToDelete = null;
        EPStructureElement parentStructureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) parentStructure);
        for (Iterator<EPStructureToStructureLink> linkIt = parentStructureEl.getInternalChildren().iterator(); linkIt.hasNext(); ) {
            EPStructureToStructureLink link = linkIt.next();
            if (link.getChild().getKey().equals(childStructure.getKey())) {
                linkIt.remove();
                linkToDelete = link;
                break;
            }
        }
        // I have not set the cascade all delete
        if (linkToDelete != null) {
            dbInstance.updateObject(parentStructureEl);
            dbInstance.deleteObject(linkToDelete);
        }
    }
    if (parentStructure == childStructure) {
        deleteRootStructure(childStructure);
        return;
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink)

Aggregations

EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)18 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)16 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)2 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)2 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)2 OLATResource (org.olat.resource.OLATResource)2