Search in sources :

Example 16 with EPStructureElement

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

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

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

the class EPStructureManager method createPortfolioStructure.

/**
 * Create a basic structure element
 * @param title
 * @param description
 * @return The structure element
 */
protected PortfolioStructure createPortfolioStructure(PortfolioStructure root, String title, String description) {
    EPStructureElement el = new EPStructureElement();
    el.setRoot((EPStructureElement) root);
    if (root != null && root.getRootMap() == null && root instanceof PortfolioStructureMap) {
        el.setRootMap((PortfolioStructureMap) root);
    } else if (root != null) {
        el.setRootMap(root.getRootMap());
    }
    return fillStructureElement(el, title, description);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap)

Example 18 with EPStructureElement

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

the class EPStructureManager method getRestrictionStatistics.

protected Integer[] getRestrictionStatistics(PortfolioStructure structure) {
    if (structure instanceof EPStructureElement) {
        EPStructureElement structEl = (EPStructureElement) structure;
        structEl = (EPStructureElement) reloadPortfolioStructure(structEl);
        final List<CollectRestriction> restrictions = structEl.getCollectRestrictions();
        if (restrictions != null && !restrictions.isEmpty()) {
            int todo = 0;
            int done = 0;
            List<AbstractArtefact> artefacts = getArtefacts(structEl);
            for (CollectRestriction cR : restrictions) {
                if (RestrictionsConstants.MIN.equals(cR.getRestriction()) || RestrictionsConstants.EQUAL.equals(cR.getRestriction())) {
                    todo += cR.getAmount();
                    int actualCRCount = countRestrictionType(artefacts, cR);
                    done += actualCRCount;
                }
            }
            return new Integer[] { done, todo };
        }
    }
    return null;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 19 with EPStructureElement

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

the class EPStructureManager method getReflexionForArtefactToStructureLink.

protected String getReflexionForArtefactToStructureLink(AbstractArtefact artefact, PortfolioStructure structure) {
    if (structure == null)
        return null;
    EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
    List<EPStructureToArtefactLink> links = structureEl.getInternalArtefacts();
    for (EPStructureToArtefactLink epStructureToArtefactLink : links) {
        if (epStructureToArtefactLink.getArtefact().getKey().equals(artefact.getKey())) {
            return epStructureToArtefactLink.getReflexion();
        }
    }
    return null;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink)

Example 20 with EPStructureElement

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

the class EPStructureManager method moveArtefactInStruct.

protected boolean moveArtefactInStruct(AbstractArtefact artefact, PortfolioStructure parStruct, int position) {
    EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) parStruct);
    Identity author = structureEl.getInternalArtefacts().get(0).getAuthor();
    // old model without author, doesn't work!
    if (author == null)
        return false;
    List<EPStructureToArtefactLink> artefactLinks = structureEl.getInternalArtefacts();
    int currentIndex = -1;
    for (EPStructureToArtefactLink link : artefactLinks) {
        currentIndex++;
        if (link.getArtefact().equals(artefact)) {
            break;
        }
    }
    if (currentIndex > -1 && currentIndex < artefactLinks.size()) {
        EPStructureToArtefactLink link = artefactLinks.remove(currentIndex);
        if (position > currentIndex) {
            position--;
        }
        artefactLinks.add(position, link);
    }
    return true;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) Identity(org.olat.core.id.Identity)

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