Search in sources :

Example 51 with EPStructureElement

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

the class EPStructureManager method moveArtefactFromStructToStruct.

protected boolean moveArtefactFromStructToStruct(AbstractArtefact artefact, PortfolioStructure oldParStruct, PortfolioStructure newParStruct) {
    EPStructureElement oldEPSt = (EPStructureElement) dbInstance.loadObject((EPStructureElement) oldParStruct);
    Identity author = oldEPSt.getInternalArtefacts().get(0).getAuthor();
    // old model without author, doesn't work!
    if (author == null)
        return false;
    String reflexion = getReflexionForArtefactToStructureLink(artefact, oldParStruct);
    removeArtefactFromStructure(artefact, oldParStruct);
    boolean allOk = false;
    allOk = addArtefactToStructure(author, artefact, newParStruct);
    if (allOk)
        return setReflexionForArtefactToStructureLink(artefact, newParStruct, reflexion);
    return allOk;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) Identity(org.olat.core.id.Identity)

Example 52 with EPStructureElement

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

the class EPStructureManager method syncStructureRecursively.

/**
 * Sync the tree structure recursively with or without artefacts
 * @param sourceEl
 * @param targetEl
 * @param withArtefacts
 */
protected void syncStructureRecursively(PortfolioStructure source, PortfolioStructure target, boolean withArtefacts) {
    // all changes are overwritten
    EPStructureElement sourceEl = (EPStructureElement) source;
    // update the source
    dbInstance.updateObject(target);
    // reconnect to the session
    EPStructureElement targetEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) target);
    syncEPStructureElementRecursively(sourceEl, targetEl, withArtefacts);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement)

Example 53 with EPStructureElement

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

the class EPStructureManager method getReferencedMapsForArtefact.

protected List<PortfolioStructure> getReferencedMapsForArtefact(AbstractArtefact artefact) {
    List<PortfolioStructure> pfList = getAllReferencesForArtefact(artefact);
    List<PortfolioStructure> mapList = new ArrayList<PortfolioStructure>();
    for (Iterator<?> iterator = pfList.iterator(); iterator.hasNext(); ) {
        EPStructureElement portfolioStructure = (EPStructureElement) iterator.next();
        EPStructureElement actStruct = portfolioStructure;
        while (actStruct.getRoot() != null) {
            EPStructureElement actRoot = actStruct.getRoot();
            if (actRoot != null) {
                actStruct = actRoot;
            }
        }
        if (!mapList.contains(actStruct))
            mapList.add(actStruct);
    }
    return mapList;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList)

Example 54 with EPStructureElement

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

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

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

the class EPStructureManager method setReflexionForArtefactToStructureLink.

protected boolean setReflexionForArtefactToStructureLink(AbstractArtefact artefact, PortfolioStructure structure, String reflexion) {
    EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
    List<EPStructureToArtefactLink> links = structureEl.getInternalArtefacts();
    boolean changed = false;
    for (EPStructureToArtefactLink epStructureToArtefactLink : links) {
        if (epStructureToArtefactLink.getArtefact().getKey().equals(artefact.getKey())) {
            epStructureToArtefactLink.setReflexion(reflexion);
            if (epStructureToArtefactLink.getKey() == null) {
                dbInstance.saveObject(epStructureToArtefactLink);
            } else {
                dbInstance.updateObject(epStructureToArtefactLink);
            }
            changed = true;
            break;
        }
    }
    // savePortfolioStructure(structure);
    return changed;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink)

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