Search in sources :

Example 21 with NarrowedPropertyManager

use of org.olat.properties.NarrowedPropertyManager in project openolat by klemens.

the class GroupMgmtTest method setUp.

/**
 * Set up a course with learn group and group area
 * @see org.olat.test.OlatJerseyTestCase#setUp()
 */
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    conn = new RestConnection();
    // create a course with learn group
    owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
    owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
    owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
    part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
    part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
    part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
    OLATResourceManager rm = OLATResourceManager.getInstance();
    // create course and persist as OLATResourceImpl
    OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
    course = rm.findOrPersistResourceable(resourceable);
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
    DBFactory.getInstance().commit();
    assertNotNull(re);
    // create learn group
    // 1) context one: learning groups
    RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create groups without waiting list
    g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
    g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
    DBFactory.getInstance().commit();
    // permission to see owners and participants
    businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
    businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
    // members g1
    businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
    // members g2
    businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
    // 2) context two: right groups
    RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
    // groups
    g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
    g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
    DBFactory.getInstance().commit();
    // members
    businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
    // 3) collaboration tools
    CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
    collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
    collabTools1.saveNews("<p>Hello world</p>");
    try {
        collabTools1.createForumController(null, null, true, false, null);
    } catch (Exception e) {
    // will fail but generate the forum key
    }
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    // simulate user clicks
    DBFactory.getInstance().closeSession();
    // 4) fill forum for g1
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
    Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    ForumManager fm = ForumManager.getInstance();
    Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
    m1 = fm.createMessage(forum, owner1, false);
    m1.setTitle("Thread-1");
    m1.setBody("Body of Thread-1");
    fm.addTopMessage(m1);
    m2 = fm.createMessage(forum, owner2, false);
    m2.setTitle("Thread-2");
    m2.setBody("Body of Thread-2");
    fm.addTopMessage(m2);
    DBFactory.getInstance().intermediateCommit();
    m3 = fm.createMessage(forum, owner3, false);
    m3.setTitle("Message-1.1");
    m3.setBody("Body of Message-1.1");
    fm.replyToMessage(m3, m1);
    m4 = fm.createMessage(forum, part1, false);
    m4.setTitle("Message-1.1.1");
    m4.setBody("Body of Message-1.1.1");
    fm.replyToMessage(m4, m3);
    m5 = fm.createMessage(forum, part2, false);
    m5.setTitle("Message-1.2");
    m5.setBody("Body of Message-1.2");
    fm.replyToMessage(m5, m1);
    DBFactory.getInstance().intermediateCommit();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ForumManager(org.olat.modules.fo.manager.ForumManager) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) RepositoryEntry(org.olat.repository.RepositoryEntry) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryService(org.olat.repository.RepositoryService) Forum(org.olat.modules.fo.Forum) Before(org.junit.Before)

Example 22 with NarrowedPropertyManager

use of org.olat.properties.NarrowedPropertyManager in project openolat by klemens.

the class GroupForumIndexer method doIndex.

/**
 * Index a forum in a group.
 * @param parentResourceContext
 * @param businessGroup
 * @param indexWriter
 * @throws IOException
 */
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    ForumManager fom = ForumManager.getInstance();
    Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
        Long forumKey = forumKeyProperty.getLongValue();
        Forum forum = fom.loadForum(forumKey);
        SearchResourceContext forumSearchResourceContext = new SearchResourceContext(parentResourceContext);
        forumSearchResourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLFORUM);
        forumSearchResourceContext.setDocumentType(TYPE);
        forumSearchResourceContext.setParentContextType(GroupDocument.TYPE);
        forumSearchResourceContext.setParentContextName(businessGroup.getName());
        if (forum == null) {
            // fxdiff: FXOLAT-104 warn about missing forums
            logError("found a forum-key " + forumKey + " for businessgroup " + businessGroup.getName() + " [" + businessGroup.getKey() + "] to index a forum that could not be " + "found by key! skip indexing, check if forum should still be enabled. context: " + forumSearchResourceContext.getResourceUrl(), null);
            return;
        }
        doIndexAllMessages(forumSearchResourceContext, forum, indexWriter);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) ForumManager(org.olat.modules.fo.manager.ForumManager) SearchResourceContext(org.olat.search.service.SearchResourceContext) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) Forum(org.olat.modules.fo.Forum)

Example 23 with NarrowedPropertyManager

use of org.olat.properties.NarrowedPropertyManager in project openolat by klemens.

the class GroupPortfolioIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    Property mapKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_PORTFOLIO);
    // Check if portfolio map property exist
    if (mapKeyProperty != null) {
        Long mapKey = mapKeyProperty.getLongValue();
        String version = mapKeyProperty.getStringValue();
        if (version == null || !version.equals("2")) {
            PortfolioStructure map = frontendManager.loadPortfolioStructureByKey(mapKey);
            if (map != null) {
                SearchResourceContext resourceContext = new SearchResourceContext(parentResourceContext);
                resourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLPORTFOLIO);
                resourceContext.setDocumentType(TYPE);
                resourceContext.setParentContextType(GroupDocument.TYPE);
                resourceContext.setParentContextName(businessGroup.getName());
                Document document = PortfolioMapDocument.createDocument(resourceContext, map);
                indexerWriter.addDocument(document);
            }
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document) GroupDocument(org.olat.search.service.document.GroupDocument) Property(org.olat.properties.Property)

Example 24 with NarrowedPropertyManager

use of org.olat.properties.NarrowedPropertyManager in project openolat by klemens.

the class CollaborationTools method saveNewsAccessProperty.

/**
 * @param Save news access property.
 */
public void saveNewsAccessProperty(String access) {
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    Property property = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_NEWS_ACCESS);
    if (property == null) {
        // create a new one
        Property nP = npm.createPropertyInstance(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_NEWS_ACCESS, null, null, access, null);
        npm.saveProperty(nP);
    } else {
        // modify the existing one
        property.setStringValue(access);
        npm.updateProperty(property);
    }
}
Also used : NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property)

Example 25 with NarrowedPropertyManager

use of org.olat.properties.NarrowedPropertyManager in project openolat by klemens.

the class CollaborationTools method lookupNewsDBEntry.

public Property lookupNewsDBEntry() {
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    Property property = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_NEWS);
    if (property == null) {
        // no entry
        return null;
    } else
        return property;
}
Also used : NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property)

Aggregations

NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)32 Property (org.olat.properties.Property)32 AssertException (org.olat.core.logging.AssertException)8 ForumManager (org.olat.modules.fo.manager.ForumManager)8 Forum (org.olat.modules.fo.Forum)6 BusinessGroup (org.olat.group.BusinessGroup)4 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)4 SearchResourceContext (org.olat.search.service.SearchResourceContext)4 File (java.io.File)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Document (org.apache.lucene.document.Document)2 Before (org.junit.Before)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 CalendarManager (org.olat.commons.calendar.CalendarManager)2 ImportToCalendarManager (org.olat.commons.calendar.manager.ImportToCalendarManager)2 CalendarController (org.olat.commons.calendar.ui.CalendarController)2 WeeklyCalendarController (org.olat.commons.calendar.ui.WeeklyCalendarController)2