/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans.shedule.insertion_point;
import framework.beans.SecuredBean;
import framework.beans.security.BeanRights;
import beans.directory.worktypes.entities.WorkType;
import framework.generic.ClipsServerException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import javax.ejb.Stateful;
import javax.persistence.Query;
import beans.UserRightsSet;
/**
* Вспомогательный Бин для получения сотрудников, которые имеют заданные типы работ
* @security OK
* @author axe
*/
@Stateful(mappedName="clips-beans/SheduleInsertionPointBean")
public class SheduleInsertionPointBean extends SecuredBean
implements SheduleInsertionPointBeanRemote {
public static int COMMAND_READ = 0;
@Override
protected void initBeanRights() {
int[] r = new int[1];
r[COMMAND_READ] = RightPresence(UserRightsSet.CREATE_RECEPTION.id);
if(r[COMMAND_READ] <= 0) {
r[COMMAND_READ] = RightPresence(UserRightsSet.CREATE_OWN_RECEPTION.id);
}
if(r[COMMAND_READ] <= 0) {
r[COMMAND_READ] = RightPresence(UserRightsSet.CREATE_RECEPTION.id);
}
if(r[COMMAND_READ] <= 0) {
r[COMMAND_READ] = RightPresence(UserRightsSet.CREATE_OWN_RECEPTION.id);
}
rights = new BeanRights(r);
}
/**
* Возвращает список идентификаторов сотрудников, имеющих задданый вид работ
* @param workType вид работ
* @return List<Integer> список сотрудников
* @throws generic.ClipsServerException
* @security для вызова функции нужно иметь любое из прав: CREATE_RECEPTION,
* CREATE_OWN_RECEPTION, MODIFY_RECEPTION, MODIFY_OWN_RECEPTION
*/
@Override
public List<Integer> getInsertionPoint(int workType)
throws ClipsServerException {
checkCommandAccessibility(COMMAND_READ);
WorkType wt = findEntity(WorkType.class, workType);
String sql = "SELECT DISTINCT coll.id FROM SheduleIndividualWork siw, Collaborator coll"
+ " WHERE siw.collaborator = coll"
+ " AND coll.trash = false"
+ " AND siw.workType = :type"
+ " AND ((siw.timeBegin > '2007-1-1' AND siw.timeBegin < '2008-1-1')"
+ " OR siw.timeBegin > :today)";
Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
Query query = manager.createQuery(sql);
query.setParameter("today", cal.getTime());
query.setParameter("type", wt);
List<Integer> list = new ArrayList<Integer>(query.getResultList());
return list;
}
}