Search in sources :

Example 31 with EPStructureElement

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

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

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

the class EPStructureManager method checkCollectRestriction.

/**
 * Check the collect restriction against the structure element
 * @param structure
 * @return
 */
protected boolean checkCollectRestriction(PortfolioStructure structure) {
    if (structure instanceof EPStructureElement) {
        EPStructureElement structureEl = (EPStructureElement) structure;
        List<CollectRestriction> restrictions = structureEl.getCollectRestrictions();
        if (restrictions == null || restrictions.isEmpty())
            return true;
        boolean allOk = true;
        List<String> artefactTypeAllowed = new ArrayList<String>();
        List<AbstractArtefact> artefacts = getArtefacts(structureEl);
        for (CollectRestriction restriction : restrictions) {
            int count = countRestrictionType(artefacts, restriction);
            artefactTypeAllowed.add(restriction.getArtefactType());
            boolean ok = true;
            if (RestrictionsConstants.MAX.equals(restriction.getRestriction())) {
                ok &= (restriction.getAmount() > 0 && count <= restriction.getAmount());
            } else if (RestrictionsConstants.MIN.equals(restriction.getRestriction())) {
                ok &= (restriction.getAmount() > 0 && count >= restriction.getAmount());
            } else if (RestrictionsConstants.EQUAL.equals(restriction.getRestriction())) {
                ok &= (restriction.getAmount() > 0 && count == restriction.getAmount());
            } else {
                ok &= false;
            }
            allOk &= ok;
        }
        for (AbstractArtefact artefact : artefacts) {
            allOk &= artefactTypeAllowed.contains(artefact.getResourceableTypeName());
        }
        return allOk;
    }
    return true;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) ArrayList(java.util.ArrayList) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 33 with EPStructureElement

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

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)

Example 34 with EPStructureElement

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

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

use of org.olat.portfolio.model.structel.EPStructureElement 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)

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