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

import java.util.HashMap;

import com.cim.idm.framework.action.info.ValidationFormat;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.data.TransitionInfo;
import com.cim.idm.framework.exception.ext.DuplicateNameSignal;
import com.cim.idm.framework.exception.ext.FrameworkErrorSignal;
import com.cim.idm.framework.orm.info.DataInfo;
import com.cim.idm.mwmsextend.checkrecord.CheckRecordServiceProxy;
import com.cim.idm.mwmsextend.checkrecord.management.data.CheckRecord;
import com.cim.idm.mwmsextend.checkrecord.management.data.CheckRecordKey;
import com.cim.idm.mwmsextend.checkrecord.management.info.CreateInfo;
import com.cim.idm.wmspackage.action.CommonAction;

public class CreateAction extends CommonAction{
	public void create(DataInfo oldCheckRecordData,
			DataInfo newCheckRecordData, EventInfo eventInfo,
			TransitionInfo transitionInfo,
			HashMap<String, ValidationFormat> validationList)
			throws DuplicateNameSignal, FrameworkErrorSignal {
		CheckRecord checkRecord = (CheckRecord) newCheckRecordData;
		CreateInfo createInfo = (CreateInfo) transitionInfo;
		checkRecord.setKey(new CheckRecordKey(createInfo.getPlanDate(),
				createInfo.getCheckPlanName(),
				createInfo.getSiteName(),
				createInfo.getMaterialPackingName(),
				createInfo.getActLocation(),
				createInfo.getCheckMaterialType(),
				createInfo.getCheckPackingType()
				));
		CheckRecordServiceProxy.getCheckRecordService().insert(checkRecord);
	}
	
	public void create(DataInfo[] oldCheckRecordDataArray, DataInfo[] newCheckRecordDataArray,
			EventInfo eventInfo, TransitionInfo[] transitionInfoArray,
			HashMap<String, ValidationFormat> validationList)
			throws DuplicateNameSignal, FrameworkErrorSignal{
		    CheckRecord[] checkRecordArray = new CheckRecord[newCheckRecordDataArray.length];
		    System.arraycopy(newCheckRecordDataArray,0,checkRecordArray,0,newCheckRecordDataArray.length);
		    CreateInfo[] createInfo=(CreateInfo[])transitionInfoArray;
		    for(int i=0;i<newCheckRecordDataArray.length;i++)
		    {
		    	checkRecordArray[i].setKey(new CheckRecordKey(createInfo[i].getPlanDate(),
		    			createInfo[i].getCheckPlanName(),createInfo[i].getSiteName(),createInfo[i].getMaterialPackingName(),
		    			createInfo[i].getActLocation(),createInfo[i].getCheckMaterialType(),createInfo[i].getCheckPackingType()
		    			));
		    }
		    CheckRecordServiceProxy.getCheckRecordService().insert(checkRecordArray);
	}
}
