/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans.service.mes;
import framework.beans.SecuredBean;
import framework.beans.security.BeanRights;
import beans.directory.mkb10.entity.Mkb10;
import beans.service.mes.entity.MedicEconomicStandart;
import beans.service.mes.entity.MedicEconomicStandartDetail;
import framework.generic.ClipsServerException;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateful;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import framework.security.RightChecker;
import beans.UserRightsSet;
/**
*
* @author finder
*/
@Stateful(mappedName="clips-beans/MedicEconomicStandartSearchBean")
public class MedicEconomicStandartSearchBean extends SecuredBean implements MedicEconomicStandartSearchBeanRemote {
public static int COMMAND_READ = 0;
@Override
protected void initBeanRights() {
int[] r = new int[1];
r[COMMAND_READ] = RightPresence(UserRightsSet.READ_REPORT_STRUCTURE.id);
rights = new BeanRights(r);
}
@Override
public List<MedicEconomicStandartDetail> getList(int typeid) throws ClipsServerException {
checkCommandAccessibility(COMMAND_READ);
List<MedicEconomicStandartDetail> resould = new ArrayList<MedicEconomicStandartDetail>();
List<MedicEconomicStandart> set = findEntityList(MedicEconomicStandart.class, "mesType.id", typeid);
for(int i = 0; i < set.size(); i++) {
resould.add(set.get(i).getDetails(this));
}
return resould;
}
@Override
public MedicEconomicStandartDetail getMes(int typeid, int mkb10id) throws ClipsServerException {
return getMes(typeid, findEntity(Mkb10.class, mkb10id));
}
private MedicEconomicStandartDetail getMes(int typeid, Mkb10 mkb) throws ClipsServerException {
checkCommandAccessibility(COMMAND_READ);
try {
Query query = manager.createQuery("SELECT a FROM MedicEconomicStandart a where a.mesType.id = :type and :mkb IN (a.mkb10Collection)");
query.setParameter("type", typeid);
query.setParameter("mkb", mkb);
@SuppressWarnings("unchecked")
List<MedicEconomicStandart> set = query.getResultList();
for(int i = 0; i < set.size(); i++) {
return set.get(i).getDetails((RightChecker) this);
}
}
catch (NoResultException ex) {
// drop
}
if (mkb.getRef() != null){
return getMes(typeid, mkb.getRef());
}
else{
return null;
}
}
}