//#############################################################################
//#                                                                           #
//#  Copyright (C) <2014>  <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/>.    #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Dara Hickey using IMS Development Environment (version 1.45 build 2265.41281)
// Copyright (C) 1995-2006 IMS MAXIMS plc. All rights reserved.

package ims.core.domain.impl;

import ims.core.clinical.domain.objects.MskJoints;
import ims.core.clinical.vo.MskJointsRefVo;
import ims.core.domain.base.impl.BaseJointConfigurationImpl;
import ims.core.vo.MskJointVo;
import ims.core.vo.domain.MskJointVoAssembler;
import ims.domain.DomainFactory;
import ims.domain.exceptions.DomainRuntimeException;
import ims.domain.exceptions.UniqueKeyViolationException;
import ims.domain.exceptions.UnqViolationUncheckedException;

public class JointConfigurationImpl extends BaseJointConfigurationImpl
{
	private static final long serialVersionUID = 1L;

	/**
	* list
	*/
	public ims.core.vo.MskJointVoCollection list(Boolean boolActive)
	{
		DomainFactory factory = getDomainFactory();
		String strSQL = new String();
		if (boolActive.equals(Boolean.TRUE))
			strSQL = "from MskJoints m where m.isActive = "+ boolActive; 
		else
			strSQL = "from MskJoints ";
		
		return ims.core.vo.domain.MskJointVoAssembler.createMskJointVoCollectionFromMskJoints(factory.find(strSQL));
		
	}

	/**
	* save
	*/
	public ims.core.vo.MskJointVo save(ims.core.vo.MskJointVo voMskJoint) throws ims.domain.exceptions.StaleObjectException, UniqueKeyViolationException
	{
		if(voMskJoint == null)
			throw new DomainRuntimeException("Invalid MskJoint record to save");		
		if(!voMskJoint.isValidated())
			throw new DomainRuntimeException("MskJoint record not validated");
			
		DomainFactory factory = getDomainFactory();
				
		MskJoints domJoint = MskJointVoAssembler.extractMskJoints(factory, voMskJoint);
		try
		{
			factory.save(domJoint);		 
		}
		catch(UnqViolationUncheckedException e)
		{
			String strMsg = "A joint with the name '" + voMskJoint.getName() + "' already exists within the system.";
			throw new UniqueKeyViolationException(strMsg, e);
		}

		return MskJointVoAssembler.create(domJoint);		
	}

	public MskJointVo get(MskJointsRefVo voMskJoint) 
	{
		DomainFactory factory = getDomainFactory(); 
		MskJoints domJoints  = (MskJoints) factory.getDomainObject(MskJoints.class, voMskJoint.getID_MskJoints());
		return MskJointVoAssembler.create(domJoints);
	}

}
