Commits

Sam Adams  committed 02cc3bc

Migrate to new client API

  • Participants
  • Parent commits 5eaa78a

Comments (0)

Files changed (3)

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/cif/DepositCifCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.cif;
 
+import net.chempound.client.DepositItemRequest;
+import net.chempound.client.DepositRequestMapper;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
 import net.chempound.crystal.importer.CrystalStructureImporter;
 import org.apache.commons.io.FilenameUtils;
 
 import java.io.File;
-import java.net.URI;
 
 /**
  * @author Sam Adams
 
     public DepositCifCommand() {
         super(new DepositCifOptions());
-        this.depositOptions = (DepositCifOptions) super.depositOptions;
+        this.depositOptions = (DepositCifOptions) super.options;
     }
 
     @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        final CrystalStructureImporter importer = new CrystalStructureImporter();
+    protected DepositItemRequest createDepositRequest(final GlobalOptions globalOptions) {
+        try {
+            final CrystalStructureImporter importer = new CrystalStructureImporter();
 
-        if (depositOptions.title != null) {
-            importer.setTitle(depositOptions.title);
-        }
-        if (depositOptions.slug != null) {
-            importer.setId(depositOptions.slug);
-        }
+            if (depositOptions.title != null) {
+                importer.setTitle(depositOptions.title);
+            }
+            if (depositOptions.slug != null) {
+                importer.setId(depositOptions.slug);
+            }
 
-        final String filename = depositOptions.files.get(0);
-        final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
-        importer.setCifResource(FilenameUtils.getName(filename), cifFile);
+            final String filename = depositOptions.files.get(0);
+            final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
+            importer.setCifResource(FilenameUtils.getName(filename), cifFile);
 
-        final String url = globalOptions.repository;
-        try {
-            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.build());
-
+            return DepositRequestMapper.map(importer.build());
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new RuntimeException("Error generating deposit", e);
         }
     }
 

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/gaussian/DepositGaussianCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.gaussian;
 
+import net.chempound.client.DepositItemRequest;
+import net.chempound.client.DepositRequestMapper;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
 import net.chempound.compchem.gaussian.GaussianLogImporter;
 import org.apache.commons.io.FilenameUtils;
 
 import java.io.File;
-import java.net.URI;
 
 /**
  * @author Sam Adams
 
     public DepositGaussianCommand() {
         super(new DepositGaussianOptions());
-        this.depositOptions = (DepositGaussianOptions) super.depositOptions;
+        this.depositOptions = (DepositGaussianOptions) super.options;
     }
 
     @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        final GaussianLogImporter importer = new GaussianLogImporter();
+    protected DepositItemRequest createDepositRequest(final GlobalOptions globalOptions) {
+        try {
+            final GaussianLogImporter importer = new GaussianLogImporter();
 
-//        if (depositOptions.title != null) {
-//            importer.setTitle(depositOptions.title);
-//        }
-        if (depositOptions.slug != null) {
-            importer.setId(depositOptions.slug);
-        }
+            if (depositOptions.slug != null) {
+                importer.setId(depositOptions.slug);
+            }
 
-        final String filename = depositOptions.files.get(0);
-        final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
-        importer.setLogFile(cifFile, FilenameUtils.getName(filename));
+            final String filename = depositOptions.files.get(0);
+            final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
+            importer.setLogFile(cifFile, FilenameUtils.getName(filename));
 
-        final String url = globalOptions.repository;
-        try {
-            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.generateDepositRequest());
-
+            return DepositRequestMapper.map(importer.generateDepositRequest());
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new RuntimeException("Error generating deposit", e);
         }
     }
 

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/nwchem/DepositNWChemCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.nwchem;
 
+import net.chempound.client.DepositItemRequest;
+import net.chempound.client.DepositRequestMapper;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.client.sword.DepositReceipt;
 import net.chempound.compchem.nwchem.NWChemLogImporter;
 import net.chempound.compchem.rdf.CompChemPersonalities;
 import org.apache.commons.io.FilenameUtils;
 
 import java.io.File;
-import java.net.URI;
 
 /**
  * @author Sam Adams
 
     public DepositNWChemCommand() {
         super(new DepositNWChemOptions());
-        this.depositOptions = (DepositNWChemOptions) super.depositOptions;
+        this.depositOptions = (DepositNWChemOptions) super.options;
     }
 
     @Override
-    public void invoke(final GlobalOptions globalOptions) {
-        final NWChemLogImporter importer = new NWChemLogImporter();
+    protected DepositItemRequest createDepositRequest(final GlobalOptions globalOptions) {
+        try {
+            final NWChemLogImporter importer = new NWChemLogImporter();
 
-//        if (depositOptions.title != null) {
-//            importer.setTitle(depositOptions.title);
-//        }
-        if (depositOptions.slug != null) {
-            importer.setId(depositOptions.slug);
-        }
+            if (depositOptions.slug != null) {
+                importer.setId(depositOptions.slug);
+            }
 
-        final String filename = depositOptions.files.get(0);
-        final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
-        importer.setLogFile(cifFile, FilenameUtils.getName(filename));
+            final String filename = depositOptions.files.get(0);
+            final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
+            importer.setLogFile(cifFile, FilenameUtils.getName(filename));
 
-        final String url = globalOptions.repository;
-        try {
-            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.generateDepositRequest());
-
+            return DepositRequestMapper.map(importer.generateDepositRequest());
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new RuntimeException("Error generating deposit", e);
         }
     }