Package beans.doctor.certificate

Source Code of beans.doctor.certificate.CertificateBean

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

package beans.doctor.certificate;

import beans.directory.certificate.entity.CertificateType;
import framework.beans.EntityDetails;
import framework.beans.FacadeBean;
import framework.beans.security.BeanRights;
import beans.user.client.entity.Client;
import beans.user.collaborator.entities.Collaborator;
import framework.generic.ClipsServerException;
import java.util.Date;
import javax.ejb.EJBException;
import javax.ejb.Stateful;
import beans.UserRightsSet;
import framework.audit.AuditDoc;
import java.util.List;

/**
* @security - Ok.
* Integrity - may be Ok.
* @author axe
*/
@Stateful(mappedName="clips-beans/CertificateBean")
public class CertificateBean extends FacadeBean<Certificate>
        implements CertificateBeanRemote {

    public CertificateBean() {
        super(Certificate.class);
    }
   
    @Override
    protected void initBeanRights() {
        int [] r = new int[4];
        r[COMMAND_READ] = RightPresence(UserRightsSet.READ_CERTIFICATE.id);
        r[COMMAND_CREATE] = RightPresence(UserRightsSet.MODIFY_CERTIFICATE.id);
        r[COMMAND_MODIFY] = RightPresence(UserRightsSet.MODIFY_CERTIFICATE.id);
        r[COMMAND_REMOVE] = RightPresence(UserRightsSet.MODIFY_CERTIFICATE.id);
       
        rights = new BeanRights(r);
    }

    /**
     * Обновляет данные сущности.
     * @param details новые детали сущности
     * @throws EJBException в случае если обновление отвергнуто системой
     *          безопастности либо произошла ошибка
     * @return идентификатор сущности
     * Безопасность: всё - свободно доступно.
     */
    @Override
    protected void onUpdate(Certificate entity, EntityDetails details,
            AuditDoc auditDoc, List<AuditDoc> auditDocList) throws ClipsServerException{
        CertificateDetails d = (CertificateDetails) details;

        checkCurrentCollaborator(d.collaboratorID);
        if (entity.getId() == 0) {
            entity.setDate(new Date());
        } else {
            if (getCollaboratorId() != entity.getCollaborator().getId()) {
                throwNeedAdminSecurityException("Попытка заменить автора справки");
            }
            if(d.clientID != entity.getClient().getId()) {
                throwNeedAdminSecurityException("Попытка подмены пациента");
            }
        }
        entity.setCollaborator(findEntity(Collaborator.class, getCollaboratorId()));
        entity.setClient(findEntity(Client.class, d.clientID));
        entity.setType(findEntity(CertificateType.class, d.typeID));
        entity.setXml(d.xml);
        auditDoc.addFieldFormat("xml", entity.getType().getReportDefinition().getReportParams());
    }

    @Override
    protected void onRemove(Certificate entity, List<AuditDoc> auditDocList) throws ClipsServerException {
        for (AuditDoc auditDoc : auditDocList) {
            auditDoc.addFieldFormat(entity, "xml", entity.getType().getReportDefinition().getReportParams());
        }
    }


}
TOP

Related Classes of beans.doctor.certificate.CertificateBean

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.