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.TransportCommandDetail;
import com.cim.idm.mwmsextend.transport.management.data.TransportCommandDetailHistory;
import com.cim.idm.mwmsextend.transport.management.data.TransportCommandDetailKey;
import com.cim.idm.mwmsextend.transport.management.info.CreateDetailInfo;
import com.cim.idm.wmspackage.action.CommonAction;
@Component("TransportCommandDetailCreateAction")
public class CreateDetailAction extends CommonAction<TransportCommandDetailKey,TransportCommandDetail,TransportCommandDetailHistory,CreateDetailInfo> {
	public void create(TransportCommandDetail[] oldDataArray, TransportCommandDetail[] newDataArray, EventInfo eventInfo, CreateDetailInfo[] transitionInfoArray, HashMap<String,ValidationFormat> validationList) 
			throws NotFoundSignal, DuplicateNameSignal, FrameworkErrorSignal
	{
		String thisMethodName = "create";
		if(oldDataArray.length>0){
			TransportCommandDetail[] creatingDataArray = new TransportCommandDetail[oldDataArray.length];
			for(int i=0 ; i<oldDataArray.length; i++){
				CreateDetailInfo createDetailInfo = (CreateDetailInfo)transitionInfoArray[i];
				TransportCommandDetail newData = (TransportCommandDetail)newDataArray[i];
				newData.getKey().setTransportCommandID(createDetailInfo.getTransportCommandID());
				newData.getKey().setDurableName(createDetailInfo.getDurableName());

				newData.setState(createDetailInfo.getState());
				newData.setPackingGroupName(createDetailInfo.getPackingGroupName());
				
				creatingDataArray[i] = newData;
			}
			TransportServiceProxy.getTransportCommandDetailService().insert(creatingDataArray);
		}
	}
}
