Package org.olat.properties

Examples of org.olat.properties.PropertyManager


  public void testRollback() {
    DB db = DBFactory.getInstance();
    String propertyKey = "testRollback-1";
    String testValue = "testRollback-1";
    try {
      PropertyManager pm = PropertyManager.getInstance();
      Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey, null, null, testValue, null);
      pm.saveProperty(p1);
      String propertyKey2 = "testRollback-2";
      String testValue2 = "testRollback-2";
      // name is null => generated DB error => rollback
      Property p2 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue2, null);
      pm.saveProperty(p2);
      fail("Should generate error for rollback.");
    } catch (Exception ex) {
      db.closeSession();
    }
    // check if p1 is rollbacked
    db = DBFactory.getInstance();
    PropertyManager pm = PropertyManager.getInstance();
    Property p =pm.findProperty(null, null, null, null, propertyKey);
    this.assertNull("Property.save is NOT rollbacked", p);
  }
View Full Code Here


    String testValue2 = "testMixed-2";
    String propertyKey3 = "testMixed-3";
    String testValue3 = "testMixed-3";
    try {
      // outside of transaction
      PropertyManager pm = PropertyManager.getInstance();
      Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
      pm.saveProperty(p1);
      // inside of transaction
      Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
      pm.saveProperty(p2);
      // name is null => generated DB error => rollback
      Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
      pm.saveProperty(p3);
      fail("Should generate error for rollback.");
      db.closeSession();
    } catch (Exception ex) {
      db.closeSession();
    }
    // check if p1&p2 is rollbacked
    PropertyManager pm = PropertyManager.getInstance();
    Property p_1 =pm.findProperty(null, null, null, null, propertyKey1);
    this.assertNull("Property1 is NOT rollbacked", p_1);
    Property p_2 =pm.findProperty(null, null, null, null, propertyKey2);
    this.assertNull("Property2 is NOT rollbacked", p_2);
  }
View Full Code Here

   *      org.olat.core.id.Identity, java.lang.String)
   */
  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
View Full Code Here

   * @see org.olat.core.util.locks.PersistentLockManager#releasePersistentLock(org.olat.core.util.locks.LockEntry)
   */
  public void releasePersistentLock(LockResult le) {
    //synchronisation is solved in the LockManager
    String derivedLockString = ((LockResultImpl)le).getLockEntry().getKey();
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString);
    if (p == null) throw new AssertException("could not release lock: no lock in db, " + derivedLockString);
    Identity ident = le.getOwner();
    Long ownerKey = p.getLongValue();
    if (!ownerKey.equals(ident.getKey())) throw new AssertException("user " + ident.getName()
        + " cannot release lock belonging to user with key " + ownerKey + " on resourcestring " + derivedLockString);
    pm.deleteProperty(p);
  }
View Full Code Here

    }

    /*
     * ensure that the infomessage property exists on the system
     */
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, "_o3_", "InfoMsg");
    if (p == null) {
      p =  pm.createPropertyInstance(null,  null,  null,  "_o3_", "InfoMsg", null, null, null, InfoMessageManager.EMPTY_MESSAGE);
      pm.saveProperty(p);
    }
    /*
     * ensure that the GlobalStickyMessage is initialized and registered to listen
     * -> OLAT-4168
     */
 
View Full Code Here

    //o_clusterOK by guido
    CoordinatorManager.getCoordinator().getSyncer().doInSync(
        OresHelper.createOLATResourceableInstanceWithoutCheck(LOCK_KEY, identity.getKey()), new SyncerExecutor(){

          public void execute() {
            PropertyManager pm = PropertyManager.getInstance();
            // generate x-stream serialization of this object
            String props = XStreamHelper.toXML(toUpdate);
            Property imProperty = PropertyManager.getInstance().findProperty(identity, null, null, null, ImPreferences.USER_PROPERTY_KEY);
            if (imProperty == null) { throw new AssertException("Try to update Im Prefs for (" + identity.getName() + ") but they do not exist!!"); }
            imProperty.setTextValue(props);
            pm.updateProperty(imProperty);
          }
         
        });
 
  }
