public void validateInviteUsers(InviteCommand command, MessageContext context) {
    if (!StringUtils.hasLength(command.getEmails())) {
      context.addMessage(
          new MessageBuilder()
              .error()
              .defaultText("Turite nurodyti bent vieną e-pašto adresą")
              .build());
      return;
    }

    StringTokenizer t = new StringTokenizer(command.getEmails());

    while (t.hasMoreTokens()) {
      String email = t.nextToken();
      EmailAddress a = new EmailAddress(email);
      logger.debug("validating email " + email);
      if (!a.isValid()) {
        context.addMessage(
            new MessageBuilder()
                .error()
                .defaultText(
                    "Nurodytas adresas \""
                        + email
                        + "\" neatitinka e-pašto adresų standarto. Ištrinkite arba pataisykite jį ir mėginkite dar kartą.")
                .build());
      }
    }
  }
Ejemplo n.º 2
0
 public void validateSelectFileStep(ValidationContext context) {
   MessageContext messageContext = context.getMessageContext();
   if (file == null || file.getSize() <= 0) {
     messageContext.addMessage(
         new MessageBuilder()
             .error()
             .source("file")
             .code("errors.importexport.mandatory_file")
             .build());
   }
 }
 /**
  * Adds a warning message to the message context.
  *
  * @param context Message context.
  * @param warning Warning message.
  */
 protected static void addMessageDescriptorToMessageContext(
     final MessageContext context, final MessageDescriptor warning) {
   final MessageBuilder builder =
       new MessageBuilder()
           .warning()
           .code(warning.getCode())
           .defaultText(warning.getDefaultMessage())
           .args((Object[]) warning.getParams());
   context.addMessage(builder.build());
 }
  /**
   * Spring Web Flow activated validation (validate + ${state}). Validates 'personForm' view state
   * after binding to person.
   */
  public void validatePersonForm(Person person, MessageContext context) {
    if (!StringUtils.hasText(person.getFirstName())) {
      context.addMessage(
          new MessageBuilder()
              .error()
              .source("firstName")
              .code("person.form.firstName.error")
              .build());
    }

    if (!StringUtils.hasText(person.getLastName())) {
      context.addMessage(
          new MessageBuilder()
              .error()
              .source("lastName")
              .code("person.form.lastName.error")
              .build());
    }
  }
Ejemplo n.º 5
0
 /**
  * Validates the dining information entered in the <code>enterDiningInformation</code> state of
  * the <code>newReward</code> flow.
  *
  * @param messageContext a message context that allows you to build validation error messages
  */
 public void validateEnterDiningInformation(MessageContext messageContext) {
   if (StringUtils.hasText(creditCardNumber)) {
     if (creditCardNumber.length() != 16) {
       messageContext.addMessage(
           new MessageBuilder()
               .error()
               .source("creditCardNumber")
               .code("error.invalidFormat.DiningForm.creditCardNumber")
               .build());
     }
   }
 }
  public void setConfirmationMessage(
      final ServiceExecutionResult<Person> serviceExecutionResult,
      final ReconciliationResult reconciliationResult,
      final MessageContext context) {
    // if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
    // a force add, would result in no reconciliationResult.

    if (reconciliationResult != null) {
      if (reconciliationResult.getReconciliationType()
              == ReconciliationResult.ReconciliationType.EXACT
          || reconciliationResult.getReconciliationType()
              == ReconciliationResult.ReconciliationType.MAYBE) {
        context.addMessage(new MessageBuilder().info().code("roleAdded").build());
        return;
      }
    }

    final Person person = serviceExecutionResult.getTargetObject();
    final Identifier netId =
        person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);

    if (person.getCurrentActivationKey() != null) {
      final MessageResolver message =
          new MessageBuilder()
              .info()
              .code("personAddedFinalConfirm")
              .arg(netId.getValue())
              .arg(person.getCurrentActivationKey().asString())
              .build();
      context.addMessage(message);
    } else {
      context.addMessage(
          new MessageBuilder()
              .info()
              .code("personAddedFinalConfirm")
              .arg(netId.getValue())
              .arg("TempKey")
              .build());
    }
  }
  @Override
  public Boolean checkRegistratorByEmailAndRefCode(Person registrator, MessageContext context) {
    // now find the person
    Person p =
        personRepository.findByEmailAndRegistrationInfo_refCode(
            registrator.getEmail(), registrator.getRegistrationInfo().getRefCode());

    if (p != null && p.getId() != null) {
      // registrator = p;
      // logger.debug(registrator.getTitleDisplayValue());
      return true;
    }

    context.addMessage(
        new MessageBuilder()
            .error()
            .defaultText(
                "There is no record of such Email and Invoice Number, Please Enter both information again.")
            .build());
    return false;
  }
 /**
  * validateDeliveryOptions
  *
  * @param deliveryOptions a {@link org.opennms.reporting.core.DeliveryOptions} object.
  * @param context a {@link org.springframework.binding.validation.ValidationContext} object.
  */
 public void validateDeliveryOptions(DeliveryOptions deliveryOptions, ValidationContext context) {
   MessageContext messages = context.getMessageContext();
   if (!((deliveryOptions.getSendMail() | deliveryOptions.getPersist()))) {
     messages.addMessage(
         new MessageBuilder()
             .error()
             .source("sendMail")
             .defaultText("one of send mail or persist should be selected")
             .build());
     messages.addMessage(
         new MessageBuilder()
             .error()
             .source("persist")
             .defaultText("one of send mail or persist should be selected")
             .build());
   } else {
     if (deliveryOptions.getSendMail() && (deliveryOptions.getMailTo() == "")) {
       messages.addMessage(
           new MessageBuilder()
               .error()
               .source("mailTo")
               .defaultText("cannot have empty mail recipient")
               .build());
     }
   }
   if (deliveryOptions.getInstanceId().length() == 0) {
     messages.addMessage(
         new MessageBuilder()
             .error()
             .source("instanceId")
             .defaultText("cannot have an empty Id for the report instance")
             .build());
   } else if (m_reportSchedulerService.exists(deliveryOptions.getInstanceId())) {
     messages.addMessage(
         new MessageBuilder()
             .error()
             .source("instanceId")
             .defaultText("report instanceId is already in use")
             .build());
   }
 }