--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+package com.pentila.evalcomp.workflow.engine;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.ow2.bonita.env.Environment;
+import org.ow2.bonita.facade.APIAccessor;
+import org.ow2.bonita.facade.IdentityAPI;
+import org.ow2.bonita.facade.ManagementAPI;
+import org.ow2.bonita.facade.QueryDefinitionAPI;
+import org.ow2.bonita.facade.QueryRuntimeAPI;
+import org.ow2.bonita.facade.RuntimeAPI;
+import org.ow2.bonita.facade.def.element.BusinessArchive;
+import org.ow2.bonita.facade.def.majorElement.ActivityDefinition;
+import org.ow2.bonita.facade.def.majorElement.DataFieldDefinition;
+import org.ow2.bonita.facade.def.majorElement.ParticipantDefinition;
+import org.ow2.bonita.facade.def.majorElement.ProcessDefinition;
+import org.ow2.bonita.facade.def.majorElement.TransitionDefinition;
+import org.ow2.bonita.facade.exception.ActivityNotFoundException;
+import org.ow2.bonita.facade.exception.DataFieldNotFoundException;
+import org.ow2.bonita.facade.exception.InstanceNotFoundException;
+import org.ow2.bonita.facade.exception.ProcessNotFoundException;
+import org.ow2.bonita.facade.exception.VariableNotFoundException;
+import org.ow2.bonita.facade.runtime.ActivityInstance;
+import org.ow2.bonita.facade.runtime.ActivityState;
+import org.ow2.bonita.facade.runtime.ProcessInstance;
+import org.ow2.bonita.facade.runtime.TaskInstance;
+import org.ow2.bonita.facade.uuid.ActivityInstanceUUID;
+import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID;
+import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
+import org.ow2.bonita.identity.auth.DomainOwner;
+
+import org.ow2.bonita.util.AccessorUtil;
+import org.ow2.bonita.util.BusinessArchiveFactory;
+import org.ow2.bonita.util.Command;
+
+import com.pentila.evalcomp.domain.Role;
+import com.pentila.evalcomp.domain.User;
+import com.pentila.evalcomp.domain.definition.EvaluationDefinition;
+import com.pentila.evalcomp.domain.definition.Property;
+import com.pentila.evalcomp.domain.definition.ScenarioDefinition;
+import com.pentila.evalcomp.domain.service.ExtendProcessDefinition;
+import com.pentila.evalcomp.domain.transit.Activity;
+import com.pentila.evalcomp.domain.transit.Process;
+import com.pentila.evalcomp.domain.transit.TPackageDefinition;
+import com.pentila.evalcomp.domain.transit.TransitProcessDefinition;
+import com.pentila.evalcomp.domain.transit.Transition;
+import com.pentila.evalcomp.manager.Beans;
+import com.pentila.evalcomp.utilities.InstanceUtil;
+import com.pentila.evalcomp.utilities.Utils;
+import com.pentila.evalcomp.workflow.engine.IEngine;
+
+public class Engine5 implements IEngine {
+
+ org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Engine5.class);
+
+
+ /** The env file. */
+ private String envFile;
+
+ /** The workflowsdir. */
+ private String workflowsdir;
+
+ private Map<ProcessDefinitionUUID, ExtendProcessDefinition> extDefinitions;
+
+ private final List<String> propertyTypesDefinition = Arrays.asList(new String[] { Property.PROPERTY,
+ Property.DEADLINE });
+
+ private final List<String> propertyTypesInstance = Arrays.asList(new String[] { Property.PROPERTY,
+ Property.VARIABLE });
+
+ /**
+ * Convert. Convert a Bonita ProcessDefintion to a TrasitProcessDefinition
+ *
+ * @param pd
+ * the pd (Bonita)
+ *
+ * @return the transit process definition
+ */
+ private TransitProcessDefinition convert(ProcessDefinition pd) {
+ TransitProcessDefinition tpd = new TransitProcessDefinition();
+
+ try {
+
+ APIAccessor apiac = getAPIAccessor();
+
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+
+ /*PackageDefinition packDef = e.getPackage(pd
+ .getPackageDefinitionUUID());
+ */
+ // Get and Convert Package Definition information
+ TPackageDefinition tpack = new TPackageDefinition();
+
+ tpack.setAuthor("Pentila");
+ tpack.setCreationDate(pd.getDeployedDate().toString());
+ tpack.setDescription(pd.getDescription());
+ tpack.setVersion(pd.getVersion());
+ tpack.setXpdlVersion("2.0");
+ tpack.setUUID(pd.getUUID().toString());
+ tpack.setDeployedDate(pd.getDeployedDate());
+ tpack.setName(pd.getName());
+
+ tpd.setPackageDefinition(tpack);
+
+ // Build Process Definition information
+ tpd.setId(pd.getName());
+ String defuuid = pd.getUUID().toString();
+ tpd.setUUID(defuuid);
+ tpd.setName(pd.getLabel());
+ tpd.setDescription(pd.getDescription());
+ tpd.setAuthor("Pentila");
+ tpd.setVersion(pd.getVersion());
+
+ tpd.setCreationDate(pd.getDeployedDate().toString());
+ ProcessDefinitionUUID uuid = new ProcessDefinitionUUID(defuuid);
+
+ ExtendProcessDefinition EPD = extDefinitions.get(pd.getUUID());
+
+ try {
+ DataFieldDefinition ob;
+ ob = e.getProcessDataField(uuid, "INIT_ROLE");
+ String value = (String)ob.getInitialValue();
+ tpd.setInitRole(value);
+ } catch (DataFieldNotFoundException e1) {
+
+ // e1.printStackTrace();
+ }
+
+ try {
+ DataFieldDefinition ob;
+ ob = e.getProcessDataField(uuid, "INSTANCIATION_MODE");
+
+ String value = (String)ob.getInitialValue();
+
+ Integer instanciationMode = new Integer(value);
+ tpd.setInstanciationMode(instanciationMode);
+ } catch (DataFieldNotFoundException e1) {
+ // TODO Auto-generated catch block
+ // e1.printStackTrace();
+ tpd.setInstanciationMode(EvaluationDefinition.MODE_NONE);
+ }
+
+ try {
+ DataFieldDefinition ob;
+ ob = e.getProcessDataField(uuid, "TYPE");
+ String value = (String)ob.getInitialValue();
+ tpd.setType(value);
+ } catch (DataFieldNotFoundException e1) {
+ String type = ScenarioDefinition.EVALUATION;
+
+ tpd.setType(type);
+ // e1.printStackTrace();
+ }
+
+
+ Map<String, Role> mapRoles = new HashMap<String, Role>();
+
+
+
+ if (tpd.getInitRole() != null){
+ Role initRole = new Role();
+ initRole.setName(tpd.getInitRole());
+ mapRoles.put(tpd.getInitRole(), initRole);
+
+
+ }
+
+ Set<ParticipantDefinition> sp = e.getProcessParticipants(uuid);
+ for (ParticipantDefinition pad : sp) {
+
+ if (!mapRoles.containsKey(pad.getName())){
+ Role role = new Role();
+ role.setName(pad.getName());
+
+ mapRoles.put(pad.getName(), role);
+ }
+
+ if (EPD != null && EPD.getRoles() != null){
+ for(Role r : EPD.getRoles()){
+ if (r.getName().equals(pad.getName())){
+ mapRoles.get(pad.getName()).setSingleMember(r.isSingleMember());
+ }
+ }
+ }
+
+
+ }
+ if (!mapRoles.isEmpty()){
+
+ tpd.setRoles(new HashSet<Role>(mapRoles.values()));
+ }
+ Set<ActivityDefinition> sad = e.getProcessActivities(pd
+ .getUUID());
+
+ Set<Activity> sa = new HashSet<Activity>();
+ for (ActivityDefinition ad : sad) {
+
+ // Take only manual (Humain Activities)
+ if (!ad.isAutomatic()) {
+
+ Activity a = new Activity();
+ a.setId(ad.getName());
+ a.setName(ad.getName());
+ a.setDescription(ad.getDescription());
+
+
+
+ a.setRoleNamePerformers(ad.getPerformers());
+ sa.add(a);
+ }
+ }
+
+ tpd.setActivities(sa);
+ Set<Property> spp = getDefProperties(e, pd
+ .getUUID(), propertyTypesDefinition);
+
+ tpd.getProperties().addAll(spp);
+
+ } catch (ProcessNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return tpd;
+
+ }
+
+ /**
+ * Deploy and return a Map of deployed ProcessDefiniton.
+ *
+ * @param managementAPI
+ * the management api
+ * @param barFile
+ * the bar file
+ *
+ * @return the map< string, process definition>
+ *
+ * @throws Exception
+ * the exception
+ */
+ protected ProcessDefinition deploy(
+ ManagementAPI managementAPI, File barFile) throws Exception {
+ try {
+ if (barFile != null) {
+
+ /* final java.io.InputStream in = new FileInputStream(barFile);
+
+ if (in == null) {
+ throw new Exception("Can't find ressource: " + barFile);
+ }
+ */
+
+ BusinessArchive ba = BusinessArchiveFactory.getBusinessArchive(barFile);
+
+ //byte[] bar = Misc.getAllContentFrom(in);
+
+
+
+ return managementAPI.deploy(ba);
+ }else{
+ logger.error("Usage: " + Engine.class + " bpar file");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error("Deploy Workflow Warning");
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#deployWF(org.ow2.bonita.facade.RuntimeAPI, org.ow2.bonita.facade.QueryRuntimeAPI, org.ow2.bonita.facade.ManagementAPI, org.ow2.bonita.facade.QueryDefinitionAPI, java.lang.String)
+ */
+
+ @Override
+ public void deployWF(RuntimeAPI runtimeAPI,
+ QueryRuntimeAPI queryRuntimeAPI, ManagementAPI managementAPI,
+ QueryDefinitionAPI queryDefinitionAPI, String barFile)
+ throws Exception {
+
+ File dir = new File(Beans.getApplicationPath("/")+ "/WEB-INF/"+workflowsdir);
+
+ logger.info("PATH of WORKFLOW :" + dir.getAbsolutePath());
+
+ File[] filesWanted = dir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".bar");
+ }
+ });
+
+ if (filesWanted != null){
+
+ for (File f : filesWanted) {
+ try {
+
+
+ logger.info("Engine bar File at : " +f.getAbsolutePath());
+
+ deploy(managementAPI, f);
+
+ } catch (Exception e) {
+ logger.warn("Eric Test");
+ logger.warn("Deployer Workflow Warning");
+ }
+ }
+ }
+
+ // Initilize Extenstion Definition data struct
+ extDefinitions = new HashMap<ProcessDefinitionUUID, ExtendProcessDefinition>();
+
+ for (ProcessDefinition pd : queryDefinitionAPI.getProcesses()){
+
+ logger.info("ProcessDefintion name : " + pd.getName());
+
+ if (!extDefinitions.containsKey(pd.getUUID())){
+
+ String xmldef = getExtendXML(pd.getUUID(), "forms/resources/extension.xml");
+ if (xmldef != null){
+ extDefinitions.put(pd.getUUID(), XMLUtil.getExtendProcessDefinition(xmldef));
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#execute(org.ow2.bonita.util.Command)
+ */
+ @Override
+ public Object execute(Command m) {
+ Object result = null;
+ try {
+ result = getAPIAccessor().getCommandAPI().execute(m);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Gets the activity transitions.
+ *
+ * @param ad
+ * the ad
+ *
+ * @return the activity transition
+ */
+
+ private List<Transition> getActivityTransition(ActivityDefinition ad) {
+ List<Transition> lt = new ArrayList<Transition>();
+
+ Set<DataFieldDefinition> setFields = ad.getDataFields();
+ for (DataFieldDefinition dataF : setFields) {
+ String id = dataF.getLabel();
+ String[] l = id.split("_");
+
+ if (l.length > 1 && l[0].equals("TRANSITION")) {
+ Transition t = new Transition();
+ t.setId(id);
+ t.setName((String)dataF.getInitialValue());
+ t.setDescription(dataF.getDescription());
+ lt.add(t);
+ }
+ }
+ return lt;
+ }
+
+ /**
+ * Gets the properties from Bonita ProcessDefinition.
+ *
+ * @param qda
+ * the qda
+ * @param pdUUID
+ * the pd uuid
+ * @param pstyle
+ * the pstyle
+ *
+ * @return the def properties
+ *
+ * @throws ProcessNotFoundException
+ * the process not found exception
+ */
+ private Set<Property> getDefProperties(QueryDefinitionAPI qda,
+ ProcessDefinitionUUID pdUUID, List<String> pstyle)
+ throws ProcessNotFoundException {
+
+ Set<Property> sp = new HashSet<Property>();
+
+ for (DataFieldDefinition dfd : qda.getProcessDataFields(pdUUID)) {
+ String id = dfd.getLabel();
+ String description = dfd.getDescription();
+ String v = (String)dfd.getInitialValue();
+
+ String[] c = id.split("_", 2);
+
+ if (c.length == 2) {
+
+ String type = c[0];
+
+ if (pstyle.contains(type)) {
+ Property p = new Property();
+ p.setName(id);
+ p.setType(type);
+ p.setDescription(description);
+ p.setValue(v);
+
+ sp.add(p);
+ }
+ }
+ }
+ return sp;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getEnvFile()
+ */
+ @Override
+ public String getEnvFile() {
+ return envFile;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getInstance(java.lang.String)
+ */
+ @Override
+ public ProcessInstance getInstance(String id)
+ throws InstanceNotFoundException {
+ ProcessInstanceUUID processInstanceUUID = new ProcessInstanceUUID(id);
+
+ APIAccessor apiac = getAPIAccessor();
+
+ return apiac.getQueryRuntimeAPI().getProcessInstance(
+ processInstanceUUID);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#printInstanceDebug(java.lang.String)
+ */
+ @Override
+ public void printInstanceDebug(String id)
+ throws InstanceNotFoundException {
+ProcessInstanceUUID processInstanceUUID = new ProcessInstanceUUID(id);
+
+APIAccessor apiac = getAPIAccessor();
+
+ ProcessInstance pi = apiac.getQueryRuntimeAPI().getProcessInstance(
+ processInstanceUUID);
+
+ logger.info(pi.toString());
+
+ Set<ActivityInstance> a = apiac.getQueryRuntimeAPI().getActivityInstances(processInstanceUUID);
+
+ Set<TaskInstance> b = apiac.getQueryRuntimeAPI().getTasks(processInstanceUUID);
+
+ for (ActivityInstance z: b){
+
+ logger.info("Activity ID:" + z.getActivityName());
+ logger.info("State : " + z.getTask().getState());
+ logger.info("Candidates : ");
+ for (String cand : z.getTask().getTaskCandidates()){
+ logger.info(cand);
+ }
+ }
+
+
+
+}
+
+
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcessDefinitionRoleNames(java.lang.String)
+ */
+ @Override
+ public Set<String> getProcessDefinitionRoleNames(String id) {
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+
+ Set<String> rolenames = new HashSet<String>();
+
+ ProcessDefinitionUUID u = new ProcessDefinitionUUID(id);
+
+ try {
+
+ Set<ParticipantDefinition> sp = e.getProcessParticipants(u);
+ for (ParticipantDefinition pd : sp) {
+ rolenames.add(pd.getName());
+ }
+
+ } catch (ProcessNotFoundException e1) {
+
+ e1.printStackTrace();
+ }
+
+ return rolenames;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcessDefinitions(java.util.Set)
+ */
+ @Override
+ public Set<TransitProcessDefinition> getProcessDefinitions(
+ Set<String> filterTypes) {
+
+ Set<TransitProcessDefinition> stpd = new HashSet<TransitProcessDefinition>();
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+
+ Set<ProcessDefinition> spd = e.getProcesses();
+
+ Map<String, TransitProcessDefinition> map = new HashMap<String, TransitProcessDefinition>();
+
+ for (ProcessDefinition pd : spd) {
+ TransitProcessDefinition tpd = convert(pd);
+
+ if (filterTypes != null && !filterTypes.contains(tpd.getType())) {
+ continue;
+ }
+
+ // Apply a filter for get the lastest Scenario Def by Version
+
+ if (map.containsKey(tpd.getId())) {
+ String currentVersion = map.get(tpd.getId()).getVersion();
+ Float cv = new Float(currentVersion);
+ Float newv = new Float(tpd.getVersion());
+
+ if (java.lang.Math.max(cv, newv) == newv) {
+ map.put(tpd.getId(), tpd);
+ }
+ } else {
+ map.put(tpd.getId(), tpd);
+ }
+
+ }
+
+ stpd.addAll(map.values());
+
+ return stpd;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcessDefinitionUUIDs()
+ */
+ @Override
+ public List<String> getProcessDefinitionUUIDs() {
+
+ List<String> ps = new ArrayList<String>();
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+
+ Set<ProcessDefinition> spd = e.getProcesses();
+
+ for (ProcessDefinition pd : spd) {
+ String s = pd.getUUID().toString();// pd.getProcessId();
+ ps.add(s);
+ }
+
+ return ps;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcessDefinitionVariableByUUID(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getProcessDefinitionVariableByUUID(String defuuid,
+ String variableName) {
+
+ String value = "";
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+ ProcessDefinitionUUID uuid = new ProcessDefinitionUUID(defuuid);
+
+ try {
+
+ try {
+ DataFieldDefinition ob;
+ ob = e.getProcessDataField(uuid, variableName);
+ value = (String)ob.getInitialValue();
+ } catch (DataFieldNotFoundException e1) {
+
+ e1.printStackTrace();
+ }
+
+ } catch (ProcessNotFoundException e1) {
+
+ e1.printStackTrace();
+ }
+
+ return value;
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcesses(java.lang.String)
+ */
+
+ @Override
+ public Set<Process> getProcesses(String login) {
+
+ Map<String, Process> sp = new HashMap<String, Process>();
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ QueryDefinitionAPI qda = apiac.getQueryDefinitionAPI();
+
+ try {
+
+ final Collection<TaskInstance> activities = queryRuntimeAPI
+ .getTaskList(ActivityState.READY);
+
+ for (ActivityInstance activity : activities) {
+
+ ExtendProcessDefinition EPD = extDefinitions.get(activity.getProcessDefinitionUUID());
+
+ String pi = activity.getProcessInstanceUUID().toString();
+ Process pp = null;
+ if (!sp.containsKey(pi)) {
+ pp = new Process();
+ pp.setId(pi);
+ sp.put(pi, pp);
+ } else {
+ pp = (sp.get(pi));
+ }
+
+ String SSIID = (String) queryRuntimeAPI
+ .getProcessInstanceVariable(activity
+ .getProcessInstanceUUID(), "SIID");
+
+
+ try {
+ String TYPE = (String) queryRuntimeAPI
+
+ .getProcessInstanceVariable(activity
+ .getProcessInstanceUUID(), "TYPE");
+
+ pp.setType(TYPE);
+ } catch (Exception e) {
+ pp.setType(ScenarioDefinition.EVALUATION);
+ }
+ Long SIID = new Long(SSIID);
+
+ pp.setSIID(SIID);
+
+ String activityUUID = activity.getUUID().toString();
+
+ String activityId = activity.getActivityName();
+
+ Activity a = new Activity();
+ a.setId(activityId);
+ a.setUUID(activityUUID);
+ try{
+ a.setTaskCandidates(activity.getTask().getTaskCandidates());
+ }catch (Exception e){
+ //e.printStackTrace();
+ }
+ if (EPD != null) {
+ a
+ .setExtActivity(EPD
+ .getExtActivityByActivityId(activityId));
+ }
+
+ // Valiable D'activité
+
+
+ Set<Property> setP = new HashSet<Property>();
+ for ( Entry<String, Object> vv : activity.getLastKnownVariableValues().entrySet()){
+
+ String key = vv.getKey();
+ String value = (String) vv.getValue();
+
+ logger.debug("Variable : " + key + " with value : " + value);
+ if (key.startsWith(Property.VARIABLE)){
+
+ Property p = new Property();
+
+ p.setName(key);
+ p.setValue(value);
+
+ setP.add(p);
+
+ }
+ }
+
+ a.setProperties(setP);
+
+ // Activity Definition
+ ActivityDefinition ad;
+ try {
+
+ ad = qda.getProcessActivity(activity
+ .getProcessDefinitionUUID(), activityId);
+
+ a.setDescription(ad.getDescription());
+
+ a.setRoleNamePerformers(ad.getPerformers());
+
+ List<Transition> lt = getActivityTransition(ad);
+
+ a.setTransitions(lt);
+ pp.getActivities().add(a);
+ Set<Property> spp = getDefProperties(qda, activity
+ .getProcessDefinitionUUID(), propertyTypesInstance);
+
+ Map<String, Object> mapVars = queryRuntimeAPI
+ .getProcessInstanceVariables(activity
+ .getProcessInstanceUUID());
+
+ for (Property p : spp) {
+ if (mapVars.containsKey(p.getName())) {
+ String v = (String) mapVars.get(p.getName());
+ p.setValue(v);
+ }
+
+ }
+
+ pp.setProperties(spp);
+
+ } catch (ProcessNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ } catch (ActivityNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (VariableNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return new HashSet<Process>(sp.values());
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getTransitProcessDefinition(java.lang.String)
+ */
+ @Override
+ public TransitProcessDefinition getTransitProcessDefinition(String uuid) {
+
+ TransitProcessDefinition tpd = null;
+
+ try {
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI e = apiac.getQueryDefinitionAPI();
+ ProcessDefinitionUUID myuuid = new ProcessDefinitionUUID(uuid);
+
+ ProcessDefinition pd = e.getProcess(myuuid);
+
+ tpd = convert(pd);
+
+ } catch (ProcessNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return tpd;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getUserScenarioInstanceIds(java.lang.String)
+ */
+ @Override
+ public Set<Long> getUserScenarioInstanceIds(String login) {
+ APIAccessor apiac = getAPIAccessor();
+
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ Set<Long> sid = new HashSet<Long>();
+ try {
+ final Collection<TaskInstance> activities = queryRuntimeAPI
+ .getTaskList(ActivityState.READY);
+
+ for (ActivityInstance activity : activities) {
+
+ String SSIID = (String) queryRuntimeAPI
+ .getProcessInstanceVariable(activity
+ .getProcessInstanceUUID(), "SIID");
+
+ Long SIID = new Long(SSIID);
+ sid.add(SIID);
+ }
+
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (VariableNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return sid;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getWorkflowsdir()
+ */
+ @Override
+ public String getWorkflowsdir() {
+ return workflowsdir;
+ }
+
+ /**
+ * Checks for transition.
+ *
+ * @param actionId
+ * the action id
+ * @param activity
+ * the activity uuid
+ *
+ * @return true, if successful
+ */
+ private boolean hasTransition(ActivityInstance activity,
+ String actionId) {
+ try{
+ return activity.getLastKnownVariableValues().keySet().contains(actionId);
+ }catch (Exception e){
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#initializeWorkers()
+ */
+ @Override
+ public void initializeWorkers() throws Exception {
+
+ logger.info("Bonita environment at : " + Beans.getApplicationPath("/")+ "WEB-INF/"+envFile);
+
+ //System.setProperty("org.ow2.bonita.environment", Beans.getApplicationPath("/")+ "WEB-INF/"+envFile);
+ System.setProperty("org.ow2.bonita.api-type", "Standard");
+
+
+ APIAccessor apiac =getAPIAccessor();
+ DomainOwner.setDomain("default");
+ deployWF(apiac.getRuntimeAPI(), apiac.getQueryRuntimeAPI(), apiac
+ .getManagementAPI(), apiac.getQueryDefinitionAPI(), "");
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#instanciate(java.lang.String, java.lang.String, java.util.Map)
+ */
+ @Override
+ public String instanciate(String login, String processDefinitionUUID,
+ Map parameters) {
+
+ ProcessInstanceUUID instanceUUID = null;
+
+ APIAccessor apiac = getAPIAccessor();
+ RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+
+ ProcessDefinitionUUID PDUUID = new ProcessDefinitionUUID(
+ processDefinitionUUID);
+
+ try {
+
+ instanceUUID = runtimeAPI.instantiateProcess(PDUUID, parameters);
+ } catch (ProcessNotFoundException e) {
+ e.printStackTrace();
+ } catch (VariableNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ return instanceUUID.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#refreshAssignation(java.lang.String)
+ */
+ @Override
+ public void refreshAssignation(String processInstanceId) {
+ APIAccessor apiac = getAPIAccessor();
+
+ final QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+ final RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+
+ final ProcessInstanceUUID processInstanceUUID = new ProcessInstanceUUID(
+ processInstanceId);
+
+ Command<Boolean> assignCommand = new Command<Boolean>(){
+
+ public Boolean execute(Environment arg0) throws Exception {
+ final Collection<TaskInstance> activities = queryRuntimeAPI
+ .getTasks(processInstanceUUID);
+
+ for (ActivityInstance activity : activities) {
+ runtimeAPI.assignTask(activity.getTask().getUUID());
+ }
+
+ return true;
+ }
+
+
+
+ };
+ execute(assignCommand);
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#removeInstance(java.lang.String)
+ */
+
+ @Override
+ public void removeInstance(String id) {
+
+ APIAccessor apiac = getAPIAccessor();
+ ProcessInstanceUUID processInstanceUUID = new ProcessInstanceUUID(id);
+
+ RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+
+ try {
+ if (logger.isDebugEnabled()){
+ logger.debug("Deleting ProcessInstance : " + processInstanceUUID);
+ }
+ runtimeAPI.deleteProcessInstance(processInstanceUUID);
+
+ } catch (InstanceNotFoundException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getExtendXML(org.ow2.bonita.facade.uuid.ProcessDefinitionUUID, java.lang.String)
+ */
+ public String getExtendXML(ProcessDefinitionUUID pduuid, String filename) {
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryDefinitionAPI qda = apiac.getQueryDefinitionAPI();
+ ProcessDefinition p;
+
+ try {
+ BusinessArchive ba = qda.getBusinessArchive(pduuid);
+ Map<String, byte[]> m = ba.getResources();
+
+ System.out.println("Size of Map is : " + m.size());
+
+ for (String name : m.keySet()){
+ System.out.println("Filename is : " + name);
+ }
+
+ byte[] a = ba.getResource(filename);
+ System.out.println("A = " + a);
+
+ String ss = new String(a, "UTF-8");
+ return ss;
+ } catch (ProcessNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e){
+
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#runProcessActivity(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+
+ @Override
+ public void runProcessActivity(String login, String processuuid,
+ String selectedActivityId, String actionId) {
+
+ try {
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ ActivityInstanceUUID selectedUUID = new ActivityInstanceUUID(
+ selectedActivityId);
+
+ ActivityInstance activity;
+
+ activity = queryRuntimeAPI.getActivityInstance(selectedUUID);
+
+ ActivityInstanceUUID taskUUID = activity.getTask().getUUID();
+ ActivityInstanceUUID activityUUID = activity.getUUID();
+
+
+ String value = null;
+
+ if (hasTransition(activity, actionId)) {
+ value = "yes";
+ }
+
+ StartFinishCommand5 sfc = new StartFinishCommand5(taskUUID, activityUUID, actionId, value);
+ execute(sfc);
+
+ } catch (ActivityNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#setEnvFile(java.lang.String)
+ */
+ @Override
+ public void setEnvFile(String envFile) {
+ this.envFile = envFile;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#setWorkflowsdir(java.lang.String)
+ */
+ @Override
+ public void setWorkflowsdir(String workflowsdir) {
+ this.workflowsdir = workflowsdir;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#setProcessInstanceVariables(java.lang.String, java.util.Map)
+ */
+ @Override
+ public void setProcessInstanceVariables(final String processuuid,
+ final Map<String, String> variablesValues) {
+ final APIAccessor apiac = getAPIAccessor();
+ final RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+
+ Command<Boolean> setPIVariable = new Command<Boolean>(){
+
+ public Boolean execute(Environment arg0) throws Exception {
+
+ for (Entry<String, String> e : variablesValues.entrySet()) {
+ runtimeAPI.setProcessInstanceVariable(new ProcessInstanceUUID(
+ processuuid), e.getKey(), e.getValue());
+ }
+
+ return true;
+ }
+
+ };
+
+ execute(setPIVariable);
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getProcessByActivityUUID(java.lang.String)
+ */
+ @Override
+ public Process getProcessByActivityUUID(String activityUUID) {
+ // UNSED YET !!!
+
+ try {
+ APIAccessor apiac = getAPIAccessor();
+
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ QueryDefinitionAPI qda = apiac.getQueryDefinitionAPI();
+
+ ActivityInstance activity = queryRuntimeAPI
+ .getActivityInstance(new ActivityInstanceUUID(""));
+
+ ExtendProcessDefinition EPD = extDefinitions.get(activity
+ .getProcessDefinitionUUID());
+
+ String pi = activity.getProcessInstanceUUID().toString();
+ Process pp = new Process();
+ pp.setId(pi);
+ String SSIID = (String) queryRuntimeAPI.getProcessInstanceVariable(
+ activity.getProcessInstanceUUID(), "SIID");
+
+ try {
+ String TYPE = (String) queryRuntimeAPI
+
+ .getProcessInstanceVariable(activity.getProcessInstanceUUID(),
+ "TYPE");
+
+ pp.setType(TYPE);
+ } catch (Exception e) {
+ pp.setType(ScenarioDefinition.EVALUATION);
+ }
+ Long SIID = new Long(SSIID);
+
+ pp.setSIID(SIID);
+
+ String activityId = activity.getActivityName();
+
+ Activity a = new Activity();
+ a.setId(activityId);
+ a.setUUID(activityUUID);
+
+ if (EPD != null) {
+ a.setExtActivity(EPD.getExtActivityByActivityId(activityId));
+ }
+
+ ActivityDefinition ad;
+ try {
+
+ ad = qda.getProcessActivity(
+ activity.getProcessDefinitionUUID(), activityId);
+
+ a.setDescription(ad.getDescription());
+
+ a.setRoleNamePerformers(ad.getPerformers());
+
+ List<Transition> lt = getActivityTransition(ad);
+
+ a.setTransitions(lt);
+ pp.getActivities().add(a);
+
+ Set<Property> spp = getDefProperties(qda, activity
+ .getProcessDefinitionUUID(), propertyTypesInstance);
+
+ Map<String, Object> mapVars = queryRuntimeAPI
+ .getProcessInstanceVariables(activity
+ .getProcessInstanceUUID());
+
+ for (Property p : spp) {
+ if (mapVars.containsKey(p.getName())) {
+ String v = (String) mapVars.get(p.getName());
+ p.setValue(v);
+ }
+
+ }
+
+ pp.setProperties(spp);
+
+ } catch (ProcessNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ } catch (ActivityNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return pp;
+
+ } catch (ActivityNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (VariableNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#getCandidates(java.lang.String)
+ */
+ @Override
+ public Map<String, Map<String, Object>> getCandidates(String bonitaProcessId) {
+ APIAccessor apiac = getAPIAccessor();
+
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ ProcessInstanceUUID PIUUID = new ProcessInstanceUUID(bonitaProcessId);
+
+ InstanceUtil IU = new InstanceUtil();
+
+ IU.applyContext(getProcess("", bonitaProcessId), null, null);
+
+ Map<String, Map<String, Object>> activityUsers = new HashMap<String, Map<String, Object>>();
+ try {
+ for (ActivityInstance ai : queryRuntimeAPI.getActivityInstances(PIUUID)){
+ if (ai != null && ai.getTask() != null && ai.getTask().getState()!=null && ai.getTask().getState().equals(ActivityState.READY)){
+ if (logger.isDebugEnabled()){
+ try {
+ logger.debug("getCandidates SIID : "+queryRuntimeAPI.getProcessInstanceVariable(PIUUID, "SIID"));
+ } catch (VariableNotFoundException e) {
+
+ e.printStackTrace();
+ }
+ }
+ ExtendProcessDefinition EPD = extDefinitions.get(ai.getProcessDefinitionUUID());
+
+ ActivityInstance t = (ActivityInstance)ai;
+
+ Map<String, Object> map = new HashMap<String, Object>();
+
+ map.put("users", t.getTask().getTaskCandidates());
+ map.put("extActivity", IU.switchLabel(EPD.getExtActivityByActivityId(ai.getActivityName())));
+ activityUsers.put(ai.getActivityName(), map);
+
+ }
+ }
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return activityUsers;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#testCoherence(java.lang.String, java.util.Set, java.lang.String)
+ */
+ @Override
+ public boolean testCoherence(String id, Set<String> uids, String actId) {
+
+ boolean ret = false;
+
+ ProcessInstanceUUID processInstanceUUID = new ProcessInstanceUUID(id);
+ APIAccessor apiac = getAPIAccessor();
+
+ try {
+
+ ProcessInstance pi = apiac.getQueryRuntimeAPI().getProcessInstance(
+ processInstanceUUID);
+
+ Set<TaskInstance> b = apiac.getQueryRuntimeAPI().getTasks(processInstanceUUID);
+
+ for (ActivityInstance z: b){
+
+ if (z.getActivityName().equals(actId)){
+
+ for (String uid : uids){
+ if (!z.getTask().getTaskCandidates().contains(uid) && z.getTask().getState().equals(ActivityState.READY)){
+ logger.info("Process id : " + id + " is wrong !");
+ logger.info("ProcessTaskCandidates : " + z.getTask().getTaskCandidates());
+ logger.info("EMa localroles : " + uids);
+
+ ret = true;
+ }
+ }
+ }
+ }
+
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return ret;
+ }
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#displayDB(java.lang.String)
+ */
+ @Override
+ public void displayDB(String stateName){
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ if (logger.isInfoEnabled()){
+ try{
+
+ Set<ProcessInstance> s = queryRuntimeAPI.getProcessInstances();
+ for (ProcessInstance pii : s){
+
+ logger.info("ProcessInstanceUUID : " + pii.getUUID());
+
+ for (TaskInstance a : queryRuntimeAPI.getTasks(pii.getProcessInstanceUUID())){
+
+
+
+
+
+ String users = "#nousers#";
+ String nstate = "#missing#";
+ String gouser = "#noGOUser#";
+
+
+
+ if (a != null){
+
+
+
+ nstate = a.getState().name();
+
+
+
+ if (stateName != null && !nstate.equals(stateName)){
+ continue;
+ }
+
+ Set<String> sss = a.getTaskCandidates();
+ if (sss != null){
+ users = "";
+ for (String uid : sss){
+ users += uid + "\n";
+ }
+ }
+ try{
+ gouser = a.getTaskUser();
+ } catch(IllegalStateException e){
+ logger.debug(e.getMessage());
+ }
+ }
+
+ logger.info("ActivityID : " + a.getActivityName() +"\n" + "State : " + nstate + "\n" + "Users Candidates = " + users + "GO USER : " + gouser + "\nDate : " + a.getCreatedDate() + "\nStart Date : "+ a.getStartedDate() + "\nEnd Date : "+a.getEndedDate()+"\n\n");
+
+ boolean ok = false;
+ for ( Entry<String, Object> vu : a.getLastKnownVariableValues().entrySet()){
+ logger.info("Variable Name : " + vu.getKey()+ " value : " + vu.getValue());
+
+ if (!vu.getValue().equals("--")){
+ ok = true;
+ }
+
+ }
+
+ if (a.getLastKnownVariableValues().size() == 0){
+ ok = true;
+ }
+
+
+ if (nstate.equals("FINISH") && !ok){
+ logger.info("######################## ALARM !!!!! ");
+ logger.info("A Activity is finish and not transaction left !!!");
+ }
+
+ }
+
+ }
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+ }
+
+ /*
+ * Fix les Process dans l'etat EXECUTING
+ */
+
+ /* (non-Javadoc)
+ * @see com.pentila.evalcomp.workflow.engine.IEngine#fixState()
+ */
+ @Override
+ public void fixState(){
+
+
+ APIAccessor apiac = getAPIAccessor();
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+ final RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+ if (logger.isInfoEnabled()){
+ try{
+
+ Set<ProcessInstance> s = queryRuntimeAPI.getProcessInstances();
+ for (ProcessInstance pii : s){
+
+ for (final TaskInstance a : queryRuntimeAPI.getTasks(pii.getProcessInstanceUUID())){
+
+
+
+
+ String users = "#nousers#";
+ String nstate = "#missing#";
+ String gouser = "#noGOUser#";
+
+
+
+ if (a != null){
+
+ nstate = a.getState().name();
+
+ if (!a.getState().equals(ActivityState.EXECUTING)){
+ logger.debug(a.getUUID() + ": State was : " + a.getState().name());
+ continue;
+ }
+
+ logger.info("ProcessInstanceUUID : " + pii.getUUID());
+ Set<String> sss = a.getTaskCandidates();
+ if (sss != null){
+ users = "";
+ for (String uid : sss){
+ Utils.fakeUser(uid);
+ users += uid + "\n";
+ break;
+ }
+ }
+ try{
+ gouser = a.getTaskUser();
+ } catch(IllegalStateException e){
+ logger.info(e.getMessage());
+ }
+ }
+
+ logger.info("ActivityID : " + a.getActivityName() +"\n" + "State : " + nstate + "\n" + "Users Candidates = " + users + "GO USER : " + gouser + "\n\n");
+
+
+ for ( Entry<String, Object> vu : a.getLastKnownVariableValues().entrySet()){
+ logger.info("Variable Name : " + vu.getKey()+ " value : " + vu.getValue());
+ }
+
+
+
+
+
+ User u = Beans.getEntityManagerBean().getCurrentUser();
+
+ logger.info("Fake logged user : " + u.getLastname() + " " + u.getFirstname());
+
+
+ Command<Boolean> finishCommand = new Command<Boolean>(){
+
+
+
+ public Boolean execute(Environment arg0)
+ throws Exception {
+
+ runtimeAPI.finishTask(a.getUUID(), false);
+
+ return true;
+ }
+
+ };
+
+ execute(finishCommand);
+
+
+
+
+
+
+
+ }
+ }
+
+
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+
+
+
+
+ }
+}
+
+ public void setActivitiesInstanceVariables(
+ final Map<String, Map<String, String>> vva) {
+
+ final APIAccessor apiac = getAPIAccessor();
+ final RuntimeAPI runtimeAPI = apiac.getRuntimeAPI();
+
+ Command<Boolean> setPIVariable = new Command<Boolean>(){
+
+ public Boolean execute(Environment arg0) throws Exception {
+ for (Entry<String, Map<String, String>> act : vva.entrySet() ){
+
+ String ActivityUUID = act.getKey();
+ Map<String, String> p = act.getValue();
+ for (Entry<String, String> f : p.entrySet()){
+
+ String var_name = f.getKey();
+ String var_value = f.getValue();
+
+ runtimeAPI.setActivityInstanceVariable(new ActivityInstanceUUID(ActivityUUID), var_name, var_value);
+
+ }
+
+
+ }
+ return true;
+ }
+
+ };
+
+ execute(setPIVariable);
+
+ }
+
+
+ public APIAccessor getAPIAccessor(){
+ DomainOwner.setDomain("default");
+ return AccessorUtil.getAPIAccessor();
+ }
+
+ public Process getProcess(String login, String processuuid) {
+
+
+ if (logger.isDebugEnabled()){
+ logger.debug("Enter in getProcess Method" );
+ logger.debug("ProcessUUID : " + processuuid);
+ }
+ APIAccessor apiac = AccessorUtil.getAPIAccessor();
+ QueryRuntimeAPI queryRuntimeAPI = apiac.getQueryRuntimeAPI();
+
+ QueryDefinitionAPI qda = apiac.getQueryDefinitionAPI();
+
+ ProcessInstanceUUID piu = new ProcessInstanceUUID(processuuid);
+ Process pp = null;
+ try {
+
+ final Set<TaskInstance> activities = queryRuntimeAPI
+ .getTasks(piu);
+
+
+ pp = new Process();
+ if(!activities.isEmpty()){
+ pp = new Process();
+ }else{
+ if (logger.isDebugEnabled()){
+ logger.debug("Activity Collection is Empty");
+ }
+ }
+
+ for (ActivityInstance activity : activities) {
+ if (logger.isDebugEnabled()){
+
+ logger.debug("getProcesses for " + login + " : " + activity.toString() + "( " + activity.getState()+") ");
+ }
+
+
+
+ if (!activity.getState().equals(ActivityState.READY)){
+ continue;
+ }
+
+ ExtendProcessDefinition EPD = extDefinitions.get(activity.getProcessDefinitionUUID()
+ );
+
+ String SSIID = (String) queryRuntimeAPI
+ .getProcessInstanceVariable(activity
+ .getProcessInstanceUUID(), "SIID");
+
+
+ try {
+ String TYPE = (String) queryRuntimeAPI
+
+ .getProcessInstanceVariable(activity
+ .getProcessInstanceUUID(), "TYPE");
+
+ pp.setType(TYPE);
+ } catch (Exception e) {
+ pp.setType(ScenarioDefinition.EVALUATION);
+ }
+ Long SIID = new Long(SSIID);
+
+ pp.setSIID(SIID);
+
+ String activityUUID = activity.getUUID().toString();
+
+ String activityId = activity.getActivityName();
+
+ Activity a = new Activity();
+ a.setId(activityId);
+ a.setUUID(activityUUID);
+ try{
+ a.setTaskCandidates(activity.getTask().getTaskCandidates());
+ }catch (Exception e){
+ //e.printStackTrace();
+ }
+ if (EPD != null) {
+ a
+ .setExtActivity(EPD
+ .getExtActivityByActivityId(activityId));
+ }
+
+ // Valiable D'activité
+
+
+ Set<Property> setP = new HashSet<Property>();
+ for ( Entry<String, Object> vv : activity.getLastKnownVariableValues().entrySet()){
+
+ String key = vv.getKey();
+ String value = (String) vv.getValue();
+
+ logger.debug("Variable : " + key + " with value : " + value);
+ if (key.startsWith(Property.VARIABLE)){
+
+ Property p = new Property();
+
+ p.setName(key);
+ p.setValue(value);
+
+ setP.add(p);
+
+ }
+ }
+
+ a.setProperties(setP);
+
+ // Activity Definition
+ ActivityDefinition ad;
+ try {
+
+ ad = qda.getProcessActivity(activity
+ .getProcessDefinitionUUID(), activityId);
+
+ a.setDescription(ad.getDescription());
+
+ a.setRoleNamePerformers(ad.getPerformers());
+
+ List<Transition> lt = getActivityTransition(ad);
+
+ a.setTransitions(lt);
+ pp.getActivities().add(a);
+
+ Set<Property> spp = getDefProperties(qda, activity
+ .getProcessDefinitionUUID(), propertyTypesInstance);
+
+ Map<String, Object> mapVars = queryRuntimeAPI
+ .getProcessInstanceVariables(activity
+ .getProcessInstanceUUID());
+
+ for (Property p : spp) {
+ if (mapVars.containsKey(p.getName())) {
+ String v = (String) mapVars.get(p.getName());
+ p.setValue(v);
+ }
+
+ }
+
+ pp.setProperties(spp);
+
+ } catch (ProcessNotFoundException e) {
+
+ e.printStackTrace();
+
+ } catch (ActivityNotFoundException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ } catch (InstanceNotFoundException e) {
+
+ e.printStackTrace();
+ } catch (VariableNotFoundException e) {
+
+ e.printStackTrace();
+ }
+
+
+
+
+ return pp;
+ }
+
+}