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