com.evasion.plugin.partnership.PartnershipManager Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.plugin.partnership;
import com.evasion.ejb.local.PartnershipManagerLocal;
import com.evasion.ejb.remote.PartnershipManagerRemote;
import com.evasion.entity.Corporation;
import com.evasion.entity.Partenaire;
import com.evasion.exception.PersistenceViolationException;
import com.evasion.plugin.partnership.dao.PartenaireDAO;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author sebastien
*/
@Stateless
@Local(value = PartnershipManagerLocal.class)
@Remote(value = PartnershipManagerRemote.class)
public class PartnershipManager implements PartnershipManagerLocal, PartnershipManagerRemote {
/** LOGGER */
private static final Logger LOGGER = LoggerFactory.getLogger(PartnershipManager.class);
@PersistenceContext(unitName = "EvasionPU")
private EntityManager em;
private PartenaireDAO partenaireDAO;
public PartnershipManager() {
partenaireDAO = new PartenaireDAO();
}
protected PartnershipManager(EntityManager em) {
this.em = em;
partenaireDAO = new PartenaireDAO();
partenaireDAO.setEntityManager(em);
}
@SuppressWarnings("PMD.UnusedPrivateMethod")
@edu.umd.cs.findbugs.annotations.SuppressWarnings("UPM_UNCALLED_PRIVATE_METHOD")
@PostConstruct
private void init() {
partenaireDAO.setEntityManager(em);
}
public Partenaire savePartnership(final Partenaire partenaire) throws PersistenceViolationException {
Partenaire newPartenaire = partenaire;
try {
em.merge(newPartenaire.getPerson());
newPartenaire = em.merge(newPartenaire);
em.flush();
} catch (Exception e) {
throw new PersistenceViolationException("Erreur dans la validation. ", e.fillInStackTrace());
}
return newPartenaire;
}
public List listActivePartenaires() {
Query query = em.createNamedQuery(Partenaire.FIND_ALL_ACTIF);
return query.getResultList();
}
public List listAllPartenaires() {
return partenaireDAO.findAll();
}
public List listPotentialPartenaires() {
Query query = em.createNamedQuery(Partenaire.POTENTIAL_PARTENAIRE);
List list = query.getResultList();
for (Corporation corp : list) {
corp.getLogo();
}
return list;
}
}