www-jrtorres042-github-enterprise-org
/
git_microsoft-powershell_achived-credential_shield.io-tracker_covid-19_live-bpm-platform-diff-1
Public template
forked from camunda/camunda-bpm-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): support composite incident handlers
* adds new engine flag for enabling composite incident handlers so multiple incident handlers can be triggered for the same type related to CAM-13569 closes camunda#1561
- Loading branch information
1 parent
2f8ce04
commit c11c7d2
Showing
4 changed files
with
586 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
engine/src/main/java/org/camunda/bpm/engine/impl/incident/CompositeIncidentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. Camunda licenses this file to you under the Apache License, | ||
* Version 2.0; you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.camunda.bpm.engine.impl.incident; | ||
|
||
import org.camunda.bpm.engine.ProcessEngineException; | ||
import org.camunda.bpm.engine.impl.util.EnsureUtil; | ||
import org.camunda.bpm.engine.runtime.Incident; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* <p> | ||
* A composite incident handler that handles incidents of a certain type by the multiple handlers. | ||
* The result of handling depends on main handler. | ||
* | ||
* @see #mainIncidentHandler | ||
* </p> | ||
* @see IncidentHandler | ||
*/ | ||
public class CompositeIncidentHandler implements IncidentHandler { | ||
|
||
protected IncidentHandler mainIncidentHandler; | ||
protected final List<IncidentHandler> incidentHandlers = new ArrayList<>(); | ||
|
||
/** | ||
* Constructor that takes a list of {@link IncidentHandler} that consume | ||
* the incident. | ||
* | ||
* @param mainIncidentHandler the main incident handler {@link IncidentHandler} that consume the incident and return result. | ||
* @param incidentHandlers the list of {@link IncidentHandler} that consume the incident. | ||
*/ | ||
public CompositeIncidentHandler(IncidentHandler mainIncidentHandler, final List<IncidentHandler> incidentHandlers) { | ||
initializeIncidentsHandlers(mainIncidentHandler, incidentHandlers); | ||
} | ||
|
||
/** | ||
* Constructor that takes a varargs parameter {@link IncidentHandler} that | ||
* consume the incident. | ||
* | ||
* @param mainIncidentHandler the main incident handler {@link IncidentHandler} that consume the incident and return result. | ||
* @param incidentHandlers the list of {@link IncidentHandler} that consume the incident. | ||
*/ | ||
public CompositeIncidentHandler(IncidentHandler mainIncidentHandler, final IncidentHandler... incidentHandlers) { | ||
EnsureUtil.ensureNotNull("Incident handlers", (Object[]) incidentHandlers); | ||
initializeIncidentsHandlers(mainIncidentHandler, Arrays.asList(incidentHandlers)); | ||
} | ||
|
||
/** | ||
* Initialize {@link #incidentHandlers} with data transfered from constructor | ||
* | ||
* @param incidentHandlers | ||
*/ | ||
protected void initializeIncidentsHandlers(IncidentHandler mainIncidentHandler, | ||
final List<IncidentHandler> incidentHandlers) { | ||
EnsureUtil.ensureNotNull("Incident handler", mainIncidentHandler); | ||
this.mainIncidentHandler = mainIncidentHandler; | ||
|
||
EnsureUtil.ensureNotNull("Incident handlers", incidentHandlers); | ||
for (IncidentHandler incidentHandler : incidentHandlers) { | ||
add(incidentHandler); | ||
} | ||
} | ||
|
||
/** | ||
* Adds the {@link IncidentHandler} to the list of | ||
* {@link IncidentHandler} that consume the incident. | ||
* | ||
* @param incidentHandler the {@link IncidentHandler} that consume the incident. | ||
*/ | ||
public void add(final IncidentHandler incidentHandler) { | ||
EnsureUtil.ensureNotNull("Incident handler", incidentHandler); | ||
String incidentHandlerType = getIncidentHandlerType(); | ||
if (!incidentHandlerType.equals(incidentHandler.getIncidentHandlerType())) { | ||
throw new ProcessEngineException( | ||
"Incorrect incident type handler in composite handler with type: " + incidentHandlerType); | ||
} | ||
this.incidentHandlers.add(incidentHandler); | ||
} | ||
|
||
@Override | ||
public String getIncidentHandlerType() { | ||
return mainIncidentHandler.getIncidentHandlerType(); | ||
} | ||
|
||
@Override | ||
public Incident handleIncident(IncidentContext context, String message) { | ||
Incident incident = mainIncidentHandler.handleIncident(context, message); | ||
for (IncidentHandler incidentHandler : this.incidentHandlers) { | ||
incidentHandler.handleIncident(context, message); | ||
} | ||
return incident; | ||
} | ||
|
||
@Override | ||
public void resolveIncident(IncidentContext context) { | ||
mainIncidentHandler.resolveIncident(context); | ||
for (IncidentHandler incidentHandler : this.incidentHandlers) { | ||
incidentHandler.resolveIncident(context); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteIncident(IncidentContext context) { | ||
mainIncidentHandler.deleteIncident(context); | ||
for (IncidentHandler incidentHandler : this.incidentHandlers) { | ||
incidentHandler.deleteIncident(context); | ||
} | ||
} | ||
} |
Oops, something went wrong.