public ValidationResponse validate(final CCapability capability, final boolean isCreateMode) {
    final ValidationResponse response = new ValidationResponse();

    if (!isCreateMode && StringUtils.isEmpty(capability.getId())) {
      final ValidationMessage msg = new ValidationMessage("id", "Capability ID cannot be empty.");

      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(capability.getName())) {
      final ValidationMessage msg =
          new ValidationMessage("name", "Capability name cannot be empty.");

      response.addValidationError(msg);
    }
    if (StringUtils.isEmpty(capability.getTypeId())) {
      final ValidationMessage msg =
          new ValidationMessage("typeId", "Capability type cannot be empty.");

      response.addValidationError(msg);
    }

    for (final CCapabilityProperty property : capability.getProperties()) {
      if (StringUtils.isEmpty(property.getKey())) {
        final ValidationMessage msg =
            new ValidationMessage("type", "Capability properties cannot cannot have an empty key.");

        response.addValidationError(msg);
        break;
      }
    }

    return response;
  }
Пример #2
0
  private static CapabilityResponseResource asCapabilityResponseResource(
      final CCapability capability) {
    assert capability != null : "Capability cannot be null";

    final CapabilityResource resource = new CapabilityResource();

    resource.setId(capability.getId());
    resource.setName(capability.getName());
    resource.setTypeId(capability.getTypeId());

    if (capability.getProperties() != null) {
      for (final CCapabilityProperty propery : capability.getProperties()) {
        final CapabilityPropertyResource resourceProp = new CapabilityPropertyResource();
        resourceProp.setKey(propery.getKey());
        resourceProp.setValue(propery.getValue());

        resource.addProperty(resourceProp);
      }
    }

    final CapabilityResponseResource response = new CapabilityResponseResource();
    response.setData(resource);

    return response;
  }
Пример #3
0
  static CapabilityListItemResource asCapabilityListItemResource(
      final CCapability capability,
      final String uri,
      final CapabilityDescriptorRegistry capabilityDescriptorRegistry) {
    assert capability != null : "Capability cannot be null";

    final CapabilityListItemResource item = new CapabilityListItemResource();
    item.setId(capability.getId());
    item.setName(capability.getName());
    item.setTypeId(capability.getTypeId());
    item.setTypeName(capabilityDescriptorRegistry.get(capability.getTypeId()).name());

    item.setResourceURI(uri);

    return item;
  }