@Override
  public Authentication attemptAuthentication(
      HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    if (!request.getMethod().equals("POST")) {
      throw new AuthenticationServiceException(
          "Authentication method not supported: " + request.getMethod());
    }

    String username = obtainUsername(request);
    String password = obtainPassword(request);

    // Validates username and password
    username = username.trim();

    User user = UserUtil.getUser(username);
    Md5PasswordEncoder encoder = new Md5PasswordEncoder();
    password = encoder.encodePassword(password, AuthenticationFilter.SALT);
    if (user == null || !user.getPassword().equals(password)) {
      throw new AuthenticationServiceException("password or username is notEquals");
    }

    UsernamePasswordAuthenticationToken authRequest =
        new UsernamePasswordAuthenticationToken(username, password);

    setDetails(request, authRequest);

    // return authRequest;
    return this.getAuthenticationManager().authenticate(authRequest);
  }
Example #2
0
 /**
  * Selects the entities
  *
  * @return the SUCCESS result
  */
 public String load() throws ServiceException {
   ActionContext context = ActionContext.getContext();
   Map<String, Object> session = context.getSession();
   User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);
   this.userID = loginUser.getId();
   return SUCCESS;
 }
Example #3
0
 /**
  * Gets the list data.
  *
  * @return null
  */
 public String listFew() throws Exception {
   UserUtil.permissionCheck("view_document");
   User loginUser = UserUtil.getLoginUser();
   SearchCondition searchCondition = getFewSearchCondition(loginUser.getScope_task(), loginUser);
   String hql = "select new Document(id,name) from Document";
   SearchResult<Document> result =
       baseService.getPaginationObjectsWithHql(CLAZZ, hql, searchCondition);
   Iterator<Document> tasks = result.getResult().iterator();
   getJson(tasks);
   return null;
 }
Example #4
0
  /**
   * Gets the list data.
   *
   * @return null
   */
  public String listFull() throws Exception {
    UserUtil.permissionCheck("view_document");
    User loginUser = UserUtil.getLoginUser();
    int scope = loginUser.getScope_document();
    StringBuilder hqlBuilder = new StringBuilder("select new Document(id,name) from Document");

    if (scope == Role.OWNER_OR_DISABLED) {
      hqlBuilder.append(" where owner = ").append(loginUser.getId());
    }
    hqlBuilder.append(" order by created_on desc");
    List<Document> result = baseService.findByHQL(hqlBuilder.toString());
    documents = result.iterator();
    return SUCCESS;
  }
 /**
  * Gets the entity.
  *
  * @return the SUCCESS result
  */
 public String get() throws Exception {
   if (this.getId() != null) {
     targetList = baseService.getEntityById(TargetList.class, this.getId());
     User assignedTo = targetList.getAssigned_to();
     if (assignedTo != null) {
       this.setAssignedToID(assignedTo.getId());
       this.setAssignedToText(assignedTo.getName());
     }
     this.getBaseInfo(targetList, TargetList.class.getSimpleName(), Constant.CRM_NAMESPACE);
   } else {
     this.initBaseInfo();
   }
   return SUCCESS;
 }
  /**
   * Gets the list data.
   *
   * @return null
   */
  public String listFull() throws Exception {
    UserUtil.permissionCheck("view_targetList");

    Map<String, String> fieldTypeMap = new HashMap<String, String>();
    fieldTypeMap.put("created_on", Constant.DATA_TYPE_DATETIME);
    fieldTypeMap.put("updated_on", Constant.DATA_TYPE_DATETIME);

    User loginUser = UserUtil.getLoginUser();
    SearchCondition searchCondition =
        getSearchCondition(fieldTypeMap, loginUser.getScope_targetList(), loginUser);
    SearchResult<TargetList> result = baseService.getPaginationObjects(CLAZZ, searchCondition);
    Iterator<TargetList> targetLists = result.getResult().iterator();
    long totalRecords = result.getTotalRecords();
    getListJson(targetLists, totalRecords, searchCondition, true);
    return null;
  }
