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

/**
 * Linked to NAES.ActionDetail business object (ID: 1097100002).
 */
public class ActionDetailVo extends ims.naes.vo.ActionDetailRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public ActionDetailVo()
	{
	}
	public ActionDetailVo(Integer id, int version)
	{
		super(id, version);
	}
	public ActionDetailVo(ims.naes.vo.beans.ActionDetailVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.action = bean.getAction() == null ? null : ims.naes.vo.lookups.Action.buildLookup(bean.getAction());
		this.startdate = bean.getStartDate() == null ? null : bean.getStartDate().buildDate();
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo();
		this.responsibletechnician = bean.getResponsibleTechnician() == null ? null : bean.getResponsibleTechnician().buildVo();
		this.timeelapsed = bean.getTimeElapsed();
		this.comment = bean.getComment();
		this.statushistory = ims.naes.vo.ActionDetailStatusVoCollection.buildFromBeanCollection(bean.getStatusHistory());
		this.sysinfo = bean.getSysinfo() == null ? null : bean.getSysinfo().buildSystemInformation();
		this.actiontemplate = bean.getActionTemplate() == null ? null : bean.getActionTemplate().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.naes.vo.beans.ActionDetailVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.action = bean.getAction() == null ? null : ims.naes.vo.lookups.Action.buildLookup(bean.getAction());
		this.startdate = bean.getStartDate() == null ? null : bean.getStartDate().buildDate();
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo(map);
		this.responsibletechnician = bean.getResponsibleTechnician() == null ? null : bean.getResponsibleTechnician().buildVo(map);
		this.timeelapsed = bean.getTimeElapsed();
		this.comment = bean.getComment();
		this.statushistory = ims.naes.vo.ActionDetailStatusVoCollection.buildFromBeanCollection(bean.getStatusHistory());
		this.sysinfo = bean.getSysinfo() == null ? null : bean.getSysinfo().buildSystemInformation();
		this.actiontemplate = bean.getActionTemplate() == null ? null : bean.getActionTemplate().buildVo(map);
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.naes.vo.beans.ActionDetailVoBean bean = null;
		if(map != null)
			bean = (ims.naes.vo.beans.ActionDetailVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.naes.vo.beans.ActionDetailVoBean();
			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("ACTION"))
			return getAction();
		if(fieldName.equals("STARTDATE"))
			return getStartDate();
		if(fieldName.equals("CURRENTSTATUS"))
			return getCurrentStatus();
		if(fieldName.equals("RESPONSIBLETECHNICIAN"))
			return getResponsibleTechnician();
		if(fieldName.equals("TIMEELAPSED"))
			return getTimeElapsed();
		if(fieldName.equals("COMMENT"))
			return getComment();
		if(fieldName.equals("STATUSHISTORY"))
			return getStatusHistory();
		if(fieldName.equals("SYSINFO"))
			return getSysinfo();
		if(fieldName.equals("ACTIONTEMPLATE"))
			return getActionTemplate();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getActionIsNotNull()
	{
		return this.action != null;
	}
	public ims.naes.vo.lookups.Action getAction()
	{
		return this.action;
	}
	public void setAction(ims.naes.vo.lookups.Action value)
	{
		this.isValidated = false;
		this.action = value;
	}
	public boolean getStartDateIsNotNull()
	{
		return this.startdate != null;
	}
	public ims.framework.utils.Date getStartDate()
	{
		return this.startdate;
	}
	public void setStartDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.startdate = value;
	}
	public boolean getCurrentStatusIsNotNull()
	{
		return this.currentstatus != null;
	}
	public ims.naes.vo.ActionDetailStatusVo getCurrentStatus()
	{
		return this.currentstatus;
	}
	public void setCurrentStatus(ims.naes.vo.ActionDetailStatusVo value)
	{
		this.isValidated = false;
		this.currentstatus = value;
	}
	public boolean getResponsibleTechnicianIsNotNull()
	{
		return this.responsibletechnician != null;
	}
	public ims.core.vo.MemberOfStaffLiteVo getResponsibleTechnician()
	{
		return this.responsibletechnician;
	}
	public void setResponsibleTechnician(ims.core.vo.MemberOfStaffLiteVo value)
	{
		this.isValidated = false;
		this.responsibletechnician = value;
	}
	public boolean getTimeElapsedIsNotNull()
	{
		return this.timeelapsed != null;
	}
	public Integer getTimeElapsed()
	{
		return this.timeelapsed;
	}
	public void setTimeElapsed(Integer value)
	{
		this.isValidated = false;
		this.timeelapsed = value;
	}
	public boolean getCommentIsNotNull()
	{
		return this.comment != null;
	}
	public String getComment()
	{
		return this.comment;
	}
	public static int getCommentMaxLength()
	{
		return 255;
	}
	public void setComment(String value)
	{
		this.isValidated = false;
		this.comment = value;
	}
	public boolean getStatusHistoryIsNotNull()
	{
		return this.statushistory != null;
	}
	public ims.naes.vo.ActionDetailStatusVoCollection getStatusHistory()
	{
		return this.statushistory;
	}
	public void setStatusHistory(ims.naes.vo.ActionDetailStatusVoCollection value)
	{
		this.isValidated = false;
		this.statushistory = value;
	}
	public boolean getSysinfoIsNotNull()
	{
		return this.sysinfo != null;
	}
	public ims.vo.SystemInformation getSysinfo()
	{
		return this.sysinfo;
	}
	public void setSysinfo(ims.vo.SystemInformation value)
	{
		this.isValidated = false;
		this.sysinfo = value;
	}
	public boolean getActionTemplateIsNotNull()
	{
		return this.actiontemplate != null;
	}
	public ims.core.vo.ActionPlanTemplateVo getActionTemplate()
	{
		return this.actiontemplate;
	}
	public void setActionTemplate(ims.core.vo.ActionPlanTemplateVo value)
	{
		this.isValidated = false;
		this.actiontemplate = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.currentstatus != null)
		{
			if(!this.currentstatus.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.responsibletechnician != null)
		{
			if(!this.responsibletechnician.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.statushistory != null)
		{
			if(!this.statushistory.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.action == null)
			listOfErrors.add("Action is mandatory");
		if(this.currentstatus == null)
			listOfErrors.add("CurrentStatus is mandatory");
		if(this.currentstatus != null)
		{
			String[] listOfOtherErrors = this.currentstatus.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.responsibletechnician != null)
		{
			String[] listOfOtherErrors = this.responsibletechnician.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.comment != null)
			if(this.comment.length() > 255)
				listOfErrors.add("The length of the field [comment] in the value object [ims.naes.vo.ActionDetailVo] is too big. It should be less or equal to 255");
		if(this.statushistory != null)
		{
			String[] listOfOtherErrors = this.statushistory.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;
	
		ActionDetailVo clone = new ActionDetailVo(this.id, this.version);
		
		if(this.action == null)
			clone.action = null;
		else
			clone.action = (ims.naes.vo.lookups.Action)this.action.clone();
		if(this.startdate == null)
			clone.startdate = null;
		else
			clone.startdate = (ims.framework.utils.Date)this.startdate.clone();
		if(this.currentstatus == null)
			clone.currentstatus = null;
		else
			clone.currentstatus = (ims.naes.vo.ActionDetailStatusVo)this.currentstatus.clone();
		if(this.responsibletechnician == null)
			clone.responsibletechnician = null;
		else
			clone.responsibletechnician = (ims.core.vo.MemberOfStaffLiteVo)this.responsibletechnician.clone();
		clone.timeelapsed = this.timeelapsed;
		clone.comment = this.comment;
		if(this.statushistory == null)
			clone.statushistory = null;
		else
			clone.statushistory = (ims.naes.vo.ActionDetailStatusVoCollection)this.statushistory.clone();
		if(this.sysinfo == null)
			clone.sysinfo = null;
		else
			clone.sysinfo = (ims.vo.SystemInformation)this.sysinfo.clone();
		if(this.actiontemplate == null)
			clone.actiontemplate = null;
		else
			clone.actiontemplate = (ims.core.vo.ActionPlanTemplateVo)this.actiontemplate.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 (!(ActionDetailVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A ActionDetailVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		ActionDetailVo compareObj = (ActionDetailVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getStartDate() == null && compareObj.getStartDate() != null)
				return -1;
			if(this.getStartDate() != null && compareObj.getStartDate() == null)
				return 1;
			if(this.getStartDate() != null && compareObj.getStartDate() != null)
				retVal = this.getStartDate().compareTo(compareObj.getStartDate());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.action != null)
			count++;
		if(this.startdate != null)
			count++;
		if(this.currentstatus != null)
			count++;
		if(this.responsibletechnician != null)
			count++;
		if(this.timeelapsed != null)
			count++;
		if(this.comment != null)
			count++;
		if(this.statushistory != null)
			count++;
		if(this.sysinfo != null)
			count++;
		if(this.actiontemplate != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 9;
	}
	protected ims.naes.vo.lookups.Action action;
	protected ims.framework.utils.Date startdate;
	protected ims.naes.vo.ActionDetailStatusVo currentstatus;
	protected ims.core.vo.MemberOfStaffLiteVo responsibletechnician;
	protected Integer timeelapsed;
	protected String comment;
	protected ims.naes.vo.ActionDetailStatusVoCollection statushistory;
	protected ims.vo.SystemInformation sysinfo;
	protected ims.core.vo.ActionPlanTemplateVo actiontemplate;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
