Package clips.delegate.contract

Source Code of clips.delegate.contract.PolisData

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

package clips.delegate.contract;

import beans.contract.entity.PolisDetails;
import cli_fmw.delegate.AuditListener;
import cli_fmw.delegate.client.Address;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import clips.delegate.client.ClientLocal;
import cli_fmw.delegate.lists.DataChunk;
import cli_fmw.delegate.lists.Mappable;
import clips.delegate.client.CollaboratorLocal;
import clips.delegate.directory.simple.insurer.DirectoryInsurer;
import clips.delegate.directory.simple.insurer.DirectoryInsurerItem;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCode;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCodeItem;
import framework.beans.address.entities.AddressDetails;
import java.util.Date;

/**
*
* @author lacoste
*/
public class PolisData extends DataChunk<PolisDetails>
        implements Comparable<PolisData>, Mappable<Integer> {

    private ClientLocal client;
    private ContractLocal contract;
   
    public PolisData(ContractLocal contract, ClientLocal client) throws ClipsException {
        super(new PolisDetails());
        this.contract = contract;
        this.client = client;
        getDetails().clientID = client.getID();
        getDetails().contractID = contract.getID();
        if (! client.getAddress().isEmpty()) {
            getDetails().addressDetail = client.getAddress().getDetails();
        }
    }

    public PolisData(ContractLocal contract, ClientLocal client, PolisDetails details) throws ClipsException {
        super(details);
        this.contract = contract;
        this.client = client;
       
        if(client != null &&
                getDetails().clientID != client.getID()) {
            throw new IllegalArgumentException("Inconsistent client data");
        }
       
    }
   
    @Override
    public Integer getKey() {
        return getDetails().getId();
    }

    public ClientLocal getClient() throws ClipsException {
        if(getId() != 0
                && client == null) {
            client = new ClientLocal(getDetails().clientID, null);//NULL AL
        }
        return client;
    }

    public ClientLocal getClient(AuditListener al) throws ClipsException {
        if (getId() != 0
                && client == null) {
            client = new ClientLocal(getDetails().clientID, al);
        }
        return client;
    }

    public ContractLocal getContract() {
        if(getId() != 0
                && contract == null) {
            contract = new ContractLocal(getDetails().contractID, null);//NULL AL
        }
        return contract;
    }

    public CollaboratorLocal getCollaborator(AuditListener al) throws ClipsException {
        if (getDetails().collabID != 0) {
            return new CollaboratorLocal(getDetails().collabID, al);
        }
        return null;
    }

    public void setCollaborator(CollaboratorLocal collab) {
        getDetails().collabID = collab.getID();
        fireContentStateEvent();
    }

    public boolean isMember() {
        return getDetails().member;
    }

    public void setMember(boolean member) {
        getDetails().member = member;
        fireContentStateEvent();
    }  

    public String getNumber() {
        return getDetails().number != null ? getDetails().number : "";
    }

    public void setNumber(String number) {
        if (number == null || number.trim().equals("")) {
            getDetails().number = null;
        } else {
            getDetails().number = number;
        }
        fireContentStateEvent();
    }

    public String getSeries() {
        return getDetails().series != null ? getDetails().series : "";
    }

    public void setSeries(String series) {
        if (series == null || series.trim().equals("")) {
            getDetails().series = null;
        } else {
            getDetails().series = series;
        }
        fireContentStateEvent();
    }

    public Date getTillDate() {
        return getDetails().tillDate;
    }

    public void setTillDate(Date tillDate) {
        getDetails().tillDate = tillDate;
        fireContentStateEvent();
    }

    public Date getFromDate() {
        return getDetails().fromDate;
    }

    public void setFromDate(Date fromDate) {
        getDetails().fromDate = fromDate;
        fireContentStateEvent();
    }

    public DirectoryInsurerItem getInsurer() throws ClipsException {
        DirectoryInsurer di = DirectoryLocator.getDirectory(DirectoryInsurer.class);
        System.out.println("getInsurer: " + di.getItemFromID(getDetails().insurerID));
        return di.getItemFromID(getDetails().insurerID);
    }

    public void setInsurer(DirectoryInsurerItem item) {
        System.out.println("setInsurer: " + item);
        getDetails().insurerID = item.getID();
        fireContentStateEvent();
    }

    public DirectoryRegionIdCodeItem getRegionCode() throws ClipsException {
        DirectoryRegionIdCode di = DirectoryLocator.getDirectory(DirectoryRegionIdCode.class);
        return di.getItemFromID(getDetails().regionCodeId);
    }

    public void setRegionCode(DirectoryRegionIdCodeItem item) {
        getDetails().regionCodeId = item.getID();
        fireContentStateEvent();
    }

    public Address getAddress() throws ClipsException {
        if (getDetails().addressDetail != null) {
            return new Address(getDetails().addressDetail);
        }
        return new Address(new AddressDetails());
    }

    public void setAddress(Address address) {
        getDetails().addressDetail = address.getDetails();
        fireContentStateEvent();
    }

    @Override
    public int compareTo(PolisData cm) {
        try {
            String y = cm.getClient().toString() + cm.getSeries() + cm.getNumber();
            String x = getClient().toString() + getSeries() + getNumber();
            return x.compareTo(y);
        } catch (ClipsException ex) {
            return 0;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        int hash = super.hashCode();
        hash = 67 * hash + (this.client != null ? this.client.hashCode() : 0);
        hash = 67 * hash + (this.contract != null ? this.contract.hashCode() : 0);
        return hash;
    }


}
TOP

Related Classes of clips.delegate.contract.PolisData

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.