Search in sources :

Example 1 with DeployedAsset

use of org.jbpm.services.api.model.DeployedAsset 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 DeployedAsset

use of org.jbpm.services.api.model.DeployedAsset in project jbpm by kiegroup.

the class KModuleDeploymentService method boostrapRuntimeEnvironmentBuilder.

/**
 * This creates and fills a {@link RuntimeEnvironmentBuilder} instance, which is later used when creating services.
 * </p>
 * A lot of the logic here is used to process the information in the {@link DeploymentDescriptor} instance, which is
 * part of the {@link DeploymentUnit}.
 *
 * @param deploymentUnit The {@link KModuleDeploymentUnit}, which is filled by the method
 * @param deployedUnit The {@link DeployedUnit}, which is also filled by the method
 * @param kieContainer The {@link KieContainer}, which contains information needed to fill the above two arguments
 * @param mode The {@link MergeMode} used to resolve conflicts in the {@link DeploymentDescriptor}.
 * @return A {@link RuntimeEnvironmentBuilder} instance ready for use
 */
protected RuntimeEnvironmentBuilder boostrapRuntimeEnvironmentBuilder(KModuleDeploymentUnit deploymentUnit, DeployedUnit deployedUnit, KieContainer kieContainer, MergeMode mode) {
    DeploymentDescriptor descriptor = deploymentUnit.getDeploymentDescriptor();
    if (descriptor == null || ((DeploymentDescriptorImpl) descriptor).isEmpty()) {
        // skip empty descriptors as its default can override settings
        DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
        List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
        descriptor = merger.merge(descriptorHierarchy, mode);
        deploymentUnit.setDeploymentDescriptor(descriptor);
    } else if (descriptor != null && !deploymentUnit.isDeployed()) {
        DeploymentDescriptorManager descriptorManager = new DeploymentDescriptorManager("org.jbpm.domain");
        List<DeploymentDescriptor> descriptorHierarchy = descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);
        descriptorHierarchy.add(0, descriptor);
        descriptor = merger.merge(descriptorHierarchy, mode);
        deploymentUnit.setDeploymentDescriptor(descriptor);
    }
    // first set on unit the strategy
    deploymentUnit.setStrategy(descriptor.getRuntimeStrategy());
    // setting up runtime environment via builder
    RuntimeEnvironmentBuilder builder = null;
    if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
    } else {
        builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
    }
    // populate various properties of the builder
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
    builder.entityManagerFactory(emf);
    Map<String, Object> contaxtParams = new HashMap<String, Object>();
    contaxtParams.put("entityManagerFactory", emf);
    contaxtParams.put("classLoader", kieContainer.getClassLoader());
    // process object models that are globally configured (environment entries, session configuration)
    for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addEnvironmentEntry(model.getName(), entry);
    }
    for (NamedObjectModel model : descriptor.getConfiguration()) {
        Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
        builder.addConfiguration(model.getName(), (String) entry);
    }
    ObjectMarshallingStrategy[] mStrategies = new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
    int index = 0;
    for (ObjectModel model : descriptor.getMarshallingStrategies()) {
        Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
        mStrategies[index] = (ObjectMarshallingStrategy) strategy;
        index++;
    }
    // lastly add the main default strategy
    mStrategies[index] = new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
    builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);
    builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor);
    builder.addEnvironmentEntry("KieContainer", kieContainer);
    if (executorService != null) {
        builder.addEnvironmentEntry("ExecutorService", executorService);
    }
    if (identityProvider != null) {
        builder.addEnvironmentEntry(EnvironmentName.IDENTITY_PROVIDER, identityProvider);
    }
    // populate all assets with roles for this deployment unit
    List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_VIEW);
    if (requiredRoles != null && !requiredRoles.isEmpty()) {
        for (DeployedAsset desc : deployedUnit.getDeployedAssets()) {
            if (desc instanceof ProcessAssetDesc) {
                ((ProcessAssetDesc) desc).setRoles(requiredRoles);
            }
        }
    }
    // Classes 3: classes added from descriptor
    List<String> remoteableClasses = descriptor.getClasses();
    if (remoteableClasses != null && !remoteableClasses.isEmpty()) {
        for (String className : remoteableClasses) {
            Class descriptorClass = null;
            try {
                descriptorClass = kieContainer.getClassLoader().loadClass(className);
                logger.debug("Loaded {} into the classpath from deployment descriptor {}", className, kieContainer.getReleaseId().toExternalForm());
            } catch (ClassNotFoundException cnfe) {
                throw new IllegalArgumentException("Class " + className + " not found in the project");
            } catch (NoClassDefFoundError e) {
                throw new IllegalArgumentException("Class " + className + " not found in the project");
            }
            addClassToDeployedUnit(descriptorClass, (DeployedUnitImpl) deployedUnit);
        }
    }
    return builder;
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) EntityManagerFactory(javax.persistence.EntityManagerFactory) List(java.util.List)

Example 3 with DeployedAsset

use of org.jbpm.services.api.model.DeployedAsset in project jbpm by kiegroup.

the class RuntimeDataServiceImpl method onDeploy.

/*
     * start
     * helper methods to index data upon deployment
     */
public void onDeploy(DeploymentEvent event) {
    Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
    List<String> roles = null;
    for (DeployedAsset asset : assets) {
        if (asset instanceof ProcessAssetDesc) {
            addProcessDefinition((ProcessAssetDesc) asset);
            if (roles == null) {
                roles = ((ProcessAssetDesc) asset).getRoles();
            }
        }
    }
    if (roles == null) {
        roles = Collections.emptyList();
    }
    deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
Also used : ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) DeployedAsset(org.jbpm.services.api.model.DeployedAsset)

Example 4 with DeployedAsset

use of org.jbpm.services.api.model.DeployedAsset in project jbpm by kiegroup.

the class QueryServiceImpl method onDeploy.

public void onDeploy(DeploymentEvent event) {
    Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
    List<String> roles = null;
    for (DeployedAsset asset : assets) {
        if (asset instanceof ProcessAssetDesc) {
            if (roles == null) {
                roles = ((ProcessAssetDesc) asset).getRoles();
            }
        }
    }
    if (roles == null) {
        roles = Collections.emptyList();
    }
    deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
Also used : ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) DeployedAsset(org.jbpm.services.api.model.DeployedAsset)

Aggregations

ProcessAssetDesc (org.jbpm.kie.services.impl.model.ProcessAssetDesc)4 DeployedAsset (org.jbpm.services.api.model.DeployedAsset)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)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 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseRuntimeDataService (org.jbpm.casemgmt.api.CaseRuntimeDataService)1 AuthorizationManager (org.jbpm.casemgmt.api.auth.AuthorizationManager)1