コード例 #1
0
 public static AbstractPropertyValue getDefaultPropertyValueFromPropertyDefinition(
     PropertyDefinition propertyDefinition) {
   if (propertyDefinition == null) {
     return null;
   }
   Object defaultValue = propertyDefinition.getDefault();
   if (defaultValue == null) {
     return null;
   }
   return (AbstractPropertyValue) defaultValue;
 }
  @ApiIgnore
  @RequestMapping(
      value = "/deployment-prop-check",
      method = RequestMethod.POST,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  @PreAuthorize("isAuthenticated()")
  public RestResponse<ConstraintUtil.ConstraintInformation> checkPluginDeploymentProperties(
      @ApiParam(
              value = "Id of the orchestrators for which to check deployment property.",
              required = true)
          @PathVariable
          @Valid
          @NotEmpty
          String orchestratorId,
      @ApiParam(value = "Value and id of the property to check.", required = true)
          @Valid
          @NotEmpty
          @RequestBody
          PropertyRequest deploymentPropertyValidationRequest) {
    Map<String, PropertyDefinition> deploymentPropertyDefinitions =
        orchestratorDeploymentService.getDeploymentPropertyDefinitions(orchestratorId);

    if (deploymentPropertyDefinitions != null) {
      PropertyDefinition propertyDefinition =
          deploymentPropertyDefinitions.get(deploymentPropertyValidationRequest.getDefinitionId());
      if (propertyDefinition != null && propertyDefinition.getConstraints() != null) {
        try {
          constraintPropertyService.checkSimplePropertyConstraint(
              deploymentPropertyValidationRequest.getDefinitionId(),
              deploymentPropertyValidationRequest.getValue(),
              propertyDefinition);
        } catch (ConstraintViolationException e) {
          log.error(
              "Constraint violation error for property <"
                  + deploymentPropertyValidationRequest.getDefinitionId()
                  + "> with value <"
                  + deploymentPropertyValidationRequest.getValue()
                  + ">",
              e);
          return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder()
              .data(e.getConstraintInformation())
              .error(
                  RestErrorBuilder.builder(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR)
                      .message(e.getMessage())
                      .build())
              .build();
        } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
          log.error(
              "Constraint value violation error for property <"
                  + e.getConstraintInformation().getName()
                  + "> with value <"
                  + e.getConstraintInformation().getValue()
                  + "> and type <"
                  + e.getConstraintInformation().getType()
                  + ">",
              e);
          return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder()
              .data(e.getConstraintInformation())
              .error(
                  RestErrorBuilder.builder(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR)
                      .message(e.getMessage())
                      .build())
              .build();
        }
      }
    }
    return RestResponseBuilder.<ConstraintUtil.ConstraintInformation>builder().build();
  }