Skip to content

Commit

Permalink
Add querying by scopeIds
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed May 11, 2024
1 parent 7154a2e commit d8147e7
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,169 @@ void testFindEntityLinksWithSameRootWithNullRootInSameContext() {
});
}

@Test
void testFindEntityLinkByScopeAndReferenceScopeAndType() {
managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "other-test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "2", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("2", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.CMMN, "1", ScopeTypes.BPMN, "some-test", entityLinkServiceConfiguration);

assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("test")
.singleResult()).isNotNull();
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("test")
.singleResult()).isNotNull();

assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("dummy")
.singleResult()).isNull();
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("dummy")
.singleResult()).isNull();

return null;
});

managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("test")
.singleResult()).isNotNull();
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("test")
.singleResult()).isNotNull();

assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("dummy")
.singleResult()).isNull();
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeId("1").scopeType(ScopeTypes.BPMN)
.referenceScopeId("1").referenceScopeType(ScopeTypes.CMMN)
.linkType("dummy")
.singleResult()).isNull();

return null;
});

managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
entityLinkService.deleteEntityLinksByScopeIdAndType("1", ScopeTypes.BPMN);
entityLinkService.deleteEntityLinksByScopeIdAndType("2", ScopeTypes.BPMN);
entityLinkService.deleteEntityLinksByScopeIdAndType("1", ScopeTypes.CMMN);

HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("1", ScopeTypes.BPMN);
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("2", ScopeTypes.BPMN);
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("1", ScopeTypes.CMMN);
return null;
});
}

@Test
void testFindEntityLinksByScopeIds() {
managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "other-test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.BPMN, "2", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("2", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("1", ScopeTypes.CMMN, "1", ScopeTypes.BPMN, "some-test", entityLinkServiceConfiguration);
createEntityLinkWithScopeAndRefScopeAndType("3", ScopeTypes.BPMN, "2", ScopeTypes.CMMN, "other-test", entityLinkServiceConfiguration);

assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeIds(List.of("1", "2")).scopeType(ScopeTypes.BPMN)
.list())
.extracting(EntityLinkInfo::getReferenceScopeId, EntityLinkInfo::getReferenceScopeType, EntityLinkInfo::getLinkType)
.containsExactlyInAnyOrder(
tuple("1", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "other-test"),
tuple("2", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "test")
);
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeIds(List.of("1", "2")).scopeType(ScopeTypes.BPMN)
.list())
.extracting(EntityLinkInfo::getReferenceScopeId, EntityLinkInfo::getReferenceScopeType, EntityLinkInfo::getLinkType)
.containsExactlyInAnyOrder(
tuple("1", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "other-test"),
tuple("2", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "test")
);
return null;
});

managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
assertThat(entityLinkService.createInternalEntityLinkQuery()
.scopeIds(List.of("1", "2")).scopeType(ScopeTypes.BPMN)
.list())
.extracting(EntityLinkInfo::getReferenceScopeId, EntityLinkInfo::getReferenceScopeType, EntityLinkInfo::getLinkType)
.containsExactlyInAnyOrder(
tuple("1", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "other-test"),
tuple("2", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "test")
);
assertThat(historicEntityLinkService.createInternalHistoricEntityLinkQuery()
.scopeIds(List.of("1", "2")).scopeType(ScopeTypes.BPMN)
.list())
.extracting(EntityLinkInfo::getReferenceScopeId, EntityLinkInfo::getReferenceScopeType, EntityLinkInfo::getLinkType)
.containsExactlyInAnyOrder(
tuple("1", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "other-test"),
tuple("2", ScopeTypes.CMMN, "test"),
tuple("1", ScopeTypes.CMMN, "test")
);

return null;
});

managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
entityLinkService.deleteEntityLinksByScopeIdAndType("1", ScopeTypes.BPMN);
entityLinkService.deleteEntityLinksByScopeIdAndType("2", ScopeTypes.BPMN);
entityLinkService.deleteEntityLinksByScopeIdAndType("1", ScopeTypes.CMMN);
entityLinkService.deleteEntityLinksByScopeIdAndType("3", ScopeTypes.BPMN);

HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("1", ScopeTypes.BPMN);
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("2", ScopeTypes.BPMN);
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("1", ScopeTypes.CMMN);
historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType("3", ScopeTypes.BPMN);
return null;
});
}


protected List<EntityLink> findEntityLinksByScopeId(String scopeId) {
return managementService.executeCommand(commandContext -> processEngineConfiguration.getEntityLinkServiceConfiguration().getEntityLinkService()
.findEntityLinksByScopeIdAndType(scopeId, ScopeTypes.BPMN, EntityLinkType.CHILD));
Expand Down Expand Up @@ -260,4 +423,27 @@ protected void createEntityLinkWithoutRootScope(String scopeId, String subScopeI
historicEntityLink.setHierarchyType(hierarchyType);
historicEntityLinkService.insertHistoricEntityLink(historicEntityLink, false);
}

protected void createEntityLinkWithScopeAndRefScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType, EntityLinkServiceConfiguration entityLinkServiceConfiguration) {

EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
EntityLinkEntity entityLink = (EntityLinkEntity) entityLinkService.createEntityLink();
entityLink.setScopeId(scopeId);
entityLink.setScopeType(scopeType);
entityLink.setReferenceScopeId(referenceScopeId);
entityLink.setReferenceScopeType(referenceScopeType);
entityLink.setLinkType(linkType);
entityLinkService.insertEntityLink(entityLink);

HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
HistoricEntityLinkEntity historicEntityLink = (HistoricEntityLinkEntity) historicEntityLinkService.createHistoricEntityLink();
historicEntityLink.setScopeId(scopeId);
historicEntityLink.setScopeType(scopeType);
historicEntityLink.setReferenceScopeId(referenceScopeId);
historicEntityLink.setReferenceScopeType(referenceScopeType);
historicEntityLink.setLinkType(linkType);
historicEntityLinkService.insertHistoricEntityLink(historicEntityLink, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.flowable.entitylink.api;

import java.util.Collection;
import java.util.List;

/**
Expand All @@ -24,6 +25,11 @@ public interface InternalEntityLinkQuery<E extends EntityLinkInfo> {
*/
InternalEntityLinkQuery<E> scopeId(String scopeId);

/**
* Query entity links with the given scope ids.
*/
InternalEntityLinkQuery<E> scopeIds(Collection<String> scopeIds);

/**
* Query entity links with the given scope definition id.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class InternalEntityLinkQueryImpl<E extends Entity & EntityLinkInfo>
protected final Function<InternalEntityLinkQueryImpl<E>, E> singleResultProvider;

protected String scopeId;
protected Collection<String> scopeIds;
protected String scopeDefinitionId;
protected String scopeType;
protected String referenceScopeId;
Expand All @@ -60,6 +61,15 @@ public InternalEntityLinkQuery<E> scopeId(String scopeId) {
return this;
}

@Override
public InternalEntityLinkQuery<E> scopeIds(Collection<String> scopeIds) {
if (scopeIds == null || scopeIds.isEmpty()) {
throw new FlowableIllegalArgumentException("scopeIds is empty");
}
this.scopeIds = scopeIds;
return this;
}

@Override
public InternalEntityLinkQuery<E> scopeDefinitionId(String scopeDefinitionId) {
if (StringUtils.isEmpty(scopeDefinitionId)) {
Expand Down Expand Up @@ -151,6 +161,10 @@ public E singleResult() {
return singleResultProvider.apply(this);
}

public Collection<String> getScopeIds() {
return scopeIds;
}

public String getScopeId() {
return scopeId;
}
Expand Down Expand Up @@ -212,6 +226,10 @@ public boolean isRetained(E entity, InternalEntityLinkQueryImpl<?> param) {
return false;
}

if (param.scopeIds != null && !param.scopeIds.contains(entity.getScopeId())) {
return false;
}

if (param.scopeDefinitionId != null && !param.scopeDefinitionId.equals(entity.getScopeDefinitionId())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,40 @@
from ${prefix}ACT_RU_ENTITYLINK RES
<where>
<if test="parameter.scopeId != null">
AND RES.SCOPE_ID_ = #{parameter.scopeId}
AND RES.SCOPE_ID_ = #{parameter.scopeId, jdbcType=VARCHAR}
</if>
<if test="parameter.scopeIds != null">
AND RES.SCOPE_ID_ in
<foreach collection="parameter.scopeIds" item="item" open="(" separator="," close=")">
#{item, jdbcType=VARCHAR}
</foreach>
</if>
<if test="parameter.scopeDefinitionId != null">
AND RES.SCOPE_DEFINITION_ID_ = #{parameter.scopeDefinitionId}
AND RES.SCOPE_DEFINITION_ID_ = #{parameter.scopeDefinitionId, jdbcType=VARCHAR}
</if>
<if test="parameter.scopeType != null">
AND RES.SCOPE_TYPE_ = #{parameter.scopeType}
AND RES.SCOPE_TYPE_ = #{parameter.scopeType, jdbcType=VARCHAR}
</if>
<if test="parameter.referenceScopeId != null">
AND RES.REF_SCOPE_ID_ = #{parameter.referenceScopeId}
AND RES.REF_SCOPE_ID_ = #{parameter.referenceScopeId, jdbcType=VARCHAR}
</if>
<if test="parameter.referenceScopeDefinitionId != null">
AND RES.REF_SCOPE_DEFINITION_ID_ = #{parameter.referenceScopeDefinitionId}
AND RES.REF_SCOPE_DEFINITION_ID_ = #{parameter.referenceScopeDefinitionId, jdbcType=VARCHAR}
</if>
<if test="parameter.referenceScopeType != null">
AND RES.REF_SCOPE_TYPE_ = #{parameter.referenceScopeType}
AND RES.REF_SCOPE_TYPE_ = #{parameter.referenceScopeType, jdbcType=VARCHAR}
</if>
<if test="parameter.rootScopeId != null">
AND RES.ROOT_SCOPE_ID_ = #{parameter.rootScopeId}
AND RES.ROOT_SCOPE_ID_ = #{parameter.rootScopeId, jdbcType=VARCHAR}
</if>
<if test="parameter.rootScopeType != null">
AND RES.ROOT_SCOPE_TYPE_ = #{parameter.rootScopeType}
AND RES.ROOT_SCOPE_TYPE_ = #{parameter.rootScopeType, jdbcType=VARCHAR}
</if>
<if test="parameter.linkType != null">
AND RES.LINK_TYPE_ = #{parameter.linkType}
AND RES.LINK_TYPE_ = #{parameter.linkType, jdbcType=VARCHAR}
</if>
<if test="parameter.hierarchyType != null">
AND RES.HIERARCHY_TYPE_ = #{parameter.hierarchyType}
AND RES.HIERARCHY_TYPE_ = #{parameter.hierarchyType, jdbcType=VARCHAR}
</if>
</where>
</select>
Expand Down
Loading

0 comments on commit d8147e7

Please sign in to comment.