/*
 * $Id: VKCAssignmentManager.java,v 1.2 2004/09/20 10:26:14 koppy Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * Created on 24.08.2004
 *
 * $Log: VKCAssignmentManager.java,v $
 * Revision 1.2  2004/09/20 10:26:14  koppy
 * +javadoc Dokumentation
 *
 * Revision 1.1  2004/08/30 14:49:58  koppy
 * Initiale Version der Workflow-Komponente
 *
 */
package vkc.workflow.shark;

import java.util.ArrayList;
import java.util.List;

import org.enhydra.shark.api.RootException;
import org.enhydra.shark.api.SharkTransaction;
import org.enhydra.shark.api.internal.assignment.AssignmentManager;
import org.enhydra.shark.api.internal.assignment.PerformerData;
import org.enhydra.shark.api.internal.working.CallbackUtilities;

import vkc.util.VKCStringUtils;
import vkc.workflow.util.WorkflowUtils;

/**
 * This class represents a custom
 * assignment manager for shark.
 * <p>
 * It makes possible to use process variables
 * for assignments.
 * 
 * @author Andreas Koop
 */
public class VKCAssignmentManager implements AssignmentManager {

    
    
    
    /** 
     * (non-Javadoc)
     * @see org.enhydra.shark.api.internal.assignment.AssignmentManager#configure(org.enhydra.shark.api.internal.working.CallbackUtilities)
     */
    public void configure(CallbackUtilities cus) throws RootException {

    }


    /** 
     * (non-Javadoc)
     * @see org.enhydra.shark.api.internal.assignment.AssignmentManager#getAssignments(org.enhydra.shark.api.SharkTransaction, java.lang.String, java.lang.String, java.lang.String, java.util.List, java.util.List, java.lang.String, java.lang.String, org.enhydra.shark.api.internal.assignment.PerformerData, java.util.List)
     */
    public List getAssignments(SharkTransaction t, String engineName,
            String procId, String actId, List userIds, List responsibleIds,
            String extAttribs, String processRequesterId,
            PerformerData xpdlPerformer, List xpdlResponsiblePerformers) throws RootException{

        
        
        // As Performer of an activity 
        // a workflow variable is used (<Performer>variable</Performer>).
        if( xpdlPerformer != null && xpdlPerformer.isUnresolvedExpressionParticipant){
            return VKCStringUtils.stringToVector( xpdlPerformer.participantIdOrExpression, ";");
        }
        
        // default assignment
        return getDefaultAssignments( userIds, responsibleIds, processRequesterId);

    }

   

    /**
     * Returns the default assigments
     * 
     * @param userIds list of user ids
     * @param responsibleIds list of responsible ids
     * @param processRequesterId id of the process requester 
     * @return list of user ids (assignees)
     */
    protected List getDefaultAssignments(List userIds, List responsibleIds, String processRequesterId){

        if (!WorkflowUtils.isEmpty(userIds)) {
            return userIds;
        } else if (!WorkflowUtils.isEmpty(responsibleIds)) {
            return responsibleIds;
        }
        
        List result = new ArrayList();
        result.add(processRequesterId);
        
        return result;
        
    }
}
