Commits

Sam Adams committed 3cd5225

Made loads of stuff final\!

Comments (0)

Files changed (3)

src/main/java/uk/ac/cam/ch/wwmm/chempound/deposit/DepositClient.java

         return swordEndpoint;
     }
 
-    public void setSwordEndpoint(URI swordEndpoint) {
+    public void setSwordEndpoint(final URI swordEndpoint) {
         this.swordEndpoint = swordEndpoint;
     }
 
-    public void setSwordEndpoint(String swordEndpoint) {
+    public void setSwordEndpoint(final String swordEndpoint) {
         this.swordEndpoint = URI.create(swordEndpoint);
     }
 
 
     public DepositReceipt executeDeposit() throws SWORDClientException, SWORDError, ProtocolViolationException, IOException {
 
-        SWORDClient client = new SWORDClient();
-        Deposit deposit = prepareSwordDeposit();
-        DepositReceipt receipt = client.deposit(swordEndpoint.toString(), deposit);
+        final SWORDClient client = new SWORDClient();
+        final Deposit deposit = prepareSwordDeposit();
+        final DepositReceipt receipt = client.deposit(swordEndpoint.toString(), deposit);
 
         return receipt;
     }
 
     private Deposit prepareSwordDeposit() throws IOException {
-        DepositRequest depositRequest = getDepositRequest();
+        final DepositRequest depositRequest = getDepositRequest();
         return SwordUtil.createSwordDeposit(depositRequest);
     }
 

src/main/java/uk/ac/cam/ch/wwmm/chempound/deposit/DepositCollection.java

     private String id;
     private String title;
 
-    public void setCollectionId(String id) {
+    public void setCollectionId(final String id) {
         this.id = id;
     }
 
-    public void setCollectionTitle(String title) {
+    public void setCollectionTitle(final String title) {
         this.title = title;
     }
 
     @Override
     protected DepositRequest getDepositRequest() {
-        DepositRequest request = new DefaultDepositRequest();
+        final DepositRequest request = new DefaultDepositRequest();
         request.setSlug(id);
         request.getResourceMetadata().setTitle(title);
         request.getResourceMetadata().addProperty(RDF.type, CPTerms.Collection);
     }
 
 
-    public static void main(String[] args) throws Exception {
+    public static void main(final String[] args) throws Exception {
 
         if (args.length != 3) {
             System.err.println("Two arguments required:");
             System.exit(1);
         }
 
-        String swordEndpoint = args[0];
-        String id = args[1];
-        String title = args[2];
+        final String swordEndpoint = args[0];
+        final String id = args[1];
+        final String title = args[2];
 
         System.err.println();
         System.err.println("**");
         System.err.println("**");
         System.err.println();
 
-        DepositCollection client = new DepositCollection();
+        final DepositCollection client = new DepositCollection();
         client.setSwordEndpoint(swordEndpoint);
         client.setCollectionId(id);
         client.setCollectionTitle(title);
-        DepositReceipt receipt = client.executeDeposit();
+        final DepositReceipt receipt = client.executeDeposit();
 
         if (receipt == null) {
             System.err.println();

src/main/java/uk/ac/cam/ch/wwmm/chempound/deposit/SwordUtil.java

  */
 public class SwordUtil {
 
-    public static Deposit createSwordDeposit(DepositRequest request) throws IOException {
-        Deposit deposit = new Deposit();
+    public static Deposit createSwordDeposit(final DepositRequest request) throws IOException {
+        final Deposit deposit = new Deposit();
 
-        EntryPart entryPart = new EntryPart();
+        final EntryPart entryPart = new EntryPart();
 
         String title = "untitled";
         if (!request.getMetadataModel().isEmpty()) {
             attachMetaData(request, entryPart);
-            Statement s = getTitleStatement(request);
+            final Statement s = getTitleStatement(request);
             if (s != null) {
                 if (s.getObject().isLiteral()) {
                     title = s.getString();
         deposit.setEntryPart(entryPart);
 
         deposit.setSlug(request.getSlug());
-        byte[] zip = createZipFile(request);
+        final byte[] zip = createZipFile(request);
         if (zip != null) {
             deposit.setFile(new ByteArrayInputStream(zip));
             deposit.setMimeType("application/zip");
         return deposit;
     }
 
-    private static Statement getTitleStatement(DepositRequest request) {
+    private static Statement getTitleStatement(final DepositRequest request) {
         Statement s = request.getResourceMetadata().getProperty(DCTerms.title);
         if (s == null) {
             s = request.getResourceMetadata().getProperty(DC.title);
         return s;
     }
 
-    private static byte[] createZipFile(DepositRequest request) throws IOException {
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        ZipOutputStream out = new ZipOutputStream(buffer);
+    private static byte[] createZipFile(final DepositRequest request) throws IOException {
+        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        final ZipOutputStream out = new ZipOutputStream(buffer);
         int n = 0;
-        for (DepositResource resource : request.getAggregatedResources()) {
+        for (final DepositResource resource : request.getAggregatedResources()) {
             if (resource instanceof LocalResource) {
-                ZipEntry zipEntry = new ZipEntry(resource.getUri().toString());
+                final ZipEntry zipEntry = new ZipEntry(resource.getUri().toString());
                 out.putNextEntry(zipEntry);
-                InputStream in = resource.openInputStream();
+                final InputStream in = resource.openInputStream();
                 IOUtils.copy(in, out);
                 IOUtils.closeQuietly(in);
                 n++;
         return buffer.toByteArray();
     }
 
-    private static void attachMetaData(DepositRequest request, EntryPart entryPart) {
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+    private static void attachMetaData(final DepositRequest request, final EntryPart entryPart) {
+        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
 
-        RDFXMLWriterI w = new Abbreviated();
+        final RDFXMLWriterI w = new Abbreviated();
         w.setProperty("allowBadURIs", true);
         w.write(request.getMetadataModel(), buffer, null);
 
-        Abdera abdera = new Abdera();
-        Document doc = abdera.getParser().parse(new ByteArrayInputStream(buffer.toByteArray()));
+        final Abdera abdera = new Abdera();
+        final Document doc = abdera.getParser().parse(new ByteArrayInputStream(buffer.toByteArray()));
         entryPart.getEntry().addExtension(doc.getRoot());
     }