View Full Code Here

    CourseConfig cc = userCourseEnv.getCourseEnvironment().getCourseConfig();
    // write only when enabled for this course
    if (cc.isEfficencyStatementEnabled()) {
      final boolean logDebug = log.isDebug();
      final Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
      final PropertyManager pm = PropertyManager.getInstance();         
      final String courseRepoEntryKey = getPropertyName(repoEntryKey);         
       
      CourseNode rootNode = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
      List<Map<String,Object>> assessmentNodes = AssessmentHelper.addAssessableNodeAndDataToList(0, rootNode, userCourseEnv, true, true);
         
      EfficiencyStatement efficiencyStatement = new EfficiencyStatement();
      efficiencyStatement.setAssessmentNodes(assessmentNodes);
      efficiencyStatement.setCourseTitle(userCourseEnv.getCourseEnvironment().getCourseTitle());
      efficiencyStatement.setCourseRepoEntryKey(repoEntryKey);
      User user = identity.getUser();
      efficiencyStatement.setDisplayableUserInfo(user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null) + " (" + identity.getName() + ")");
      efficiencyStatement.setLastUpdated(System.currentTimeMillis());
         
      // save efficiency statement as xtream persisted list
      final String efficiencyStatementX = XStreamHelper.toXML(efficiencyStatement);           
      Property efficiencyProperty = null;
      if (checkForExistingProperty) {
        efficiencyProperty = pm.findUserProperty(identity, PROPERTY_CATEGORY, courseRepoEntryKey);
      }
      if (assessmentNodes != null) {       
        if (efficiencyProperty == null) {
          // create new
          efficiencyProperty = pm.createUserPropertyInstance(identity, PROPERTY_CATEGORY, courseRepoEntryKey, null, null, null,  efficiencyStatementX);
          pm.saveProperty(efficiencyProperty);
          if (logDebug) log.debug("creating new efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
                  + identity.getName() + " repoEntry::" + courseRepoEntryKey);
        } else {
          // update existing
          if (logDebug) log.debug("updatting efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
                  + identity.getName() + " repoEntry::" + courseRepoEntryKey);
          efficiencyProperty.setTextValue(efficiencyStatementX);
          pm.updateProperty(efficiencyProperty);
        }
      } else {
        if (efficiencyProperty != null) {
          // remove existing since now empty empty efficiency statements
          if (logDebug) log.debug("removing efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
                  + identity.getName() + " repoEntry::" + courseRepoEntryKey + " since empty");
          pm.deleteProperty(efficiencyProperty);
        }
        // else nothing to create and nothing to delete
      }         
     
      // send modified event to everybody
View Full Code Here

   * @param identity
   * @return Map containing a list of maps that contain the nodeData for this user and course using the
   * keys defined in the AssessmentHelper and the title of the course
   */
  public EfficiencyStatement getUserEfficiencyStatement(Long courseRepoEntryKey, Identity identity){
    PropertyManager pm = PropertyManager.getInstance();
    Property efficiencyProperty;

    efficiencyProperty = pm.findUserProperty(identity,PROPERTY_CATEGORY, getPropertyName(courseRepoEntryKey));
    if (efficiencyProperty == null) {
      return null;
    } else {
      return (EfficiencyStatement) XStreamHelper.fromXML(efficiencyProperty.getTextValue());
    }
View Full Code Here

   * Find all efficiency statements for a specific user
   * @param identity
   * @return List of efficiency statements
   */
  protected List<EfficiencyStatement> findEfficiencyStatements(Identity identity) {
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> esProperties = pm.listProperties(identity, null, null, PROPERTY_CATEGORY, null);
    List<EfficiencyStatement> efficiencyStatements = new ArrayList<EfficiencyStatement>();
    Iterator<Property> iter = esProperties.iterator();
    while (iter.hasNext()) {
      Property efficiencyProperty = iter.next();
      EfficiencyStatement efficiencyStatement = (EfficiencyStatement) XStreamHelper.fromXML(efficiencyProperty.getTextValue());
View Full Code Here

   * Find all identities who have an efficiency statement for this course repository entry
   * @param courseRepoEntryKey
   * @return List of identities
   */
  protected List<Identity> findIdentitiesWithEfficiencyStatements(Long courseRepoEntryKey) {
    PropertyManager pm = PropertyManager.getInstance();
    return pm.findIdentitiesWithProperty(null, PROPERTY_CATEGORY, getPropertyName(courseRepoEntryKey), false);
  }
View Full Code Here

TOP

Related Classes of org.olat.properties.PropertyManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.