use of org.olat.portfolio.model.structel.EPStructureToArtefactLink in project OpenOLAT by OpenOLAT.
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.EPStructureToArtefactLink in project OpenOLAT by OpenOLAT.
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 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.EPStructureToArtefactLink 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.EPStructureToArtefactLink 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