package com.cim.idm.mwmsextend.transport.management.action;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.cim.idm.framework.action.info.ValidationFormat;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.exception.ext.DuplicateNameSignal;
import com.cim.idm.framework.exception.ext.FrameworkErrorSignal;
import com.cim.idm.framework.exception.ext.NotFoundSignal;
import com.cim.idm.mwmsextend.transport.TransportServiceProxy;
import com.cim.idm.mwmsextend.transport.management.data.TransportCommand;
import com.cim.idm.mwmsextend.transport.management.data.TransportCommandHistory;
import com.cim.idm.mwmsextend.transport.management.data.TransportCommandKey;
import com.cim.idm.mwmsextend.transport.management.info.CreateInfo;
import com.cim.idm.wmspackage.action.CommonAction;
@Component("TransportCommandCreateAction")
public class CreateAction extends CommonAction<TransportCommandKey,TransportCommand,TransportCommandHistory,CreateInfo> {
	public void create(TransportCommand[] oldDataArray, TransportCommand[] newDataArray, EventInfo eventInfo, CreateInfo[] transitionInfoArray, HashMap<String,ValidationFormat> validationList) 
			throws NotFoundSignal, DuplicateNameSignal, FrameworkErrorSignal
	{
		String thisMethodName = "create";
		if(oldDataArray.length>0){
			TransportCommand[] creatingDataArray = new TransportCommand[oldDataArray.length];
			for(int i=0 ; i<oldDataArray.length; i++){
				CreateInfo createInfo = transitionInfoArray[i];
				TransportCommand newData =  newDataArray[i];
				newData.getKey().setTransportCommandID(createInfo.getTransportCommandID());
				newData.setDestination(createInfo.getDestination());
				newData.setInvoiceNo(createInfo.getInvoiceNo());
				newData.setPackingGroupQty(createInfo.getPackingGroupQty());
				newData.setPriority(createInfo.getPriority());
				newData.setState(createInfo.getState());
				newData.setTransportCommandDetailType(createInfo.getTransportCommandDetailType());
				
				creatingDataArray[i] = newData;
			}
			TransportServiceProxy.getTransportCommandService().insert(creatingDataArray);
		}
	}
}
