Ejemplo n.º 1
0
  @Override
  public Comment addComment(Long complaintId, Comment comment) throws Exception {
    final EntityManager em = createEntityManager();
    try {
      em.getTransaction().begin();
      Complaint c = em.find(Complaint.class, complaintId);
      comment.setId(0);
      if (c.getComments() == null) c.setComments(new Complaint.Comments());

      c.getComments().getComments().add(comment);
      em.getTransaction().commit();

    } catch (Exception e) {
      // TODO
      e.printStackTrace();
    } finally {
      // em.close();
    }
    return comment;
  }
Ejemplo n.º 2
0
 @Override
 public Complaint updateComplaint(Complaint complaint) throws Exception {
   final EntityManager em = createEntityManager();
   Complaint updateComplaint;
   try {
     em.getTransaction().begin();
     updateComplaint = em.find(Complaint.class, complaint.getId());
     if (updateComplaint != null) {
       // updating
       updateComplaint.setAddress(complaint.getAddress());
       updateComplaint.setAverageRating(complaint.getAverageRating());
       updateComplaint.setCategory(complaint.getCategory());
       updateComplaint.setComments(complaint.getComments());
       updateComplaint.setCreationTime(complaint.getCreationTime());
       updateComplaint.setDescription(complaint.getDescription());
       updateComplaint.setGeolocation(complaint.getGeolocation());
       updateComplaint.setPhotos(complaint.getPhotos());
       updateComplaint.setRatings(complaint.getRatings());
       updateComplaint.setStatus(complaint.getStatus());
       updateComplaint.setTags(complaint.getTags());
       updateComplaint.setTitle(complaint.getTitle());
       updateComplaint.setUserId(complaint.getUserId());
       em.merge(updateComplaint);
       logger.debug("complaint [" + complaint.getId() + "] updated"); // $NON-NLS-1$ //$NON-NLS-2$
     } else {
       throw new Exception(
           "complaint ["
               + complaint.getId() // $NON-NLS-1$
               + "] not found"); //$NON-NLS-1$
     }
     em.getTransaction().commit();
   } finally {
     em.close();
   }
   return refactorComplaint(updateComplaint);
 }
Ejemplo n.º 3
0
 /**
  * sets properties comments, ratings and photos to null
  *
  * @param c the complete complaint
  * @return the complaint without comments, ratings and photos
  */
 private Complaint refactorComplaint(Complaint c) {
   c.setComments(null);
   c.setRatings(null);
   c.setPhotos(null);
   return c;
 }