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;
  }
  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;
  }
  /**
   * Update the configuration of an existing capability.
   *
   * @param capabilityId ID of capability to update.
   */
  @Override
  @PUT
  @ResourceMethodSignature(
      pathParams = {@PathParam(CapabilityPlexusResource.CAPABILITIES_ID_KEY)},
      input = CapabilityRequestResource.class,
      output = CapabilityStatusResponseResource.class)
  public Object put(
      final Context context, final Request request, final Response response, final Object payload)
      throws ResourceException {
    final CapabilityRequestResource envelope = (CapabilityRequestResource) payload;
    final CCapability capability = asCCapability(envelope.getData());
    try {
      capabilitiesConfiguration.update(capability);
      capabilitiesConfiguration.save();

      final CapabilityStatusResponseResource result =
          asCapabilityStatusResponseResource(
              capability,
              createChildReference(request, this, capability.getId()).toString(),
              capabilityDescriptorRegistry);
      return result;
    } catch (final InvalidConfigurationException e) {
      handleConfigurationException(e);
      return null;
    } catch (final IOException e) {
      throw new ResourceException(
          Status.SERVER_ERROR_INTERNAL,
          "Could not manage capabilities configuration persistence store");
    }
  }
  private void convertToKazuki(final File configFile) throws Exception {
    try (Reader r = new FileReader(configFile);
        FileInputStream is = new FileInputStream(configFile);
        Reader fr = new InputStreamReader(is)) {

      Xpp3DomBuilder.build(r);
      Configuration configuration = new NexusCapabilitiesConfigurationXpp3Reader().read(fr);
      List<CCapability> capabilities = configuration.getCapabilities();

      if (capabilities != null) {
        for (final CCapability c : capabilities) {

          // NEXUS-6349: do not convert outreach related capabilities and let outreach plugin
          // recreate them
          if ("OutreachMarkerCapability".equals(c.getTypeId())
              || "OutreachManagementCapability".equals(c.getTypeId())) {
            continue;
          }

          Map<String, String> properties = Maps.newHashMap();
          if (c.getProperties() != null) {
            for (final CCapabilityProperty property : c.getProperties()) {
              properties.put(property.getKey(), property.getValue());
            }
          }

          capabilityStorage.add(
              new CapabilityStorageItem(
                  c.getVersion(), c.getTypeId(), c.isEnabled(), c.getNotes(), properties));
        }
        log.info("Converted {} capabilities from capabilities.xml to Kazuki", capabilities.size());
      }
    }
  }
  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;
  }
  static CCapability asCCapability(final CapabilityResource resource) {
    assert resource != null : "Resource cannot be null";

    final CCapability capability = new CCapability();

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

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

        capability.addProperty(capabilityProp);
      }
    }

    return capability;
  }
 private CCapability asCCapability(final String id, final CapabilityStorageItem item) {
   final CCapability capability = new CCapability();
   capability.setId(id);
   capability.setVersion(item.getVersion());
   capability.setTypeId(item.getType());
   capability.setEnabled(item.isEnabled());
   capability.setNotes(item.getNotes());
   if (item.getProperties() != null) {
     for (Map.Entry<String, String> entry : item.getProperties().entrySet()) {
       final CCapabilityProperty property = new CCapabilityProperty();
       property.setKey(entry.getKey());
       property.setValue(entry.getValue());
       capability.addProperty(property);
     }
   }
   return capability;
 }