Search in sources :

Example 21 with PropertyManager

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

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 22 with PropertyManager

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

the class QuotaManagerImpl method listCustomQuotasKB.

/**
 * Get a list of all objects which have an individual quota.
 *
 * @return list of quotas.
 */
@Override
public List<Quota> listCustomQuotasKB() {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    List<Quota> results = new ArrayList<Quota>();
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> props = pm.listProperties(null, null, quotaResource, QUOTA_CATEGORY, null);
    if (props == null || props.size() == 0)
        return results;
    for (Iterator<Property> iter = props.iterator(); iter.hasNext(); ) {
        Property prop = iter.next();
        results.add(parseQuota(prop));
    }
    return results;
}
Also used : Quota(org.olat.core.util.vfs.Quota) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property)

Example 23 with PropertyManager

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

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 24 with PropertyManager

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

the class StatusWebservice method getSystemSummaryVO.

/**
 * Return the statistics about runtime: uptime, classes loaded, memory
 * summary, threads count...
 *
 * @response.representation.200.qname {http://www.example.com}runtimeVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The version of the instance
 * @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param request The HTTP request
 * @return The informations about runtime, uptime, classes loaded, memory summary...
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
    StatusVO stats = new StatusVO();
    // File
    try {
        long startFile = System.nanoTime();
        File infoFile = setInfoFiles("ping");
        WorkThreadInformations.unset();
        stats.setWriteFileInMilliseconds(CodeHelper.nanoToMilliTime(startFile));
        stats.setWriteFile(infoFile.exists());
        infoFile.delete();
    } catch (Exception e) {
        stats.setWriteFile(false);
        stats.setWriteFileInMilliseconds(-1l);
        log.error("", e);
    }
    // Datebase
    try {
        stats.setWriteDb(true);
        PropertyManager propertyManager = CoreSpringFactory.getImpl(PropertyManager.class);
        List<Property> props = propertyManager.findProperties((Identity) null, (BusinessGroup) null, PING_RESOURCE, PING_REF, PING_REF);
        if (props != null && props.size() > 0) {
            for (Property prop : props) {
                propertyManager.deleteProperty(prop);
            }
            DBFactory.getInstance().commit();
        }
        long startDB = System.nanoTime();
        Property prop = propertyManager.createPropertyInstance(null, null, PING_RESOURCE, PING_REF, PING_REF, 0f, 0l, "-", "-");
        DBFactory.getInstance().commit();
        stats.setWriteDbInMilliseconds(CodeHelper.nanoToMilliTime(startDB));
        propertyManager.deleteProperty(prop);
        DBFactory.getInstance().commit();
    } catch (Exception e) {
        stats.setWriteDb(false);
        stats.setWriteDbInMilliseconds(-1l);
        log.error("", e);
    }
    // Secure authenticated user
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    Set<UserSession> userSessions = sessionManager.getAuthenticatedUserSessions();
    int secureAuthenticatedCount = 0;
    for (UserSession usess : userSessions) {
        SessionInfo sessInfo = usess.getSessionInfo();
        if (sessInfo.isWebDAV() || sessInfo.isREST()) {
        // 
        } else if (sessInfo.isSecure()) {
            secureAuthenticatedCount++;
        }
    }
    stats.setSecureAuthenticatedCount(secureAuthenticatedCount);
    // Concurrent dispatch threads
    SessionStatsManager sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class);
    stats.setConcurrentDispatchThreads(sessionStatsManager.getConcurrentCounter());
    return Response.ok(stats).build();
}
Also used : PropertyManager(org.olat.properties.PropertyManager) SessionInfo(org.olat.core.util.SessionInfo) SessionStatsManager(org.olat.admin.sysinfo.manager.SessionStatsManager) IOException(java.io.IOException) UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) File(java.io.File) Property(org.olat.properties.Property) StatusVO(org.olat.restapi.system.vo.StatusVO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with PropertyManager

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

the class UserManagerImpl method getUserCharset.

@Override
public String getUserCharset(Identity identity) {
    String charset;
    charset = WebappHelper.getDefaultCharset();
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(identity, null, null, null, CHARSET);
    if (p != null) {
        charset = p.getStringValue();
        // (a rather rare case)
        if (!Charset.isSupported(charset)) {
            charset = WebappHelper.getDefaultCharset();
        }
    } else {
        charset = WebappHelper.getDefaultCharset();
    }
    return charset;
}
Also used : 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