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

	public AppNavFormVo()
	{
	}
	public AppNavFormVo(Integer id, int version)
	{
		super(id, version);
	}
	public AppNavFormVo(ims.admin.vo.beans.AppNavFormVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.nodetext = bean.getNodeText();
		this.form = bean.getForm() == null ? null : bean.getForm().buildVo();
		this.isreadonly = bean.getIsReadOnly();
		this.accessforrip = bean.getAccessForRip() == null ? null : ims.admin.vo.lookups.FormReadWrite.buildLookup(bean.getAccessForRip());
		this.accessforepisend = bean.getAccessForEpisEnd() == null ? null : ims.admin.vo.lookups.FormReadWrite.buildLookup(bean.getAccessForEpisEnd());
		this.posindex = bean.getPosIndex();
		this.linkedclasses = ims.core.vo.GenericIdentifierVoCollection.buildFromBeanCollection(bean.getLinkedClasses());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.admin.vo.beans.AppNavFormVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.nodetext = bean.getNodeText();
		this.form = bean.getForm() == null ? null : bean.getForm().buildVo(map);
		this.isreadonly = bean.getIsReadOnly();
		this.accessforrip = bean.getAccessForRip() == null ? null : ims.admin.vo.lookups.FormReadWrite.buildLookup(bean.getAccessForRip());
		this.accessforepisend = bean.getAccessForEpisEnd() == null ? null : ims.admin.vo.lookups.FormReadWrite.buildLookup(bean.getAccessForEpisEnd());
		this.posindex = bean.getPosIndex();
		this.linkedclasses = ims.core.vo.GenericIdentifierVoCollection.buildFromBeanCollection(bean.getLinkedClasses());
	}
	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.AppNavFormVoBean bean = null;
		if(map != null)
			bean = (ims.admin.vo.beans.AppNavFormVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.admin.vo.beans.AppNavFormVoBean();
			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("NODETEXT"))
			return getNodeText();
		if(fieldName.equals("FORM"))
			return getForm();
		if(fieldName.equals("ISREADONLY"))
			return getIsReadOnly();
		if(fieldName.equals("ACCESSFORRIP"))
			return getAccessForRip();
		if(fieldName.equals("ACCESSFOREPISEND"))
			return getAccessForEpisEnd();
		if(fieldName.equals("POSINDEX"))
			return getPosIndex();
		if(fieldName.equals("LINKEDCLASSES"))
			return getLinkedClasses();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getNodeTextIsNotNull()
	{
		return this.nodetext != null;
	}
	public String getNodeText()
	{
		return this.nodetext;
	}
	public static int getNodeTextMaxLength()
	{
		return 50;
	}
	public void setNodeText(String value)
	{
		this.isValidated = false;
		this.nodetext = value;
	}
	public boolean getFormIsNotNull()
	{
		return this.form != null;
	}
	public ims.admin.vo.AppFormVo getForm()
	{
		return this.form;
	}
	public void setForm(ims.admin.vo.AppFormVo value)
	{
		this.isValidated = false;
		this.form = value;
	}
	public boolean getIsReadOnlyIsNotNull()
	{
		return this.isreadonly != null;
	}
	public Boolean getIsReadOnly()
	{
		return this.isreadonly;
	}
	public void setIsReadOnly(Boolean value)
	{
		this.isValidated = false;
		this.isreadonly = value;
	}
	public boolean getAccessForRipIsNotNull()
	{
		return this.accessforrip != null;
	}
	public ims.admin.vo.lookups.FormReadWrite getAccessForRip()
	{
		return this.accessforrip;
	}
	public void setAccessForRip(ims.admin.vo.lookups.FormReadWrite value)
	{
		this.isValidated = false;
		this.accessforrip = value;
	}
	public boolean getAccessForEpisEndIsNotNull()
	{
		return this.accessforepisend != null;
	}
	public ims.admin.vo.lookups.FormReadWrite getAccessForEpisEnd()
	{
		return this.accessforepisend;
	}
	public void setAccessForEpisEnd(ims.admin.vo.lookups.FormReadWrite value)
	{
		this.isValidated = false;
		this.accessforepisend = value;
	}
	public boolean getPosIndexIsNotNull()
	{
		return this.posindex != null;
	}
	public Integer getPosIndex()
	{
		return this.posindex;
	}
	public void setPosIndex(Integer value)
	{
		this.isValidated = false;
		this.posindex = value;
	}
	public boolean getLinkedClassesIsNotNull()
	{
		return this.linkedclasses != null;
	}
	public ims.core.vo.GenericIdentifierVoCollection getLinkedClasses()
	{
		return this.linkedclasses;
	}
	public void setLinkedClasses(ims.core.vo.GenericIdentifierVoCollection value)
	{
		this.isValidated = false;
		this.linkedclasses = value;
	}
	/**
	* INavForm interface methods
	*/
		public ims.framework.interfaces.IAppForm getAppForm()
		{
			return this.getForm();
		}
		public boolean isReadOnly()
		{
			if (this.getIsReadOnly() == null)
				return false;
			else
				return this.getIsReadOnly().booleanValue();
		}
		public ims.framework.enumerations.FormAccess getFormAccessForRip()
		{
			if (this.getAccessForRip() == null)
				return ims.framework.enumerations.FormAccess.READ_WRITE;
			else
			{
				if (this.getAccessForRip().equals(ims.admin.vo.lookups.FormReadWrite.DENIED))
					return ims.framework.enumerations.FormAccess.NO_ACCESS;
				else if (this.getAccessForRip().equals(ims.admin.vo.lookups.FormReadWrite.READ))
					return ims.framework.enumerations.FormAccess.READ_ONLY;
				else 
					return ims.framework.enumerations.FormAccess.READ_WRITE;
			}
		}
		public ims.framework.enumerations.FormAccess getFormAccessForEpisEnd()
		{
			if (this.getAccessForEpisEnd() == null)
				return ims.framework.enumerations.FormAccess.READ_WRITE;
			else
			{
				if (this.getAccessForEpisEnd().equals(ims.admin.vo.lookups.FormReadWrite.DENIED))
					return ims.framework.enumerations.FormAccess.NO_ACCESS;
				else if (this.getAccessForEpisEnd().equals(ims.admin.vo.lookups.FormReadWrite.READ))
					return ims.framework.enumerations.FormAccess.READ_ONLY;
				else 
					return ims.framework.enumerations.FormAccess.READ_WRITE;
			}
		}
		public int getPositionIndex()
		{
			if (this.getPosIndex() == null)
				return -1;
			else 
				return this.getPosIndex().intValue();
		}
	
		public ims.framework.interfaces.IGenericIdentifier[] getIdentifiers()
		{
			if (this.getLinkedClasses() == null)
				return new ims.framework.interfaces.IGenericIdentifier[0];
			else
				return this.getLinkedClasses().toArray();
		}
	/**
	* INavNode interface methods
	*/
	public AppImageVo getImageNode()
	{
		if ( getForm()==null )
			return null;
		return getForm().getImage();
	}
	public Integer getIndexPositionNode()
	{
		return getPosIndex();
	}
	public String getTextNode() 
	{
		return getNodeText();
	}
	public void setImageNode(AppImageVo image)
	{
		return;
	}
	public void setIndexPositionNode(Integer index)
	{
		setPosIndex(index);
	}
	public void setTextNode(String text)
	{
		setNodeText(text);
	}
	public AppNavAccessRightsVo getAccessRightsNode()
	{
		AppNavAccessRightsVo rights= new AppNavAccessRightsVo();
		rights.setReadOnly(getIsReadOnly());
		rights.setAccessForRIP(getAccessForRip());
		rights.setAccessForEPISE(getAccessForEpisEnd());
		return rights;
	}
	public ims.admin.vo.enums.NavigationNodeType getTypeNode()
	{
		return ims.admin.vo.enums.NavigationNodeType.FORM;
	}
	public void setAccessRightsNode(AppNavAccessRightsVo rights)
	{
		if (rights == null)
			return;
		
		if (rights.getAccessForRIPIsNotNull())
		{
			setAccessForRip(rights.getAccessForRIP());
			return;
		}
		if (rights.getAccessForEPISEIsNotNull())
		{
			setAccessForEpisEnd(rights.getAccessForEPISE());
			return;
		}
		if (rights.getReadOnlyIsNotNull())
		{
			setIsReadOnly(rights.getReadOnly());
		}
				
	}
	public void setFormChildsNode(AppNavFormVoCollection childs)
	{
		return;
			
	}
	public void setGroupsChildsNode(AppNavSecondGroupVoCollection groups)
	{
		return;	
	}
	public AppNavFormVoCollection getFormChildsNode()
	{
		return null;
	}
	public AppNavSecondGroupVoCollection getGroupsChildsNode()
	{
		return null;
		
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.form != null)
		{
			if(!this.form.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.linkedclasses != null)
		{
			if(!this.linkedclasses.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.nodetext == null || this.nodetext.length() == 0)
			listOfErrors.add("NodeText is mandatory");
		else if(this.nodetext.length() > 50)
			listOfErrors.add("The length of the field [nodetext] in the value object [ims.admin.vo.AppNavFormVo] is too big. It should be less or equal to 50");
		if(this.form != null)
		{
			String[] listOfOtherErrors = this.form.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.isreadonly == null)
			listOfErrors.add("IsReadOnly is mandatory");
		if(this.linkedclasses != null)
		{
			String[] listOfOtherErrors = this.linkedclasses.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;
	
		AppNavFormVo clone = new AppNavFormVo(this.id, this.version);
		
		clone.nodetext = this.nodetext;
		if(this.form == null)
			clone.form = null;
		else
			clone.form = (ims.admin.vo.AppFormVo)this.form.clone();
		clone.isreadonly = this.isreadonly;
		if(this.accessforrip == null)
			clone.accessforrip = null;
		else
			clone.accessforrip = (ims.admin.vo.lookups.FormReadWrite)this.accessforrip.clone();
		if(this.accessforepisend == null)
			clone.accessforepisend = null;
		else
			clone.accessforepisend = (ims.admin.vo.lookups.FormReadWrite)this.accessforepisend.clone();
		clone.posindex = this.posindex;
		if(this.linkedclasses == null)
			clone.linkedclasses = null;
		else
			clone.linkedclasses = (ims.core.vo.GenericIdentifierVoCollection)this.linkedclasses.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 (!(AppNavFormVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A AppNavFormVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((AppNavFormVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((AppNavFormVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.nodetext != null)
			count++;
		if(this.form != null)
			count++;
		if(this.isreadonly != null)
			count++;
		if(this.accessforrip != null)
			count++;
		if(this.accessforepisend != null)
			count++;
		if(this.posindex != null)
			count++;
		if(this.linkedclasses != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 7;
	}
	protected String nodetext;
	protected ims.admin.vo.AppFormVo form;
	protected Boolean isreadonly;
	protected ims.admin.vo.lookups.FormReadWrite accessforrip;
	protected ims.admin.vo.lookups.FormReadWrite accessforepisend;
	protected Integer posindex;
	protected ims.core.vo.GenericIdentifierVoCollection linkedclasses;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
