use of org.olat.portfolio.model.structel.EPStructureToArtefactLink in project openolat by klemens.
the class EPStructureManager method instantiateClone.
private EPStructureToArtefactLink instantiateClone(EPStructureToArtefactLink link) {
EPStructureToArtefactLink clone = new EPStructureToArtefactLink();
clone.setArtefact(link.getArtefact());
clone.setAuthor(link.getAuthor());
clone.setCreationDate(new Date());
clone.setReflexion(link.getReflexion());
return clone;
}
use of org.olat.portfolio.model.structel.EPStructureToArtefactLink 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.EPStructureToArtefactLink 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.EPStructureToArtefactLink in project OpenOLAT by OpenOLAT.
the class EPStructureManager method copyEPStructureElementRecursively.
private void copyEPStructureElementRecursively(EPStructureElement sourceEl, EPStructureElement targetEl, boolean withArtefacts, boolean cloneRestrictions) {
// needed if the sourceEl come from a link. Hibernate doesn't initialize the list properly
sourceEl = (EPStructureElement) dbInstance.loadObject(sourceEl);
if (withArtefacts) {
List<EPStructureToArtefactLink> artefactLinks = sourceEl.getInternalArtefacts();
for (EPStructureToArtefactLink artefactLink : artefactLinks) {
EPStructureToArtefactLink link = instantiateClone(artefactLink);
// make the pseudo
link.setStructureElement(targetEl);
// bidirectional relations
targetEl.getInternalArtefacts().add(link);
}
}
// clone the links
List<EPStructureToStructureLink> childLinks = sourceEl.getInternalChildren();
for (EPStructureToStructureLink childLink : childLinks) {
copy(childLink, targetEl, withArtefacts, false, cloneRestrictions);
}
savePortfolioStructure(targetEl);
}
use of org.olat.portfolio.model.structel.EPStructureToArtefactLink in project OpenOLAT by OpenOLAT.
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;
}
Aggregations