Switch to side-by-side view

--- a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/provenance/ProvenanceAccessClient.java
+++ b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/provenance/ProvenanceAccessClient.java
@@ -11,6 +11,7 @@
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -190,6 +191,9 @@
 
                 Identified identified = pc.getReferenceService().resolveIdentifier(ref, null, ic);
                 if (identified instanceof ReferenceSet) {
+
+                    LOGGER.info("try to fetch reference set for binding "+binding.getPortName());
+
                     ReferenceSet referenceSet = (ReferenceSet) identified;
                     Set<ExternalReferenceSPI> externalReferences = referenceSet.getExternalReferences();
 
@@ -197,6 +201,7 @@
                         if (externalReference instanceof ValueCarryingExternalReference<?>) {
                             ValueCarryingExternalReference<?> vcer = (ValueCarryingExternalReference<?>) externalReference;
 
+
                             // string ? filepath or URL
                             if (String.class.isAssignableFrom(vcer.getValueType())) {
 
@@ -204,15 +209,19 @@
 
                                 // valid file ?
                                 File file = isFile(possibleFilePath);
-                                if (file != null) {
+                                if (file != null && file.length() > 0) {
 
                                     LOGGER.debug("\t Found file (" + file.getPath() + ") for port= "
                                             + binding.getPortName());
 
-                                    fileName += "[" + binding.getPortName() + "]-";
-                                    File tmpFile = File.createTempFile(fileName.toString(), ".file", tempDir.toFile());
-
-                                    FileUtils.copyFile(file, tmpFile);
+                                    fileName += "[" + binding.getProcessorName() + "][" + binding.getPortName() + "]-";
+                                    File tmpFile = File.createTempFile(fileName, ".file", tempDir.toFile());
+
+                                    try {
+                                        FileUtils.copyFile(file, tmpFile);
+                                    } catch (IOException e) {
+                                        LOGGER.error("Error during fetching file. " + e.getMessage());
+                                    }
                                     fileName = "";
                                 }
 
@@ -224,7 +233,7 @@
                                             + binding.getPortName());
 
                                     // download file and copy it to temp directory
-                                    fileName += "[" + binding.getPortName() + "]-";
+                                    fileName += "[" + binding.getProcessorName() + "][" + binding.getPortName() + "]-";
                                     File content = File.createTempFile(fileName, ".url", tempDir.toFile());
                                     FileUtils.copyURLToFile(url, content);
 
@@ -240,7 +249,7 @@
 
                                 fileName += "[" + binding.getPortName() + "]-";
                                 byte[] content = (byte[]) vcer.getValue();
-                                File tmpFile = File.createTempFile(fileName.toString(), ".binary", tempDir.toFile());
+                                File tmpFile = File.createTempFile(fileName, ".binary", tempDir.toFile());
                                 FileUtils.writeByteArrayToFile(tmpFile, content);
 
                                 LOGGER.debug("\t Create " + fileName + " file for port= " + binding.getPortName());
@@ -405,28 +414,39 @@
      */
     private File isFile(String possibleFilePath) {
 
-        String regexPath = "([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?";
-
-        if (possibleFilePath != null && possibleFilePath.length() > 5 && possibleFilePath.contains(File.separator)
-                && Pattern.matches(regexPath, possibleFilePath)) {
-
-            LOGGER.debug("\t Detect if file path (" + possibleFilePath + ") point to a file. ");
-            try {
-                // can we create a file of the possibleFilePath
-                File file = new File(possibleFilePath);
-                if (!file.isDirectory()) {
-                    return file;
-                }
-
-            } catch (Exception e) {
-                LOGGER.debug("\t File can not be detected. " + e.getMessage());
-                return null;
-            }
-        }
-        return null;
+        LOGGER.debug("call isFile(" + possibleFilePath + ")");
+
+        LOGGER.debug("\t Detect if file path (" + possibleFilePath + ") point to a file. ");
+        try {
+            return Paths.get(possibleFilePath).toFile();
+        } catch (Exception e) {
+            LOGGER.debug("\t File can not be detected. " + e.getMessage());
+            return null;
+        }
+
+//        String regexPath = "([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?";
+//
+//        if (possibleFilePath != null && possibleFilePath.length() > 5 && possibleFilePath.contains(File.separator)
+//                && Pattern.matches(regexPath, possibleFilePath)) {
+//
+//            LOGGER.debug("\t Detect if file path (" + possibleFilePath + ") point to a file. ");
+//            try {
+//                // can we create a file of the possibleFilePath
+//                File file = new File(possibleFilePath);
+//                if (!file.isDirectory()) {
+//                    return file;
+//                }
+//
+//            } catch (Exception e) {
+//                LOGGER.debug("\t File can not be detected. " + e.getMessage());
+//                return null;
+//            }
+//        }
     }
 
     private URL isURL(String possibleURL) {
+
+        LOGGER.debug("call isURL(" + possibleURL + ")");
 
         String regexURL = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
 
@@ -437,7 +457,7 @@
             try {
                 return new URL(possibleURL);
             } catch (MalformedURLException e) {
-                LOGGER.debug("\t Not a valid URL.");
+                LOGGER.debug("\t Not a valid URL. "+e.getMessage());
             }
         }
         return null;