Search in sources :

Example 61 with Property

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

the class NotificationsManagerImpl method processSubscribersByEmail.

private void processSubscribersByEmail(Identity ident) {
    if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
        // send only to active user
        return;
    }
    String userInterval = getUserIntervalOrDefault(ident);
    if ("never".equals(userInterval)) {
        return;
    }
    long start = System.currentTimeMillis();
    Date compareDate = getCompareDateFromInterval(userInterval);
    Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
    if (p != null) {
        Date latestEmail = new Date(p.getLongValue());
        if (latestEmail.after(compareDate)) {
            // nothing to do
            return;
        }
    }
    Date defaultCompareDate = getDefaultCompareDate();
    List<Subscriber> subscribers = getSubscribers(ident);
    if (subscribers.isEmpty()) {
        return;
    }
    String langPrefs = null;
    if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
        langPrefs = ident.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
    boolean veto = false;
    Subscriber latestSub = null;
    List<SubscriptionItem> items = new ArrayList<>();
    List<Subscriber> subsToUpdate = new ArrayList<>();
    for (Subscriber sub : subscribers) {
        Date latestEmail = sub.getLatestEmailed();
        SubscriptionItem subsitem = null;
        if (latestEmail == null || compareDate.after(latestEmail)) {
            // no notif. ever sent until now
            if (latestEmail == null) {
                latestEmail = defaultCompareDate;
            } else if (latestEmail.before(defaultCompareDate)) {
                // no notification older than a month
                latestEmail = defaultCompareDate;
            }
            subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
        } else if (latestEmail != null && latestEmail.after(compareDate)) {
        // already send an email within the user's settings interval
        // veto = true;
        }
        if (subsitem != null) {
            items.add(subsitem);
            subsToUpdate.add(sub);
        }
        latestSub = sub;
    }
    Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
    notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
Also used : Locale(java.util.Locale) SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) Subscriber(org.olat.core.commons.services.notifications.Subscriber) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property) Date(java.util.Date)

Example 62 with Property

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

the class DBPersistentLockManager method aquirePersistentLock.

/**
 * @see org.olat.core.util.locks.PersistentLockManager#aquirePersistentLock(org.olat.core.id.OLATResourceable,
 *      org.olat.core.id.Identity, java.lang.String)
 */
@Override
public LockResult aquirePersistentLock(OLATResourceable ores, Identity ident, String locksubkey) {
    // synchronisation is solved in the LockManager
    LockResult lres;
    PropertyManager pm = PropertyManager.getInstance();
    String derivedLockString = OresHelper.createStringRepresenting(ores, locksubkey);
    long aqTime;
    Identity lockOwner;
    boolean success;
    Property p;
    p = pm.findProperty(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString);
    if (p == null) {
        // no persistent lock acquired yet
        // save a property: cat = o_lock, key = derivedLockString, Longvalue = key
        // of identity acquiring the lock
        Property newp = pm.createPropertyInstance(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString, null, ident.getKey(), null, null);
        pm.saveProperty(newp);
        aqTime = System.currentTimeMillis();
        lockOwner = ident;
        success = true;
    } else {
        // already acquired, but check on reaquiring
        aqTime = p.getLastModified().getTime();
        Long lockOwnerKey = p.getLongValue();
        if (ident.getKey().equals(lockOwnerKey)) {
            // reaquire ok
            success = true;
        } else {
            // already locked by an other person
            success = false;
        }
        // FIXME:fj:c find a better way to retrieve information about the
        // lock-holder
        lockOwner = BaseSecurityManager.getInstance().loadIdentityByKey(lockOwnerKey);
    }
    LockEntry le = new LockEntry(derivedLockString, aqTime, lockOwner);
    lres = new LockResultImpl(success, le);
    return lres;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property)

Example 63 with Property

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

the class CourseNodePasswordManagerImpl method deleteAllPasswordsFor.

/**
 * @see de.bps.course.nodes.CourseNodePasswordManager#deleteAllPasswordsFor(java.lang.Long)
 */
public void deleteAllPasswordsFor(OLATResourceable ores) {
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> properties = pm.listProperties(null, null, AdditionalConditionAnswerContainer.RESOURCE_NAME, null, null, AdditionalConditionAnswerContainer.RESOURCE_NAME, ores.getResourceableId(), null);
    for (Property p : properties) {
        Long nodeId = p.getResourceTypeId();
        Long courseId = p.getLongValue();
        removeAnswers(nodeId, courseId);
        pm.deleteProperty(p);
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 64 with Property

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

the class UserDeletionManager method setProperty.

private void setProperty(String propertyName, int value) {
    List<Property> properties = PropertyManager.getInstance().findProperties(null, null, null, PROPERTY_CATEGORY, propertyName);
    Property property = null;
    if (properties.size() == 0) {
        property = PropertyManager.getInstance().createPropertyInstance(null, null, null, PROPERTY_CATEGORY, propertyName, null, new Long(value), null, null);
    } else {
        property = properties.get(0);
        property.setLongValue(new Long(value));
    }
    PropertyManager.getInstance().saveProperty(property);
}
Also used : Property(org.olat.properties.Property)

Example 65 with Property

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

the class InfoMessageManager method setInfoMessageNodeOnly.

/**
 * set info message on node level only, no need to sync
 * @param message
 */
public void setInfoMessageNodeOnly(String message) {
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG_NODE_ONLY + nodeId);
    if (p == null) {
        p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG_NODE_ONLY + nodeId, null, null, null, "");
        pm.saveProperty(p);
    }
    p.setTextValue(message);
    // set Message in RAM
    InfoMessageManager.infoMessageNodeOnly = message;
    pm.updateProperty(p);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

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