Search in sources :

Example 31 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class FeedDAOTest method createFeed_ores.

@Test
public void createFeed_ores() {
    OLATResource resource = JunitTestHelper.createRandomResource();
    Feed feed = feedDao.createFeedForResourcable(resource);
    Assert.assertNotNull(feed);
    dbInstance.commitAndCloseSession();
    // check values
    Assert.assertNotNull(feed.getKey());
    Assert.assertNotNull(feed.getCreationDate());
    Assert.assertNotNull(feed.getLastModified());
    Assert.assertEquals(resource.getResourceableId(), feed.getResourceableId());
    Assert.assertEquals(resource.getResourceableTypeName(), feed.getResourceableTypeName());
}
Also used : OLATResource(org.olat.resource.OLATResource) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

Example 32 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class NoteTest method saveUpdateNote.

@Test
public void saveUpdateNote() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("note-2-");
    OLATResource resource = JunitTestHelper.createRandomResource();
    Note note = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
    note.setNoteTitle("Very important");
    note.setNoteText("Critical update with new features");
    noteManager.saveNote(note);
    dbInstance.commitAndCloseSession();
    Note updateNote = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
    updateNote.setNoteTitle("Important");
    updateNote.setNoteText("Cool update with new features");
    noteManager.saveNote(updateNote);
    dbInstance.commitAndCloseSession();
    List<Note> notes = noteManager.listUserNotes(identity);
    Assert.assertNotNull(notes);
    Assert.assertEquals(1, notes.size());
    Assert.assertEquals(updateNote, notes.get(0));
    Note reloadedNote = notes.get(0);
    Assert.assertEquals("Important", reloadedNote.getNoteTitle());
    Assert.assertEquals("Cool update with new features", reloadedNote.getNoteText());
}
Also used : OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 33 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class NoteTest method testGenericLoadDeleteNote.

@Test
public void testGenericLoadDeleteNote() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("note-1-");
    OLATResource resource = JunitTestHelper.createRandomResource();
    Note n = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
    n.setNoteTitle("Notiz Titel");
    n.setNoteText("Notiz Text");
    noteManager.saveNote(n);
    dbInstance.commitAndCloseSession();
    Note note = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
    Assert.assertNotNull(note);
    noteManager.deleteNote(note);
    List<Note> notes = noteManager.listUserNotes(identity);
    Assert.assertTrue(notes.isEmpty());
}
Also used : OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 34 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class CatalogTest method createRepository.

