/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/admin/vo/PrintAgentDocumentsVo.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.admin.vo;

/**
 * Linked to core.admin.PrintAgentDocuments business object (ID: 1004100015).
 */
public class PrintAgentDocumentsVo extends ims.core.admin.vo.PrintAgentDocumentsRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public PrintAgentDocumentsVo()
	{
	}
	public PrintAgentDocumentsVo(Integer id, int version)
	{
		super(id, version);
	}
	public PrintAgentDocumentsVo(ims.admin.vo.beans.PrintAgentDocumentsVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.printagent = bean.getPrintAgent() == null ? null : bean.getPrintAgent().buildVo();
		this.document = bean.getDocument();
		this.printedrecords = bean.getPrintedRecords();
		this.lastupdatedatetime = bean.getLastUpdateDateTime() == null ? null : bean.getLastUpdateDateTime().buildDateTime();
		this.printedletters = bean.getPrintedLetters();
		this.description = bean.getDescription();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.admin.vo.beans.PrintAgentDocumentsVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.printagent = bean.getPrintAgent() == null ? null : bean.getPrintAgent().buildVo(map);
		this.document = bean.getDocument();
		this.printedrecords = bean.getPrintedRecords();
		this.lastupdatedatetime = bean.getLastUpdateDateTime() == null ? null : bean.getLastUpdateDateTime().buildDateTime();
		this.printedletters = bean.getPrintedLetters();
		this.description = bean.getDescription();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.admin.vo.beans.PrintAgentDocumentsVoBean bean = null;
		if(map != null)
			bean = (ims.admin.vo.beans.PrintAgentDocumentsVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.admin.vo.beans.PrintAgentDocumentsVoBean();
			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("PRINTAGENT"))
			return getPrintAgent();
		if(fieldName.equals("DOCUMENT"))
			return getDocument();
		if(fieldName.equals("PRINTEDRECORDS"))
			return getPrintedRecords();
		if(fieldName.equals("LASTUPDATEDATETIME"))
			return getLastUpdateDateTime();
		if(fieldName.equals("PRINTEDLETTERS"))
			return getPrintedLetters();
		if(fieldName.equals("DESCRIPTION"))
			return getDescription();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPrintAgentIsNotNull()
	{
		return this.printagent != null;
	}
	public ims.admin.vo.PrintAgentVo getPrintAgent()
	{
		return this.printagent;
	}
	public void setPrintAgent(ims.admin.vo.PrintAgentVo value)
	{
		this.isValidated = false;
		this.printagent = value;
	}
	public boolean getDocumentIsNotNull()
	{
		return this.document != null;
	}
	public String getDocument()
	{
		return this.document;
	}
	public static int getDocumentMaxLength()
	{
		return 900000;
	}
	public void setDocument(String value)
	{
		this.isValidated = false;
		this.document = value;
	}
	public boolean getPrintedRecordsIsNotNull()
	{
		return this.printedrecords != null;
	}
	public Integer[] getPrintedRecords()
	{
		return this.printedrecords;
	}
	public void setPrintedRecords(Integer[] value)
	{
		this.isValidated = false;
		this.printedrecords = value;
	}
	public boolean getLastUpdateDateTimeIsNotNull()
	{
		return this.lastupdatedatetime != null;
	}
	public ims.framework.utils.DateTime getLastUpdateDateTime()
	{
		return this.lastupdatedatetime;
	}
	public void setLastUpdateDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.lastupdatedatetime = value;
	}
	public boolean getPrintedLettersIsNotNull()
	{
		return this.printedletters != null;
	}
	public Integer getPrintedLetters()
	{
		return this.printedletters;
	}
	public void setPrintedLetters(Integer value)
	{
		this.isValidated = false;
		this.printedletters = value;
	}
	public boolean getDescriptionIsNotNull()
	{
		return this.description != null;
	}
	public String getDescription()
	{
		return this.description;
	}
	public static int getDescriptionMaxLength()
	{
		return 255;
	}
	public void setDescription(String value)
	{
		this.isValidated = false;
		this.description = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.printagent != null)
		{
			if(!this.printagent.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.printagent == null)
			listOfErrors.add("PrintAgent is mandatory");
		if(this.printagent != null)
		{
			String[] listOfOtherErrors = this.printagent.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.document == null || this.document.length() == 0)
			listOfErrors.add("Document is mandatory");
		if(this.printedrecords == null || this.printedrecords.length == 0)
			listOfErrors.add("PrintedRecords are mandatory");
		if(this.description != null)
			if(this.description.length() > 255)
				listOfErrors.add("The length of the field [description] in the value object [ims.admin.vo.PrintAgentDocumentsVo] is too big. It should be less or equal to 255");
		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;
	
		PrintAgentDocumentsVo clone = new PrintAgentDocumentsVo(this.id, this.version);
		
		if(this.printagent == null)
			clone.printagent = null;
		else
			clone.printagent = (ims.admin.vo.PrintAgentVo)this.printagent.clone();
		clone.document = this.document;
		clone.printedrecords = this.printedrecords;
		if(this.lastupdatedatetime == null)
			clone.lastupdatedatetime = null;
		else
			clone.lastupdatedatetime = (ims.framework.utils.DateTime)this.lastupdatedatetime.clone();
		clone.printedletters = this.printedletters;
		clone.description = this.description;
		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 (!(PrintAgentDocumentsVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A PrintAgentDocumentsVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		PrintAgentDocumentsVo compareObj = (PrintAgentDocumentsVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getLastUpdateDateTime() == null && compareObj.getLastUpdateDateTime() != null)
				return -1;
			if(this.getLastUpdateDateTime() != null && compareObj.getLastUpdateDateTime() == null)
				return 1;
			if(this.getLastUpdateDateTime() != null && compareObj.getLastUpdateDateTime() != null)
				retVal = this.getLastUpdateDateTime().compareTo(compareObj.getLastUpdateDateTime());
		}
		if (retVal == 0)
		{
			if(this.getID_PrintAgentDocuments() == null && compareObj.getID_PrintAgentDocuments() != null)
				return -1;
			if(this.getID_PrintAgentDocuments() != null && compareObj.getID_PrintAgentDocuments() == null)
				return 1;
			if(this.getID_PrintAgentDocuments() != null && compareObj.getID_PrintAgentDocuments() != null)
				retVal = this.getID_PrintAgentDocuments().compareTo(compareObj.getID_PrintAgentDocuments());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.printagent != null)
			count++;
		if(this.document != null)
			count++;
		if(this.printedrecords != null)
			count++;
		if(this.lastupdatedatetime != null)
			count++;
		if(this.printedletters != null)
			count++;
		if(this.description != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 6;
	}
	protected ims.admin.vo.PrintAgentVo printagent;
	protected String document;
	protected Integer[] printedrecords;
	protected ims.framework.utils.DateTime lastupdatedatetime;
	protected Integer printedletters;
	protected String description;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
