use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.
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 klemens.
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 klemens.
the class EPStructureManager method removeArtefactFromStructure.
private PortfolioStructure removeArtefactFromStructure(AbstractArtefact artefact, PortfolioStructure structure, boolean updateFirst) {
if (artefact == null || structure == null)
throw new NullPointerException();
// not persisted
if (artefact.getKey() == null)
return null;
if (structure instanceof EPStructureElement) {
// save eventual changes
if (updateFirst) {
dbInstance.updateObject(structure);
}
// reconnect to the session
EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
EPStructureToArtefactLink linkToDelete = null;
for (Iterator<EPStructureToArtefactLink> linkIt = structureEl.getInternalArtefacts().iterator(); linkIt.hasNext(); ) {
EPStructureToArtefactLink link = linkIt.next();
if (link.getArtefact().getKey().equals(artefact.getKey())) {
linkIt.remove();
linkToDelete = link;
break;
}
}
// I have not set the cascade all delete
if (linkToDelete != null) {
dbInstance.updateObject(structureEl);
dbInstance.deleteObject(linkToDelete);
}
return structureEl;
}
return null;
}
use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.
the class EPStructureManager method addArtefactToStructure.
/**
* Add a link between a structure element and an artefact
* @param author
* @param artefact
* @param structure
* @return
*/
protected boolean addArtefactToStructure(Identity author, AbstractArtefact artefact, PortfolioStructure structure) {
if (author == null || artefact == null || structure == null)
throw new NullPointerException();
if (structure instanceof EPStructureElement) {
EPStructureElement structureEl = (EPStructureElement) structure;
boolean canAdd = canAddArtefact(structureEl, artefact);
if (!canAdd) {
return false;
}
// save eventual changes
// TODO update the changes before dbInstance.updateObject(structureEl);
// reconnect to the session
structureEl = (EPStructureElement) dbInstance.loadObject(structureEl);
EPStructureToArtefactLink link = new EPStructureToArtefactLink();
link.setArtefact(artefact);
link.setStructureElement(structureEl);
link.setAuthor(author);
structureEl.getInternalArtefacts().add(link);
dbInstance.updateObject(structureEl);
return true;
}
return false;
}
use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.
the class EPStructureManager method move.
private void move(PortfolioStructure parentStructure, PortfolioStructure childStructure, boolean up) {
if (childStructure == null || parentStructure == null)
throw new NullPointerException();
if (parentStructure instanceof EPStructureElement) {
// save eventual changes
dbInstance.updateObject(parentStructure);
// reconnect to the session
EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) parentStructure);
List<EPStructureToStructureLink> structureLinks = structureEl.getInternalChildren();
int index = indexOf(structureLinks, childStructure);
if (up && index > 0) {
// swap the link with the previous link in the list
Collections.swap(structureLinks, index, index - 1);
dbInstance.updateObject(structureEl);
} else if (!up && (index >= 0 && index < (structureLinks.size() - 1))) {
// swap the link with the next link in the list
Collections.swap(structureLinks, index, index + 1);
dbInstance.updateObject(structureEl);
}
}
}
Aggregations