private RepositoryEntry createRepository(String displayName, final Long resourceableId) {
    OLATResourceable resourceable = new OLATResourceable() {

        public String getResourceableTypeName() {
            return CourseModule.ORES_TYPE_COURSE;
        }

        public Long getResourceableId() {
            return resourceableId;
        }
    };
    OLATResourceManager rm = OLATResourceManager.getInstance();
    // create course and persist as OLATResourceImpl
    OLATResource r = rm.findResourceable(resourceable);
    if (r == null) {
        r = rm.createOLATResourceInstance(resourceable);
    }
    DBFactory.getInstance().saveObject(r);
    DBFactory.getInstance().intermediateCommit();
    RepositoryEntry d = RepositoryManager.getInstance().lookupRepositoryEntry(resourceable, false);
    if (d == null) {
        d = repositoryService.create("Rei Ayanami", "-", displayName, "Repo entry", r);
        DBFactory.getInstance().saveObject(d);
    }
    DBFactory.getInstance().intermediateCommit();
    return d;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 35 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EPFrontendManagerTest method testSyncMapTemplateToUserMap.

@Test
public void testSyncMapTemplateToUserMap() {
    // create a template
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // create a repository entry
    RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "Template in user", "Template in use", resource, RepositoryEntry.ACC_OWNERS);
    // create the template owned by ident1
    PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    // create five pages
    List<PortfolioStructure> pageRefs = new ArrayList<PortfolioStructure>();
    List<PortfolioStructure> elementRefs = new ArrayList<PortfolioStructure>();
    for (int i = 0; i < 5; i++) {
        PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(templateEl, "sync-template-page-" + i, "sync-template-page-" + i);
        pageRefs.add(page);
        for (int j = 0; j < 5; j++) {
            PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(page, "template-structure-" + i + "." + j, "template-structure-" + i + "." + j);
            epStructureManager.addCollectRestriction(struct, "Forum", "minimum", 2);
            epStructureManager.savePortfolioStructure(struct);
            elementRefs.add(struct);
        }
    }
    // save the template
    dbInstance.commitAndCloseSession();
    // end create template
    // ////////////////////
    // make the copy
    PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(map);
    // ////////////////////////////////
    // shuffle the pages and delete one
    PortfolioStructure retrievedTemplateEl = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedTemplateEl);
    epStructureManager.moveUp(retrievedTemplateEl, pages.get(1));
    epStructureManager.moveDown(retrievedTemplateEl, pages.get(2));
    epStructureManager.removeStructure(retrievedTemplateEl, pages.get(3));
    epStructureManager.savePortfolioStructure(retrievedTemplateEl);
    // shuffle a page
    List<PortfolioStructure> page1Children = epFrontendManager.loadStructureChildren(pages.get(1));
    epStructureManager.moveUp(pages.get(1), page1Children.get(3));
    epStructureManager.moveUp(pages.get(1), page1Children.get(2));
    epStructureManager.moveUp(pages.get(1), page1Children.get(4));
    // and add an element and sub-elements
    PortfolioStructure newStruct = epFrontendManager.createAndPersistPortfolioStructureElement(pages.get(1), "new-template-structure-1.6", "template-structure-1.6");
    epStructureManager.addCollectRestriction(pages.get(1), "Forum", "minimum", 2);
    epStructureManager.savePortfolioStructure(newStruct);
    epStructureManager.savePortfolioStructure(pages.get(1));
    for (int k = 0; k < 5; k++) {
        PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(newStruct, "new-template-structure-2." + k, "template-structure-2." + k);
        epStructureManager.addCollectRestriction(struct, "bc", "minimum", 2);
        epStructureManager.savePortfolioStructure(struct);
        elementRefs.add(struct);
    }
    dbInstance.commitAndCloseSession();
    // end shuffle the pages
    // ////////////////////////////////
    // //////////////////
    // check the template
    PortfolioStructure retrievedTemplate2El = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
    assertNotNull(retrievedTemplate2El);
    assertTrue(retrievedTemplate2El instanceof EPStructuredMapTemplate);
    List<PortfolioStructure> retrievedPages2 = epFrontendManager.loadStructureChildren(retrievedTemplate2El);
    assertEquals(4, retrievedPages2.size());
    assertEquals(4, ((EPStructuredMapTemplate) retrievedTemplate2El).getInternalChildren().size());
    // check the shuffled pages
    assertEquals(pageRefs.get(1).getKey(), retrievedPages2.get(0).getKey());
    assertEquals(pageRefs.get(0).getKey(), retrievedPages2.get(1).getKey());
    assertEquals(pageRefs.get(2).getKey(), retrievedPages2.get(2).getKey());
    assertEquals(pageRefs.get(4).getKey(), retrievedPages2.get(3).getKey());
    // check added element
    List<PortfolioStructure> retrievedChildren2 = epFrontendManager.loadStructureChildren(retrievedPages2.get(0));
    assertEquals(6, retrievedChildren2.size());
    dbInstance.commitAndCloseSession();
    // check the template
    // //////////////////
    // sync the map
    epFrontendManager.synchronizeStructuredMapToUserCopy(map);
    dbInstance.commitAndCloseSession();
    // ///////////////
    // check the sync
    PortfolioStructure synchedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    assertNotNull(synchedMap);
    assertTrue(synchedMap instanceof EPStructuredMap);
    List<PortfolioStructure> synchedPages = epFrontendManager.loadStructureChildren(synchedMap);
    assertNotNull(synchedPages);
    assertEquals(4, synchedPages.size());
    assertEquals(((EPStructureElement) pageRefs.get(1)).getTitle(), ((EPStructureElement) synchedPages.get(0)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getTitle(), ((EPStructureElement) synchedPages.get(1)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getTitle(), ((EPStructureElement) synchedPages.get(2)).getTitle());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getTitle(), ((EPStructureElement) synchedPages.get(3)).getTitle());
    // check synched key
    assertEquals(((EPStructureElement) pageRefs.get(1)).getKey(), ((EPStructureElement) synchedPages.get(0)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(0)).getKey(), ((EPStructureElement) synchedPages.get(1)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(2)).getKey(), ((EPStructureElement) synchedPages.get(2)).getStructureElSource());
    assertEquals(((EPStructureElement) pageRefs.get(4)).getKey(), ((EPStructureElement) synchedPages.get(3)).getStructureElSource());
    // check the new elements
    List<PortfolioStructure> retrievedPage1Children = epFrontendManager.loadStructureChildren(synchedPages.get(0));
    assertEquals(6, retrievedPage1Children.size());
    PortfolioStructure retrievedNewStruct = retrievedPage1Children.get(5);
    assertEquals("new-template-structure-1.6", ((EPStructureElement) retrievedNewStruct).getTitle());
    List<PortfolioStructure> retrievedNewStructChildren = epFrontendManager.loadStructureChildren(retrievedNewStruct);
    assertNotNull(retrievedNewStructChildren);
    assertEquals(5, retrievedNewStructChildren.size());
    for (int k = 0; k < 5; k++) {
        assertEquals("new-template-structure-2." + k, ((EPStructureElement) retrievedNewStructChildren.get(k)).getTitle());
    }
// end check the sync
// //////////////////
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26