Commits

Sam Adams committed 20aaf39

Added deposit item to client

Comments (0)

Files changed (4)

chempound-client/src/main/java/net/chempound/client/ChempoundClient.java

         return mapCreateCollectionResponse(receipt);
     }
 
+    public DepositItemResponse depositItem(final DepositItemRequest request) throws Exception {
+        final DepositReceipt receipt = swordClient.deposit(request.getURI().toString(), mapDepositItemRequest(request));
+        return mapDepositItemResponse(receipt);
+    }
+
+
     private Deposit mapCreateCollectionRequest(final CreateCollectionRequest request) {
         final EntryPart entryPart = new EntryPart();
         if (request.getTitle() != null) {
         return deposit;
     }
 
+    private CreateCollectionResponse mapCreateCollectionResponse(final DepositReceipt receipt) {
+        return new CreateCollectionResponse(URI.create(receipt.getSplashPageIRI().toString()), null);
+    }
+
+
+    private Deposit mapDepositItemRequest(final DepositItemRequest request) {
+        final EntryPart entryPart = new EntryPart();
+        if (request.getTitle() != null) {
+            entryPart.getEntry().setTitle(request.getTitle());
+        }
+
+        final Deposit deposit = new DepositFactory().newMetadataOnly(entryPart);
+        if (request.getSlug() != null) {
+            deposit.setSlug(request.getSlug());
+        }
+        return deposit;
+    }
+
+    private DepositItemResponse mapDepositItemResponse(final DepositReceipt receipt) {
+        return new DepositItemResponse(URI.create(receipt.getSplashPageIRI().toString()));
+    }
+
+
     private void attachMetadata(final EntryPart entryPart, final Model metadataModel) {
         final byte[] bytes = RdfIO.writeRdf(metadataModel);
         final Document document = Abdera.getNewParser().parse(new ByteArrayInputStream(bytes));
         entryPart.getEntry().addExtension(document.getRoot());
     }
 
-    private CreateCollectionResponse mapCreateCollectionResponse(final DepositReceipt receipt) {
-        return new CreateCollectionResponse(URI.create(receipt.getSplashPageIRI().toString()), null);
-    }
-
 }

chempound-client/src/main/java/net/chempound/client/DepositItemRequest.java

+package net.chempound.client;
+
+import java.net.URI;
+
+/**
+ * @author Sam Adams
+ */
+public class DepositItemRequest {
+
+    private URI uri;
+    private String title;
+    private String slug;
+
+    public URI getURI() {
+        return uri;
+    }
+
+    public DepositItemRequest withUri(final URI uri) {
+        this.uri = uri;
+        return this;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public DepositItemRequest withTitle(final String title) {
+        this.title = title;
+        return this;
+    }
+
+    public String getSlug() {
+        return slug;
+    }
+
+    public DepositItemRequest withSlug(final String slug) {
+        this.slug = slug;
+        return this;
+    }
+
+}

chempound-client/src/main/java/net/chempound/client/DepositItemResponse.java

+package net.chempound.client;
+
+import java.net.URI;
+
+/**
+ * @author Sam Adams
+ */
+public class DepositItemResponse {
+
+    private final URI uri;
+
+    public DepositItemResponse(final URI uri) {
+        this.uri = uri;
+    }
+
+    public URI getUri() {
+        return uri;
+    }
+
+}

chempound-webapp/src/main/resources/net/chempound/templates/default/resource.ftl

+<div class="item">
 <#-- @ftlvariable name="aggregation" type="net.chempound.rdf.chempound.ChempoundAggregationImpl" -->
 <#if aggregation.title??>
-        <h1 style="padding-bottom: 0">${aggregation.title}</h1>
+        <h1 class="title" style="padding-bottom: 0">${aggregation.title}</h1>
         <small>${aggregation.uri}</small>
 <#else>
         <h1>${aggregation.uri}</h1>
         <div class="clear"></div>
 
     </div>
-
+</div>