Package beans.directory.collaborator

Source Code of beans.directory.collaborator.DirectoryCollaboratorBean

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

package beans.directory.collaborator;

import beans.UserRightsSet;
import beans.user.collaborator.entities.Collaborator;
import beans.user.collaborator.entities.CollaboratorDetails;
import framework.beans.directory.collaborator.DirectoryCollaboratorBeanAbstract;
import framework.generic.ClipsServerException;
import framework.generic.EDataIntegrity;
import framework.generic.ESecurity;
import framework.security.UserRight;
import java.util.List;
import javax.ejb.Stateful;

/**
* @security  Ok.
* @author axe
*/
@Stateful(mappedName="clips-beans/DirectoryCollaboratorBean")
public class DirectoryCollaboratorBean
        extends DirectoryCollaboratorBeanAbstract<Collaborator, CollaboratorDetails>
        implements DirectoryCollaboratorBeanRemote {

  public DirectoryCollaboratorBean() {
    super(Collaborator.class);
  }


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

    @Override
    protected UserRight getRightForWriteToDirectory() {
        return UserRightsSet.WRITE_DEVELOPER_DIRECTORY;
    }


    /**
     * Возвращает список
     * @param withDischarged
     * @return
     * @security без ограничений
     */
    /*@Override
    public List<CollaboratorDirectoryDetails> getDirectory(boolean withDischarged) {
        Field[] f = {new Field("trash", false)};
        if (withDischarged){
            f = null;
        }
        ArrayList <CollaboratorDirectoryDetails> det = new ArrayList<CollaboratorDirectoryDetails>();
        List<Collaborator> res = findEntityList(Collaborator.class.getSimpleName(), f);
        for(int i=0; i<res.size(); i++) {
            Collaborator coll = res.get(i);
            det.add(coll.getDirectoryDetails());
        }
        return det;
    }*/


    /**
     * Ищет сотрудника, соответствующего данному человеку (по id)
     * @param clientID
     * @return
     * @throws framework.generic.ClipsServerException
     */
    @Override
    public int getByClient(int clientID) throws ClipsServerException {
        if (clientID == 0) {
            return 0;
        }
        Field f[] = {
            new Field("client.id", clientID)
        };
        List<Collaborator> collabList = findEntityList(Collaborator.class, f);
        if (collabList.size() == 0) {
            return 0;
        } else if (collabList.size() == 1) {
            return collabList.get(0).getId();
        } else {
            throw new EDataIntegrity("В базе зарегистрировано " + collabList.size() +
                    " сотрудников для данного человека");
        }
    }

    @Override
    protected void set(Collaborator entity, CollaboratorDetails details) throws ClipsServerException {
        throw new ESecurity("Справочник сотрудников нельзя редактировать данным методом");
    }

    @Override
    public List<CollaboratorDetails> getDirectory() {
        return super.getDirectory();
    }

    @Override
    public int getByCardID(String cardID) throws ClipsServerException {
        Field f[] = { new Field("client.socialCardId", cardID)};
        List<Collaborator> collabList = findEntityList(Collaborator.class, f);
        if (collabList.size() == 0) {
            return 0;
        } else if (collabList.size() == 1) {
            return collabList.get(0).getId();
        } else {
            throw new EDataIntegrity("В базе зарегистрировано " + collabList.size() +
                    " сотрудников для этой социальной карты");
        }
    }


}
TOP

Related Classes of beans.directory.collaborator.DirectoryCollaboratorBean

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.