Package org.olat.core.commons.persistence

Examples of org.olat.core.commons.persistence.DB


   */
  public List getIdentitiesOfSecurityGroup(SecurityGroup secGroup) {
    if (secGroup == null) {
      throw new AssertException("getIdentitiesOfSecurityGroup: ERROR secGroup was null !!");
    }
    DB db = DBFactory.getInstance();
    if (db == null) {
      throw new AssertException("getIdentitiesOfSecurityGroup: ERROR db was null !!");
    }
    List idents = DBFactory.getInstance().find(
              "select ii from"
View Full Code Here


   */
  public Date getSecurityGroupJoinDateForIdentity(SecurityGroup secGroup, Identity identity){
    String query = "select creationDate from " + "  org.olat.basesecurity.SecurityGroupMembershipImpl as sgi "
        + " where sgi.securityGroup = :secGroup and sgi.identity = :identId";
   
    DB db = DBFactory.getInstance();
    DBQuery dbq = db.createQuery(query);
    dbq.setLong("identId", identity.getKey().longValue());
    dbq.setLong("secGroup", secGroup.getKey());
    List result = dbq.list();
    if (result.size()==0){
      return null;
View Full Code Here

  /**
   * @see org.olat.basesecurity.Manager#countIdentitiesOfSecurityGroup(org.olat.basesecurity.SecurityGroup)
   */
  public int countIdentitiesOfSecurityGroup(SecurityGroup secGroup) {
    DB db = DBFactory.getInstance();
    String q = "select count(sgm) from org.olat.basesecurity.SecurityGroupMembershipImpl sgm where sgm.securityGroup = :group";
    DBQuery query = db.createQuery(q);
    query.setEntity("group", secGroup);
    int result = ((Long) query.list().get(0)).intValue();
    return result;
  }
View Full Code Here

   */
  public Authentication findAuthentication(Identity identity, String provider) {
    if (identity==null) {
      throw new IllegalArgumentException("identity must not be null");
    }
    DB dbInstance = DBFactory.getInstance();
    if (dbInstance==null) {
      throw new IllegalStateException("DBFactory.getInstance() returned null");
    }
    List results = dbInstance.find(
        "select auth from org.olat.basesecurity.AuthenticationImpl as auth where auth.identity.key = ? and auth.provider = ?",
        new Object[] { identity.getKey(), provider }, new Type[] { Hibernate.LONG, Hibernate.STRING });
    if (results == null || results.size() == 0) return null;
    if (results.size() > 1) throw new AssertException("Found more than one Authentication for a given subject and a given provider.");
    return (Authentication) results.get(0);
View Full Code Here

      }
    }
     
    // create query object now from string
    String query = sb.toString();
    DB db = DBFactory.getInstance();
    DBQuery dbq = db.createQuery(query);
   
    // add user attributes
    if (login != null)
      dbq.setString("login", login);
View Full Code Here

    Manager secMgr = ManagerFactory.getManager();


    // loop over users to be edited:
    for (Identity identity : selIdentities) {
      DB db = DBFactory.getInstance();
      //reload identity from cache, to prevent stale object
      identity = (Identity) db.loadObject(identity);
      User user = identity.getUser();
      String errorDesc = "";
      boolean updateError = false;
      // change pwd
      if (attributeChangeMap.containsKey(PWD_IDENTIFYER)) {
        String newPwd = attributeChangeMap.get(PWD_IDENTIFYER);
        if (StringHelper.containsNonWhitespace(newPwd)) {
          if (!UserManager.getInstance().syntaxCheckOlatPassword(newPwd)) {
            errorDesc = transWithFallback.translate("error.password");
            updateError = true;
          }
        } else newPwd = null;
        OLATAuthManager.changePasswordAsAdmin(identity, newPwd);
      }

      // set language
      String userLanguage = user.getPreferences().getLanguage();
      if (attributeChangeMap.containsKey(LANG_IDENTIFYER)) {
        String inputLanguage = attributeChangeMap.get(LANG_IDENTIFYER);
        if (!userLanguage.equals(inputLanguage)) {
          Preferences preferences = user.getPreferences();
          preferences.setLanguage(inputLanguage);
          user.setPreferences(preferences);
        }
      }

      Context vcContext = new VelocityContext();
      // set all properties as context
      setUserContext(identity, vcContext, isAdministrativeUser);
      // loop for each property configured in
      // src/serviceconfig/org/olat/_spring/olat_userconfig.xml -> Key:
      // org.olat.admin.user.bulkChange.UserBulkChangeStep00
      for (int k = 0; k < userPropertyHandlers.size(); k++) {
        UserPropertyHandler propHandler = userPropertyHandlers.get(k);
        String propertyName = propHandler.getName();
        String userValue = identity.getUser().getProperty(propertyName, null);
        String inputFieldValue = "";
        if (attributeChangeMap.containsKey(propertyName)) {
          inputFieldValue = attributeChangeMap.get(propertyName);
          inputFieldValue = inputFieldValue.replace("$", "$!");
          String evaluatedInputFieldValue = evaluateValueWithUserContext(inputFieldValue, vcContext)
         
          // validate evaluated property-value
          ValidationError validationError = new ValidationError();
          // do validation checks with users current locale!
          Locale locale = transWithFallback.getLocale();
          if (!propHandler.isValidValue(evaluatedInputFieldValue, validationError, locale)) {
            errorDesc = transWithFallback.translate(validationError.getErrorKey()) + " (" + evaluatedInputFieldValue + ")";
            updateError = true;
            break;
          }

          if (!evaluatedInputFieldValue.equals(userValue)) {
            String stringValue = propHandler.getStringValue(evaluatedInputFieldValue, locale);
              propHandler.setUserProperty(user, stringValue);
          }
        }

      } // for (propertyHandlers)

      // set roles for identity
      // loop over securityGroups defined above
      for (String securityGroup : securityGroups) {
        SecurityGroup secGroup = secMgr.findSecurityGroupByName(securityGroup);
        Boolean isInGroup = secMgr.isIdentityInSecurityGroup(identity, secGroup);
        String thisRoleAction = "";
        if (roleChangeMap.containsKey(securityGroup)) {
          thisRoleAction = roleChangeMap.get(securityGroup);
          // user not anymore in security group, remove him
          if (isInGroup && thisRoleAction.equals("remove")) secMgr.removeIdentityFromSecurityGroup(identity, secGroup);
          // user not yet in security group, add him
          if (!isInGroup && thisRoleAction.equals("add")) secMgr.addIdentityToSecurityGroup(identity, secGroup);
        }
      }
     
      // set status
      if (roleChangeMap.containsKey("Status")) {
        Integer status = Integer.parseInt(roleChangeMap.get("Status"));
        secMgr.saveIdentityStatus(identity, status);
        identity = (Identity) db.loadObject(identity);
      }

      // persist changes:
      if (updateError) {
        String errorOutput = identity.getName() + ": " + errorDesc;
        log.debug("error during bulkChange of users, following user could not be updated: " + errorOutput);
        notUpdatedIdentities.add(errorOutput);
      } else {
        um.updateUserFromIdentity(identity);
        changedIdentities.add(identity);
        log.audit("user successfully changed during bulk-change: " + identity.getName());
      }

      // commit changes for this user
      db.intermediateCommit();
    }

  }
View Full Code Here

  /**
   * @see org.olat.group.context.BGContextManager#getGroupsOfBGContext(org.olat.group.context.BGContext)
   */
  public List<BusinessGroup> getGroupsOfBGContext(BGContext bgContext) {
    DB db = DBFactory.getInstance();
    DBQuery query;
    if (bgContext == null) {
      String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext is null";
      query = db.createQuery(q);
    } else {
      String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context";
      query = db.createQuery(q);
      query.setEntity("context", bgContext);
    }
    return (List<BusinessGroup>) query.list();
  }
View Full Code Here

  /**
   * @see org.olat.group.context.BGContextManager#countGroupsOfBGContext(org.olat.group.context.BGContext)
   */
  public int countGroupsOfBGContext(BGContext bgContext) {
    DB db = DBFactory.getInstance();
    String q = "select count(bg) from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context";
    DBQuery query = db.createQuery(q);
    query.setEntity("context", bgContext);
    return ((Long) query.list().get(0)).intValue();
  }
View Full Code Here

  /**
   * @see org.olat.group.context.BGContextManager#countGroupsOfType(java.lang.String)
   */
  public int countGroupsOfType(String groupType) {
    DB db = DBFactory.getInstance();
    String q = "select count(bg) from org.olat.group.BusinessGroupImpl bg where bg.type = :type";
    DBQuery query = db.createQuery(q);
    query.setString("type", groupType);
    return ((Long) query.list().get(0)).intValue();
  }
View Full Code Here

  /**
   * @see org.olat.group.context.BGContextManager#findGroupOfBGContext(java.lang.String,
   *      org.olat.group.context.BGContext)
   */
  public BusinessGroup findGroupOfBGContext(String groupName, BGContext bgContext) {
    DB db = DBFactory.getInstance();
    String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context and bg.name = :name";
    DBQuery query = db.createQuery(q);
    query.setEntity("context", bgContext);
    query.setString("name", groupName);
    List results = query.list();
    if (results.size() == 0) return null;
    return (BusinessGroup) results.get(0);
View Full Code Here

TOP

Related Classes of org.olat.core.commons.persistence.DB

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.