Package br.net.woodstock.rockframework.security.cert.ext.icpbrasil

Source Code of br.net.woodstock.rockframework.security.cert.ext.icpbrasil.DadoPessoa

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security.cert.ext.icpbrasil;

import java.io.Serializable;
import java.util.Date;

import br.net.woodstock.rockframework.core.RockFrameworkVersion;
import br.net.woodstock.rockframework.core.utils.Conditions;
import br.net.woodstock.rockframework.security.cert.CertificateException;

public class DadoPessoa implements Serializable {

  private static final long  serialVersionUID  = RockFrameworkVersion.VERSION;

  private Date        dataNascimento;

  private String        cpf;

  private String        pis;

  private String        rg;

  private String        emissorRG;

  public DadoPessoa() {
    super();
  }

  public DadoPessoa(final Date dataNascimento, final String cpf, final String pis, final String rg, final String emissorRG) {
    super();
    this.dataNascimento = dataNascimento;
    this.cpf = cpf;
    this.pis = pis;
    this.rg = rg;
    this.emissorRG = emissorRG;
  }

  public DadoPessoa(final String otherNameString) {
    super();
    try {
      if (Conditions.isNotEmpty(otherNameString)) {
        String dataStr = otherNameString.substring(0, 8); // Data Nascimento
        this.setCpf(ICPBrasilHelper.getValueFromNumeric(otherNameString.substring(8, 19))); // CPF
        this.setPis(ICPBrasilHelper.getValueFromNumeric(otherNameString.substring(20, 30))); // PIS
        this.setRg(ICPBrasilHelper.getValueFromNumeric(otherNameString.substring(30, 45))); // RG
        this.setEmissorRG(otherNameString.substring(45).trim()); // Emissor RG

        if ((Conditions.isNotEmpty(dataStr)) && (Conditions.isNotEmpty(dataStr.replaceAll("0", "")))) {
          this.setDataNascimento(ICPBrasilHelper.getDateFromString(dataStr));
        }
      }
    } catch (Exception e) {
      throw new CertificateException(e);
    }

  }

  public Date getDataNascimento() {
    return this.dataNascimento;
  }

  public void setDataNascimento(final Date dataNascimento) {
    this.dataNascimento = dataNascimento;
  }

  public String getCpf() {
    return this.cpf;
  }

  public void setCpf(final String cpf) {
    this.cpf = cpf;
  }

  public String getPis() {
    return this.pis;
  }

  public void setPis(final String pis) {
    this.pis = pis;
  }

  public String getRg() {
    return this.rg;
  }

  public void setRg(final String rg) {
    this.rg = rg;
  }

  public String getEmissorRG() {
    return this.emissorRG;
  }

  public void setEmissorRG(final String emissorRG) {
    this.emissorRG = emissorRG;
  }

  // Aux
  @Override
  public String toString() {
    return this.toOtherNameString();
  }

  public String toOtherNameString() {
    String dataNascimento = ICPBrasilHelper.getDateValue(this.getDataNascimento());
    String cpf = ICPBrasilHelper.getNumericValue(this.getCpf(), 11);
    String pis = ICPBrasilHelper.getNumericValue(this.getPis(), 11);
    String rg = ICPBrasilHelper.getNumericValue(this.getRg(), 15);
    String emissorRG = ICPBrasilHelper.getValue(this.getEmissorRG());

    String str = dataNascimento + cpf + pis + rg + emissorRG;
    return str;
  }

}
TOP

Related Classes of br.net.woodstock.rockframework.security.cert.ext.icpbrasil.DadoPessoa

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.