/*******************************************************************************
 *  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.print.printsourceimpl;

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

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCommandField;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSOPClassUIDs;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumImplOpsStatus;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DicomMessage;
import cdac.medinfo.sdk.dcm30_04.services.print.dbhelper.Print_DBAgent;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.ResourceBundleWrapper;

/**
 * This class process N-Action Request for Print Queue Management.
 */
class PrintQueueMangSourceImpl 
{
	/**
	 * This is default Constructor for PrintQueueMangSourceImpl.
	 */
	public PrintQueueMangSourceImpl() {
		super();
	}
	
	/**
	 * This fucntion processes Print Queue Management Get Request.
	 */
	@SuppressWarnings("unchecked")
	short retrievePrintQueueSOPInstance(Print_DBAgent objPrintDBAgent, DicomMessage objDicomMessage, ISingleCollection<IDataSet> objDataSetColl, String strValue) throws IOException, SQLException
	{
		EnumCommandField enumRequestType = objDicomMessage.getCommandType();
		switch(enumRequestType)
		{
		case N_GET_RQ :
		{
			ISingleCollection<ITag> objTagCollection = (ISingleCollection<ITag>)objDicomMessage.getCommandSet().getValue(0x0000,0x1005);
			IDataSet objIDataSet = objPrintDBAgent.retrieveSOPInstance(EnumSOPClassUIDs.PRINTQUEUEMANAGEMENTIOD, objTagCollection, strValue);
			objDataSetColl.add(objIDataSet);
			return EnumImplOpsStatus.SUCCESS.getValue();
		}
		default : 
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger objDicomLogger =DicomLogger.getLogger();
				objDicomLogger.log(ResourceBundleWrapper.getValue("exceptions","ServiceRequestNotSupported", new Locale(DicomConfig.createInstance().getLocale())) + enumRequestType);
			}
			return EnumImplOpsStatus.FAILURE.getValue();
		}
		}
	}
}
