		
package com.sa.ibiz.demo.workflow.config;

import org.flowable.common.engine.impl.history.HistoryLevel;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.history.DefaultHistoryManager;
import org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntity;
import org.flowable.engine.runtime.ActivityInstance;

public class CustomerHistoryManager extends DefaultHistoryManager {

	public CustomerHistoryManager(ProcessEngineConfigurationImpl processEngineConfiguration, HistoryLevel historyLevel,
			boolean usePrefixId) {
		super(processEngineConfiguration, historyLevel, usePrefixId);
	}

	
	protected HistoricActivityInstanceEntity createNewHistoricActivityInstance(ActivityInstance activityInstance) {
        HistoricActivityInstanceEntity historicActivityInstanceEntity = getHistoricActivityInstanceEntityManager().create();

        historicActivityInstanceEntity.setId(activityInstance.getId());

        historicActivityInstanceEntity.setProcessDefinitionId(activityInstance.getProcessDefinitionId());
        historicActivityInstanceEntity.setProcessInstanceId(activityInstance.getProcessInstanceId());
        historicActivityInstanceEntity.setCalledProcessInstanceId(activityInstance.getCalledProcessInstanceId());
        historicActivityInstanceEntity.setExecutionId(activityInstance.getExecutionId());
        historicActivityInstanceEntity.setTaskId(activityInstance.getTaskId());
        historicActivityInstanceEntity.setActivityId(activityInstance.getActivityId());
        historicActivityInstanceEntity.setActivityName(activityInstance.getActivityName());
        historicActivityInstanceEntity.setActivityType(activityInstance.getActivityType());
        historicActivityInstanceEntity.setAssignee(Authentication.getAuthenticatedUserId());
        historicActivityInstanceEntity.setStartTime(activityInstance.getStartTime());
        historicActivityInstanceEntity.setEndTime(activityInstance.getEndTime());
        historicActivityInstanceEntity.setDeleteReason(activityInstance.getDeleteReason());
        historicActivityInstanceEntity.setDurationInMillis(activityInstance.getDurationInMillis());
        historicActivityInstanceEntity.setTenantId(activityInstance.getTenantId());


        getHistoricActivityInstanceEntityManager().insert(historicActivityInstanceEntity);
        return historicActivityInstanceEntity;
    }
	
}
