
org.ow2.bonita.runtime.event.CreateJob Maven / Gradle / Ivy
/**
* Copyright (C) 2012 BonitaSoft S.A.
* BonitaSoft, 32 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 org.ow2.bonita.env.Environment;
import org.ow2.bonita.facade.runtime.impl.InternalProcessInstance;
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 CreateJob implements Command {
private static final long serialVersionUID = -803942547334112806L;
private final EventCoupleId eventCoupleId;
public CreateJob(final EventCoupleId eventCoupleId) {
this.eventCoupleId = eventCoupleId;
}
@Override
public Void execute(final Environment environment) throws Exception {
final EventService eventService = EnvTool.getEventService();
final IncomingEventInstance ie = eventService.getIncomingEvent(eventCoupleId.getIncoming());
final OutgoingEventInstance oe = eventService.getOutgoingEvent(eventCoupleId.getOutgoing());
String eventPosition = null;
final String event = ie.getSignal();
if (event.contains(EventConstants.START)) {
eventPosition = EventConstants.START;
} else if (event.contains(EventConstants.BOUNDARY)) {
eventPosition = EventConstants.BOUNDARY;
} else if (event.contains(EventConstants.INTERMEDIATE)) {
eventPosition = EventConstants.INTERMEDIATE;
}
final ProcessInstanceUUID instanceUUID = ie.getInstanceUUID();
ProcessInstanceUUID rootInstanceUUID = null;
if (instanceUUID != null) {
final InternalProcessInstance instance = EnvTool.getJournal().getProcessInstance(instanceUUID);
rootInstanceUUID = instance.getRootInstanceUUID();
}
final Job job = new Job(ie.getName(), eventPosition, EventConstants.MESSAGE, rootInstanceUUID,
ie.getExecutionUUID(), ie.getActivityDefinitionUUID(), null, System.currentTimeMillis(), instanceUUID);
job.setEventSubProcessRootInstanceUUID(ie.getEventSubProcessRootInstanceUUID());
if (!EventConstants.START.equals(job.getEventPosition())) {
eventService.removeEvent(ie);
} else {
ie.unlock();
}
if (oe.getParameters().isEmpty()) {
eventService.removeEvent(oe);
} else {
job.setOutgoingEvent(oe);
}
eventService.storeJob(job);
return null;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("CreateJob [eventCoupleId=");
builder.append(eventCoupleId);
builder.append("]");
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy