use of org.olat.core.id.Persistable in project openolat by klemens.
the class PersistenceHelper method removeObjectsFromList.
/**
* Removes a list of persistable objects from another list with
* persistable objects by comparing the hibernate key instead of the
* object identity.
* @param originalList
* @param toBeRemovedObjects
* @return int number of objects removed from the originalList
* After calling this operation the originalList will contain less or the same amount of
* objects
*/
public static int removeObjectsFromList(List<? extends Persistable> originalList, List<? extends Persistable> toBeRemovedObjects) {
int counter = 0;
Iterator<? extends Persistable> removeIter = toBeRemovedObjects.iterator();
while (removeIter.hasNext()) {
Persistable toBeRemoved = removeIter.next();
Iterator<? extends Persistable> originalIter = originalList.iterator();
while (originalIter.hasNext()) {
Persistable fromOriginal = originalIter.next();
if (fromOriginal.getKey().equals(toBeRemoved.getKey())) {
originalList.remove(fromOriginal);
counter++;
break;
}
}
}
return counter;
}
use of org.olat.core.id.Persistable in project OpenOLAT by OpenOLAT.
the class PersistsEvent method isAtLeastOneKeyInList.
/**
* @param persistables a List of Persistable objects
* @return true if at least one of the objects in the list has the same key as the keys given.
*/
public boolean isAtLeastOneKeyInList(List<? extends Persistable> persistables) {
for (Iterator<? extends Persistable> it_per = persistables.iterator(); it_per.hasNext(); ) {
Persistable per = it_per.next();
Long key = per.getKey();
if (keys.contains(key))
return true;
}
return false;
}
use of org.olat.core.id.Persistable in project OpenOLAT by OpenOLAT.
the class EPStructureManagerTest method testGetReferencedMapsForArtefact.
@Test
public void testGetReferencedMapsForArtefact() {
PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el", "structure-element");
dbInstance.commitAndCloseSession();
AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
epFrontendManager.addArtefactToStructure(ident1, artefact, el);
dbInstance.commitAndCloseSession();
// get the referenced maps
List<PortfolioStructure> mapList = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList.get(0)));
dbInstance.commitAndCloseSession();
// make the test more complex
// reload the structure element
el = epFrontendManager.loadPortfolioStructureByKey(el.getKey());
// add artefact to substructure (page) and check for the same map
PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(el, "child-structure-el", "child-structure-element");
el = epFrontendManager.removeArtefactFromStructure(artefact, el);
epFrontendManager.addArtefactToStructure(ident1, artefact, childEl);
dbInstance.commitAndCloseSession();
// get the referenced maps
List<PortfolioStructure> mapList2 = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList2.get(0)));
dbInstance.commitAndCloseSession();
// add artefact to 3 maps and check to get all of them
PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-2", "structure-element-2");
epFrontendManager.addArtefactToStructure(ident1, artefact, el2);
PortfolioStructure el3 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-3", "structure-element-3");
epFrontendManager.addArtefactToStructure(ident1, artefact, el3);
List<PortfolioStructure> mapList3 = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertEquals(3, mapList3.size());
boolean found = false;
for (PortfolioStructure mapValue : mapList3) {
if (((Persistable) mapValue).equalsByPersistableKey((Persistable) el)) {
found = true;
}
}
assertTrue(found);
}
use of org.olat.core.id.Persistable in project OpenOLAT by OpenOLAT.
the class QuestionPoolMainEditorController method findNodeByPersistableUserObject.
private TreeNode findNodeByPersistableUserObject(TreeNode parentNode, Long id) {
if (parentNode == null || id == null) {
return null;
}
for (int i = parentNode.getChildCount(); i-- > 0; ) {
INode node = parentNode.getChildAt(i);
if (node instanceof TreeNode) {
TreeNode treeNode = (TreeNode) node;
Object userObj = treeNode.getUserObject();
if (userObj instanceof Persistable) {
Persistable obj = (Persistable) userObj;
if (id.equals(obj.getKey())) {
return treeNode;
}
}
}
}
return null;
}
use of org.olat.core.id.Persistable in project openolat by klemens.
the class PersistsEvent method isAtLeastOneKeyInList.
/**
* @param persistables a List of Persistable objects
* @return true if at least one of the objects in the list has the same key as the keys given.
*/
public boolean isAtLeastOneKeyInList(List<? extends Persistable> persistables) {
for (Iterator<? extends Persistable> it_per = persistables.iterator(); it_per.hasNext(); ) {
Persistable per = it_per.next();
Long key = per.getKey();
if (keys.contains(key))
return true;
}
return false;
}
Aggregations