All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.runtime.event.GetExecutableJobIds Maven / Gradle / Ivy

/**
 * Copyright (C) 2012 BonitaSoft S.A.
 * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/
package org.ow2.bonita.runtime.event;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.ow2.bonita.env.Environment;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
import org.ow2.bonita.services.EventService;
import org.ow2.bonita.util.Command;
import org.ow2.bonita.util.EnvTool;

/**
 * 
 * @author Matthieu Chaffotte
 * 
 */
public class GetExecutableJobIds implements Command>> {

  private static final long serialVersionUID = 117724435875640884L;

  static final Logger LOG = Logger.getLogger(GetExecutableJobIds.class.getName());

  private final List lockedRootInstances;

  private final int maxResult;

  public GetExecutableJobIds(final List locks, final int maxResult) {
    this.lockedRootInstances = locks;
    this.maxResult = maxResult;
  }

  @Override
  public Map> execute(final Environment environment) throws Exception {
    final EventService eventService = EnvTool.getEventService();
    final List executableJobs = eventService.getExecutableJobs(lockedRootInstances, maxResult);
    final Map> jobsbyRoot = new HashMap>();
    for (final Job job : executableJobs) {
      final ProcessInstanceUUID rootProcessInstanceUUID = job.getRootProcessInstanceUUID();
      ProcessInstanceUUID rootUUID = null;
      if (rootProcessInstanceUUID != null) {
        rootUUID = rootProcessInstanceUUID;
      } else {
        rootUUID = new ProcessInstanceUUID("start-events");
      }
      List list = jobsbyRoot.get(rootUUID);
      if (list == null) {
        list = new ArrayList();
        jobsbyRoot.put(rootUUID, list);
      }
      list.add(job.getId());
      job.lock();
    }
    return jobsbyRoot;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy