Skip to content

Commit

Permalink
Expos plan item instance local variables via query and rest api (#3971)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Welsch <[email protected]>
  • Loading branch information
WelschChristopher and WelschChristopher authored Oct 3, 2024
1 parent d0989be commit aa7d3ee
Show file tree
Hide file tree
Showing 36 changed files with 589 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.cmmn.api.history;

import java.util.Date;
import java.util.Map;

/**
* @author Dennis Federico
Expand Down Expand Up @@ -88,4 +89,6 @@ public interface HistoricPlanItemInstance {

/** Sets an optional localized name for the plan item */
void setLocalizedName(String localizedName);

Map<String, Object> getPlanItemInstanceLocalVariables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public interface HistoricPlanItemInstanceQuery extends Query<HistoricPlanItemIns
*/
HistoricPlanItemInstanceQuery withLocalizationFallback();

HistoricPlanItemInstanceQuery includeLocalVariables();

HistoricPlanItemInstanceQuery orderByCreateTime();
HistoricPlanItemInstanceQuery orderByEndedTime();
HistoricPlanItemInstanceQuery orderByLastAvailableTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.cmmn.api.runtime;

import java.util.Date;
import java.util.Map;

/**
* @author Joram Barrez
Expand Down Expand Up @@ -58,7 +59,7 @@ default Date getStartTime() {
String getFormKey();
String getExtraValue();
String getTenantId();

Map<String, Object> getPlanItemInstanceLocalVariables();

/** Sets an optional localized name for the plan item */
void setLocalizedName(String localizedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ public interface PlanItemInstanceQuery extends Query<PlanItemInstanceQuery, Plan
*/
PlanItemInstanceQuery caseVariableNotExists(String name);

/**
*
* Include local plan item instance variables in the query result
*/
PlanItemInstanceQuery includeLocalVariables();

/**
* Localize plan item name to specified locale.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ReadOnlyDelegatePlanItemInstanceImpl implements ReadOnlyDelegatePla
protected final String formKey;
protected final String extraValue;
protected final Map<String, Object> variables;
protected final Map<String, Object> localVariables;
protected final String tenantId;
protected final PlanItem planItem;

Expand Down Expand Up @@ -94,6 +95,7 @@ public ReadOnlyDelegatePlanItemInstanceImpl(DelegatePlanItemInstance planItemIns
this.formKey = planItemInstance.getFormKey();
this.extraValue = planItemInstance.getExtraValue();
this.variables = new HashMap<>(planItemInstance.getVariables());
this.localVariables = new HashMap<>(planItemInstance.getPlanItemInstanceLocalVariables());
this.tenantId = planItemInstance.getTenantId();
this.planItem = planItemInstance.getPlanItem();
}
Expand Down Expand Up @@ -268,6 +270,11 @@ public String getTenantId() {
return tenantId;
}

@Override
public Map<String, Object> getPlanItemInstanceLocalVariables() {
return localVariables;
}

@Override
public PlanItem getPlanItem() {
return planItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class HistoricPlanItemInstanceQueryImpl extends AbstractQuery<HistoricPla
protected boolean withoutTenantId;
protected String locale;
protected boolean withLocalizationFallback;
protected boolean includeLocalVariables;

public HistoricPlanItemInstanceQueryImpl() {

Expand Down Expand Up @@ -439,6 +440,13 @@ public HistoricPlanItemInstanceQuery withLocalizationFallback() {
return this;
}

@Override
public HistoricPlanItemInstanceQuery includeLocalVariables() {
this.includeLocalVariables = true;
return this;
}


@Override
public HistoricPlanItemInstanceQuery orderByCreateTime() {
return orderBy(HistoricPlanItemInstanceQueryProperty.CREATE_TIME);
Expand Down Expand Up @@ -511,7 +519,12 @@ public long executeCount(CommandContext commandContext) {

@Override
public List<HistoricPlanItemInstance> executeList(CommandContext commandContext) {
List<HistoricPlanItemInstance> historicPlanItems = CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findByCriteria(this);
List<HistoricPlanItemInstance> historicPlanItems;
if (includeLocalVariables){
historicPlanItems = CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findWithVariablesByCriteria(this);
} else {
historicPlanItems =CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findByCriteria(this);
}

CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
if (cmmnEngineConfiguration.getPlanItemLocalizationManager() != null) {
Expand Down Expand Up @@ -676,6 +689,9 @@ public String getTenantIdLike() {
public boolean isWithoutTenantId() {
return withoutTenantId;
}
public boolean isIncludeLocalVariables() {
return includeLocalVariables;
}

public List<List<String>> getSafeInvolvedGroups() {
return safeInvolvedGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
package org.flowable.cmmn.engine.impl.persistence.entity;

import java.util.Date;
import java.util.List;

import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.common.engine.impl.db.HasRevision;
import org.flowable.common.engine.impl.persistence.entity.Entity;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntity;

/**
* @author Dennis Federico
Expand Down Expand Up @@ -91,4 +93,5 @@ public interface HistoricPlanItemInstanceEntity extends Entity, HasRevision, His

void setTenantId(String tenantId);

List<HistoricVariableInstanceEntity> getQueryVariables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.flowable.cmmn.api.runtime.PlanItemInstance;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.common.engine.impl.context.Context;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInitializingList;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntity;

/**
* @author Dennis Federico
Expand Down Expand Up @@ -57,6 +62,7 @@ public class HistoricPlanItemInstanceEntityImpl extends AbstractCmmnEngineEntity
protected boolean showInOverview;
protected String tenantId = CmmnEngineConfiguration.NO_TENANT_ID;
protected String localizedName;
protected List<HistoricVariableInstanceEntity> queryVariables;

public HistoricPlanItemInstanceEntityImpl() {
}
Expand Down Expand Up @@ -466,6 +472,33 @@ public void setLocalizedName(String localizedName) {
this.localizedName = localizedName;
}

@Override
public Map<String, Object> getPlanItemInstanceLocalVariables() {
Map<String, Object> variables = new HashMap<>();
if (queryVariables != null) {
for (HistoricVariableInstance variableInstance : queryVariables) {
if (variableInstance.getId() != null && variableInstance.getSubScopeId() != null) {
variables.put(variableInstance.getVariableName(), variableInstance.getValue());
}
}
}
return variables;
}

@Override
public List<HistoricVariableInstanceEntity> getQueryVariables() {
if (queryVariables == null && Context.getCommandContext() != null) {
queryVariables = new HistoricVariableInitializingList();
}
return queryVariables;
}

public void setQueryVariables(List<HistoricVariableInstanceEntity> queryVariables) {
this.queryVariables = queryVariables;
}



@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.cmmn.api.history.HistoricPlanItemInstanceQuery;
import org.flowable.cmmn.api.runtime.PlanItemInstance;
import org.flowable.cmmn.engine.impl.history.HistoricPlanItemInstanceQueryImpl;
import org.flowable.common.engine.impl.persistence.entity.EntityManager;

/**
Expand All @@ -38,4 +39,6 @@ public interface HistoricPlanItemInstanceEntityManager extends EntityManager<His
void bulkDeleteHistoricPlanItemInstancesForCaseInstanceIds(Collection<String> caseInstanceIds);

void deleteHistoricPlanItemInstancesForNonExistingCaseInstances();

List<HistoricPlanItemInstance> findWithVariablesByCriteria(HistoricPlanItemInstanceQueryImpl historicPlanItemInstanceQuery);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public void bulkDeleteHistoricPlanItemInstancesForCaseInstanceIds(Collection<Str
public void deleteHistoricPlanItemInstancesForNonExistingCaseInstances() {
dataManager.deleteHistoricPlanItemInstancesForNonExistingCaseInstances();
}

@Override
public List<HistoricPlanItemInstance> findWithVariablesByCriteria(HistoricPlanItemInstanceQueryImpl historicPlanItemInstanceQuery) {
return dataManager.findWithVariablesByCriteria(historicPlanItemInstanceQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
*/
package org.flowable.cmmn.engine.impl.persistence.entity;

import java.util.List;

import org.flowable.cmmn.api.delegate.DelegatePlanItemInstance;
import org.flowable.common.engine.impl.db.HasRevision;
import org.flowable.common.engine.impl.persistence.entity.Entity;
import org.flowable.variable.api.delegate.VariableScope;
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;

/**
* @author Joram Barrez
Expand All @@ -32,4 +35,6 @@ public interface PlanItemInstanceEntity extends Entity, HasRevision, DelegatePla
boolean isStateChangeUnprocessed();
void setStateChangeUnprocessed(boolean stateChangeUnprocessed);


List<VariableInstanceEntity> getQueryVariables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import org.flowable.cmmn.model.PlanItem;
import org.flowable.cmmn.model.RepetitionRule;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.context.Context;
import org.flowable.variable.api.persistence.entity.VariableInstance;
import org.flowable.variable.service.VariableServiceConfiguration;
import org.flowable.variable.service.impl.persistence.entity.VariableInitializingList;
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
import org.flowable.variable.service.impl.persistence.entity.VariableScopeImpl;

Expand Down Expand Up @@ -77,7 +79,7 @@ public class PlanItemInstanceEntityImpl extends AbstractCmmnEngineVariableScopeE
protected String exitCriterionId;
protected String extraValue;
protected String tenantId = CmmnEngineConfiguration.NO_TENANT_ID;

protected List<VariableInstanceEntity> queryVariables;
// Counts
protected boolean countEnabled;
protected int variableCount;
Expand Down Expand Up @@ -457,6 +459,7 @@ public void setExtraValue(String extraValue) {
public String getTenantId() {
return tenantId;
}

@Override
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
Expand Down Expand Up @@ -669,6 +672,31 @@ public void setStateChangeUnprocessed(boolean stateChangeUnprocessed) {
this.stateChangeUnprocessed = stateChangeUnprocessed;
}

@Override
public Map<String, Object> getPlanItemInstanceLocalVariables() {
Map<String, Object> variables = new HashMap<>();
if (queryVariables != null) {
for (VariableInstance variableInstance : queryVariables) {
if (variableInstance.getId() != null && variableInstance.getSubScopeId() != null) {
variables.put(variableInstance.getName(), variableInstance.getValue());
}
}
}
return variables;
}

@Override
public List<VariableInstanceEntity> getQueryVariables() {
if (queryVariables == null && Context.getCommandContext() != null) {
queryVariables = new VariableInitializingList();
}
return queryVariables;
}

public void setQueryVariables(List<VariableInstanceEntity> queryVariables) {
this.queryVariables = queryVariables;
}

@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.cmmn.api.runtime.PlanItemInstance;
import org.flowable.cmmn.api.runtime.PlanItemInstanceQuery;
import org.flowable.cmmn.engine.impl.runtime.PlanItemInstanceQueryImpl;
import org.flowable.common.engine.impl.persistence.entity.EntityManager;

/**
Expand All @@ -38,6 +39,8 @@ public interface PlanItemInstanceEntityManager extends EntityManager<PlanItemIns

List<PlanItemInstance> findByCriteria(PlanItemInstanceQuery planItemInstanceQuery);

List<PlanItemInstance> findWithVariablesByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery);

List<PlanItemInstanceEntity> findByCaseInstanceId(String caseInstanceId);

List<PlanItemInstanceEntity> findByStagePlanItemInstanceId(String stagePlanItemInstanceId);
Expand All @@ -55,4 +58,5 @@ public interface PlanItemInstanceEntityManager extends EntityManager<PlanItemIns
void deleteByStageInstanceId(String stageInstanceId);

void deleteByCaseInstanceId(String caseInstanceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ public long countByCriteria(PlanItemInstanceQuery planItemInstanceQuery) {
public List<PlanItemInstance> findByCriteria(PlanItemInstanceQuery planItemInstanceQuery) {
return dataManager.findByCriteria((PlanItemInstanceQueryImpl) planItemInstanceQuery);
}


@Override
public List<PlanItemInstance> findWithVariablesByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery) {
return dataManager.findWithVariablesByCriteria((PlanItemInstanceQueryImpl) planItemInstanceQuery);
}

@Override
public List<PlanItemInstanceEntity> findByCaseInstanceId(String caseInstanceId) {
return dataManager.findByCaseInstanceId(caseInstanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public interface HistoricPlanItemInstanceDataManager extends DataManager<Histori
void bulkDeleteHistoricPlanItemInstancesForCaseInstanceIds(Collection<String> caseInstanceIds);

void deleteHistoricPlanItemInstancesForNonExistingCaseInstances();

List<HistoricPlanItemInstance> findWithVariablesByCriteria(HistoricPlanItemInstanceQueryImpl historicPlanItemInstanceQuery);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public interface PlanItemInstanceDataManager extends DataManager<PlanItemInstanc
List<PlanItemInstanceEntity> findByStageInstanceIdAndPlanItemId(String stageInstanceId, String planItemId);

List<PlanItemInstance> findByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery);


List<PlanItemInstance> findWithVariablesByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery);

long countByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery);

void deleteByCaseDefinitionId(String caseDefinitionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public void deleteHistoricPlanItemInstancesForNonExistingCaseInstances() {
getDbSqlSession().delete("bulkDeleteHistoricPlanItemInstancesForNonExistingCaseInstances", null, getManagedEntityClass());
}

@Override
@SuppressWarnings("unchecked")
public List<HistoricPlanItemInstance> findWithVariablesByCriteria(HistoricPlanItemInstanceQueryImpl historicPlanItemInstanceQuery) {
setSafeInValueLists(historicPlanItemInstanceQuery);
return getDbSqlSession().selectList("selectHistoricPlanItemInstancesWithLocalVariablesByQueryCriteria", historicPlanItemInstanceQuery,
getManagedEntityClass());
}

@Override
public Class<? extends HistoricPlanItemInstanceEntity> getManagedEntityClass() {
return HistoricPlanItemInstanceEntityImpl.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ public List<PlanItemInstance> findByCriteria(PlanItemInstanceQueryImpl planItemI
setSafeInValueLists(planItemInstanceQuery);
return getDbSqlSession().selectList("selectPlanItemInstancesByQueryCriteria", planItemInstanceQuery, getManagedEntityClass());
}


@Override
@SuppressWarnings("unchecked")
public List<PlanItemInstance> findWithVariablesByCriteria(PlanItemInstanceQueryImpl planItemInstanceQuery) {
setSafeInValueLists(planItemInstanceQuery);
return getDbSqlSession().selectList("selectPlanItemInstancesWithLocalVariablesByQueryCriteria", planItemInstanceQuery, getManagedEntityClass());
}

@Override
public void deleteByCaseDefinitionId(String caseDefinitionId) {
getDbSqlSession().delete("deletePlanItemInstanceByCaseDefinitionId", caseDefinitionId, getManagedEntityClass());
Expand Down
Loading

0 comments on commit aa7d3ee

Please sign in to comment.