package sn.unitech.stock.metier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import sn.unitech.stock.dao.SysActiviteDao;
import sn.unitech.stock.dao.SysAdherentDao;
import sn.unitech.stock.dao.SysEventsDao;
import sn.unitech.stock.dao.SysNiveauDao;
import sn.unitech.stock.dao.iface.ISysActiviteDao;
import sn.unitech.stock.dao.iface.ISysAdherentDao;
import sn.unitech.stock.dao.iface.ISysEventsDao;
import sn.unitech.stock.dao.iface.ISysNiveauDao;
import sn.unitech.stock.entity.SysActivite;
import sn.unitech.stock.entity.SysAdherActivite;
import sn.unitech.stock.entity.SysAdherActiviteId;
import sn.unitech.stock.entity.SysAdherEvent;
import sn.unitech.stock.entity.SysAdherEventId;
import sn.unitech.stock.entity.SysAdherent;
import sn.unitech.stock.entity.SysEvents;
import sn.unitech.stock.entity.SysNiveau;
import sn.unitech.stock.metier.iface.ISysAdherentM;
import sn.unitech.stock.modal.Resultat;
public class SysAdherentM<E> implements ISysAdherentM<SysAdherent>{
ISysEventsDao<SysEvents> iSysEventsDao=new SysEventsDao<SysEvents>();
ISysAdherentDao<SysAdherent> iAdherentDao=new SysAdherentDao<SysAdherent>();
ISysActiviteDao<SysActivite> iActiviteDao=new SysActiviteDao<SysActivite>();
ISysNiveauDao<SysNiveau> iSysNiveauDao=new SysNiveauDao<SysNiveau>();
public SysAdherentM() {
}
@Override
public Resultat persistAdherent(SysAdherent adherent) {
return iAdherentDao.persistAdherent(adherent);
}
@Override
public List<SysAdherEvent> getListAdherEvents(String jpql,SysAdherent adherent) {
List<SysEvents> listEvents= iSysEventsDao.getResultList(jpql, null, null);
List<SysAdherEvent> listAdherEvent=new ArrayList<SysAdherEvent>();
SysAdherEvent sysAdherEvent;
int i=1;
for(SysEvents events:listEvents){
sysAdherEvent=new SysAdherEvent(new SysAdherEventId(adherent.getIdAdherent(),events.getIdEvent()),adherent,events);
sysAdherEvent.setUseMontant("True");
sysAdherEvent.setPriorite(i++);
listAdherEvent.add(sysAdherEvent);
}
return listAdherEvent;
}
@Override
public List<SysAdherActivite> getListAdherActivite(String jpql,SysAdherent adherent) {
List<SysActivite> listActivite= iActiviteDao.getResultList(jpql, null, null);
List<SysAdherActivite> listAdherActivite=new ArrayList<SysAdherActivite>();
SysAdherActivite sysAdherActivite;
for(SysActivite activite:listActivite){
sysAdherActivite=new SysAdherActivite(new SysAdherActiviteId(adherent.getIdAdherent(),activite.getIdActivite()),activite,adherent);
sysAdherActivite.setSysNiveau(new SysNiveau());
listAdherActivite.add(sysAdherActivite);
}
return listAdherActivite;
}
@Override
public Map<String, Integer> findAllNiveau(String jpql) {
List<SysNiveau> listNiveau=this.iSysNiveauDao.getResultList(jpql, null, null);
Map<String, Integer> curMap=new HashMap<String, Integer>();
for(SysNiveau niveau:listNiveau){
curMap.put(niveau.getDescription(), niveau.getIdNiveau());
}
return curMap;
}
}