Search in sources :

Example 6 with Persistable

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;
}
Also used : Persistable(org.olat.core.id.Persistable)

Example 7 with Persistable

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;
}
Also used : Persistable(org.olat.core.id.Persistable)

Example 8 with Persistable

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);
}
Also used : Persistable(org.olat.core.id.Persistable) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) Test(org.junit.Test)

Example 9 with Persistable

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;
}
Also used : INode(org.olat.core.util.nodes.INode) Persistable(org.olat.core.id.Persistable) MyQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode) ControllerTreeNode(org.olat.modules.qpool.ui.tree.ControllerTreeNode) CollectionTreeNode(org.olat.modules.qpool.ui.tree.CollectionTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) MarkedQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode)

Example 10 with Persistable

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;
}
Also used : Persistable(org.olat.core.id.Persistable)

Aggregations

Persistable (org.olat.core.id.Persistable)10 EntityManager (javax.persistence.EntityManager)2 Test (org.junit.Test)2 TreeNode (org.olat.core.gui.components.tree.TreeNode)2 AssertException (org.olat.core.logging.AssertException)2 INode (org.olat.core.util.nodes.INode)2 CollectionTreeNode (org.olat.modules.qpool.ui.tree.CollectionTreeNode)2 ControllerTreeNode (org.olat.modules.qpool.ui.tree.ControllerTreeNode)2 MarkedQuestionsTreeNode (org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode)2 MyQuestionsTreeNode (org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode)2 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)2 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)2