Example #7
0
  /** Mass update entity record information */
  public String massUpdate() throws Exception {
    saveEntity();
    String[] fieldNames = this.massUpdate;
    if (fieldNames != null) {
      Collection<String> feildNameCollection = new ArrayList<String>();
      for (int i = 0; i < fieldNames.length; i++) {
        feildNameCollection.add(fieldNames[i]);
        if ("reminder_pop".equals(fieldNames[i])) {
          feildNameCollection.add("reminder_email");
          feildNameCollection.add("reminder_option_pop");
          feildNameCollection.add("reminder_option_email");
        }
      }

      String[] selectIDArray = this.seleteIDs.split(",");
      Collection<Call> calls = new ArrayList<Call>();
      User loginUser = this.getLoginUser();
      User user = userService.getEntityById(User.class, loginUser.getId());
      Collection<ChangeLog> allChangeLogs = new ArrayList<ChangeLog>();
      for (String IDString : selectIDArray) {
        int id = Integer.parseInt(IDString);
        Call callInstance = this.baseService.getEntityById(Call.class, id);
        Call originalCall = callInstance.clone();
        for (String fieldName : feildNameCollection) {
          Object value = BeanUtil.getFieldValue(call, fieldName);
          BeanUtil.setFieldValue(callInstance, fieldName, value);
        }
        callInstance.setUpdated_by(user);
        callInstance.setUpdated_on(new Date());
        Collection<ChangeLog> changeLogs = changeLog(originalCall, callInstance);
        allChangeLogs.addAll(changeLogs);
        calls.add(callInstance);
      }
      final Collection<ChangeLog> changeLogsForSave = allChangeLogs;
      if (calls.size() > 0) {
        this.baseService.batchUpdate(calls);
        taskExecutor.execute(
            new Runnable() {
              public void run() {
                batchInserChangeLogs(changeLogsForSave);
              }
            });
      }
    }
    return SUCCESS;
  }
Example #8
0
 /**
  * Gets the entity.
  *
  * @return the SUCCESS result
  */
 public String get() throws Exception {
   if (this.getId() != null) {
     UserUtil.permissionCheck("view_call");
     call = baseService.getEntityById(Call.class, this.getId());
     UserUtil.scopeCheck(call, "scope_call");
     CallStatus status = call.getStatus();
     if (status != null) {
       statusID = status.getId();
     }
     CallDirection direction = call.getDirection();
     if (direction != null) {
       directionID = direction.getId();
     }
     ReminderOption reminderOptionEmail = call.getReminder_option_email();
     if (reminderOptionEmail != null) {
       reminderOptionEmailID = reminderOptionEmail.getId();
     }
     EmailTemplate reminderTemplate = call.getReminder_template();
     if (reminderTemplate != null) {
       reminderTemplateID = reminderTemplate.getId();
     }
     User assignedTo = call.getAssigned_to();
     if (assignedTo != null) {
       this.setAssignedToID(assignedTo.getId());
       this.setAssignedToText(assignedTo.getName());
     }
     Date start_date = call.getStart_date();
     SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT);
     if (start_date != null) {
       startDate = dateFormat.format(start_date);
     }
     String relatedObject = call.getRelated_object();
     Integer relatedRecord = call.getRelated_record();
     if (relatedRecord != null) {
       setRelatedRecord(relatedObject, relatedRecord);
     }
     this.getBaseInfo(call, Call.class.getSimpleName(), Constant.CRM_NAMESPACE);
   } else {
     this.initBaseInfo();
     if (!CommonUtil.isNullOrEmpty(this.getRelationKey())) {
       call.setRelated_object(this.getRelationKey());
       setRelatedRecord(this.getRelationKey(), Integer.parseInt(this.getRelationValue()));
     }
   }
   return SUCCESS;
 }
