Exemplo n.º 1
0
  public void activate(final DateTimeFormatter formatter, final LocalDate activationLocalDate) {
    if (isActive()) {
      final String defaultUserMessage = "Cannot activate group. Group is already active.";
      final ApiParameterError error =
          ApiParameterError.parameterError(
              "error.msg.group.already.active",
              defaultUserMessage,
              "activationDate",
              activationLocalDate.toString(formatter));

      final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
      dataValidationErrors.add(error);

      throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    if (isDateInTheFuture(activationLocalDate)) {

      final String defaultUserMessage = "Activation date cannot be in the future.";
      final ApiParameterError error =
          ApiParameterError.parameterError(
              "error.msg.group.activationDate.in.the.future",
              defaultUserMessage,
              "activationDate",
              activationLocalDate);

      final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
      dataValidationErrors.add(error);

      throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    this.activationDate = activationLocalDate.toDate();
    this.status = GroupingTypeStatus.ACTIVE.getValue();
  }
  @Transactional
  @Override
  @CacheEvict(value = "usersByUsername", allEntries = true)
  public CommandProcessingResult createUser(final JsonCommand command) {

    try {
      this.context.authenticatedUser();

      this.fromApiJsonDeserializer.validateForCreate(command.json());

      final String officeIdParamName = "officeId";
      final Long officeId = command.longValueOfParameterNamed(officeIdParamName);

      final Office userOffice = this.officeRepository.findOne(officeId);
      if (userOffice == null) {
        throw new OfficeNotFoundException(officeId);
      }

      final String[] roles = command.arrayValueOfParameterNamed("roles");
      final Set<Role> allRoles = assembleSetOfRoles(roles);

      final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command);
      final Boolean sendPasswordToEmail =
          command.booleanObjectValueOfParameterNamed("sendPasswordToEmail");
      this.userDomainService.create(appUser, sendPasswordToEmail);

      return new CommandProcessingResultBuilder() //
          .withCommandId(command.commandId()) //
          .withEntityId(appUser.getId()) //
          .withOfficeId(userOffice.getId()) //
          .build();
    } catch (final DataIntegrityViolationException dve) {
      handleDataIntegrityIssues(command, dve);
      return CommandProcessingResult.empty();
    } catch (final PlatformEmailSendException e) {
      final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();

      final String email = command.stringValueOfParameterNamed("email");
      final ApiParameterError error =
          ApiParameterError.parameterError(
              "error.msg.user.email.invalid", "The parameter email is invalid.", "email", email);
      dataValidationErrors.add(error);

      throw new PlatformApiDataValidationException(
          "validation.msg.validation.errors.exist",
          "Validation errors exist.",
          dataValidationErrors);
    }
  }
Exemplo n.º 3
0
 public static void validateClientImageNotEmpty(final String imageFileName) {
   final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
   if (imageFileName == null) {
     final StringBuilder validationErrorCode =
         new StringBuilder("validation.msg.clientImage.cannot.be.blank");
     final StringBuilder defaultEnglishMessage =
         new StringBuilder("The parameter image cannot be blank.");
     final ApiParameterError error =
         ApiParameterError.parameterError(
             validationErrorCode.toString(), defaultEnglishMessage.toString(), "image");
     dataValidationErrors.add(error);
     throw new PlatformApiDataValidationException(
         "validation.msg.validation.errors.exist",
         "Validation errors exist.",
         dataValidationErrors);
   }
 }
  private String validateColumn(
      final ResultsetColumnHeaderData columnHeader,
      final String pValue,
      final String dateFormat,
      final Locale clientApplicationLocale) {

    String paramValue = pValue;
    if (columnHeader.isDateDisplayType()
        || columnHeader.isIntegerDisplayType()
        || columnHeader.isDecimalDisplayType()) {
      paramValue = paramValue.trim();
    }

    if (StringUtils.isEmpty(paramValue) && columnHeader.isMandatory()) {

      final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
      final ApiParameterError error =
          ApiParameterError.parameterError(
              "error.msg.column.mandatory", "Mandatory", columnHeader.getColumnName());
      dataValidationErrors.add(error);
      throw new PlatformApiDataValidationException(
          "validation.msg.validation.errors.exist",
          "Validation errors exist.",
          dataValidationErrors);
    }

    if (StringUtils.isNotEmpty(paramValue)) {

      if (columnHeader.hasColumnValues()) {
        if (columnHeader.isCodeValueDisplayType()) {

          if (columnHeader.isColumnValueNotAllowed(paramValue)) {
            final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
            final ApiParameterError error =
                ApiParameterError.parameterError(
                    "error.msg.invalid.columnValue",
                    "Value not found in Allowed Value list",
                    columnHeader.getColumnName(),
                    paramValue);
            dataValidationErrors.add(error);
            throw new PlatformApiDataValidationException(
                "validation.msg.validation.errors.exist",
                "Validation errors exist.",
                dataValidationErrors);
          }

          return paramValue;
        } else if (columnHeader.isCodeLookupDisplayType()) {

          final Integer codeLookup = Integer.valueOf(paramValue);
          if (columnHeader.isColumnCodeNotAllowed(codeLookup)) {
            final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
            final ApiParameterError error =
                ApiParameterError.parameterError(
                    "error.msg.invalid.columnValue",
                    "Value not found in Allowed Value list",
                    columnHeader.getColumnName(),
                    paramValue);
            dataValidationErrors.add(error);
            throw new PlatformApiDataValidationException(
                "validation.msg.validation.errors.exist",
                "Validation errors exist.",
                dataValidationErrors);
          }

          return paramValue;
        } else {
          throw new PlatformDataIntegrityException(
              "error.msg.invalid.columnType.",
              "Code: "
                  + columnHeader.getColumnName()
                  + " - Invalid Type "
                  + columnHeader.getColumnType()
                  + " (neither varchar nor int)");
        }
      }

      if (columnHeader.isDateDisplayType()) {
        final LocalDate tmpDate =
            helper.convertFrom(
                paramValue, columnHeader.getColumnName(), dateFormat, clientApplicationLocale);
        if (tmpDate == null) {
          paramValue = null;
        } else {
          paramValue = tmpDate.toString();
        }
      }

      if (columnHeader.isIntegerDisplayType()) {
        Integer tmpInt =
            helper.convertToInteger(
                paramValue, columnHeader.getColumnName(), clientApplicationLocale);
        if (tmpInt == null) {
          paramValue = null;
        } else {
          paramValue = tmpInt.toString();
        }
      }

      if (columnHeader.isDecimalDisplayType()) {
        BigDecimal tmpDecimal =
            helper.convertFrom(paramValue, columnHeader.getColumnName(), clientApplicationLocale);
        if (tmpDecimal == null) {
          paramValue = null;
        } else {
          paramValue = tmpDecimal.toString();
        }
      }
    }

    return paramValue;
  }