use of org.olat.portfolio.model.structel.EPStructureToArtefactLink in project OpenOLAT by OpenOLAT.
the class EPStructureManager method setReflexionForArtefactToStructureLink.
protected boolean setReflexionForArtefactToStructureLink(AbstractArtefact artefact, PortfolioStructure structure, String reflexion) {
EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
List<EPStructureToArtefactLink> links = structureEl.getInternalArtefacts();
boolean changed = false;
for (EPStructureToArtefactLink epStructureToArtefactLink : links) {
if (epStructureToArtefactLink.getArtefact().getKey().equals(artefact.getKey())) {
epStructureToArtefactLink.setReflexion(reflexion);
if (epStructureToArtefactLink.getKey() == null) {
dbInstance.saveObject(epStructureToArtefactLink);
} else {
dbInstance.updateObject(epStructureToArtefactLink);
}
changed = true;
break;
}
}
// savePortfolioStructure(structure);
return changed;
}
use of org.olat.portfolio.model.structel.EPStructureToArtefactLink in project openolat by klemens.
the class EPStructureManager method setReflexionForArtefactToStructureLink.
protected boolean setReflexionForArtefactToStructureLink(AbstractArtefact artefact, PortfolioStructure structure, String reflexion) {
EPStructureElement structureEl = (EPStructureElement) dbInstance.loadObject((EPStructureElement) structure);
List<EPStructureToArtefactLink> links = structureEl.getInternalArtefacts();
boolean changed = false;
for (EPStructureToArtefactLink epStructureToArtefactLink : links) {
if (epStructureToArtefactLink.getArtefact().getKey().equals(artefact.getKey())) {
epStructureToArtefactLink.setReflexion(reflexion);
if (epStructureToArtefactLink.getKey() == null) {
dbInstance.saveObject(epStructureToArtefactLink);
} else {
dbInstance.updateObject(epStructureToArtefactLink);
}
changed = true;
break;
}
}
// savePortfolioStructure(structure);
return changed;
}
use of org.olat.portfolio.model.structel.EPStructureToArtefactLink 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.EPStructureToArtefactLink 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.EPStructureToArtefactLink 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;
}
Aggregations