Commits

Sam Adams committed f3157fa

Developing deposit ATs

Comments (0)

Files changed (4)

 
     <dependencies>
 
-    <!--
         <dependency>
-            <groupId>net.chempound.client</groupId>
-            <artifactId>client-utils</artifactId>
+            <groupId>net.chempound</groupId>
+            <artifactId>chempound-client</artifactId>
             <version>0.1-SNAPSHOT</version>
         </dependency>
-    -->
 
         <dependency>
             <groupId>org.slf4j</groupId>
         </dependency>
 
         <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

src/main/java/net/chempound/client/cli/command/CreateCollectionCommand.java

 package net.chempound.client.cli.command;
 
-import com.hp.hpl.jena.vocabulary.RDF;
-import net.chempound.client.SwordClient;
+import net.chempound.client.ChempoundClient;
+import net.chempound.client.CreateCollectionRequest;
+import net.chempound.client.CreateCollectionResponse;
 import net.chempound.client.cli.options.CreateCollectionOptions;
 import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.content.DefaultDepositRequest;
-import net.chempound.content.DepositRequest;
-import net.chempound.rdf.CPTerms;
 
 import java.net.URI;
 
 
     @Override
     public void invoke(final GlobalOptions globalOptions) {
-        final SwordClient swordClient = new SwordClient();
-        final DepositRequest depositRequest = new DefaultDepositRequest();
+        final ChempoundClient chempoundClient = new ChempoundClient();
         if (options.args == null || options.args.isEmpty()) {
             throw new RuntimeException("Title must be specified");
         }
         final String title = options.args.get(0);
-        depositRequest.setTitle(title);
+        final CreateCollectionRequest request = new CreateCollectionRequest();
+        request.withTitle(title);
         if (options.slug == null) {
-            depositRequest.setSlug(title);
+            request.withSlug(title);
         } else {
-            depositRequest.setSlug(options.slug);
+            request.withSlug(options.slug);
         }
-        depositRequest.getMetadataModel().getResource("").addProperty(RDF.type, CPTerms.Collection);
 
-        final URI uri = URI.create(globalOptions.repository);
+        request.withUri(URI.create(globalOptions.repository));
 
+        final CreateCollectionResponse response;
         try {
-            swordClient.deposit(uri, depositRequest);
+            response = chempoundClient.createCollection(request);
+            System.out.println("Collection created: " + response.getUri());
         } catch (Exception e) {
             e.printStackTrace();
         }

src/main/java/net/chempound/client/cli/command/DepositCommand.java

 package net.chempound.client.cli.command;
 
-import net.chempound.client.DepositBuilder;
-import net.chempound.client.SwordClient;
+import net.chempound.client.ChempoundClient;
+import net.chempound.client.DepositItemRequest;
+import net.chempound.client.DepositItemResponse;
 import net.chempound.client.cli.options.DepositOptions;
 import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.client.sword.DepositReceipt;
 import net.chempound.storage.LocalFileResource;
 import net.chempound.storage.LocalResource;
 import org.apache.commons.io.FilenameUtils;
 public class DepositCommand implements Command<DepositOptions> {
 
     protected final DepositOptions depositOptions;
-    protected final SwordClient swordClient;
+    protected final ChempoundClient swordClient;
 
     public DepositCommand() {
         this(new DepositOptions());
     }
 
     protected DepositCommand(final DepositOptions depositOptions) {
-        this(depositOptions, new SwordClient());
+        this(depositOptions, new ChempoundClient());
     }
 
-    protected DepositCommand(final DepositOptions depositOptions, final SwordClient swordClient) {
+    protected DepositCommand(final DepositOptions depositOptions, final ChempoundClient swordClient) {
         this.depositOptions = depositOptions;
         this.swordClient = swordClient;
     }
     @Override
     public void invoke(final GlobalOptions globalOptions) {
 
-        final DepositBuilder depositBuilder = new DepositBuilder();
+        final DepositItemRequest request = new DepositItemRequest();
 
-        attachFiles(globalOptions, depositBuilder);
-        setTitle(depositBuilder);
-        setSlug(depositBuilder);
+        attachFiles(globalOptions, request);
+        setTitle(request);
+        setSlug(request);
 
-        final String url = globalOptions.repository;
+        request.withUri(URI.create(globalOptions.repository));
         try {
-            final DepositReceipt depositReceipt = swordClient.deposit(URI.create(url), depositBuilder.buildDepositRequest());
+            final DepositItemResponse depositReceipt = swordClient.depositItem(request);
         } catch (Exception e) {
             e.printStackTrace();
         }
 
     }
 
-    protected void setTitle(final DepositBuilder depositBuilder) {
+    protected void setTitle(final DepositItemRequest request) {
         if (depositOptions.title != null) {
-            depositBuilder.setTitle(depositOptions.title);
+            request.withTitle(depositOptions.title);
         }
     }
 
-    protected void setSlug(final DepositBuilder depositBuilder) {
+    protected void setSlug(final DepositItemRequest request) {
         if (depositOptions.slug != null) {
-            depositBuilder.setSlug(depositOptions.slug);
+            request.withSlug(depositOptions.slug);
         }
     }
 
-    protected void attachFiles(final GlobalOptions globalOptions, final DepositBuilder depositBuilder) {
+    protected void attachFiles(final GlobalOptions globalOptions, final DepositItemRequest request) {
         if (depositOptions.files != null) {
             for (final String filename : depositOptions.files) {
                 final File file = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
                 final String depositFilename = FilenameUtils.getName(filename);
                 final LocalResource resource = new LocalFileResource(depositFilename, file);
-                depositBuilder.addResource(resource);
+                request.addResource(resource);
             }
         }
     }

src/test/java/net/chempound/client/cli/ChempoundClientCLIIntegrationTest.java

         FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
 
         client.runMain("-R", "http://localhost:12080/repo/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
-                "deposit", "wibble.txt");
+                "deposit", "-s", "foobar", "wibble.txt");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), title, createPlainLiteral("FooBar")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), type, Collection));
         assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/wibble.txt")));
     }
 
     @Test
     }
 
     @Test
-    public void testDepositMultipleItems() throws Exception {
+    public void testDepositItemWithMultipleFiles() throws Exception {
         FileUtils.forceMkdir(tmpDir);
         FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
         FileUtils.writeStringToFile(new File(tmpDir, "wobble.txt"), "wobble");