Search in sources :

Example 56 with EPStructureElement

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

the class EPStructureManager method move.

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

Example 57 with EPStructureElement

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

the class EPStructureManager method copyStructureRecursively.

protected void copyStructureRecursively(PortfolioStructure source, PortfolioStructure target, boolean withArtefacts) {
    // all changes are overwritten
    EPStructureElement targetEl = (EPStructureElement) target;
    if (targetEl instanceof EPStructuredMap) {
        ((EPStructuredMap) targetEl).setCopyDate(new Date());
    }
    // update the source
    dbInstance.updateObject(source);
    // reconnect to the session
    EPStructureElement sourceEl = (EPStructureElement) source;
    targetEl.setStyle(sourceEl.getStyle());
    copyEPStructureElementRecursively(sourceEl, targetEl, withArtefacts, true);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) Date(java.util.Date)

Example 58 with EPStructureElement

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

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 59 with EPStructureElement

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

the class EPStructureManager method addArtefactToStructure.

/**
 * Add a link between a structure element and an artefact
 * @param author
 * @param artefact
 * @param structure
 * @return
 */
protected boolean addArtefactToStructure(Identity author, AbstractArtefact artefact, PortfolioStructure structure) {
    if (author == null || artefact == null || structure == null)
        throw new NullPointerException();
    if (structure instanceof EPStructureElement) {
        EPStructureElement structureEl = (EPStructureElement) structure;
        boolean canAdd = canAddArtefact(structureEl, artefact);
        if (!canAdd) {
            return false;
        }
        // save eventual changes
        // TODO update the changes before dbInstance.updateObject(structureEl);
        // reconnect to the session
        structureEl = (EPStructureElement) dbInstance.loadObject(structureEl);
        EPStructureToArtefactLink link = new EPStructureToArtefactLink();
        link.setArtefact(artefact);
        link.setStructureElement(structureEl);
        link.setAuthor(author);
        structureEl.getInternalArtefacts().add(link);
        dbInstance.updateObject(structureEl);
        return true;
    }
    return false;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink)

Example 60 with EPStructureElement

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

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)

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