예제 #1
0
 /** {@inheritDoc} */
 @Override
 public UserDetails loadUserByUsername(String userName)
     throws UsernameNotFoundException, DataAccessException {
   User u = userDAO.getUser(userName);
   if (u == null) {
     log.warn("User " + userName + " not found.");
     throw new UsernameNotFoundException("User " + userName + " not found.");
   }
   log.info("User " + userName + " found, id " + u.getId().toString() + ".");
   return new UserDetails(u);
 }
  /** {@inheritDoc} */
  @Override
  public void executeAction(Session sesh, Threshold threshold, Object entity, Action action)
      throws ClassNotFoundException {

    String entityDisplayName =
        String.format(
            propertyService.getMessage(
                entity.getClass().getCanonicalName(), entity.getClass().getName()));
    String subject =
        String.format(
            propertyService.getMessage("action.handler.email.subject.template"), entityDisplayName);

    StringBuilder builder = new StringBuilder();

    if (entity instanceof User) {
      User u = (User) entity;
      // No need for null checks. These fields are non nullable
      // in the User model object.
      builder.append(String.format("First Name : %s%n", u.getFirstName()));
      builder.append(String.format("Last Name : %s%n", u.getLastName()));
      builder.append(String.format("Login : %s%n", u.getName()));
      builder.append(String.format("Email : %s%n%n", u.getEmailAddress()));
    }

    for (Condition condition : threshold.getConditions()) {

      builder.append(condition.getPropertyPath());
      if (condition.isSimplePropertyType()) {
        builder.append(
            String.format(
                SIMPLE_PROPERTY_TEMPLATE,
                condition.getValueOperator().getDisplayText(),
                condition.getValue()));
      } else {
        ComplexTypeOperator operator = condition.getComplexTypeOperator();
        builder.append(
            String.format(
                COMPLEX_PROPERTY_TEMPLATE,
                operator.getKeyLabel(),
                condition.getKeyOperator().getDisplayText(),
                condition.getKey(),
                operator.getValueLabel(),
                condition.getValueOperator().getDisplayText(),
                condition.getValue()));
      }
    }

    String message =
        String.format(
            propertyService.getMessage("action.handler.email.message.template"),
            entityDisplayName,
            builder.toString());
    emailService.sendMessage(action.getValue(), null, subject, message);
  }