Skip to content

Commit

Permalink
RuleChainService - improved saveRuleChainMetaData - doValidate in cas…
Browse files Browse the repository at this point in the history
…e general save and ignore validation for messages from cloud
  • Loading branch information
volodymyr-babak committed Sep 4, 2024
1 parent 6014c5f commit f5dba94
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ListenableFuture<Void> processRuleChainMetadataMsgFromCloud(TenantId tena
throw new RuntimeException("[{" + tenantId + "}] ruleChainMetadataUpdateMsg {" + ruleChainMetadataUpdateMsg + "} cannot be converted to rule chain metadata");
}
if (ruleChainMetadata.getNodes().size() > 0) {
ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetadata, Function.identity());
ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetadata, Function.identity(), true, false);
}
break;
case UNRECOGNIZED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public RuleChain createRuleChainFromFile(TenantId tenantId, Path templateFilePat
ruleChain = ruleChainService.saveRuleChain(ruleChain, false);

ruleChainMetaData.setRuleChainId(ruleChain.getId());
ruleChainService.saveRuleChainMetaData(TenantId.SYS_TENANT_ID, ruleChainMetaData, Function.identity(), false);
ruleChainService.saveRuleChainMetaData(TenantId.SYS_TENANT_ID, ruleChainMetaData, Function.identity(), false, true);

return ruleChain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public interface RuleChainService extends EntityDaoService {

RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater);

RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater, boolean publishSaveEvent);
RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater,
boolean publishSaveEvent, boolean doValidate);

RuleChainMetaData loadRuleChainMetaData(TenantId tenantId, RuleChainId ruleChainId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ private void setRootAndSave(TenantId tenantId, RuleChain ruleChain) {
@Override
@Transactional
public RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater) {
return saveRuleChainMetaData(tenantId, ruleChainMetaData, ruleNodeUpdater, true);
return saveRuleChainMetaData(tenantId, ruleChainMetaData, ruleNodeUpdater, true, true);
}

@Transactional
@Override
public RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater, boolean publishSaveEvent) {
public RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData, Function<RuleNode, RuleNode> ruleNodeUpdater,
boolean publishSaveEvent, boolean doValidate) {
Validator.validateId(ruleChainMetaData.getRuleChainId(), "Incorrect rule chain id.");
RuleChain ruleChain = findRuleChainById(tenantId, ruleChainMetaData.getRuleChainId());
if (ruleChain == null) {
return RuleChainUpdateResult.failed();
} else if (ruleChainMetaData.getVersion() != null && !ruleChainMetaData.getVersion().equals(ruleChain.getVersion())) {
} else if (doValidate && ruleChainMetaData.getVersion() != null && !ruleChainMetaData.getVersion().equals(ruleChain.getVersion())) {
throw new EntityVersionMismatchException(EntityType.RULE_CHAIN, null);
}
RuleChainDataValidator.validateMetaDataFieldsAndConnections(ruleChainMetaData);
Expand All @@ -189,15 +190,16 @@ public RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainM
if (nodes != null) {
for (RuleNode node : nodes) {
setSingletonMode(node);
/* TODO: voba - merge comment
if (node.getId() != null) {
ruleNodeIndexMap.put(node.getId(), nodes.indexOf(node));
if (doValidate) {
if (node.getId() != null) {
ruleNodeIndexMap.put(node.getId(), nodes.indexOf(node));
} else {
toAddOrUpdate.add(node);
}
} else {
ruleNodeIndexMap.put(node.getId(), nodes.indexOf(node));
toAddOrUpdate.add(node);
}
*/
ruleNodeIndexMap.put(node.getId(), nodes.indexOf(node));
toAddOrUpdate.add(node);
}
}

Expand All @@ -208,9 +210,10 @@ public RuleChainUpdateResult saveRuleChainMetaData(TenantId tenantId, RuleChainM
Integer index = ruleNodeIndexMap.get(existingNode.getId());
RuleNode newRuleNode = null;
if (index != null) {
// edge-only: merge comment
// newRuleNode = ruleChainMetaData.getNodes().get(index);
// toAddOrUpdate.add(newRuleNode);
if (doValidate) {
newRuleNode = ruleChainMetaData.getNodes().get(index);
toAddOrUpdate.add(newRuleNode);
}
} else {
updatedRuleNodes.add(new RuleNodeUpdateResult(existingNode, null));
toDelete.add(existingNode);
Expand Down

0 comments on commit f5dba94

Please sign in to comment.