/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/admin/vo/AppNavigationVo.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.configuration.AppNavigation business object (ID: 1028100027).
 */
public class AppNavigationVo extends ims.admin.vo.AppNavShortVo implements ims.vo.ImsCloneable, Comparable, ims.framework.interfaces.INavigation
{
	private static final long serialVersionUID = 1L;

	public AppNavigationVo()
	{
	}
	public AppNavigationVo(Integer id, int version)
	{
		super(id, version);
	}
	public AppNavigationVo(ims.admin.vo.beans.AppNavigationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.navigationname = bean.getNavigationName();
		this.isactive = bean.getIsActive();
		this.comment = bean.getComment();
		this.rootgroups = ims.admin.vo.AppNavRootGroupVoCollection.buildFromBeanCollection(bean.getRootGroups());
		this.patientsearchform = bean.getPatientSearchForm() == null ? null : bean.getPatientSearchForm().buildVo();
		this.startform = bean.getStartForm() == null ? null : bean.getStartForm().buildVo();
		this.style = bean.getStyle() == null ? null : ims.admin.vo.lookups.NavigationStyle.buildLookup(bean.getStyle());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.admin.vo.beans.AppNavigationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.navigationname = bean.getNavigationName();
		this.isactive = bean.getIsActive();
		this.comment = bean.getComment();
		this.rootgroups = ims.admin.vo.AppNavRootGroupVoCollection.buildFromBeanCollection(bean.getRootGroups());
		this.patientsearchform = bean.getPatientSearchForm() == null ? null : bean.getPatientSearchForm().buildVo(map);
		this.startform = bean.getStartForm() == null ? null : bean.getStartForm().buildVo(map);
		this.style = bean.getStyle() == null ? null : ims.admin.vo.lookups.NavigationStyle.buildLookup(bean.getStyle());
	}
	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.AppNavigationVoBean bean = null;
		if(map != null)
			bean = (ims.admin.vo.beans.AppNavigationVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.admin.vo.beans.AppNavigationVoBean();
			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("ROOTGROUPS"))
			return getRootGroups();
		if(fieldName.equals("PATIENTSEARCHFORM"))
			return getPatientSearchForm();
		if(fieldName.equals("STARTFORM"))
			return getStartForm();
		if(fieldName.equals("STYLE"))
			return getStyle();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getRootGroupsIsNotNull()
	{
		return this.rootgroups != null;
	}
	public ims.admin.vo.AppNavRootGroupVoCollection getRootGroups()
	{
		return this.rootgroups;
	}
	public void setRootGroups(ims.admin.vo.AppNavRootGroupVoCollection value)
	{
		this.isValidated = false;
		this.rootgroups = value;
	}
	public boolean getPatientSearchFormIsNotNull()
	{
		return this.patientsearchform != null;
	}
	public ims.admin.vo.AppFormVo getPatientSearchForm()
	{
		return this.patientsearchform;
	}
	public void setPatientSearchForm(ims.admin.vo.AppFormVo value)
	{
		this.isValidated = false;
		this.patientsearchform = value;
	}
	public boolean getStartFormIsNotNull()
	{
		return this.startform != null;
	}
	public ims.admin.vo.AppFormVo getStartForm()
	{
		return this.startform;
	}
	public void setStartForm(ims.admin.vo.AppFormVo value)
	{
		this.isValidated = false;
		this.startform = value;
	}
	public boolean getStyleIsNotNull()
	{
		return this.style != null;
	}
	public ims.admin.vo.lookups.NavigationStyle getStyle()
	{
		return this.style;
	}
	public void setStyle(ims.admin.vo.lookups.NavigationStyle value)
	{
		this.isValidated = false;
		this.style = value;
	}
	/**
	* INavigation interface methods
	*/
		public int getId()
		{
			if (this.getID_AppNavigation() == null)
				return 0;
			else
				return this.getID_AppNavigation().intValue();
		}
		public ims.framework.interfaces.INavRootGroup[] getNavRootGroups()
		{
			if (this.getRootGroups() == null)
				return new ims.framework.interfaces.INavRootGroup[0];
			else
				return this.getRootGroups().toArray();
		}
		public ims.framework.interfaces.IAppForm getPatSearchForm()
		{
			return this.getPatientSearchForm();
		}
		public ims.framework.interfaces.IAppForm getStartupForm()
		{
			return this.getStartForm();
		}
		public ims.framework.interfaces.INavForm getNavForm(ims.framework.FormName form)
		{
			return getNavForm(form.getID());
		}
		public ims.framework.interfaces.INavForm getNavForm(int formId)
		{
			for (int i = 0; i < this.getRootGroups().size(); i++)
			{
				AppNavRootGroupVo rootGrp = this.getRootGroups().get(i);			
				for (int j = 0; j < rootGrp.getGroups().size(); j++)
				{
					AppNavSecondGroupVo secGrp = rootGrp.getGroups().get(j);
					for (int k = 0; k < secGrp.getForms().size(); k++)
					{
						if (secGrp.getForms().get(k).getForm().getID_AppForm().intValue() == formId)
							return secGrp.getForms().get(k);
					}
				}
				for (int k = 0; k < rootGrp.getForms().size(); k++)
				{
					if (rootGrp.getForms().get(k).getForm().getID_AppForm().intValue() == formId)
						return rootGrp.getForms().get(k);
				}
			}
			return null;
		}
		public ims.framework.interfaces.INavForm[] getAllForms()
		{
			java.util.List<ims.framework.interfaces.INavForm> list = new java.util.ArrayList<ims.framework.interfaces.INavForm>();
			
			for (int i = 0; i < this.getRootGroups().size(); i++)
			{
				AppNavRootGroupVo rootGrp = this.getRootGroups().get(i);			
				for (int j = 0; j < rootGrp.getGroups().size(); j++)
				{
					AppNavSecondGroupVo secGrp = rootGrp.getGroups().get(j);
					for (int k = 0; k < secGrp.getForms().size(); k++)
					{
						list.add(secGrp.getForms().get(k));						
					}
				}
				for (int k = 0; k < rootGrp.getForms().size(); k++)
				{
					list.add(rootGrp.getForms().get(k));
				}
			}
			
			ims.framework.interfaces.INavForm[] result = new ims.framework.interfaces.INavForm[list.size()];
			list.toArray(result);
			return result;
		}
		public ims.framework.enumerations.NavigationStyle getNavigationStyle()
		{
			if(style != null && style.getID() == ims.admin.vo.lookups.NavigationStyle.TEXT.getID())
				return ims.framework.enumerations.NavigationStyle.Text;
			return ims.framework.enumerations.NavigationStyle.Image;
		}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.rootgroups != null)
		{
			if(!this.rootgroups.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.patientsearchform != null)
		{
			if(!this.patientsearchform.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.startform != null)
		{
			if(!this.startform.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.navigationname == null || this.navigationname.length() == 0)
			listOfErrors.add("NavigationName is mandatory");
		else if(this.navigationname.length() > 100)
			listOfErrors.add("The length of the field [navigationname] in the value object [ims.admin.vo.AppNavigationVo] is too big. It should be less or equal to 100");
		if(this.isactive == null)
			listOfErrors.add("IsActive is mandatory");
		if(this.comment != null)
			if(this.comment.length() > 200)
				listOfErrors.add("The length of the field [comment] in the value object [ims.admin.vo.AppNavigationVo] is too big. It should be less or equal to 200");
		if(this.rootgroups != null)
		{
			String[] listOfOtherErrors = this.rootgroups.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.patientsearchform == null)
			listOfErrors.add("PatientSearchForm is mandatory");
		if(this.patientsearchform != null)
		{
			String[] listOfOtherErrors = this.patientsearchform.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.startform == null)
			listOfErrors.add("StartForm is mandatory");
		if(this.startform != null)
		{
			String[] listOfOtherErrors = this.startform.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;
	
		AppNavigationVo clone = new AppNavigationVo(this.id, this.version);
		
		clone.navigationname = this.navigationname;
		clone.isactive = this.isactive;
		clone.comment = this.comment;
		if(this.rootgroups == null)
			clone.rootgroups = null;
		else
			clone.rootgroups = (ims.admin.vo.AppNavRootGroupVoCollection)this.rootgroups.clone();
		if(this.patientsearchform == null)
			clone.patientsearchform = null;
		else
			clone.patientsearchform = (ims.admin.vo.AppFormVo)this.patientsearchform.clone();
		if(this.startform == null)
			clone.startform = null;
		else
			clone.startform = (ims.admin.vo.AppFormVo)this.startform.clone();
		if(this.style == null)
			clone.style = null;
		else
			clone.style = (ims.admin.vo.lookups.NavigationStyle)this.style.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 (!(AppNavigationVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A AppNavigationVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((AppNavigationVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((AppNavigationVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.rootgroups != null)
			count++;
		if(this.patientsearchform != null)
			count++;
		if(this.startform != null)
			count++;
		if(this.style != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 4;
	}
	protected ims.admin.vo.AppNavRootGroupVoCollection rootgroups;
	protected ims.admin.vo.AppFormVo patientsearchform;
	protected ims.admin.vo.AppFormVo startform;
	protected ims.admin.vo.lookups.NavigationStyle style;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
