Github user stain commented on a diff in the pull request:

    
https://github.com/apache/incubator-taverna-common-activities/pull/13#discussion_r72437990
  
    --- Diff: 
taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
 ---
    @@ -16,72 +16,167 @@
      
*******************************************************************************/
     package org.apache.taverna.cwl.ui.serviceprovider;
     
    -import java.io.File;
     import java.io.FileInputStream;
    -import java.io.FileNotFoundException;
    -import java.io.FilenameFilter;
    +import java.io.IOException;
     import java.net.URI;
    +import java.nio.file.DirectoryStream;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.nio.file.Paths;
     import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Iterator;
     import java.util.List;
     import java.util.Map;
    +import java.util.stream.Stream;
    +import java.util.stream.StreamSupport;
     
     import javax.swing.Icon;
     
    +import org.apache.log4j.Logger;
    +import org.apache.taverna.scufl2.api.common.Visitor;
    +import org.apache.taverna.scufl2.api.configurations.Configuration;
    +import 
org.apache.taverna.servicedescriptions.AbstractConfigurableServiceProvider;
    +import org.apache.taverna.servicedescriptions.ConfigurableServiceProvider;
    +import org.apache.taverna.servicedescriptions.ServiceDescriptionProvider;
     import org.yaml.snakeyaml.Yaml;
     
    -import 
net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
    -import net.sf.taverna.t2.servicedescriptions.ConfigurableServiceProvider;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ObjectNode;
     
    -public class CwlServiceProvider extends 
AbstractConfigurableServiceProvider<CwlServiceProviderConfig>
    -           implements 
ConfigurableServiceProvider<CwlServiceProviderConfig> {
    +public class CwlServiceProvider extends 
AbstractConfigurableServiceProvider implements ConfigurableServiceProvider {
    +
    +   public static final String TOOL_NAME = "toolName";
    +   public static final String CWL_CONF = "cwl_conf";
    +   public static final String CWL_PATH = "cwl_path";
    +
    +   public static final String DEFAULT_PATH_1 = "/usr/share/commonwl/";
    +   public static final String DEFAULT_PATH_2 = 
"/usr/local/share/commonwl/";
    +   public static final String XDF_DATA_HOME = "XDF_DATA_HOME";
    +   public static final String COMMONWL = "commonwl/";
    +   private static Logger logger = 
Logger.getLogger(CwlServiceProvider.class);
     
        CwlServiceProvider() {
    -           super(new CwlServiceProviderConfig());
    +           // FIXME
    +           super(getDefaultConfiguration());
        }
    -   private static final String providerName ="CWL Services";
    -   private static final URI providerId = URI
    -                   
.create("http://cwl.com/2016/service-provider/cwlcommandlinetools";);
    -   private File cwlFilesLocation;
    +
    +   private static final String providerName = "CWL Services";
    +   private static final URI providerId = 
CwlServiceDesc.ACTIVITY_TYPE.resolve("#provider");
     
        @Override
        public void 
findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
     
                // get the location of the cwl tool from the workbench
    -           cwlFilesLocation = new File(getConfiguration().getPath());
    -           // This is holding the CWL configuration beans
    -           List<CwlServiceDesc> result = new ArrayList<CwlServiceDesc>();
    -
    -           File[] cwlFiles = getCwlFiles();
    -
    -           // Load the CWL file using SnakeYaml lib
    -           Yaml cwlReader = new Yaml();
    +           ArrayList<Path> paths = getPath();
     
    -           for (File file : cwlFiles) {
    -                   Map cwlFile = null;
    +           for (Path path : paths) {
    +                   // figure out the dots in the path ex: 
/maanadev/../cwltools
    +                   Path normalizedPath = path.normalize();
     
    +                   DirectoryStream<Path> stream = null;
                        try {
    -                           cwlFile = (Map) cwlReader.load(new 
FileInputStream(file));
    -                   } catch (FileNotFoundException e) {
    -                           e.printStackTrace();
    -                   }
    -                   if (cwlFile != null) {
    -                           // Creating CWl service Description
    -                           CwlServiceDesc cwlServiceDesc = new 
CwlServiceDesc();
    -                           cwlServiceDesc.setCwlConfiguration(cwlFile);
    -                           
cwlServiceDesc.setToolName(file.getName().split("\\.")[0]);
    -
    -                           // add to the result
    -                           result.add(cwlServiceDesc);
    -                           // return the service description
    -                           callBack.partialResults(result);
    +                           stream = 
Files.newDirectoryStream(normalizedPath, "*.cwl");
    +                   } catch (IOException e) {
    +                           logger.warn("Path is not correct !");
    +                           return;
                        }
    +                   // create stream with parallel capabilities
    +                   Stream<Path> paralleStream = 
StreamSupport.stream(stream.spliterator(), true);
    +
    +                   paralleStream.forEach(p -> {
    +                           Yaml reader = getYamlReader();
    +
    +                           Map cwlFile;
    +                           try (FileInputStream file = new 
FileInputStream(path.toFile())) {
    +                                   cwlFile = (Map) reader.load(file);
    +                                   JsonNode config = createJsonNode(p, 
cwlFile);
    +                                   // Creating CWl service Description
    +                                   CwlServiceDesc cwlServiceDesc = 
createCWLDesc(config);
    +                                   // return the service description
    +                                   
callBack.partialResults(Arrays.asList(cwlServiceDesc));
    +
    +                           } catch (IOException e) {
    +
    +                                   logger.warn("File not Found !");
     
    +                           }
    +
    +                   });
    +
    +                   callBack.finished();
                }
    -           callBack.finished();
     
        }
    +/**
    + * This method checks whether provided path is valid or not and if it's 
valid the it's added to the list
    + * @param defaultPaths arrylist to hold valid paths
    + * @param path 
    + * @param path1 if there is no second path argument this should be set to 
null
    + */
    +   public void addPath(ArrayList<Path> defaultPaths, String path, String 
path1) {
    +
    +           Path defaultPath;
    +           if (path1 == null)
    +                   defaultPath = Paths.get(path);
    +           else
    +                   defaultPath = Paths.get(path, path1);
    +
    +           if (defaultPath.isAbsolute())
    +                   defaultPaths.add(defaultPath);
    +   }
     
    -   
    +   private ArrayList<Path> getPath() {
    --- End diff --
    
    Return as interface `List<Path>` instead of hard-coding `ArrayList` - we 
don't need ArrayList-specific features.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to