예제 #1
0
  /**
   * Write config resources to disk.
   *
   * @param dependency the dependency
   * @param config the config
   * @param outputLocation the output location
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public static void writeConfigResourcesToDisk(
      Dependency dependency, List<ConfigurationResource> config, File outputLocation)
      throws IOException {
    String value = null;
    TransferSignature.ValueType valueType = null;
    for (ConfigurationResource portRef : config) {
      if (portRef.getReferableResource().getId().equals(dependency.getId())) {
        value = portRef.getValue();

        ConfigurationResource.RefTypes refType = portRef.getRefType();
        System.out.println("Value for " + portRef.getId() + " : " + value);

        if (refType == ConfigurationResource.RefTypes.INLINE_REF) {
          valueType = TransferSignature.ValueType.INLINE_STRING;

        } else if (refType == ConfigurationResource.RefTypes.URI_REF) {
          File success = download(value, new File("."), null);
          if (success.exists()) {
            System.out.println("Fetched " + value + " to " + success.getAbsolutePath());
            value = success.getAbsolutePath();
          } else {
            System.out.println("Failed to fetch " + value);
          }

          valueType = TransferSignature.ValueType.INLINE_URI;
        } else if (refType == ConfigurationResource.RefTypes.FILE_REF) {
          valueType = TransferSignature.ValueType.BUNDLED_FILE;
          //                            File tempFile = DataUtils.extractToTempFile(portRef);
          File tempFile = writeConfigurationResourceToFile(portRef, null, outputLocation);
          value = tempFile.getAbsolutePath();
        }
      }
    }
  }
예제 #2
0
  /**
   * Compile outputs.
   *
   * @param outputResources the output resources
   * @param outputNodeMap the output node map
   * @return the hash map
   */
  public HashMap<Node, Object> compileOutputs(
      HashMap<String, ConfigurationResource> outputResources, HashMap<String, Node> outputNodeMap) {
    HashMap<Node, Object> outputs = new HashMap<Node, Object>();
    System.out.println(outputResources.size() + " output objects.");
    for (String nodeName : outputResources.keySet()) {
      Node node = outputNodeMap.get(nodeName);
      ConfigurationResource resource = outputResources.get(nodeName);
      String resourceString = resource.getValue();

      if (resource.getRefType() == ConfigurationResource.RefTypes.INLINE_REF) {
        outputs.put(node, resourceString);
      } else if (resource.getRefType() == ConfigurationResource.RefTypes.URI_REF) {
        outputs.put(node, resourceString);
      } else if (resource.getRefType() == ConfigurationResource.RefTypes.FILE_REF) {
        //                String outputString = new String(resource.getBundleFile().getBytes());
        //                System.out.println("BundleFile at node : " + node + " contains : " +
        // outputString);
        //                outputs.put(node, outputString);
        String tempBundleLocation = resource.getBundleFile().getSystemPath();
        System.out.println(
            "BundleFile at node : " + node + " temp location : " + tempBundleLocation);
        String outputString = BundleUtils.readFile(tempBundleLocation);
        outputs.put(node, outputString);
      }

      System.out.println(
          "Node "
              + node.getAbsoluteNodeIndex()
              + " named : "
              + nodeName
              + " outputs : "
              + outputs.get(node));
    }
    return outputs;
  }
예제 #3
0
  /**
   * Creates the transfer signature.
   *
   * @param workflow the workflow
   * @param configuration the configuration
   * @return the transfer signature
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public TransferSignature createTransferSignature(ConcreteTask workflow, Mapping configuration)
      throws IOException {
    TransferSignature signature = new TransferSignature();

    signature.setName(workflow.getDefinition().getFilename());

    if (workflow.getLanguage() != null) {
      signature.setLanguage(workflow.getLanguage().toString());
    }

    for (ReferableResource referableResource : workflow.getSignature().getPorts()) {
      if (referableResource instanceof InputPort) {
        String value = null;
        boolean isReference = false;

        if (configuration != null) {
          for (ConfigurationResource portRef : configuration.getResources()) {
            System.out.println(
                portRef.getReferableResource().getId() + " " + referableResource.getId());
            if (portRef.getReferableResource().getId().equals(referableResource.getId())) {
              value = portRef.getValue();
              isReference = (portRef.getRefType() == ConfigurationResource.RefTypes.FILE_REF);
            }
          }
        }

        if (value != null) {
          if (isReference) {
            signature.addInputReference(
                referableResource.getTitle(), referableResource.getDataType(), value);
          } else {
            signature.addInput(
                referableResource.getTitle(), referableResource.getDataType(), value);
          }
        } else {
          signature.addInput(referableResource.getTitle(), referableResource.getDataType());
        }
      } else if (referableResource instanceof OutputPort) {
        signature.addOutput(referableResource.getTitle(), referableResource.getDataType());
      }
    }

    //        for (Dependency dependency : workflow.getDependencies()) {
    //            String value = null;
    //            TransferSignature.ValueType valueType = null;
    //
    //            if (configuration != null) {
    //                for (ConfigurationResource portRef :
    // getFirstConfigurationOfType(Configuration.ConfigType.ENVIRONMENT_CONFIGURATION).getResources()) {
    //                    if (portRef.getReferableResource().getId().equals(dependency.getId())) {
    //                        value = portRef.getValue();
    //
    //                        ConfigurationResource.RefTypes refType = portRef.getRefType();
    //                        System.out.println("Value for " + portRef.getId() + " : " + value);
    //
    //                        if(refType == ConfigurationResource.RefTypes.INLINE_REF){
    //                            valueType = TransferSignature.ValueType.INLINE_STRING;
    //
    //                        } else if (refType == ConfigurationResource.RefTypes.URI_REF){
    //                            File success = download(value, new File("."), null);
    //                            if(success.exists()){
    //                                System.out.println("Fetched " + value + " to " +
    // success.getAbsolutePath());
    //                                value = success.getAbsolutePath();
    //                            } else {
    //                                System.out.println("Failed to fetch " + value);
    //                            }
    //
    //                            valueType = TransferSignature.ValueType.INLINE_URI;
    //                        } else if (refType == ConfigurationResource.RefTypes.FILE_REF){
    //                            valueType =  TransferSignature.ValueType.BUNDLED_FILE;
    ////                            File tempFile = DataUtils.extractToTempFile(portRef);
    //                            File tempFile = writeConfigurationResourceToFile(portRef, null);
    //                            value = tempFile.getAbsolutePath();
    //                        }
    //                    }
    //                }
    //            }

    //            signature.addOutput(dependency.getTitle(),
    //                    dependency.getDataType(),
    //                    dependency.getDescription(),
    //                    value,
    //                    valueType
    //            );
    //        }

    if (configuration != null) {
      signature.setHasConfiguration(true);
    }
    return signature;
  }