Github user stain commented on a diff in the pull request:
https://github.com/apache/incubator-taverna-common-activities/pull/13#discussion_r70511075
--- Diff:
taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
---
@@ -16,72 +16,103 @@
*******************************************************************************/
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.util.ArrayList;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
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.yaml.snakeyaml.Yaml;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
import
net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
import net.sf.taverna.t2.servicedescriptions.ConfigurableServiceProvider;
public class CwlServiceProvider extends
AbstractConfigurableServiceProvider<CwlServiceProviderConfig>
implements
ConfigurableServiceProvider<CwlServiceProviderConfig> {
-
+
+ public static final String TOOL_NAME="toolName";
+ public static final String MAP ="map";
+ private static Logger logger =
Logger.getLogger(CwlServiceProvider.class);
+
CwlServiceProvider() {
super(new CwlServiceProviderConfig());
}
- 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 =
URI.create("http://cwl.com/2016/service-provider/cwlcommandlinetools");
@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();
-
- for (File file : cwlFiles) {
- Map cwlFile = 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);
- }
-
+ Path path = Paths.get(getConfiguration().getPath());
+ //figure out the dots in the path ex: /maanadev/../cwltools
+ Path normalizedPath = path.normalize();
+
+ DirectoryStream<Path> stream = null;
+ try {
+ 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 {
+ cwlFile = (Map) reader.load(new
FileInputStream(path.toFile()));
+ JsonNode config =
createJsonNode(p,cwlFile);
+ // Creating CWl service Description
--- End diff --
Great - this should load the Yaml in parallell - assuming `getYamlReader()`
is thread-safe?
Instead of `new FileInputStream(path.toFile())` you can do
`Files.newInputStream(path)` - which should be wrapped in a (try...) resources
block to ensure the input stream is closed. (e.g. `try (InputStream is =
Files.newInputStream(path)`).
---
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 [email protected] or file a JIRA ticket
with INFRA.
---