Package beans.cec

Source Code of beans.cec.CommitteeFactoryBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package beans.cec;

import framework.beans.SecuredBean;
import framework.beans.security.BeanRights;
import beans.cec.entity.Committee;
import beans.cec.entity.CommitteeDetails;
import framework.generic.ESecurity;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateful;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import beans.UserRightsSet; import framework.security.RightChecker;


/**
* @security OK
* @author axe
*/
@Stateful(mappedName="clips-beans/CommitteeFactoryBean")
public class CommitteeFactoryBean extends SecuredBean
        implements CommitteeFactoryBeanRemote {
   
    public static int COMMAND_READ = 0;
    @Override
    protected void initBeanRights() {
        int [] r = new int[1];
        r[COMMAND_READ] = RightPresence(UserRightsSet.READ_CEC.id);
        rights = new BeanRights(r);
    }
   
    /**
     * Возвращает список комиссий, прошедших в заданный промежуток времени
     * @param from дата начала периода, может быть null
     * @param till дата конца периода, может быть null
     * @return
     * @throws generic.ESecurity
     * @security должно быть право READ_CEC
     */
    @Override
    public List<CommitteeDetails> getCommitteeList(Date from, Date till) throws ESecurity {
        checkCommandAccessibility(COMMAND_READ);
        int size = 0;
        if (from != null) {size++;}
        if (till != null) {size++;}       
        Field f[] = new Field[size];
        int pos = 0;
        if (from != null) {
            f[pos++] = new Field("date", from, Field.OPERATOR_EQUAL_OR_MORE);
        }
        if (till != null) {
            f[pos++] = new Field("date", till, Field.OPERATOR_EQUAL_OR_LESS);
        }
       
        List list = findEntityList(Committee.class, f);
        List<CommitteeDetails> res = new ArrayList<CommitteeDetails>();
        Iterator i = list.iterator();
        while(i.hasNext()) {
            Committee j = (Committee) i.next();
            res.add(j.getDetails((RightChecker) this));
        }
        return res; 
    }
   
    /**
     * Возвращает список комиссий, прошедших в заданный промежуток времени,
     * в которых рассматривался указаный пациент
     * @param from дата начала периода, может быть null
     * @param till дата конца периода, может быть null
     * @param clientID пациент
     * @return
     * @throws generic.ESecurity
     * @security должно быть право READ_CEC
     */
    @Override
    public List<Integer> getCommitteetListWithClient(Date from, Date till, int clientID) throws ESecurity {
        checkCommandAccessibility(COMMAND_READ);
        ArrayList <Integer> det = new ArrayList<Integer>();
        try {
            String extra = "SELECT DISTINCT a.id From Committee a, CommitteeDirection b WHERE a.id = b.committee.id";
            if (from != null) {
                extra += " AND a.date >=:dateFrom";
            }
            if (till != null) {
                extra += " AND a.date <=:dateTill";
            }
            extra += " AND b.direction.serviceRender.disease.emc.client.id =:clientID";
            Query query = manager.createQuery(extra);
            if (from != null) {
                query.setParameter("dateFrom", from);           
            }
            if (till != null) {
                query.setParameter("dateTill", till);           
            }
            query.setParameter("clientID", clientID);           
            @SuppressWarnings("unchecked")
            List<Integer> res = query.getResultList();
            for(int i=0; i<res.size(); i++) {
                det.add(res.get(i));
            }
        } catch (NoResultException ex) {
            //do nothing
        }
        return det;       
    }   
}
TOP

Related Classes of beans.cec.CommitteeFactoryBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.