Search in sources :

Example 51 with Property

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

the class CollaborationTools method getForum.

public Forum getForum() {
    final ForumManager fom = ForumManager.getInstance();
    final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    Property forumProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    Forum forum;
    if (forumProperty != null) {
        forum = fom.loadForum(forumProperty.getLongValue());
    } else {
        forum = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Forum>() {

            @Override
            public Forum execute() {
                Forum aforum;
                Long forumKey;
                Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
                if (forumKeyProperty == null) {
                    // First call of forum, create new forum and save
                    aforum = fom.addAForum();
                    forumKey = aforum.getKey();
                    if (log.isDebug()) {
                        log.debug("created new forum in collab tools: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
                    }
                    forumKeyProperty = npm.createPropertyInstance(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM, null, forumKey, null, null);
                    npm.saveProperty(forumKeyProperty);
                } else {
                    // Forum does already exist, load forum with key from properties
                    forumKey = forumKeyProperty.getLongValue();
                    aforum = fom.loadForum(forumKey);
                    if (aforum == null) {
                        throw new AssertException("Unable to load forum with key " + forumKey.longValue() + " for ores " + ores.getResourceableTypeName() + " with key " + ores.getResourceableId());
                    }
                    if (log.isDebug()) {
                        log.debug("loading forum in collab tools from properties: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
                    }
                }
                return aforum;
            }
        });
    }
    return forum;
}
Also used : AssertException(org.olat.core.logging.AssertException) ForumManager(org.olat.modules.fo.manager.ForumManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) SyncerCallback(org.olat.core.util.coordinate.SyncerCallback) Property(org.olat.properties.Property) Forum(org.olat.modules.fo.Forum)

Example 52 with Property

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

the class CollaborationTools method createOrUpdateProperty.

/**
 * creates the property if non-existing, or updates the existing property to
 * the supplied values. Real changes are made persistent immediately.
 *
 * @param selectedTool
 * @param toolValue
 */
private void createOrUpdateProperty(final String selectedTool, final boolean toolValue) {
    Boolean cv = cacheToolStates.get(selectedTool);
    if (cv != null && cv.booleanValue() == toolValue) {
        // nice, cache saved a needless update
        return;
    }
    // handle Boolean Values via String Field in Property DB Table
    final String toolValueStr = toolValue ? TRUE : FALSE;
    final PropertyManager pm = PropertyManager.getInstance();
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        @Override
        public void execute() {
            // was: synchronized (CollaborationTools.class) {
            Property property = getPropertyOf(selectedTool);
            if (property == null) {
                // not existing -> create it
                property = pm.createPropertyInstance(null, null, ores, PROP_CAT_BG_COLLABTOOLS, selectedTool, null, null, toolValueStr, null);
            } else {
                // if existing -> update to desired value
                property.setStringValue(toolValueStr);
            }
            // create a room if needed
            if (toolValue && TOOL_OPENMEETINGS.equals(selectedTool)) {
                openOpenMeetingsRoom();
            }
            // property becomes persistent
            pm.saveProperty(property);
        }
    });
    this.dirty = true;
    cacheToolStates.put(selectedTool, Boolean.valueOf(toolValue));
}
Also used : PropertyManager(org.olat.properties.PropertyManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Property(org.olat.properties.Property)

Example 53 with Property

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

the class CollaborationTools method getPropertyOf.

Property getPropertyOf(String selectedTool) {
    PropertyManager pm = PropertyManager.getInstance();
    Property property = pm.findProperty(null, null, ores, PROP_CAT_BG_COLLABTOOLS, selectedTool);
    Boolean res;
    if (property == null) {
        // meaning false
        res = Boolean.FALSE;
    } else {
        String val = property.getStringValue();
        res = val.equals(TRUE) ? Boolean.TRUE : Boolean.FALSE;
    }
    cacheToolStates.put(selectedTool, res);
    return property;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property)

Example 54 with Property

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

the class CollaborationTools method saveNews.

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

Example 55 with Property

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

the class CollaborationTools method archiveForum.

private void archiveForum(String archivFilePath) {
    Property forumKeyProperty = NarrowedPropertyManager.getInstance(ores).findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    if (forumKeyProperty != null) {
        VFSContainer archiveContainer = new LocalFolderImpl(new File(archivFilePath));
        String archiveForumName = "del_forum_" + forumKeyProperty.getLongValue();
        VFSContainer archiveForumContainer = archiveContainer.createChildContainer(archiveForumName);
        ForumFormatter ff = new ForumRTFFormatter(archiveForumContainer, false, I18nModule.getDefaultLocale());
        ForumArchiveManager.getInstance().applyFormatter(ff, forumKeyProperty.getLongValue(), null);
    }
}
Also used : ForumFormatter(org.olat.modules.fo.archiver.formatters.ForumFormatter) ForumRTFFormatter(org.olat.modules.fo.archiver.formatters.ForumRTFFormatter) VFSContainer(org.olat.core.util.vfs.VFSContainer) Property(org.olat.properties.Property) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Aggregations

Property (org.olat.properties.Property)270 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)62 PropertyManager (org.olat.properties.PropertyManager)48 Identity (org.olat.core.id.Identity)36 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)36 ArrayList (java.util.ArrayList)24 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)22 BusinessGroup (org.olat.group.BusinessGroup)18 File (java.io.File)16 ICourse (org.olat.course.ICourse)16 Translator (org.olat.core.gui.translator.Translator)14 AssertException (org.olat.core.logging.AssertException)14 CourseNode (org.olat.course.nodes.CourseNode)14 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)14 Test (org.junit.Test)12 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)12 XStream (com.thoughtworks.xstream.XStream)10 HashMap (java.util.HashMap)10 List (java.util.List)10