Commits

Anonymous committed bf71cb6

Code cleanup.

Comments (0)

Files changed (4)

     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
-    <groupId>br.usp.ime.vision.vision.dataset</groupId>
+    <groupId>br.usp.ime.vision.dataset</groupId>
     <artifactId>visiondataset-client</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.0</version>
     <packaging>jar</packaging>
 
     <name>visiondataset-client</name>

src/main/java/br/usp/ime/vision/dataset/ws/client/Attachment.java

 
 import java.util.Date;
 
+/**
+ * Attachment of an remote Vision Dataset image.
+ *
+ * @author rafael
+ *
+ */
 public class Attachment {
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
+    /**
+     * Id.
      */
-    @Override
-    public String toString() {
-        return String.format("%s", name);
-    }
-
     private int id;
 
+    /**
+     * Date of creation.
+     */
     private Date dateCreation;
 
+    /**
+     * File attachment name.
+     */
     private String name;
-    
-    private int imageId;
-    
-    private String uri;
-    
-    
-    
 
     /**
-     * @return the uri
+     * Id of the image attached.
      */
-    public String getUri() {
-        return uri;
-    }
+    private int imageId;
 
     /**
-     * @param uri the uri to set
+     * URI of the attachment.
      */
-    public void setUri(String uri) {
-        this.uri = uri;
+    private String uri;
+
+    /**
+     * @return the dateCreation
+     */
+    public final Date getDateCreation() {
+        return dateCreation;
     }
 
     /**
      * @return the id
      */
-    public int getId() {
+    public final int getId() {
         return id;
     }
 
     /**
-     * @param id the id to set
+     * @return the imageId
      */
-    public void setId(int id) {
-        this.id = id;
-    }
-
-    /**
-     * @return the dateCreation
-     */
-    public Date getDateCreation() {
-        return dateCreation;
-    }
-
-    /**
-     * @param dateCreation the dateCreation to set
-     */
-    public void setDateCreation(Date dateCreation) {
-        this.dateCreation = dateCreation;
+    public final int getImageId() {
+        return imageId;
     }
 
     /**
      * @return the name
      */
-    public String getName() {
+    public final String getName() {
         return name;
     }
 
     /**
-     * @param name the name to set
+     * @return the uri
      */
-    public void setName(String name) {
-        this.name = name;
+    public final String getUri() {
+        return uri;
     }
 
     /**
-     * @return the imageId
+     * @param date
+     *            the dateCreation to set
      */
-    public int getImageId() {
-        return imageId;
+    public final void setDateCreation(final Date date) {
+        this.dateCreation = date;
     }
 
     /**
-     * @param imageId the imageId to set
+     * @param idid
+     *            the id to set
      */
-    public void setImageId(int imageId) {
-        this.imageId = imageId;
-    } 
-    
+    public final void setId(final int idid) {
+        this.id = idid;
+    }
+
+    /**
+     * @param imgId
+     *            the imageId to set
+     */
+    public final void setImageId(final int imgId) {
+        this.imageId = imgId;
+    }
+
+    /**
+     * @param newName
+     *            the name to set
+     */
+    public final void setName(final String newName) {
+        this.name = newName;
+    }
+
+    /**
+     * @param uRI
+     *            the uri to set
+     */
+    public final void setUri(final String uRI) {
+        this.uri = uRI;
+    }
+
+    @Override
+    public final String toString() {
+        return String.format("%s", name);
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/ws/client/NotFoundException.java

 package br.usp.ime.vision.dataset.ws.client;
 
+
+/**
+ * Exception throw when a entity could not be found.
+ * @author rafael
+ *
+ */
 public class NotFoundException extends Exception {
 
     /**
-     * 
+     * Serial id.
      */
     private static final long serialVersionUID = -3599225106601387409L;
 

src/main/java/br/usp/ime/vision/dataset/ws/client/VisionDatasetClient.java

 import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.multipart.FormDataMultiPart;
 
+/**
+ * Vision Dataset Rest Webservice Client.
+ *
+ * @author rafael
+ *
+ */
 public class VisionDatasetClient {
+
+    /**
+     * Jersey client.
+     */
     private final Client client;
+    /**
+     * Google json converter.
+     */
     private final Gson gson;
 
     /**
 
     /**
      * Gets the attachment list of an image.
-     * 
+     *
      * @param imageUri
      *            <code>id</code> of the image.
      * @return a list of {@link Attachment}
      * @throws NotFoundException
+     *             if could not find the image of the uri.
      */
-    public List<Attachment> attachmentList(String imageUri) throws NotFoundException {
+    public final List<Attachment> attachmentList(final String imageUri)
+            throws NotFoundException {
         final List<Attachment> attachments = new ArrayList<Attachment>();
         final WebResource resource = getImageResource(imageUri);
-        final String attachmentsString = resource.path("/attachments/").get(String.class);
+        final String attachmentsString =
+                resource.path("/attachments/").get(String.class);
         if (attachmentsString == null) {
             throw new NotFoundException();
         }
-        final List<String> list = Arrays.asList(gson.fromJson(attachmentsString, String[].class));
+        final List<String> list =
+                Arrays.asList(gson.fromJson(attachmentsString, String[].class));
         for (final String uri : list) {
             attachments.add(getAttachment(uri));
 
 
     /**
      * Create a new attachment.
-     * 
+     *
      * @param imageUri
      *            URI of the image to attach the file.
      * @param name
      *            name of the file to be attached.
      * @return the Attachment created.
-     * @throws NotFoundException
+     * @throws NotFoundException if could not find the image.
      */
-    public Attachment createAttachment(String imageUri, String name) throws NotFoundException {
+    public final Attachment
+    createAttachment(final String imageUri, final String name)
+            throws NotFoundException {
         final WebResource imageResource = getImageResource(imageUri);
         final String jsonName = gson.toJson(name);
-        final String jsonAttachment = imageResource.type(MediaType.APPLICATION_JSON_TYPE).post(String.class,
-                jsonName);
-        final String attachmentUri = gson.fromJson(jsonAttachment, String.class);
+        final String jsonAttachment =
+                imageResource.type(MediaType.APPLICATION_JSON_TYPE).
+                post(String.class, jsonName);
+        final String attachmentUri =
+                gson.fromJson(jsonAttachment, String.class);
         return getAttachment(attachmentUri);
     }
 
     /**
      * Get attachment from the uri.
-     * 
+     *
      * @param uri
      *            <code>URI</code> of the attachment.
      * @return the {@link Attachment}
      */
-    private Attachment getAttachment(String uri) {
-        final String attachmentJson = getAttachmentResource(uri).get(String.class);
-        final Attachment attachment = gson.fromJson(attachmentJson, Attachment.class);
+    private Attachment getAttachment(final String uri) {
+        final String attachmentJson =
+                getAttachmentResource(uri).get(String.class);
+        final Attachment attachment =
+                gson.fromJson(attachmentJson, Attachment.class);
         attachment.setUri(uri);
         return attachment;
     }
 
     /**
      * Get the file of attachment.
-     * 
+     *
      * @param attachment
      *            attachment with an URI.
      * @return the attached {@link File}
      * @throws NotFoundException
      *             if the attachment was not found.
      */
-    public File getAttachmentFile(Attachment attachment) throws NotFoundException {
+    public final File getAttachmentFile(final Attachment attachment)
+            throws NotFoundException {
         return this.getAttachmentFile(attachment.getUri());
 
     }
 
     /**
      * Get the attachment's file by its URI.
-     * 
+     *
      * @param attachmentUri
      *            <code>URI</code> of the attachment on remote system.
      * @return the attachment {@link File}.
-     * @throws NotFoundException
+     * @throws NotFoundException if could not find the attachment.
      */
-    public File getAttachmentFile(String attachmentUri) throws NotFoundException {
-        final File file = getAttachmentResource(attachmentUri).path("/file/").get(File.class);
+    public final File getAttachmentFile(final String attachmentUri)
+            throws NotFoundException {
+        final File file =
+                getAttachmentResource(attachmentUri).path("/file/")
+                .get(File.class);
         return file;
     }
-
-    private WebResource getAttachmentResource(String uri) {
+    /**
+     * Get the resource an attachment.
+     * @param uri uri of the attachment.
+     * @return Web resource with the <code>uri</code>.
+     */
+    private WebResource getAttachmentResource(final String uri) {
         return client.resource(uri);
     }
 
     /**
      * Get the image from the <code>URI</code> on remote system.
-     * 
-     * 
      * @param imageUri
      *            <code>URI</code> of the image.
      * @return a {@link File} of the image Stream.
-     * @throws NotFoundException
+     * @throws NotFoundException if the image could not be found.
      */
-    public File getImage(String imageUri) throws NotFoundException {
+    public final File getImage(final String imageUri) throws NotFoundException {
         final WebResource imageResource = getImageResource(imageUri);
         final File imageFile = imageResource.get(File.class);
         if (imageFile == null) {
         return imageFile;
     }
 
-    private WebResource getImageResource(String imageUri) {
+    /**
+     * Get the resource an image.
+     * @param imageUri uri of the attachment.
+     * @return Web resource with the <code>imageUri</code>.
+     */
+    private WebResource getImageResource(final String imageUri) {
         return client.resource(imageUri);
     }
 
     /**
      * Overwrite the attachment file.
-     * 
+     *
      * @param attachmentUri
      *            <code>URI</code> of the attachment.
      * @param file
      *            the new {@link File} of the image attachment.
-     * @throws NotFoundException
+     * @throws NotFoundException if the attachment could not be found.
      */
-    public void updateAttachment(String attachmentUri, File file) throws NotFoundException {
+    public final void
+    updateAttachment(final String attachmentUri, final File file)
+            throws NotFoundException {
         final WebResource r = getAttachmentResource(attachmentUri);
         final FormDataMultiPart form = new FormDataMultiPart();
         form.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);