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