Skip to content

Commit

Permalink
Add support for fetching entity link by scope, reference scope and type
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed May 11, 2024
1 parent 82337ee commit 5a7f8ad
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,54 @@ void testFindEntityLinksWithSameRootWithNullRootInSameContext() {
});
}

@Test
void testFindEntityByScopeAndReferenceScopeAndType() {
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.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test")).isNotNull();
assertThat(historicEntityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test")).isNotNull();

assertThat(entityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "dummy")).isNull();
assertThat(historicEntityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "dummy")).isNull();
return null;
});

managementService.executeCommand(commandContext -> {
EntityLinkServiceConfiguration entityLinkServiceConfiguration = processEngineConfiguration.getEntityLinkServiceConfiguration();
EntityLinkService entityLinkService = entityLinkServiceConfiguration.getEntityLinkService();
HistoricEntityLinkService historicEntityLinkService = entityLinkServiceConfiguration.getHistoricEntityLinkService();
assertThat(entityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test")).isNotNull();
assertThat(historicEntityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "test")).isNotNull();

assertThat(entityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "dummy")).isNull();
assertThat(historicEntityLinkService.findEntityLinkByScopeAndReferenceScopeAndType("1", ScopeTypes.BPMN, "1", ScopeTypes.CMMN, "dummy")).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;
});
}

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 +308,26 @@ 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 @@ -28,6 +28,9 @@ public interface EntityLinkService {
List<EntityLink> findEntityLinksWithSameRootScopeForScopeIdAndScopeType(String scopeId, String scopeType, String linkType);

List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);

EntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType);

EntityLink createEntityLink();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public interface HistoricEntityLinkService {

List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType);

HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType);

HistoricEntityLink createHistoricEntityLink();

void insertHistoricEntityLink(HistoricEntityLink entityLink, boolean fireCreateEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenc
return getEntityLinkEntityManager().findEntityLinksByReferenceScopeIdAndType(referenceScopeId, referenceScopeType, linkType);
}

@Override
public EntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType) {
return getEntityLinkEntityManager().findEntityLinkByScopeAndReferenceScopeAndType(scopeId, scopeType, referenceScopeId, referenceScopeType, linkType);
}

@Override
public EntityLinkEntity createEntityLink() {
return getEntityLinkEntityManager().create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndSco
return getHistoricEntityLinkEntityManager().findHistoricEntityLinksByScopeDefinitionIdAndScopeType(scopeDefinitionId, scopeType, linkType);
}

@Override
public HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId,
String referenceScopeType, String linkType) {
return getHistoricEntityLinkEntityManager().findEntityLinkByScopeAndReferenceScopeAndType(scopeId, scopeType, referenceScopeId, referenceScopeType, linkType);
}

@Override
public HistoricEntityLink createHistoricEntityLink() {
return getHistoricEntityLinkEntityManager().create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public interface EntityLinkEntityManager extends EntityManager<EntityLinkEntity>

List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);

EntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType);

void deleteEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType);

void deleteEntityLinksByRootScopeIdAndType(String scopeId, String scopeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenc
return dataManager.findEntityLinksByReferenceScopeIdAndType(referenceScopeId, referenceScopeType, linkType);
}

public void deleteEntityLink(EntityLinkEntity identityLink) {
delete(identityLink);
@Override
public EntityLinkEntity findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType) {
return dataManager.findEntityLinkByScopeAndReferenceScopeAndType(scopeId, scopeType, referenceScopeId, referenceScopeType, linkType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public interface HistoricEntityLinkEntityManager extends EntityManager<HistoricE

List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType);

HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId,
String referenceScopeType, String linkType);

void deleteHistoricEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType);

void deleteHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndSco
return dataManager.findHistoricEntityLinksByScopeDefinitionIdAndScopeType(scopeDefinitionId, scopeType, linkType);
}

@Override
public HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId,
String referenceScopeType, String linkType) {
return dataManager.findEntityLinkByScopeAndReferenceScopeAndType(scopeId, scopeType, referenceScopeId, referenceScopeType, linkType);
}

@Override
public void deleteHistoricEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType) {
dataManager.deleteHistoricEntityLinksByScopeIdAndType(scopeId, scopeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public interface EntityLinkDataManager extends DataManager<EntityLinkEntity> {

List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);

EntityLinkEntity findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType);

void deleteEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType);

void deleteEntityLinksByRootScopeIdAndType(String scopeId, String scopeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public interface HistoricEntityLinkDataManager extends DataManager<HistoricEntit
List<HistoricEntityLink> findHistoricEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);

List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType);

HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId,
String referenceScopeType, String linkType);

