Package clips.delegate.doctor.checkup.shedule

Source Code of clips.delegate.doctor.checkup.shedule.CheckupSheduleLocal$CheckupInfo

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.delegate.doctor.checkup.shedule;

import beans.doctor.checkup.shedule.CheckupSheduleBeanRemote;
import cli_fmw.delegate.cache.ExtraDataManager;
import clips.delegate.directory.filtered.DirectoryCheckupType;
import clips.delegate.directory.filtered.DirectoryCheckupTypeItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.doctor.checkup.CheckupLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.cache.DelegateExtraData;
import cli_fmw.main.ClipsException;
import clips.delegate.service.SerRenLocal;
import beans.doctor.checkup.CheckupDetails;
import beans.doctor.checkup.shedule.CheckupSheduleBean;
import beans.doctor.checkup.shedule.CheckupSheduleDetails;
import framework.beans.ModificationInfo;
import cli_fmw.delegate.AuditListener;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
* Делегат представляющий строку в таблице checkup_shedule
* @author vip
*/
public class CheckupSheduleLocal extends
    DelegateLine2<CheckupSheduleBeanRemote, CheckupSheduleDetails> {

    private CheckupInfo checkupSet = new CheckupInfo(getEDM());

    /**
     * Кеш чекапов
     */
    private class CheckupInfo extends DelegateExtraData<Set<CheckupLocal>> {
        private HashMap<Integer, SerRenLocal> serrenMap
                = new HashMap<Integer, SerRenLocal>();

        public CheckupInfo(ExtraDataManager contaner) {
            super(contaner);
        }

        @Override
        protected Set<CheckupLocal> init() throws Exception {
            Set<CheckupLocal> res = new HashSet<CheckupLocal>();
            Iterator<CheckupDetails> it = getBean().getCheckupList().iterator();
            while (it.hasNext()) {
                CheckupDetails d = it.next();
                int serrenID = d.serviceRenderID;
                if (serrenMap.get(serrenID) == null) {
                    serrenMap.put(serrenID, new SerRenLocal(serrenID, getAuditListener()));
                }
                res.add(new CheckupLocal(d, serrenMap.get(serrenID), getAuditListener()));
            }
            return res;
        }

        @Override
        protected  void saveDB() throws Exception {
            Set<Integer> idSet = new HashSet<Integer>();
            Iterator<CheckupLocal> it = get().iterator();
            while (it.hasNext()) {
                CheckupLocal checkup = it.next();
                idSet.add(checkup.getID());
            }
            ModificationInfo mi = getBean().setCheckupList(idSet);
            auditDetailsList.addAll(mi.getAudit());
            fireAuditEvent();
        }

        @Override
        protected Set<CheckupLocal> initNew() {
            return new HashSet<CheckupLocal>();
        }
    }
   
   
    public CheckupSheduleLocal(int id, AuditListener al) {
        super(id, al);
    }

    public CheckupSheduleLocal(DirectoryCheckupTypeItem checkUpType, Date sheduleDate, AuditListener al) throws ClipsException {
        super(al);
        getDetails().date = sheduleDate;
        getDetails().checkupTypeId = checkUpType.getID();
    }

    @Override
    protected CheckupSheduleDetails getNewDetails() {
        return new CheckupSheduleDetails();
    }

   
    //Геттеры и сеттеры
    public DirectoryCheckupTypeItem getType() throws ClipsException {
        DirectoryCheckupType checkUpTypes = DirectoryLocator.getDirectory(DirectoryCheckupType.class, false);
        return checkUpTypes.getItemFromID(getDetails().checkupTypeId);
    }

    public Date getDate() throws ClipsException {
        return getDetails().date;
    }


    /**
     * Загружает список чекапов, привязанных к этому элементу расписания
     * @return селектор с чекапами заданного типа
     * @throws ClipsException
     */
    public Set<CheckupLocal> getCheckupSet() throws ClipsException {
        return new HashSet<CheckupLocal>(checkupSet.get());
    }

    /**
     * Сохраняет список чекапов привязанных к этой шедуле
     * @param checkupSet сект чекапов
     * @throws ClipsException
     */
    public void setCheckupList(Set<CheckupLocal> checkupSet) throws ClipsException {
        this.checkupSet.set(checkupSet);
    }

    /**
     * Завершает все анализы в данном расписании:
     * за одну транзакцию совершает следующие действия
     * удаляет все чекапы из данного расписания
     * для каждого чекаба оказывает услугу, на которую он завязан
     * в услуге выставляется текущий коллаборатор, дата оказания и повторность
     * @throws ClipsException
     */
    public void finishRenderingServices() throws ClipsException {
        if (isDirty()) {
            throw new ClipsException("Список анализов в данном расписании был изменен");
        }
        try {
            ModificationInfo mi = getBean().finishRenderingServices();
            auditDetailsList.addAll(mi.getAudit());
            fireAuditEvent();
        } catch (Exception ex) {
            clearBean();
            throw new ClipsException("Не удалось завершить анализы в данном расписании", ex);
        }
//        checkupSet.clearCache(); EVIL CODE! (this shedule was remove from db)
        checkupSet.initNew();
        fireContentStateEvent();
    }

    @Override
    protected String getBeanName() {
        return CheckupSheduleBean.class.getSimpleName();
    }

    /**
     * удаляет шедулю если она пуста
     * в любом случае непустую шедулю удалить не удасться тк база заругаетсо
     * @throws ClipsException
     */
    public void removeEmpty() throws ClipsException{
        if (isNewlyCreated()) {
            return;
        }
        if (checkupSet.get().isEmpty()){
            try {
                ModificationInfo mi = getBean().remove();
                auditDetailsList.addAll(mi.getAudit());
                fireAuditEvent();
            } catch (Exception ex) {
                clearBean();
                throw new ClipsException("Не удалось удалить расписание анализов");
            }
        }
    }
}
TOP

Related Classes of clips.delegate.doctor.checkup.shedule.CheckupSheduleLocal$CheckupInfo

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.