Package beans.shedule.holiday

Source Code of beans.shedule.holiday.SheduleHolidayBean

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

package beans.shedule.holiday;

import framework.beans.SecuredBean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import framework.generic.ClipsServerException;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import beans.UserRightsSet;
import framework.beans.security.BeanRights;
import framework.security.RightChecker;

/**
* Бин контролирующий работу праздничных дней, фиксированных в течение года
* месяцем и днем месяца
* @security OK
* Для просмотра права не нужны
* Для редактирования нужно право MODIFY_SHEDULE_HOLLIDAYS_AND_EXCEPTIONS
* @author axe
*/
@Stateful(mappedName="clips-beans/SheduleHolidayBean")
public class SheduleHolidayBean extends SecuredBean
        implements SheduleHolidayBeanRemote {
   
    public static int COMMAND_MODIFY = 0;   
   
    @Override
    protected void initBeanRights() {
        int[] r = new int[1];
        r[COMMAND_MODIFY] = RightPresence(UserRightsSet.WRITE_REGION_ADMIN_DIRECTORY.id);
        rights = new BeanRights(r);
    }

    /**
     * Возвращает список праздничных дней
     * @return ArrayList<SheduleHolidayDayDetails>
     * @security Нет ограничений
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SheduleHolidayDetails> getHolidayList() {
        Iterator res = findEntityWhat(null, SheduleHoliday.class, null, " ORDER By a.month, a.day").iterator();
        ArrayList<SheduleHolidayDetails> list = new ArrayList<SheduleHolidayDetails>();
        if(res.hasNext()) {
            while(res.hasNext()) {
               SheduleHoliday sx = (SheduleHoliday) res.next();
               list.add(sx.getDetails((RightChecker) this));
            }
        }
        return list;
    }

    /**
     * Назначает новый праздник
     * @param day день (1-31)
     * @param month месяц (1-12)
     * @param desc описание праздника
     * @throws ClipsServerException
     * @security Вызывающий должен иметь право MODIFY_SHEDULE_HOLLIDAYS_AND_EXCEPTIONS
     */
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    public void setHoliday(int day, int month, String desc) throws ClipsServerException {
        checkCommandAccessibility(COMMAND_MODIFY);
        if(day < 1 || day > 31
                || month < 1 || month > 12) {
            throw new IllegalArgumentException("Date dd.mm: " + day + ":" + month);
        }
       
        Field f[] = {
            new Field("key.day", day),
            new Field("key.month", month)
        };
        Iterator res = findEntityWhat(null, SheduleHoliday.class, f, "").iterator();

        if(res.hasNext()) {
            SheduleHoliday sx = (SheduleHoliday) res.next();
            sx.setDesc(desc);
            manager.merge(sx);
        } else {
            SheduleHoliday sx = new SheduleHoliday();
            SheduleHolidayPK key = new SheduleHolidayPK();
            sx.setKey(key);

            sx.setDay(day);
            key.setDay(day);
            sx.setMonth(month);
            key.setMonth(month);
           
            sx.setDesc(desc);
            manager.persist(sx);          
        }
    }
   
    /**
     * Удаляет праздник в указанный день
     * @param day день (1-31)
     * @param month месяц (1-12)
     * @throws ClipsServerException
     * @security Вызывающий должен иметь право MODIFY_SHEDULE_HOLLIDAYS_AND_EXCEPTIONS
     */
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    public void removeHoliday(int day, int month) throws ClipsServerException {
        checkCommandAccessibility(COMMAND_MODIFY);
        if(day < 1 || day > 31
                || month < 1 || month > 12) {
            throw new IllegalArgumentException("Date dd.mm: " + day + "." + month);
        }
       
        Field f[] = {
            new Field("key.day", day),
            new Field("key.month", month)
        };
        deleteEntityList(SheduleHoliday.class, f);
    }
}
TOP

Related Classes of beans.shedule.holiday.SheduleHolidayBean

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.