Package beans.directory.expenditure

Source Code of beans.directory.expenditure.DirectoryExpenditureTypeBean

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

package beans.directory.expenditure;

import beans.directory.expenditure.entity.ExpenditureTypeDetails;
import framework.beans.directory.DirectoryBean;
import beans.directory.expenditure.entity.ExpenditureType;
import beans.expenditure.entity.Expenditure;
import beans.expenditure.entity.ExpenditureDefault;
import beans.directory.simple.entities.ExpenditureMetric;
import framework.generic.ClipsServerException;
import framework.generic.EMoveToTrash;
import javax.ejb.Stateful;
import beans.UserRightsSet;
import framework.security.UserRight;

/**
* @security ok
* @author axe
*/
@Stateful(mappedName="clips-beans/DirectoryExpenditureTypeBean")
public class DirectoryExpenditureTypeBean extends DirectoryBean<ExpenditureType, ExpenditureTypeDetails>
        implements DirectoryExpenditureTypeBeanRemote {

    public DirectoryExpenditureTypeBean() {
        super(ExpenditureType.class, "метрика");
    }

    @Override
    protected UserRight getRightForCreateDirectoryItem() {
        return UserRightsSet.WRITE_REGION_ADMIN_DIRECTORY;
    }

    @Override
    protected UserRight getRightForWriteToDirectory() {
        return UserRightsSet.WRITE_REGION_ADMIN_DIRECTORY;
    }
   
    @Override
    protected void set(ExpenditureType expenditureType, ExpenditureTypeDetails item) throws ClipsServerException {
        expenditureType.setTitle(item.title);
        expenditureType.setMetric(findEntity(ExpenditureMetric.class, item.metricID));
        expenditureType.setTrash(item.hidden);
        //expenditureType.setDirty(details.dirty);
    }

    @Override
    protected void onRemove(ExpenditureType entity) throws ClipsServerException {
        //проверяем, есть ли связанный расход материалов по умолчанию
        Field f[] = { new Field("type", entity) };
        if(getEntityCount(ExpenditureDefault.class, f) > 0) {
            throw new EMoveToTrash("Существует связанный расход материалов (по умолчанию), удаление невозможно");
        }
        //проверяем, есть ли связанный расход материалов
        if(getEntityCount(Expenditure.class, f) > 0) {
            throw new EMoveToTrash("Существует связанный расход материалов, удаление невозможно");
        }       
    }

}
TOP

Related Classes of beans.directory.expenditure.DirectoryExpenditureTypeBean

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.