Search in sources :

Example 11 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class DBTest method testDBUTF8capable.

@Test
public void testDBUTF8capable() {
    PropertyManager pm = PropertyManager.getInstance();
    String uuid = UUID.randomUUID().toString();
    String unicodetest = "a-greek a\u03E2a\u03EAa\u03E8 arab \u0630a\u0631 chinese:\u3150a\u3151a\u3152a\u3153a\u3173a\u3110-z";
    Property p = pm.createPropertyInstance(null, null, null, null, uuid, null, null, unicodetest, null);
    pm.saveProperty(p);
    // forget session cache etc.
    dbInstance.closeSession();
    Property p2 = pm.findProperty(null, null, null, null, uuid);
    String lStr = p2.getStringValue();
    assertEquals(unicodetest, lStr);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) Test(org.junit.Test)

Example 12 with PropertyManager

use of org.olat.properties.PropertyManager 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 13 with PropertyManager

use of org.olat.properties.PropertyManager 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 14 with PropertyManager

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

the class QuotaManagerImpl method setCustomQuotaKB.

/**
 * Sets or updates the quota (in KB) for this path. Important: Must provide a
 * path with a valid base.
 *
 * @param quota
 */
@Override
public void setCustomQuotaKB(Quota quota) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath());
    if (p == null) {
        // create new entry
        p = pm.createPropertyInstance(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath(), null, null, assembleQuota(quota), null);
        pm.saveProperty(p);
    } else {
        p.setStringValue(assembleQuota(quota));
        pm.updateProperty(p);
    }
    // if the quota is a default quota, rebuild the default quota list
    if (quota.getPath().startsWith(QuotaConstants.IDENTIFIER_DEFAULT)) {
        initDefaultQuotas();
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 15 with PropertyManager

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

the class QuotaManagerImpl method deleteCustomQuota.

/**
 * @param quota to be deleted
 * @return true if quota successfully deleted or no such quota, false if quota
 *         not deleted because it was a default quota that can not be deleted
 */
@Override
public boolean deleteCustomQuota(Quota quota) {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    // do not allow to delete default quotas!
    if (quota.getPath().startsWith(QuotaConstants.IDENTIFIER_DEFAULT)) {
        return false;
    }
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, quotaResource, QUOTA_CATEGORY, quota.getPath());
    if (p != null)
        pm.deleteProperty(p);
    return true;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Aggregations

PropertyManager (org.olat.properties.PropertyManager)50 Property (org.olat.properties.Property)48 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 UserSession (org.olat.core.util.UserSession)4 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)4 OLATResourceable (org.olat.core.id.OLATResourceable)3 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)3 File (java.io.File)2 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2