Example #9
0
 /**
  * Gets the entity.
  *
  * @return the SUCCESS result
  */
 public String get() throws Exception {
   if (this.getId() != null) {
     call = baseService.getEntityById(Call.class, this.getId());
     CallStatus status = call.getStatus();
     if (status != null) {
       statusID = status.getId();
     }
     CallDirection direction = call.getDirection();
     if (direction != null) {
       directionID = direction.getId();
     }
     ReminderOption reminderOptionPop = call.getReminder_option_pop();
     if (reminderOptionPop != null) {
       reminderOptionPopID = reminderOptionPop.getId();
     }
     ReminderOption reminderOptionEmail = call.getReminder_option_email();
     if (reminderOptionEmail != null) {
       reminderOptionEmailID = reminderOptionEmail.getId();
     }
     User user = call.getAssigned_to();
     if (user != null) {
       assignedToID = user.getId();
     }
     Date start_date = call.getStart_date();
     SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yyyy HH:mm:ss");
     if (start_date != null) {
       startDate = dateFormat.format(start_date);
     }
     String relatedObject = call.getRelated_object();
     Integer relatedRecord = call.getRelated_record();
     setRelatedRecord(relatedObject, relatedRecord);
   } else {
     ActionContext context = ActionContext.getContext();
     Map<String, Object> session = context.getSession();
     User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);
     this.assignedToID = loginUser.getId();
     if (!CommonUtil.isNullOrEmpty(this.getRelationKey())) {
       call.setRelated_object(this.getRelationKey());
       setRelatedRecord(this.getRelationKey(), Integer.parseInt(this.getRelationValue()));
     }
   }
   return SUCCESS;
 }
 /** Mass update entity record information */
 public String massUpdate() throws Exception {
   saveEntity();
   String[] fieldNames = this.massUpdate;
   if (fieldNames != null) {
     String[] selectIDArray = this.seleteIDs.split(",");
     Collection<TargetList> targetLists = new ArrayList<TargetList>();
     User loginUser = this.getLoginUser();
     User user = userService.getEntityById(User.class, loginUser.getId());
     Collection<ChangeLog> allChangeLogs = new ArrayList<ChangeLog>();
     for (String IDString : selectIDArray) {
       int id = Integer.parseInt(IDString);
       TargetList targetListInstance = this.baseService.getEntityById(TargetList.class, id);
       TargetList originalTargetList = targetListInstance.clone();
       for (String fieldName : fieldNames) {
         Object value = BeanUtil.getFieldValue(targetList, fieldName);
         BeanUtil.setFieldValue(targetListInstance, fieldName, value);
       }
       targetListInstance.setUpdated_by(user);
       targetListInstance.setUpdated_on(new Date());
       Collection<ChangeLog> changeLogs = changeLog(originalTargetList, targetListInstance);
       allChangeLogs.addAll(changeLogs);
       targetLists.add(targetListInstance);
     }
     final Collection<ChangeLog> changeLogsForSave = allChangeLogs;
     if (targetLists.size() > 0) {
       this.baseService.batchUpdate(targetLists);
       taskExecutor.execute(
           new Runnable() {
             public void run() {
               batchInserChangeLogs(changeLogsForSave);
             }
           });
     }
   }
   return SUCCESS;
 }
Example #11
0
  /**
   * Sends invitation mail to all participants.
   *
   * @return the SUCCESS result
   */
  public String sendInvites() throws Exception {

    UserUtil.permissionCheck("update_call");
    call = baseService.getEntityById(Call.class, call.getId());
    Date start_date = call.getStart_date();
    SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT);
    startDate = "";
    if (start_date != null) {
      startDate = dateFormat.format(start_date);
    }
    this.setId(call.getId());
    ActionContext context = ActionContext.getContext();
    Map<String, Object> session = context.getSession();
    User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);

    StringBuilder targetEmails = new StringBuilder("");
    Set<Contact> contacts = call.getContacts();
    if (contacts != null) {
      for (Contact contact : contacts) {
        String email = contact.getEmail();
        if (CommonUtil.isNullOrEmpty(email)) {
          continue;
        }
        if (targetEmails.length() > 0) {
          targetEmails.append(",");
        }
        targetEmails.append(email);
      }
    }
    Set<Lead> leads = call.getLeads();
    if (leads != null) {
      for (Lead lead : leads) {
        String email = lead.getEmail();
        if (CommonUtil.isNullOrEmpty(email)) {
          continue;
        }
        if (targetEmails.length() > 0) {
          targetEmails.append(",");
        }
        targetEmails.append(email);
      }
    }
    from = loginUser.getEmail();
    if (from == null) {
      from = "";
    }
    Set<User> users = call.getUsers();
    if (users != null) {
      for (User user : users) {
        String email = user.getEmail();
        if (CommonUtil.isNullOrEmpty(email) || (from != null && email.endsWith(from))) {
          continue;
        }
        if (targetEmails.length() > 0) {
          targetEmails.append(",");
        }
        targetEmails.append(email);
      }
    }
    if (targetEmails.length() > 0) {
      to = targetEmails.toString();
    }

    // Gets email template list
    String hql =
        "select new EmailTemplate(id,name) from EmailTemplate where type = 'callInvite' order by created_on";
    emailTemplates = emailTemplateService.findByHQL(hql);
    return SUCCESS;
  }
