X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.fileimport%2Fsrc%2Forg%2Fsimantics%2Ffileimport%2FSimanticsResourceFileImport.java;h=eea85d47d9f559e9306193b5bbdc328559ac99eb;hp=2836b670e5f0e5b5198b2cce95e01d97e8d39a07;hb=55ca14c4198659b908aeffc8d16e240b35a75e66;hpb=96bb7ef9cbe42d82eb58306d8f9b62392cc29ba8 diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsResourceFileImport.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsResourceFileImport.java index 2836b670e..eea85d47d 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsResourceFileImport.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsResourceFileImport.java @@ -19,13 +19,27 @@ import org.simantics.db.request.Read; import org.simantics.db.service.SerialisationSupport; import org.simantics.layer0.Layer0; +/** + * Most of the implementations should extend this class which handles the storing of + * the identifier of the imported entity and the removing of the entity + * + * @author Jani Simomaa + * + */ public abstract class SimanticsResourceFileImport implements IGenericFileImport { @Override final public Optional perform(Path file) throws Exception { - Path dropins = Activator.getDropinsFolder(); - Path parts = dropins.relativize(file); + Path dropins = Activator.getDropinsFolder(); + + Path parts; + if (file.toAbsolutePath().toString().startsWith(dropins.toAbsolutePath().toString())) { + parts = dropins.relativize(file); + } else { + parts = file.getFileName(); + } + Resource parent = resolveParent(null, parts); if (parent == null) return Optional.empty(); @@ -37,7 +51,15 @@ public abstract class SimanticsResourceFileImport implements IGenericFileImport } } - public abstract Optional perform(Resource parent, Path file); + /** + * Performs the import for the given file + * + * @param parent Resource parent of the imported entity in Simantics database + * @param file Path file location of file + * @return Optional Resource of the imported entity in Simantics database + * @throws Exception + */ + public abstract Optional perform(Resource parent, Path file) throws Exception; @Override public void remove(String resourceId) throws Exception {