Ejemplo n.º 1
0
 private Criterion findbyAnd(String type, String str) {
   Criterion criterion = null;
   List<String> srch = new ArrayList<String>();
   String[] srchAND = str.split(" and ");
   for (int i = 0; i < srchAND.length; i++) {
     String[] srch_ = srchAND[i].split(" ");
     for (int j = 0; j < srch_.length; j++) {
       if (cn.jsprun.utils.FormDataCheck.isValueString(srch_[j])) {
         srch.add(srch_[j]);
       }
     }
   }
   try {
     Criterion[] criterionArray = new Criterion[srch.size()];
     for (int i = 0; i < srch.size(); i++) {
       Criterion criterionCount = Expression.like(type, srch.get(i), MatchMode.ANYWHERE);
       criterionArray[i] = criterionCount;
     }
     for (int i = 0; i < criterionArray.length; i++) {
       if (i == 0) {
         criterion = Expression.and(criterionArray[i], criterionArray[i++]);
       } else {
         criterion = Expression.and(criterion, criterionArray[i]);
       }
     }
   } catch (HibernateException e) {
     e.printStackTrace();
     criterion = null;
   }
   return criterion;
 }
  @SuppressWarnings({"unchecked"})
  public Object execute(Object o) throws G16CommonBusinessException, HibernateEXC {
    Map<Integer, SystemUserEntity> map = (Map<Integer, SystemUserEntity>) o;
    SystemUserEntity argument = map.get(0);
    /** the username should be ACTIVE */
    argument.setStatus(SystemUserEntity.StatusTypeEnumeration.ACTIVE);

    LOG.info(
        "An attemp for login occured by username="******"; and status is=")
            .concat(argument.getStatus()));
    argument.setPassword(SecurityAlgorithm.encrypt(argument.getPassword()));
    /**
     * Checks the 1) username should be the same as user has been entered 2) password should be the
     * same as user has been entered 3) status should be active.
     */
    return Expression.and(
        Expression.and(
            Expression.eq("userName", argument.getUserName()),
            Expression.eq("password", argument.getPassword())),
        Expression.eq("status", argument.getStatus()));
  }