Files.write(file, bytes);
ConsumerHolder holder = new ConsumerHolder();
- String result = performFileImport(file, Optional.of(holder));
+ String result = performFileImport(file, Optional.empty(), Optional.of(holder));
if (holder.getThrowable() != null)
throw holder.getThrowable();
return result;
}
-
+
/**
* Method that performs the import of the given file. This method is called when e.g. {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_CREATE} operation
*
* @param file Path file to be imported
+ * @param possibleSelection - the selected resource (if exists)
* @param callback Optional callback which can be used to catch Throwables thrown in the import process
*/
- public static String performFileImport(Path file, Optional<Consumer<Throwable>> callback) {
+ public static String performFileImport(Path file, Optional<Resource> possibleSelection, Optional<Consumer<Throwable>> callback) {
if (file.getFileName().toString().equals(DB_FILE)) {
return null;
}
String result = "Import failed";
IGenericFileImport service = findServiceForFileExtension(file);
+
if (service != null) {
try {
- Optional<String> resource = service.perform(file);
+ Optional<String> resource;
+ if (possibleSelection.isPresent() && service.defaultParentResource() == null) {
+ resource = Optional.of(Long.toString(service.perform(possibleSelection.get(), file).get().getResourceId()));
+ }
+ else {
+ resource = service.performWithDefaultParent(file);
+ }
saveResourceForPath(file, resource);
result = resource.get();
} catch (Throwable t) {
}
return result;
}
-
/**
* Remove the entity that matches the file. This method is called when e.g. the {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_DELETE} operation
return Optional.of(value);
}
+ /**
+ * Calls the proper imported without a selection (null possibleSelection)
+ * @param path
+ * @param extension
+ * @return
+ * @throws Exception
+ */
public static String importGenericFileWithExtension(String path, String extension) throws Exception {
IGenericFileImport service = findServiceForExtension(extension);
- Optional<String> result = service.perform(Paths.get(path));
+ Optional<String> result = service.performWithDefaultParent(Paths.get(path));
return result.get();
}
+ /**
+ * Calls the proper imported without a selection (null possibleSelection)
+ * @param parent
+ * @param path
+ * @param extension
+ * @return
+ * @throws Exception
+ */
public static Resource importGenericFileWithExtensionAndParent(Resource parent, String path, String extension) throws Exception {
IGenericFileImport service = findServiceForExtension(extension);
Optional<Resource> result = service.perform(parent, Paths.get(path));