use of org.jbpm.services.api.DeploymentEvent in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method onDeploy.
/*
* Deploy and undeploy handling
*/
@Override
public void onDeploy(DeploymentEvent event) {
AbstractRuntimeManager runtimeManager = (AbstractRuntimeManager) event.getDeployedUnit().getRuntimeManager();
KieBase kieBase = runtimeManager.getEnvironment().getKieBase();
Collection<Process> processes = kieBase.getProcesses();
Map<String, DeployedAsset> mapProcessById = event.getDeployedUnit().getDeployedAssets().stream().collect(toMap(DeployedAsset::getId, asset -> asset));
for (Process process : processes) {
if (((WorkflowProcess) process).isDynamic()) {
String caseIdPrefix = collectCaseIdPrefix(process);
Collection<CaseMilestone> caseMilestones = collectMilestoness(process);
Collection<CaseStage> caseStages = collectCaseStages(event.getDeploymentId(), process.getId(), ((WorkflowProcess) process));
Collection<CaseRole> caseRoles = collectCaseRoles(process);
Collection<AdHocFragment> adHocFragments = collectAdHocFragments((WorkflowProcess) process);
Map<String, List<String>> dataAccessRestrictions = collectDataAccessRestrictions(process);
CaseDefinitionImpl caseDef = new CaseDefinitionImpl((ProcessAssetDesc) mapProcessById.get(process.getId()), caseIdPrefix, caseStages, caseMilestones, caseRoles, adHocFragments, dataAccessRestrictions);
availableCases.add(caseDef);
caseIdGenerator.register(caseIdPrefix);
}
}
// collect role information
Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
List<String> roles = null;
for (DeployedAsset asset : assets) {
if (asset instanceof ProcessAssetDesc) {
// if it's not dynamic it's considered as not case definition
if (!((ProcessAssetDesc) asset).isDynamic()) {
availableProcesses.add((ProcessAssetDesc) asset);
}
if (roles == null) {
roles = ((ProcessAssetDesc) asset).getRoles();
}
}
}
if (roles == null) {
roles = Collections.emptyList();
}
deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
use of org.jbpm.services.api.DeploymentEvent in project jbpm by kiegroup.
the class DeactivateDeploymentServiceWithSyncTest method testDeactivateDeploymentBySync.
@Test
public void testDeactivateDeploymentBySync() throws Exception {
Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(0, deployed.size());
KModuleDeploymentUnit unit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(unit);
deploymentService.deactivate(unit.getIdentifier());
((KModuleDeploymentService) deploymentService).shutdown();
sync.clear();
AtomicBoolean deploymentActive = new AtomicBoolean(true);
CoundDownDeploymentListener countDownListener = new CoundDownDeploymentListener(1) {
@Override
public void onDeploy(DeploymentEvent event) {
// This used to use a specific listener for setting the active state
deploymentActive.set(event.getDeployedUnit().isActive());
super.onDeploy(event);
}
};
countDownListener.setDeploy(true);
((ListenerSupport) deploymentService).addListener(countDownListener);
invoker.start();
countDownListener.waitTillCompleted();
assertFalse("Deployment should be deactivated", deploymentActive.get());
deployed = deploymentService.getDeployedUnits();
assertNotNull(deployed);
assertEquals(1, deployed.size());
}
use of org.jbpm.services.api.DeploymentEvent in project jbpm by kiegroup.
the class PostDeploymentServiceTest method testDuplicatedDeployment.
@Test
public void testDuplicatedDeployment() {
assertNotNull(deploymentService);
((KModuleDeploymentService) deploymentService).addListener(new DeploymentEventListener() {
@Override
public void onUnDeploy(DeploymentEvent event) {
}
@Override
public void onDeploy(DeploymentEvent event) {
throw new IllegalArgumentException("On purpose");
}
@Override
public void onActivate(DeploymentEvent event) {
}
@Override
public void onDeactivate(DeploymentEvent event) {
}
});
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "KBase-test", "ksession-test");
try {
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
fail("Deployment should fail due to post process failuer - see ThrowExceptionOnDeploymentEvent");
} catch (RuntimeException e) {
}
DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNull(deployedGeneral);
assertFalse(RuntimeManagerRegistry.get().isRegistered(deploymentUnit.getIdentifier()));
}
Aggregations