Search in sources :

Example 1 with DeploymentEvent

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);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) Process(org.kie.api.definition.process.Process) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) KieBase(org.kie.api.KieBase) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess)

Example 2 with DeploymentEvent

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) CoundDownDeploymentListener(org.jbpm.kie.services.test.objects.CoundDownDeploymentListener) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ListenerSupport(org.jbpm.services.api.ListenerSupport) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 3 with DeploymentEvent

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()));
}
Also used : KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

DeploymentEvent (org.jbpm.services.api.DeploymentEvent)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseRuntimeDataService (org.jbpm.casemgmt.api.CaseRuntimeDataService)1 AuthorizationManager (org.jbpm.casemgmt.api.auth.AuthorizationManager)1 CaseIdGenerator (org.jbpm.casemgmt.api.generator.CaseIdGenerator)1 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)1