Exemplo n.º 1
0
 public void setPublisherToMedia(Publisher p, int mediaId) throws ServiceException {
   EntityManagerFactory emf = EMFSingleton.getEMF();
   EntityManager em = emf.createEntityManager();
   mediaRepository = new Media2Repository();
   mediaRepository.setEntityManager(em);
   Media m = mediaRepository.getByID(mediaId);
   if (m != null) {
     m.setPublisher(p);
   } else {
     throw new ServiceException("The media doesn't exist.");
   }
 }
Exemplo n.º 2
0
 /* (non-Javadoc)
  * @see com.m2i.formation.services.IMainService#addAuthorToMedia(com.m2i.formation.media.entities.Author, int)
  */
 @Override
 public void addAuthorToMedia(Author a, int mediaId) throws ServiceException {
   EntityManagerFactory emf = EMFSingleton.getEMF();
   EntityManager em = emf.createEntityManager();
   mediaRepository = new Media2Repository();
   mediaRepository.setEntityManager(em);
   Media m = mediaRepository.getByID(mediaId);
   if (m != null) {
     if (!m.getAuthors().contains(a)) {
       m.getAuthors().add(a);
       mediaRepository.getTransaction();
       mediaRepository.save(m);
       mediaRepository.commit();
     } else {
       throw new ServiceException("Author already associated with the media.");
     }
   } else {
     throw new ServiceException("The media doesn't exist.");
   }
 }