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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations