/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/RefMan/vo/ContractConfigVo.java
//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program 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 Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5589.25814)
// Copyright (C) 1995-2015 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.RefMan.vo;

/**
 * Linked to core.configuration.ContractConfig business object (ID: 1096100047).
 */
public class ContractConfigVo extends ims.RefMan.vo.ContractConfigShortVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public ContractConfigVo()
	{
	}
	public ContractConfigVo(Integer id, int version)
	{
		super(id, version);
	}
	public ContractConfigVo(ims.RefMan.vo.beans.ContractConfigVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.contractid = bean.getContractId();
		this.contractname = bean.getContractName();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.contractorganisation = bean.getContractOrganisation() == null ? null : bean.getContractOrganisation().buildVo();
		this.daystorttbreachdate = bean.getDaysToRTTBreachDate();
		this.contracttype = bean.getContractType() == null ? null : ims.core.vo.lookups.ReferralManagementContractType.buildLookup(bean.getContractType());
		this.daysto1stappt = bean.getDaysTo1stAppt();
		this.contractkpihistory = ims.RefMan.vo.ContractConfigKPIHistoryVoCollection.buildFromBeanCollection(bean.getContractKPIHistory());
		this.servicelocations = ims.RefMan.vo.ContractServiceLocationsConfigVoCollection.buildFromBeanCollection(bean.getServiceLocations());
		this.ccgsforcontract = ims.RefMan.vo.CCGToContractConfigVoCollection.buildFromBeanCollection(bean.getCCGsForContract());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.RefMan.vo.beans.ContractConfigVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.contractid = bean.getContractId();
		this.contractname = bean.getContractName();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.contractorganisation = bean.getContractOrganisation() == null ? null : bean.getContractOrganisation().buildVo(map);
		this.daystorttbreachdate = bean.getDaysToRTTBreachDate();
		this.contracttype = bean.getContractType() == null ? null : ims.core.vo.lookups.ReferralManagementContractType.buildLookup(bean.getContractType());
		this.daysto1stappt = bean.getDaysTo1stAppt();
		this.contractkpihistory = ims.RefMan.vo.ContractConfigKPIHistoryVoCollection.buildFromBeanCollection(bean.getContractKPIHistory());
		this.servicelocations = ims.RefMan.vo.ContractServiceLocationsConfigVoCollection.buildFromBeanCollection(bean.getServiceLocations());
		this.ccgsforcontract = ims.RefMan.vo.CCGToContractConfigVoCollection.buildFromBeanCollection(bean.getCCGsForContract());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.RefMan.vo.beans.ContractConfigVoBean bean = null;
		if(map != null)
			bean = (ims.RefMan.vo.beans.ContractConfigVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.RefMan.vo.beans.ContractConfigVoBean();
			map.addValueObjectBean(this, bean);
			bean.populate(map, this);
		}
		return bean;
	}
	public Object getFieldValueByFieldName(String fieldName)
	{
		if(fieldName == null)
			throw new ims.framework.exceptions.CodingRuntimeException("Invalid field name");
		fieldName = fieldName.toUpperCase();
		if(fieldName.equals("DAYSTO1STAPPT"))
			return getDaysTo1stAppt();
		if(fieldName.equals("CONTRACTKPIHISTORY"))
			return getContractKPIHistory();
		if(fieldName.equals("SERVICELOCATIONS"))
			return getServiceLocations();
		if(fieldName.equals("CCGSFORCONTRACT"))
			return getCCGsForContract();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getDaysTo1stApptIsNotNull()
	{
		return this.daysto1stappt != null;
	}
	public Integer getDaysTo1stAppt()
	{
		return this.daysto1stappt;
	}
	public void setDaysTo1stAppt(Integer value)
	{
		this.isValidated = false;
		this.daysto1stappt = value;
	}
	public boolean getContractKPIHistoryIsNotNull()
	{
		return this.contractkpihistory != null;
	}
	public ims.RefMan.vo.ContractConfigKPIHistoryVoCollection getContractKPIHistory()
	{
		return this.contractkpihistory;
	}
	public void setContractKPIHistory(ims.RefMan.vo.ContractConfigKPIHistoryVoCollection value)
	{
		this.isValidated = false;
		this.contractkpihistory = value;
	}
	public boolean getServiceLocationsIsNotNull()
	{
		return this.servicelocations != null;
	}
	public ims.RefMan.vo.ContractServiceLocationsConfigVoCollection getServiceLocations()
	{
		return this.servicelocations;
	}
	public void setServiceLocations(ims.RefMan.vo.ContractServiceLocationsConfigVoCollection value)
	{
		this.isValidated = false;
		this.servicelocations = value;
	}
	public boolean getCCGsForContractIsNotNull()
	{
		return this.ccgsforcontract != null;
	}
	public ims.RefMan.vo.CCGToContractConfigVoCollection getCCGsForContract()
	{
		return this.ccgsforcontract;
	}
	public void setCCGsForContract(ims.RefMan.vo.CCGToContractConfigVoCollection value)
	{
		this.isValidated = false;
		this.ccgsforcontract = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.contractkpihistory != null)
		{
			if(!this.contractkpihistory.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.servicelocations != null)
		{
			if(!this.servicelocations.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.ccgsforcontract != null)
		{
			if(!this.ccgsforcontract.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		this.isBusy = false;
		return true;
	}
	public String[] validate()
	{
		return validate(null);
	}
	public String[] validate(String[] existingErrors)
	{
		if(this.isBusy)
			return null;
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
		if(this.contractid == null || this.contractid.length() == 0)
			listOfErrors.add("ContractId is mandatory");
		else if(this.contractid.length() > 25)
			listOfErrors.add("The length of the field [contractid] in the value object [ims.RefMan.vo.ContractConfigVo] is too big. It should be less or equal to 25");
		if(this.contractname == null || this.contractname.length() == 0)
			listOfErrors.add("ContractName is mandatory");
		else if(this.contractname.length() > 255)
			listOfErrors.add("The length of the field [contractname] in the value object [ims.RefMan.vo.ContractConfigVo] is too big. It should be less or equal to 255");
		if(this.status == null)
			listOfErrors.add("Status is mandatory");
		if(this.contractorganisation == null)
			listOfErrors.add("ContractOrganisation is mandatory");
		if(this.daystorttbreachdate == null)
			listOfErrors.add("DaysToRTTBreachDate is mandatory");
		if(this.contracttype == null)
			listOfErrors.add("ContractType is mandatory");
		if(this.daysto1stappt == null)
			listOfErrors.add("No. of Days to 1st Activity Appointment is mandatory");
		if(this.contractkpihistory == null || this.contractkpihistory.size() == 0)
			listOfErrors.add("ContractKPIHistory are mandatory");
		if(this.contractkpihistory != null)
		{
			String[] listOfOtherErrors = this.contractkpihistory.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.servicelocations != null)
		{
			String[] listOfOtherErrors = this.servicelocations.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.ccgsforcontract != null)
		{
			String[] listOfOtherErrors = this.ccgsforcontract.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
		String[] result = new String[errorCount];
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
		this.isBusy = false;
		this.isValidated = false;
		return result;
	}
	public void clearIDAndVersion()
	{
		this.id = null;
		this.version = 0;
	}
	public Object clone()
	{
		if(this.isBusy)
			return this;
		this.isBusy = true;
	
		ContractConfigVo clone = new ContractConfigVo(this.id, this.version);
		
		clone.contractid = this.contractid;
		clone.contractname = this.contractname;
		if(this.status == null)
			clone.status = null;
		else
			clone.status = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)this.status.clone();
		if(this.contractorganisation == null)
			clone.contractorganisation = null;
		else
			clone.contractorganisation = (ims.core.vo.OrganisationLiteVo)this.contractorganisation.clone();
		clone.daystorttbreachdate = this.daystorttbreachdate;
		if(this.contracttype == null)
			clone.contracttype = null;
		else
			clone.contracttype = (ims.core.vo.lookups.ReferralManagementContractType)this.contracttype.clone();
		clone.daysto1stappt = this.daysto1stappt;
		if(this.contractkpihistory == null)
			clone.contractkpihistory = null;
		else
			clone.contractkpihistory = (ims.RefMan.vo.ContractConfigKPIHistoryVoCollection)this.contractkpihistory.clone();
		if(this.servicelocations == null)
			clone.servicelocations = null;
		else
			clone.servicelocations = (ims.RefMan.vo.ContractServiceLocationsConfigVoCollection)this.servicelocations.clone();
		if(this.ccgsforcontract == null)
			clone.ccgsforcontract = null;
		else
			clone.ccgsforcontract = (ims.RefMan.vo.CCGToContractConfigVoCollection)this.ccgsforcontract.clone();
		clone.isValidated = this.isValidated;
		
		this.isBusy = false;
		return clone;
	}
	public int compareTo(Object obj)
	{
		return compareTo(obj, true);
	}
	public int compareTo(Object obj, boolean caseInsensitive)
	{
		if (obj == null)
		{
			return -1;
		}
		if(caseInsensitive); // this is to avoid eclipse warning only.
		if (!(ContractConfigVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A ContractConfigVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((ContractConfigVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((ContractConfigVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.daysto1stappt != null)
			count++;
		if(this.contractkpihistory != null)
			count++;
		if(this.servicelocations != null)
			count++;
		if(this.ccgsforcontract != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 4;
	}
	protected Integer daysto1stappt;
	protected ims.RefMan.vo.ContractConfigKPIHistoryVoCollection contractkpihistory;
	protected ims.RefMan.vo.ContractServiceLocationsConfigVoCollection servicelocations;
	protected ims.RefMan.vo.CCGToContractConfigVoCollection ccgsforcontract;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