Example #12
0
  private Collection<ChangeLog> changeLog(Call originalCall, Call call) {
    Collection<ChangeLog> changeLogs = null;
    if (originalCall != null) {
      ActionContext context = ActionContext.getContext();
      Map<String, Object> session = context.getSession();
      String entityName = Call.class.getSimpleName();
      Integer recordID = call.getId();
      User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);
      changeLogs = new ArrayList<ChangeLog>();

      String oldSubject = CommonUtil.fromNullToEmpty(originalCall.getSubject());
      String newSubject = CommonUtil.fromNullToEmpty(call.getSubject());
      if (!oldSubject.equals(newSubject)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName, recordID, "entity.subject.label", oldSubject, newSubject, loginUser);
        changeLogs.add(changeLog);
      }

      String oldStatus = getOptionValue(originalCall.getStatus());
      String newStatus = getOptionValue(call.getStatus());
      if (!oldStatus.equals(newStatus)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName, recordID, "entity.status.label", oldStatus, newStatus, loginUser);
        changeLogs.add(changeLog);
      }

      SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_EDIT_FORMAT);
      String oldStartDateValue = "";
      Date oldStartDate = originalCall.getStart_date();
      if (oldStartDate != null) {
        oldStartDateValue = dateFormat.format(oldStartDate);
      }
      String newStartDateValue = "";
      Date newStartDate = call.getStart_date();
      if (newStartDate != null) {
        newStartDateValue = dateFormat.format(newStartDate);
      }
      if (!oldStartDateValue.equals(newStartDateValue)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.start_date.label",
                oldStartDateValue,
                newStartDateValue,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldRelatedObject = CommonUtil.fromNullToEmpty(originalCall.getRelated_object());
      String newRelatedObject = CommonUtil.fromNullToEmpty(call.getRelated_object());
      if (!oldRelatedObject.equals(newRelatedObject)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.related_object.label",
                oldRelatedObject,
                newRelatedObject,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldRelatedRecord = String.valueOf(originalCall.getRelated_record());
      String newRelatedRecord = String.valueOf(call.getRelated_record());
      if (!oldRelatedRecord.equals(newRelatedRecord)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.related_record.label",
                oldRelatedRecord,
                newRelatedRecord,
                loginUser);
        changeLogs.add(changeLog);
      }

      boolean oldReminderEmail = originalCall.isReminder_email();
      boolean newReminderEmail = call.isReminder_email();
      if (oldReminderEmail != newReminderEmail) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.reminder.label",
                String.valueOf(oldReminderEmail),
                String.valueOf(newReminderEmail),
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldReminderOption = getOptionValue(originalCall.getReminder_option_email());
      String newReminderOption = getOptionValue(call.getReminder_option_email());
      if (!oldReminderOption.equals(newReminderOption)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.reminder_option_email_name.label",
                oldReminderOption,
                newReminderOption,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldReminderTemplateName = "";
      EmailTemplate oldReminderTemplate = originalCall.getReminder_template();
      if (oldReminderTemplate != null) {
        oldReminderTemplateName = CommonUtil.fromNullToEmpty(oldReminderTemplate.getName());
      }
      String newReminderTemplateName = "";
      EmailTemplate newReminderTemplate = call.getReminder_template();
      if (newReminderTemplate != null) {
        newReminderTemplateName = CommonUtil.fromNullToEmpty(newReminderTemplate.getName());
      }
      if (oldReminderTemplateName != newReminderTemplateName) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.reminder_template.label",
                oldReminderTemplateName,
                newReminderTemplateName,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldDescription = CommonUtil.fromNullToEmpty(originalCall.getDescription());
      String newDescription = CommonUtil.fromNullToEmpty(call.getDescription());
      if (!oldDescription.equals(newDescription)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.description.label",
                oldDescription,
                newDescription,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldNotes = CommonUtil.fromNullToEmpty(originalCall.getNotes());
      String newNotes = CommonUtil.fromNullToEmpty(call.getNotes());
      if (!oldNotes.equals(newNotes)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName, recordID, "entity.notes.label", oldNotes, newNotes, loginUser);
        changeLogs.add(changeLog);
      }

      String oldAssignedToName = "";
      User oldAssignedTo = originalCall.getAssigned_to();
      if (oldAssignedTo != null) {
        oldAssignedToName = oldAssignedTo.getName();
      }
      String newAssignedToName = "";
      User newAssignedTo = call.getAssigned_to();
      if (newAssignedTo != null) {
        newAssignedToName = newAssignedTo.getName();
      }
      if (oldAssignedToName != newAssignedToName) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.assigned_to.label",
                CommonUtil.fromNullToEmpty(oldAssignedToName),
                CommonUtil.fromNullToEmpty(newAssignedToName),
                loginUser);
        changeLogs.add(changeLog);
      }
    }
    return changeLogs;
  }
  private Collection<ChangeLog> changeLog(TargetList originalTargetList, TargetList targetList) {
    Collection<ChangeLog> changeLogs = null;
    if (originalTargetList != null) {
      ActionContext context = ActionContext.getContext();
      Map<String, Object> session = context.getSession();
      String entityName = TargetList.class.getSimpleName();
      Integer recordID = targetList.getId();
      User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);
      changeLogs = new ArrayList<ChangeLog>();

      String oldName = CommonUtil.fromNullToEmpty(originalTargetList.getName());
      String newName = CommonUtil.fromNullToEmpty(targetList.getName());
      if (!oldName.equals(newName)) {
        ChangeLog changeLog =
            saveChangeLog(entityName, recordID, "entity.name.label", oldName, newName, loginUser);
        changeLogs.add(changeLog);
      }

      String oldDescription = CommonUtil.fromNullToEmpty(originalTargetList.getDescription());
      String newDescription = CommonUtil.fromNullToEmpty(targetList.getDescription());
      if (!oldDescription.equals(newDescription)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.description.label",
                oldDescription,
                newDescription,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldNotes = CommonUtil.fromNullToEmpty(originalTargetList.getNotes());
      String newNotes = CommonUtil.fromNullToEmpty(targetList.getNotes());
      if (!oldNotes.equals(newNotes)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName, recordID, "entity.notes.label", oldNotes, newNotes, loginUser);
        changeLogs.add(changeLog);
      }

      String oldAssignedToName = "";
      User oldAssignedTo = originalTargetList.getAssigned_to();
      if (oldAssignedTo != null) {
        oldAssignedToName = oldAssignedTo.getName();
      }
      String newAssignedToName = "";
      User newAssignedTo = targetList.getAssigned_to();
      if (newAssignedTo != null) {
        newAssignedToName = newAssignedTo.getName();
      }
      if (oldAssignedToName != newAssignedToName) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.assigned_to.label",
                CommonUtil.fromNullToEmpty(oldAssignedToName),
                CommonUtil.fromNullToEmpty(newAssignedToName),
                loginUser);
        changeLogs.add(changeLog);
      }
    }
    return changeLogs;
  }
  /**
   * Gets the list JSON data.
   *
   * @return list JSON data
   */
  public static void getListJson(
      Iterator<TargetList> targetLists,
      long totalRecords,
      SearchCondition searchCondition,
      boolean isList)
      throws Exception {

    StringBuilder jsonBuilder = new StringBuilder("");
    jsonBuilder.append(getJsonHeader(totalRecords, searchCondition, isList));

    String assignedTo = null;
    while (targetLists.hasNext()) {
      TargetList instance = targetLists.next();
      int id = instance.getId();
      String name = CommonUtil.fromNullToEmpty(instance.getName());
      String description = CommonUtil.fromNullToEmpty(instance.getDescription());
      User user = instance.getAssigned_to();
      if (user != null) {
        assignedTo = user.getName();
      } else {
        assignedTo = "";
      }

      if (isList) {
        User createdBy = instance.getCreated_by();
        String createdByName = "";
        if (createdBy != null) {
          createdByName = CommonUtil.fromNullToEmpty(createdBy.getName());
        }
        User updatedBy = instance.getUpdated_by();
        String updatedByName = "";
        if (updatedBy != null) {
          updatedByName = CommonUtil.fromNullToEmpty(updatedBy.getName());
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT);
        Date createdOn = instance.getCreated_on();
        String createdOnName = "";
        if (createdOn != null) {
          createdOnName = dateFormat.format(createdOn);
        }
        Date updatedOn = instance.getUpdated_on();
        String updatedOnName = "";
        if (updatedOn != null) {
          updatedOnName = dateFormat.format(updatedOn);
        }

        jsonBuilder
            .append("{\"cell\":[\"")
            .append(id)
            .append("\",\"")
            .append(name)
            .append("\",\"")
            .append(description)
            .append("\",\"")
            .append(assignedTo)
            .append("\",\"")
            .append(createdByName)
            .append("\",\"")
            .append(updatedByName)
            .append("\",\"")
            .append(createdOnName)
            .append("\",\"")
            .append(updatedOnName)
            .append("\"]}");
      } else {
        jsonBuilder
            .append("{\"id\":\"")
            .append(id)
            .append("\",\"name\":\"")
            .append(name)
            .append("\",\"assigned_to.name\":\"")
            .append(assignedTo)
            .append("\"}");
      }
      if (targetLists.hasNext()) {
        jsonBuilder.append(",");
      }
    }
    jsonBuilder.append("]}");

    // Returns JSON data back to page
    HttpServletResponse response = ServletActionContext.getResponse();
    response.setContentType("text/html;charset=UTF-8");
    response.getWriter().write(jsonBuilder.toString());
  }