1. Chempound
  2. Untitled project
  3. crystallography

Commits

Sam Adams  committed efafde3

Updates for CLI tools

  • Participants
  • Parent commits 73122bd
  • Branches default

Comments (0)

Files changed (1)

File crystallography-importer/src/main/java/net/chempound/crystal/importer/CrystalStructureImporter.java

View file
 import net.chempound.rdf.DCTerms;
 import net.chempound.rdf.chempound.ChempoundAggregation;
 import net.chempound.storage.InMemoryResource;
+import net.chempound.storage.LocalFileResource;
 import net.chempound.storage.LocalResource;
 import nu.xom.Element;
 import nu.xom.ParsingException;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xmlcml.cif.CIF;
 
 import javax.inject.Inject;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 
     private static final Logger LOG = LoggerFactory.getLogger(CrystalStructureImporter.class);
 
+    private String id;
+    private String title;
+
+    private LocalResource cifResource;
+    private LocalResource cmlResource;
+
     public CrystalStructureImporter() {
         this(new ImageGenerator(), new InChIGenerator());
     }
 
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(final String id) {
+        this.id = id;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(final String title) {
+        this.title = title;
+    }
+
+
+    public LocalResource getCifResource() {
+        return cifResource;
+    }
+
+    public void setCifResource(final LocalResource cifResource) {
+        this.cifResource = cifResource;
+    }
+
+    public void setCifResource(final String filename, final File file) {
+        final LocalFileResource resource = new LocalFileResource(filename, file);
+        resource.setMimeType(ChemicalMime.CHEMICAL_CIF);
+        this.cifResource = resource;
+    }
+
+    public LocalResource getCmlResource() {
+        return cmlResource;
+    }
+
+    public void setCmlResource(final LocalResource cmlResource) {
+        this.cmlResource = cmlResource;
+    }
+
+
     @Inject
     public CrystalStructureImporter(final ImageGenerator imageGenerator, final InChIGenerator inChIGenerator) {
         super(imageGenerator, inChIGenerator);
 
     }
 
+    public DepositRequest build() throws IOException, CIFException, ParsingException {
+
+        final InputStream in = cifResource.openInputStream();
+        final CIF cif;
+        try {
+            cif = CifIO.readCif(in, "UTF-8");
+        } finally {
+            IOUtils.closeQuietly(in);
+        }
+
+        final String id = this.id == null ? FilenameUtils.getBaseName(cifResource.getPath()) : this.id;
+
+        return generateDepositRequest(cif, id);
+    }
+
+
 
     public DepositRequest generateDepositRequest(final InputStream in, final String id) throws IOException, ParsingException, CIFException {
         final CIF cif = CifIO.readCif(in, "UTF-8");
 
     public DepositRequest generateDepositRequest(final CIF cif, final String id) throws IOException, ParsingException {
 
-        final LocalResource cifResource = createCifResource(cif, id+".cif");
+        final LocalResource cifResource = this.cifResource == null ? createCifResource(cif, id+".cif") : this.cifResource;
 
         final CMLCml completeCml = convertCifToCompleteCml(cif);
         attachIdentifiers(completeCml);