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

/**
 * Linked to NTPF.Common.Comment business object (ID: 1036100000).
 */
public class CommentVo extends ims.ntpf.common.vo.CommentRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public CommentVo()
	{
	}
	public CommentVo(Integer id, int version)
	{
		super(id, version);
	}
	public CommentVo(ims.ntpf.vo.beans.CommentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.authoringdatetime = bean.getAuthoringDateTime() == null ? null : bean.getAuthoringDateTime().buildDateTime();
		this.context = bean.getContext() == null ? null : ims.ntpf.vo.lookups.CommentContextType.buildLookup(bean.getContext());
		this.commenttype = bean.getCommentType() == null ? null : ims.ntpf.vo.lookups.CommentContextType.buildLookup(bean.getCommentType());
		this.commenttext = bean.getCommentText();
		this.isfollowup = bean.getIsFollowUp();
		this.followupdate = bean.getFollowUpDate() == null ? null : bean.getFollowUpDate().buildDate();
		this.comment = ims.ntpf.vo.CommentVoCollection.buildFromBeanCollection(bean.getComment());
		this.userworkqueue = bean.getUserWorkQueue() == null ? null : bean.getUserWorkQueue().buildVo();
		this.authoringcp = bean.getAuthoringCP() == null ? null : bean.getAuthoringCP().buildVo();
		this.followupuser = bean.getFollowUpUser() == null ? null : bean.getFollowUpUser().buildVo();
		this.alertworkqueue = bean.getAlertWorkQueue() == null ? null : bean.getAlertWorkQueue().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.ntpf.vo.beans.CommentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.authoringdatetime = bean.getAuthoringDateTime() == null ? null : bean.getAuthoringDateTime().buildDateTime();
		this.context = bean.getContext() == null ? null : ims.ntpf.vo.lookups.CommentContextType.buildLookup(bean.getContext());
		this.commenttype = bean.getCommentType() == null ? null : ims.ntpf.vo.lookups.CommentContextType.buildLookup(bean.getCommentType());
		this.commenttext = bean.getCommentText();
		this.isfollowup = bean.getIsFollowUp();
		this.followupdate = bean.getFollowUpDate() == null ? null : bean.getFollowUpDate().buildDate();
		this.comment = ims.ntpf.vo.CommentVoCollection.buildFromBeanCollection(bean.getComment());
		this.userworkqueue = bean.getUserWorkQueue() == null ? null : bean.getUserWorkQueue().buildVo(map);
		this.authoringcp = bean.getAuthoringCP() == null ? null : bean.getAuthoringCP().buildVo(map);
		this.followupuser = bean.getFollowUpUser() == null ? null : bean.getFollowUpUser().buildVo(map);
		this.alertworkqueue = bean.getAlertWorkQueue() == null ? null : bean.getAlertWorkQueue().buildVo(map);
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.ntpf.vo.beans.CommentVoBean bean = null;
		if(map != null)
			bean = (ims.ntpf.vo.beans.CommentVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.ntpf.vo.beans.CommentVoBean();
			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("AUTHORINGDATETIME"))
			return getAuthoringDateTime();
		if(fieldName.equals("CONTEXT"))
			return getContext();
		if(fieldName.equals("COMMENTTYPE"))
			return getCommentType();
		if(fieldName.equals("COMMENTTEXT"))
			return getCommentText();
		if(fieldName.equals("ISFOLLOWUP"))
			return getIsFollowUp();
		if(fieldName.equals("FOLLOWUPDATE"))
			return getFollowUpDate();
		if(fieldName.equals("COMMENT"))
			return getComment();
		if(fieldName.equals("USERWORKQUEUE"))
			return getUserWorkQueue();
		if(fieldName.equals("AUTHORINGCP"))
			return getAuthoringCP();
		if(fieldName.equals("FOLLOWUPUSER"))
			return getFollowUpUser();
		if(fieldName.equals("ALERTWORKQUEUE"))
			return getAlertWorkQueue();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getAuthoringDateTimeIsNotNull()
	{
		return this.authoringdatetime != null;
	}
	public ims.framework.utils.DateTime getAuthoringDateTime()
	{
		return this.authoringdatetime;
	}
	public void setAuthoringDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.authoringdatetime = value;
	}
	public boolean getContextIsNotNull()
	{
		return this.context != null;
	}
	public ims.ntpf.vo.lookups.CommentContextType getContext()
	{
		return this.context;
	}
	public void setContext(ims.ntpf.vo.lookups.CommentContextType value)
	{
		this.isValidated = false;
		this.context = value;
	}
	public boolean getCommentTypeIsNotNull()
	{
		return this.commenttype != null;
	}
	public ims.ntpf.vo.lookups.CommentContextType getCommentType()
	{
		return this.commenttype;
	}
	public void setCommentType(ims.ntpf.vo.lookups.CommentContextType value)
	{
		this.isValidated = false;
		this.commenttype = value;
	}
	public boolean getCommentTextIsNotNull()
	{
		return this.commenttext != null;
	}
	public String getCommentText()
	{
		return this.commenttext;
	}
	public static int getCommentTextMaxLength()
	{
		return 1500;
	}
	public void setCommentText(String value)
	{
		this.isValidated = false;
		this.commenttext = value;
	}
	public boolean getIsFollowUpIsNotNull()
	{
		return this.isfollowup != null;
	}
	public Boolean getIsFollowUp()
	{
		return this.isfollowup;
	}
	public void setIsFollowUp(Boolean value)
	{
		this.isValidated = false;
		this.isfollowup = value;
	}
	public boolean getFollowUpDateIsNotNull()
	{
		return this.followupdate != null;
	}
	public ims.framework.utils.Date getFollowUpDate()
	{
		return this.followupdate;
	}
	public void setFollowUpDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.followupdate = value;
	}
	public boolean getCommentIsNotNull()
	{
		return this.comment != null;
	}
	public ims.ntpf.vo.CommentVoCollection getComment()
	{
		return this.comment;
	}
	public void setComment(ims.ntpf.vo.CommentVoCollection value)
	{
		this.isValidated = false;
		this.comment = value;
	}
	public boolean getUserWorkQueueIsNotNull()
	{
		return this.userworkqueue != null;
	}
	public ims.core.vo.UserWorkQueueVo getUserWorkQueue()
	{
		return this.userworkqueue;
	}
	public void setUserWorkQueue(ims.core.vo.UserWorkQueueVo value)
	{
		this.isValidated = false;
		this.userworkqueue = value;
	}
	public boolean getAuthoringCPIsNotNull()
	{
		return this.authoringcp != null;
	}
	public ims.core.vo.MemberOfStaffShortVo getAuthoringCP()
	{
		return this.authoringcp;
	}
	public void setAuthoringCP(ims.core.vo.MemberOfStaffShortVo value)
	{
		this.isValidated = false;
		this.authoringcp = value;
	}
	public boolean getFollowUpUserIsNotNull()
	{
		return this.followupuser != null;
	}
	public ims.core.vo.MemberOfStaffShortVo getFollowUpUser()
	{
		return this.followupuser;
	}
	public void setFollowUpUser(ims.core.vo.MemberOfStaffShortVo value)
	{
		this.isValidated = false;
		this.followupuser = value;
	}
	public boolean getAlertWorkQueueIsNotNull()
	{
		return this.alertworkqueue != null;
	}
	public ims.core.vo.UserWorkQueueVo getAlertWorkQueue()
	{
		return this.alertworkqueue;
	}
	public void setAlertWorkQueue(ims.core.vo.UserWorkQueueVo value)
	{
		this.isValidated = false;
		this.alertworkqueue = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.comment != null)
		{
			if(!this.comment.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.userworkqueue != null)
		{
			if(!this.userworkqueue.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.alertworkqueue != null)
		{
			if(!this.alertworkqueue.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.commenttype == null)
			listOfErrors.add("Please Select Comment Type.");
		if(this.commenttext == null || this.commenttext.length() == 0)
			listOfErrors.add("Comment is a mandatory field");
		else if(this.commenttext.length() > 1500)
			listOfErrors.add("The length of the field [commenttext] in the value object [ims.ntpf.vo.CommentVo] is too big. It should be less or equal to 1500");
		if(this.comment != null)
		{
			String[] listOfOtherErrors = this.comment.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.userworkqueue != null)
		{
			String[] listOfOtherErrors = this.userworkqueue.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.alertworkqueue != null)
		{
			String[] listOfOtherErrors = this.alertworkqueue.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;
	
		CommentVo clone = new CommentVo(this.id, this.version);
		
		if(this.authoringdatetime == null)
			clone.authoringdatetime = null;
		else
			clone.authoringdatetime = (ims.framework.utils.DateTime)this.authoringdatetime.clone();
		if(this.context == null)
			clone.context = null;
		else
			clone.context = (ims.ntpf.vo.lookups.CommentContextType)this.context.clone();
		if(this.commenttype == null)
			clone.commenttype = null;
		else
			clone.commenttype = (ims.ntpf.vo.lookups.CommentContextType)this.commenttype.clone();
		clone.commenttext = this.commenttext;
		clone.isfollowup = this.isfollowup;
		if(this.followupdate == null)
			clone.followupdate = null;
		else
			clone.followupdate = (ims.framework.utils.Date)this.followupdate.clone();
		if(this.comment == null)
			clone.comment = null;
		else
			clone.comment = (ims.ntpf.vo.CommentVoCollection)this.comment.clone();
		if(this.userworkqueue == null)
			clone.userworkqueue = null;
		else
			clone.userworkqueue = (ims.core.vo.UserWorkQueueVo)this.userworkqueue.clone();
		if(this.authoringcp == null)
			clone.authoringcp = null;
		else
			clone.authoringcp = (ims.core.vo.MemberOfStaffShortVo)this.authoringcp.clone();
		if(this.followupuser == null)
			clone.followupuser = null;
		else
			clone.followupuser = (ims.core.vo.MemberOfStaffShortVo)this.followupuser.clone();
		if(this.alertworkqueue == null)
			clone.alertworkqueue = null;
		else
			clone.alertworkqueue = (ims.core.vo.UserWorkQueueVo)this.alertworkqueue.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 (!(CommentVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A CommentVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		CommentVo compareObj = (CommentVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getAuthoringDateTime() == null && compareObj.getAuthoringDateTime() != null)
				return -1;
			if(this.getAuthoringDateTime() != null && compareObj.getAuthoringDateTime() == null)
				return 1;
			if(this.getAuthoringDateTime() != null && compareObj.getAuthoringDateTime() != null)
				retVal = this.getAuthoringDateTime().compareTo(compareObj.getAuthoringDateTime());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.authoringdatetime != null)
			count++;
		if(this.context != null)
			count++;
		if(this.commenttype != null)
			count++;
		if(this.commenttext != null)
			count++;
		if(this.isfollowup != null)
			count++;
		if(this.followupdate != null)
			count++;
		if(this.comment != null)
			count++;
		if(this.userworkqueue != null)
			count++;
		if(this.authoringcp != null)
			count++;
		if(this.followupuser != null)
			count++;
		if(this.alertworkqueue != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 11;
	}
	protected ims.framework.utils.DateTime authoringdatetime;
	protected ims.ntpf.vo.lookups.CommentContextType context;
	protected ims.ntpf.vo.lookups.CommentContextType commenttype;
	protected String commenttext;
	protected Boolean isfollowup;
	protected ims.framework.utils.Date followupdate;
	protected ims.ntpf.vo.CommentVoCollection comment;
	protected ims.core.vo.UserWorkQueueVo userworkqueue;
	protected ims.core.vo.MemberOfStaffShortVo authoringcp;
	protected ims.core.vo.MemberOfStaffShortVo followupuser;
	protected ims.core.vo.UserWorkQueueVo alertworkqueue;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
