/*******************************************************************************
 *  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.cservices.withdb.testcases.defaultscp;


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


import cdac.medinfo.sdk.dcm30_04.enums.EnumLoggingLevel;

import cdac.medinfo.sdk.dcm30_04.services.cmove.scp.CMoveSCP;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.IDataSource;
import cdac.medinfo.sdk.dcm30_04.services.javadbhelper.DataSourceImpl;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;

/**
 * This class tests a Stand Alone CMoveSCP.
 * "Stand Alone" means that the User is required to write a minimal set of code to create CMoveSCP
 * Once the required parameters are given to the CMoveSCP object and is started , it is 
 * capable of accepting connection, negotiation association and creating appropriate response(AssociateAC or Reject)
 * processing CMove Request and sending DIMSE Response for the same, processing Release Request and sending Release Response.
 * If User wants to handle the request sending scenarios by his/her code 
 * then please refer to sample code "CMove_SCP.java". 
 * To create DB for C-Services refer SQL Script DICOMServerDB.sql provided in install. 
 */
public class CMove_SCP_Standalone 
{
	public static void main(String[] args) 
	{
		try
		{
			DicomConfig objDicomConfig = DicomConfig.createInstance();

			//enable logging,specify the path of the directory where log files are created.
			//User can specify any directory in place of 'c:\DCM_Logs'.
			//If no directory is defined by user to create logs then it is created in User Temp DIR.
			objDicomConfig.enableLogging(EnumLoggingLevel.INFO, "C:\\DCM_Logs");

			/*
			 * Creates CStore_SCP_Standalone and Start C-Move Server.
			 */
			CMove_SCP_Standalone objCMoveSCPTest = new CMove_SCP_Standalone();
			objCMoveSCPTest.doCMove();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * This method starts the CMove SCP .
	 * @throws IOException Signals IO Exception if IO operation fails.
	 * @throws SQLException the SQL exception
	 * @throws ClassNotFoundException the class not found exception
	 * @throws IllegalAccessException the illegal access exception
	 * @throws InstantiationException the instantiation exception
	 */
	public void doCMove() throws IOException, SQLException,ClassNotFoundException,IllegalAccessException,InstantiationException
	{
		//creates object of C-Move SCP.
		CMoveSCP objCMoveSCP = CMoveSCP.createInstance();

		/*
		 * Create DatSourceImpl with ConnectionString and driver String.
		 * DatSourceImpl is default implementation of library which uses JavaDB to 
		 * MOVE Data Elements.The user has to start javaDB server before connection
		 * if Client Server model in java DB is used.
		 * This DatSourceImpl should be set in CMove SCP.
		 * User can also provide its own implementation of IDataSource interface
		 * to move the attributes.
		 */
		String dataBasePath ="C:/Database/SDKdb";
		String ConnectionString = "jdbc:derby://localhost:5050/" + dataBasePath;
		String driverString = "org.apache.derby.jdbc.ClientDriver";

		/*
		 * Set the DataSource to C-Move SCP.
		 */
		IDataSource objIDataSource = new DataSourceImpl(ConnectionString,driverString);
		objCMoveSCP.setDataSource(objIDataSource);
		objCMoveSCP.addAETitleInfo("DCMRCV", "192.168.8.94", 9002);

		//start the CMove SCP Server.
		objCMoveSCP.start("SDK",9000);
	}
}