void deleteHistoricEntityLinksByScopeIdAndType(String scopeId, String scopeType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import org.flowable.common.engine.impl.cfg.IdGenerator;
import org.flowable.common.engine.impl.db.AbstractDataManager;
import org.flowable.common.engine.impl.db.SingleCachedEntityMatcher;
import org.flowable.common.engine.impl.persistence.cache.CachedEntityMatcher;
import org.flowable.entitylink.api.EntityLink;
import org.flowable.entitylink.service.EntityLinkServiceConfiguration;
import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity;
import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntityImpl;
import org.flowable.entitylink.service.impl.persistence.entity.data.EntityLinkDataManager;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinkByScopeAndReferenceScopeAndType;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinksByReferenceScopeIdAndTypeMatcher;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinksByRootScopeIdAndTypeMatcher;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinksByScopeIdAndTypeMatcher;
Expand All @@ -38,6 +40,7 @@ public class MybatisEntityLinkDataManager extends AbstractDataManager<EntityLink
protected CachedEntityMatcher<EntityLinkEntity> entityLinksByRootScopeIdAndScopeTypeMatcher = new EntityLinksByRootScopeIdAndTypeMatcher();
protected CachedEntityMatcher<EntityLinkEntity> entityLinksWithSameRootByScopeIdAndTypeMatcher = new EntityLinksWithSameRootScopeForScopeIdAndScopeTypeMatcher<>();
protected CachedEntityMatcher<EntityLinkEntity> entityLinksByReferenceScopeIdAndTypeMatcher = new EntityLinksByReferenceScopeIdAndTypeMatcher();
protected SingleCachedEntityMatcher<EntityLinkEntity> entityLinkByScopeAndReferenceScopeAndType = new EntityLinkByScopeAndReferenceScopeAndType<>();

protected EntityLinkServiceConfiguration entityLinkServiceConfiguration;

Expand Down Expand Up @@ -94,6 +97,18 @@ public List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenc
return (List) getList("selectEntityLinksByReferenceScopeIdAndType", parameters, entityLinksByReferenceScopeIdAndTypeMatcher, true);
}

@Override
public EntityLinkEntity findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId, String referenceScopeType,
String linkType) {
Map<String, String> parameters = new HashMap<>();
parameters.put("scopeId", scopeId);
parameters.put("scopeType", scopeType);
parameters.put("referenceScopeId", referenceScopeId);
parameters.put("referenceScopeType", referenceScopeType);
parameters.put("linkType", linkType);
return getEntity("selectEntityLinkByScopeAndReferenceScopeAndType", parameters, entityLinkByScopeAndReferenceScopeAndType, true);
}

@Override
public void deleteEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType) {
Map<String, String> parameters = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

import org.flowable.common.engine.impl.cfg.IdGenerator;
import org.flowable.common.engine.impl.db.AbstractDataManager;
import org.flowable.common.engine.impl.db.SingleCachedEntityMatcher;
import org.flowable.common.engine.impl.persistence.cache.CachedEntityMatcher;
import org.flowable.entitylink.api.history.HistoricEntityLink;
import org.flowable.entitylink.service.EntityLinkServiceConfiguration;
import org.flowable.entitylink.service.impl.persistence.entity.HistoricEntityLinkEntity;
import org.flowable.entitylink.service.impl.persistence.entity.HistoricEntityLinkEntityImpl;
import org.flowable.entitylink.service.impl.persistence.entity.data.HistoricEntityLinkDataManager;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinkByScopeAndReferenceScopeAndType;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.EntityLinksWithSameRootScopeForScopeIdAndScopeTypeMatcher;
import org.flowable.entitylink.service.impl.persistence.entity.data.impl.cachematcher.HistoricEntityLinksByScopeIdAndTypeMatcher;

Expand All @@ -36,6 +38,7 @@ public class MybatisHistoricEntityLinkDataManager extends AbstractDataManager<Hi

protected CachedEntityMatcher<HistoricEntityLinkEntity> historicEntityLinksByScopeIdAndTypeMatcher = new HistoricEntityLinksByScopeIdAndTypeMatcher();
protected CachedEntityMatcher<HistoricEntityLinkEntity> entityLinksWithSameRootByScopeIdAndTypeMatcher = new EntityLinksWithSameRootScopeForScopeIdAndScopeTypeMatcher<>();
protected SingleCachedEntityMatcher<HistoricEntityLinkEntity> entityLinkByScopeAndReferenceScopeAndType = new EntityLinkByScopeAndReferenceScopeAndType<>();

protected EntityLinkServiceConfiguration entityLinkServiceConfiguration;

Expand Down Expand Up @@ -114,6 +117,18 @@ public List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndSco
return getDbSqlSession().selectList("selectHistoricEntityLinksByScopeDefinitionIdAndType", parameters);
}

@Override
public HistoricEntityLink findEntityLinkByScopeAndReferenceScopeAndType(String scopeId, String scopeType, String referenceScopeId,
String referenceScopeType, String linkType) {
Map<String, String> parameters = new HashMap<>();
parameters.put("scopeId", scopeId);
parameters.put("scopeType", scopeType);
parameters.put("referenceScopeId", referenceScopeId);
parameters.put("referenceScopeType", referenceScopeType);
parameters.put("linkType", linkType);
return getEntity("selectHistoricEntityLinkByScopeAndReferenceScopeAndType", parameters, entityLinkByScopeAndReferenceScopeAndType, true);
}

@Override
public void deleteHistoricEntityLinksByScopeIdAndType(String scopeId, String scopeType) {
Map<String, String> parameters = new HashMap<>();
Expand Down
Loading

0 comments on commit 5a7f8ad

Please sign in to comment.