Package framework.beans.collaborator

Source Code of framework.beans.collaborator.CollaboratorAbstract

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package framework.beans.collaborator;

import framework.audit.AuditProtectedProperty;
import framework.beans.directory.simple.entities.Name;
import framework.beans.directory.simple.entities.Patronymic;
import framework.beans.directory.simple.entities.Surname;
import framework.beans.client.ClientAbstract;
import framework.beans.directory.DirectoryEntity;
import framework.beans.directory.DirectoryEntityTrash;
import framework.beans.directory.collaborator.CollaboratorDirectoryDetailsAbstract;
import framework.beans.security.passwords.SessionPassword;
import framework.generic.ClipsServerException;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;
import reportgen.cores.ejb.annotations.DefineQueryEntity;
import reportgen.cores.ejb.annotations.DefineQueryProperty;

/**
*
* @param <DETAILSTYPE>
* @param <CLIENTTYPE>
* @author axe
*/
@Entity
@Table(name = "collaborator")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="coll_discriminator")
@DefineQueryEntity(title="Сотрудник")
public abstract class CollaboratorAbstract<DETAILSTYPE extends CollaboratorDirectoryDetailsAbstract, CLIENTTYPE extends ClientAbstract<?>> extends DirectoryEntity<DETAILSTYPE> implements DirectoryEntityTrash, Serializable {

    private static final long serialVersionUID = 1L;

    @Transient()
    protected String title;

    protected final static String MSGT_ID = "Идентификатор сотрудника";
    @DefineQueryProperty(title=MSGT_ID)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "coll_id", nullable = false)
    private int id;

    @AuditProtectedProperty()
    @Column(name = "coll_passwd", nullable = true)
    private String passwordHash;

    @Column(name = "coll_ldap", nullable = true)
    private String ldapName;

    protected final static String MSGT_FIRED = "Сотрудник уволен";
    @DefineQueryProperty(title=MSGT_FIRED)
    @Column(name = "coll_fired", nullable = false)
    private boolean trash;

    @Column(name = "coll_guiconfig", nullable = false)
    private String guiConfig;


    public CollaboratorAbstract() {
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public void setId(int id) {
        this.id = id;
    }

    public void setPasswordHash(byte [] aHash) {
        if (aHash == null) {
            this.passwordHash = null;
        } else {
            this.passwordHash = new String(SessionPassword.byte2char(aHash));
        }
    }

    public byte[] getPasswordHash() {
        if (passwordHash == null || passwordHash.isEmpty()) {
            return null;
        }
        return SessionPassword.char2byte(passwordHash.toCharArray());
    }

    public abstract CLIENTTYPE getClient();
    public abstract void setClient(CLIENTTYPE client);

    /**
     * В отчете не нужен, т.к. имеет встроенного клиента
   * работает только на неабстрактном коллабораторе
     * @return
     */
    @Override
    public String getTitle() {
        if (title == null) {
            title = generateTitle();
        }
        return title;
    }

  public void resetTitle(){
    title = null;
  }

  /**
   * работает только на неабстрактном коллабораторе
   * @return
   */
    private String generateTitle() {
        if (getClient() == null) {
            return "ФИО не указано";
        }
        Surname surname = getClient().getSurname();
        Name name = getClient().getName();
        Patronymic pat = getClient().getPathronymic();

        String collaborator = (surname == null) ? "?????????" : surname.getTitle();
        collaborator += " ";
        collaborator += (name == null) ? "?." : name.getTitle().substring(0, 1);
        collaborator += (pat == null) ? "?." : pat.getTitle().substring(0, 1);
        return collaborator;
    }

    @Override
    public boolean isTrash() {
        return trash;
    }

    @Override
    public void setTrash(boolean hidden) {
        this.trash = hidden;
    }


    public String getLdapName() {
        return ldapName;
    }

    public void setLdapName(String ldapName) {
        this.ldapName = ldapName;
    }


    public String getGuiConfig() {
        return guiConfig;
    }

    public void setGuiConfig(String guiConfig) {
        this.guiConfig = guiConfig;
    }

  /**
   * работает только на неабстрактном коллабораторе
   * @throws ClipsServerException
   */
  public void checkNotFired()
              throws ClipsServerException {
        if (isTrash()) {
            throw new ClipsServerException("Сотрудник " + getTitle() + " числится уволенным");
        }
    }

}
TOP

Related Classes of framework.beans.collaborator.CollaboratorAbstract

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.