/**
   * This replaces an existing list property def with a new list property definition. Primarily it
   * replaces the member prop def for the list. If the member prop def is a nested structure the
   * whole thing is replaced from the top.
   *
   * @param exList the existing prop def list
   * @param newList the new prop def list
   */
  private void replaceListProperty(PropertyDefinitionList exList, PropertyDefinitionList newList) {
    PropertyDefinition doomedMemberDef = null;

    if (newList.getMemberDefinition() == null) {
      log.error(
          "\n\n!! Member definition for new list property ["
              + newList.getName()
              + "] is null - check and fix the plugin descriptor\n");
      return;
    }

    // We did not have a member definition before (which is wrong )
    // we need to add it now
    // only remove the existing member if it is a different entity
    PropertyDefinition exListMemberDefinition = exList.getMemberDefinition();
    if (exListMemberDefinition != null
        && exListMemberDefinition.getId() != newList.getMemberDefinition().getId()) {
      doomedMemberDef = exListMemberDefinition;
    }

    exList.setMemberDefinition(newList.getMemberDefinition());
    exList.setMax(newList.getMax());
    exList.setMin(newList.getMin());

    // BZ 594706
    // Don't clean this up here because it's causing deadlocks in Oracle.  Instead we'll just leave
    // garbage in the db.  Although annoying, and confusing for db queries, it's not a lot of data,
    // just some extra prop defs and prop_def_enums.
    if (null != doomedMemberDef) {
      // entityManager.remove(doomedMemberDef);
      if (log.isDebugEnabled()) {
        log.debug("Ignoring cleanup of [" + doomedMemberDef + "] due to BZ 594706");
      }
    }

    entityManager.merge(exList);
  }
  private static PropertyDefinitionList createExcludes(
      ConfigurationDefinition configDef, boolean readOnly) {
    String name = PROP_EXCLUDES;
    String description = "A set of patterns that specify files and/or directories to exclude.";
    boolean required = false;

    PropertyDefinitionMap map = createExclude(readOnly);

    PropertyDefinitionList pd = new PropertyDefinitionList(name, description, required, map);
    pd.setDisplayName("Excludes");
    pd.setReadOnly(readOnly);
    pd.setSummary(true);
    pd.setOrder(9);
    pd.setConfigurationDefinition(configDef);
    return pd;
  }
Beispiel #3
0
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {
    report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
    Address createAddress = new Address(this.address);

    String path = report.getPluginConfiguration().getSimpleValue("path", "");
    String resourceName;
    if (!path.contains("=")) {
      // this is not a singleton subsystem
      // resources like  example=test1 and example=test2 can be created
      resourceName = report.getUserSpecifiedResourceName();
    } else {
      // this is a request to create a true singleton subsystem
      // both the path and the name are set at resource level configuration
      resourceName = path.substring(path.indexOf('=') + 1);
      path = path.substring(0, path.indexOf('='));
    }

    createAddress.add(path, resourceName);

    Operation op = new Operation("add", createAddress);
    for (Property prop : report.getResourceConfiguration().getProperties()) {
      SimpleEntry<String, ?> entry = null;

      boolean isEntryEligible = true;
      if (prop instanceof PropertySimple) {
        PropertySimple propertySimple = (PropertySimple) prop;
        PropertyDefinitionSimple propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionSimple(propertySimple.getName());

        if (propertyDefinition == null
            || (!propertyDefinition.isRequired() && propertySimple.getStringValue() == null)) {
          isEntryEligible = false;
        } else {
          entry = preparePropertySimple(propertySimple, propertyDefinition);
        }
      } else if (prop instanceof PropertyList) {
        PropertyList propertyList = (PropertyList) prop;
        PropertyDefinitionList propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionList(propertyList.getName());

        if (!propertyDefinition.isRequired() && propertyList.getList().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyList(propertyList, propertyDefinition);
        }
      } else if (prop instanceof PropertyMap) {
        PropertyMap propertyMap = (PropertyMap) prop;
        PropertyDefinitionMap propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionMap(propertyMap.getName());

        if (!propertyDefinition.isRequired() && propertyMap.getMap().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyMap(propertyMap, propertyDefinition);
        }
      }

      if (isEntryEligible) {
        op.addAdditionalProperty(entry.getKey(), entry.getValue());
      }
    }

    Result result = this.connection.execute(op);
    if (result.isSuccess()) {
      report.setStatus(CreateResourceStatus.SUCCESS);
      report.setResourceKey(createAddress.getPath());
      report.setResourceName(report.getUserSpecifiedResourceName());
    } else {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(result.getFailureDescription());
    }

    return report;
  }