/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.services.cecho.commons;

import java.io.IOException;
import java.util.Locale;

import cdac.medinfo.sdk.dcm30_04.enums.EnumCommandField;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.InvalidDICOMMessageException;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DIMSEResponse;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DicomMessage;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.ResourceBundleWrapper;

// TODO: Auto-generated Javadoc
/**
 * This class contains attributes of  C-Echo response.
 * This response is created when C-Echo operation needs to be performed.
 */
public class CEchoRSP extends DIMSEResponse 
{
	/**
	 * Instantiates a new c echo rsp.
	 */
	public CEchoRSP()
	{

	}

	/**
	 * Instantiates a new CEcho RSP when Dicom Message is given by user.
	 * Retrieves Command Set and Data Set from the DicomMessage and sets in CEcho Response.
	 * 
	 * @param objDicomMessage Object of DicomMessage from which C-Store request is initialized.
	 * 
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	public CEchoRSP(DicomMessage objDicomMessage) throws IOException
	{
		objICommandSet = objDicomMessage.getCommandSet();
		objIDataSet = objDicomMessage.getDataSet();
	}

	//No extra methods required since all set/get methods already written in base class.
	//Write validate method that checks for all the command elements presence in the CommandSet. 
	
	/**
	 * Validates the response for their mandatory attributes only.
	 * @return true, if validation is successful.
	 * @throws InvalidDICOMMessageException If validation of mandatory fields fails.
	 */
	public boolean validate() throws InvalidDICOMMessageException
	{
		super.validate();
		//Checks for service type.
		if(getCommandType() != EnumCommandField.C_ECHO_RSP)
			throw new InvalidDICOMMessageException(ResourceBundleWrapper.getValue("exceptions","RQNotMatched",new Locale(DicomConfig.createInstance().getLocale())) + getCommandType().name());
		
		return true;
	}
}