private boolean addCompositeResource(
     final String profileName,
     final ModelControllerClient client,
     final Resource resource,
     final String parentAddress,
     final CompositeOperationBuilder compositeOp,
     final boolean checkExistence)
     throws IOException {
   final String inputAddress;
   if (parentAddress == null) {
     inputAddress = resource.getAddress();
   } else if (parentAddress.equals(resource.getAddress())) {
     inputAddress = resource.getAddress();
   } else if (resource.getAddress() == null) {
     inputAddress = parentAddress;
   } else {
     inputAddress = String.format("%s,%s", parentAddress, resource.getAddress());
   }
   // The address cannot be null
   if (inputAddress == null) {
     throw new RuntimeException("You must specify the address to deploy the resource to.");
   }
   final ModelNode address = parseAddress(profileName, inputAddress);
   if (checkExistence) {
     final boolean exists = resourceExists(address, client);
     if (resource.isAddIfAbsent() && exists) {
       return false;
     }
     if (exists && force) {
       reportFailure(client.execute(ServerOperations.createRemoveOperation(address, true)));
     } else if (exists && !force) {
       throw new RuntimeException(String.format("Resource %s already exists.", address));
     }
   }
   compositeOp.addStep(buildAddOperation(address, resource.getProperties()));
   if (resource.getResources() != null) {
     final String resourceAddress = resource.getAddress();
     final String addr;
     if (parentAddress != null && resourceAddress != null) {
       addr = parentAddress + "," + resourceAddress;
     } else if (parentAddress != null) {
       addr = parentAddress;
     } else if (resourceAddress != null) {
       addr = resourceAddress;
     } else {
       addr = null;
     }
     for (Resource r : resource.getResources()) {
       addCompositeResource(profileName, client, r, addr, compositeOp, false);
     }
   }
   return true;
 }
Esempio n. 2
0
  public static DataTypeLists<String> getPropertiesByDataType(ResourceSet resourceSet) {

    if (resourceSet.isEmpty()) {
      return new DataTypeLists<String>();
    }

    // no aggregation
    DataTypeLists<String> result = new DataTypeLists<String>();
    Resource resource = resourceSet.getFirstElement();

    if (resource == null) {
      return result;
    }

    for (Entry<String, Serializable> entry : resource.getProperties().entrySet()) {

      Serializable value = entry.getValue();
      String propertyName = entry.getKey();

      if (value instanceof String) {
        result.get(DataType.TEXT).add(propertyName);
      }
      if (value instanceof Double) {
        result.get(DataType.NUMBER).add(propertyName);
      }
      if (value instanceof Resource) {
        Resource r = (Resource) value;

        if (r.getValue(LATITUDE) != null && r.getValue(LONGITUDE) != null) {

          result.get(DataType.LOCATION).add(propertyName);
        }
      }
      if (value instanceof Date) {
        result.get(DataType.DATE).add(propertyName);
      }
    }

    return result;
  }
Esempio n. 3
0
  // XXX why isn't this using the same code as getPropertiesByDataType?
  public static List<String> getPropertyNamesForDataType(
      ResourceSet resourceSet, DataType dataType) {

    if (resourceSet.isEmpty()) {
      return Collections.emptyList();
    }

    // no aggregation
    Resource resource = resourceSet.getFirstElement();
    List<String> properties = new ArrayList<String>();

    for (Entry<String, Serializable> entry : resource.getProperties().entrySet()) {

      switch (dataType) {
        case TEXT:
          {
            if (entry.getValue() instanceof String) {
              properties.add(entry.getKey());
            }
          }
          break;
        case NUMBER:
          {
            if (entry.getValue() instanceof Double) {
              properties.add(entry.getKey());
            }
          }
          break;
        case LOCATION:
          {
            if (entry.getValue() instanceof Resource) {
              Resource r = (Resource) entry.getValue();

              if (r.getValue(LATITUDE) != null && r.getValue(LONGITUDE) != null) {

                properties.add(entry.getKey());
              }
            }
          }
          break;
        case DATE:
          {
            if (entry.getValue() instanceof Date) {
              properties.add(entry.getKey());
            }
          }
          break;
        case COLOR:
          {
            if (entry.getValue() instanceof Color) {
              properties.add(entry.getKey());
            }
          }

        case SHAPE:
          {
            if (entry.getValue() instanceof String && isShape(entry.getValue())) {
              properties.add(entry.getKey());
            }
          }
      }
    }
    return properties;
  }
 protected Database(Resource resource) {
   super(resource.getProperties(), resource.getDescriptors());
   if (!checkResource(resource))
     throw new IllegalArgumentException("Incorrect database resource definition.");
 }