Esempio n. 1
0
 /**
  * Get a note by id
  *
  * @param user - User login
  * @param id - Id of note
  * @return an instance of java.lang.String
  */
 @Path("/{id}")
 @GET
 @Produces("application/xml")
 public Response getNote(@PathParam("user") String user, @PathParam("id") int id) {
   Response r = null;
   if (userAuth.Auth(hh, user)) {
     r = Response.ok(ndb.getNoteById(user, id)).build();
   } else {
     r = unAuthorized();
   }
   return r;
 }
Esempio n. 2
0
 /**
  * Delete a note by id.
  *
  * @param user
  * @param id
  * @return
  */
 @Path("/{id}")
 @DELETE
 public Response deleteNote(@PathParam("user") String user, @PathParam("id") int id) {
   Response r = null;
   if (userAuth.Auth(hh, user)) {
     ndb.deleteNote(user, id);
     r = Response.ok().build();
   } else {
     r = unAuthorized();
   }
   return r;
 }
Esempio n. 3
0
 /**
  * Update a note by id.
  *
  * @param user
  * @param id
  * @param data
  * @return an instance of javax.ws.rs.core.Response
  */
 @Path("/{id}")
 @PUT
 @Consumes("*/*")
 public Response updateNote(@PathParam("user") String user, @PathParam("id") int id, String data) {
   Response r = null;
   if (userAuth.Auth(hh, user)) {
     ndb.changeNote(user, id, data);
     r = Response.ok().build();
   } else {
     r = unAuthorized();
   }
   return r;
 }
Esempio n. 4
0
  /**
   * Get a media content by note id and media name
   *
   * @param user user name
   * @param id note id
   * @param blobName name of media
   * @return
   */
  @Path("/{id}/media/{blobName}")
  @GET
  // @Produces("image/jpeg")
  public Response getBLOB(
      @PathParam("user") String user,
      @PathParam("id") int id,
      @PathParam("blobName") String blobName) {
    Response r = null;
    if (userAuth.Auth(hh, user)) {
      Multipart mp = new MimeMultipart();
      BodyPart bp = new MimeBodyPart();
      try {
        bp.setContent(ndb.getBLOBInfo(user, id, blobName), "application/xml");
        mp.addBodyPart(bp);
      } catch (MessagingException ex) {
        ex.printStackTrace();
      }

      ByteArrayInputStream tmp = null;
      try {
        tmp = ndb.getBLOBStream(user, id, blobName);
        BodyPart stream = new MimeBodyPart();
        stream.setContent(tmp, ndb.getBLOBType(user, id, blobName));
        r = Response.ok(mp).build();
      } catch (MessagingException me) {
        me.printStackTrace();
      } finally {
        try {
          tmp.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    } else {
      r = unAuthorized();
    }
    return r;
  }
Esempio n. 5
0
 /**
  * Add new note.
  *
  * @param user
  * @param id
  * @param data
  * @return an instance of javax.ws.rs.core.Response
  */
 @POST
 @Consumes("*/*")
 public Response addNote(@PathParam("user") String user, @PathParam("id") int id, String data) {
   Response r = null;
   if (userAuth.Auth(hh, user)) {
     try {
       r =
           Response.ok()
               .contentLocation(new URI("/" + user + "/note/" + ndb.addNote(user, data)))
               .build();
     } catch (URISyntaxException ex) {
       ex.printStackTrace();
     }
   } else {
     r = unAuthorized();
   }
   return r;
 }