Sam Adams avatar Sam Adams committed 2857429

Fix to SwordClient package deposit

Comments (0)

Files changed (3)

compchem-importer/src/main/java/net/chempound/compchem/CompChemImporter.java

 
 import static org.xmlcml.cml.base.CMLConstants.CML_XPATH;
 
-public class CompChemImporter extends CmlImporter {
+public abstract class CompChemImporter extends CmlImporter {
 
     private String id;
 
         this.id = id;
     }
 
+    protected abstract String generateId();
+
+    protected String generateFilename(final String extension) {
+        return (getId() == null ? generateId() : getId()) + extension;
+    }
+
     public DepositRequest generateDepositRequest() throws Exception {
         final Document doc = generateCml();
         return generateDepositRequest(doc);
     }
 
     public DepositRequest generateDepositRequest(final Document doc) throws Exception {
-        final String cmlPath = getId() == null ? "output.cml" : getId() + ".cml";
-        cmlResource = createCmlResource(doc, cmlPath);
+        cmlResource = createCmlResource(doc, generateFilename(".cml"));
 
         final List<DepositResource> resources = new ArrayList<DepositResource>();
         addResources(resources);
         final CmlComp2RdfConverter converter = new CmlComp2RdfConverter();
         final Model model = converter.generateModel(jobList, URI.create(""));
 
-        final LocalResource rdfResource = writeRdf(getId()+".rdf", model);
+        final LocalResource rdfResource = writeRdf(generateFilename(".rdf"), model);
         depositRequest.addResource(rdfResource);
 
-        createImageResources(doc, getId());
+        createImageResources(doc, getId() == null ? generateId() : getId());
 
         final ChempoundAggregation item = depositRequest.getResourceMetadata();
 //        addResources(depositRequest, item);

compchem-importer/src/main/java/net/chempound/compchem/GaussianLogImporter.java

 import nu.xom.Document;
 import nu.xom.Element;
 import nu.xom.Node;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOUtils;
 import org.xmlcml.cml.base.CMLUtil;
 import org.xmlcml.cml.converters.compchem.gaussian.log.GaussianLog2XMLConverter;
     }
 
     @Override
+    protected String generateId() {
+        final String filename = logFile.getPath();
+        final String ext = FilenameUtils.getExtension(filename).toLowerCase();
+        if ("log".equals(ext) || "txt".equals(ext) || "out".equals(ext) || "gau".equals(ext)) {
+            final int l = filename.length();
+            return filename.substring(0, l-(ext.length()+1));
+        }
+        return filename;
+    }
+
+    @Override
     protected Document generateCml() throws Exception {
         if (logFile == null) {
             throw new IllegalStateException("Logfile must be specifed");

compchem-importer/src/main/java/net/chempound/compchem/NWChemLogImporter.java

 import nu.xom.Document;
 import nu.xom.Element;
 import nu.xom.ParsingException;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOUtils;
 import org.xmlcml.cml.converters.compchem.nwchem.log.NWChemLog2XMLConverter;
 import org.xmlcml.cml.converters.compchem.nwchem.log.NWChemLogXML2CompchemConverter;
     }
 
     @Override
+    protected String generateId() {
+        final String filename = logFile.getPath();
+        final String ext = FilenameUtils.getExtension(filename).toLowerCase();
+        if ("log".equals(ext) || "txt".equals(ext) || "out".equals(ext)) {
+            final int l = filename.length();
+            return filename.substring(0, l-(ext.length()+1));
+        }
+        return filename;
+    }
+
+    @Override
     protected Document generateCml() throws IOException, ParsingException {
         final Element cml = convertLogToCml(logFile);
         final Document doc = reloadCml(cml);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.