Commit 8b653d7065271c2392a7a5fcd648fc9be06064ae
Committed by
Andrew Shvayka
1 parent
27788790
rule chain. implemented save/update/delete @Transactional. Added sync DAO method…
…s to run in transaction. Moved loadRuleChainMetaData outside of saveRuleChainMetaData transaction
Showing
7 changed files
with
90 additions
and
55 deletions
@@ -244,7 +244,8 @@ public class RuleChainController extends BaseController { | @@ -244,7 +244,8 @@ public class RuleChainController extends BaseController { | ||
244 | } | 244 | } |
245 | 245 | ||
246 | RuleChain ruleChain = checkRuleChain(ruleChainMetaData.getRuleChainId(), Operation.WRITE); | 246 | RuleChain ruleChain = checkRuleChain(ruleChainMetaData.getRuleChainId(), Operation.WRITE); |
247 | - RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData)); | 247 | + checkNotNull(ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData) ? true : null); |
248 | + RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId())); | ||
248 | 249 | ||
249 | if (RuleChainType.CORE.equals(ruleChain.getType())) { | 250 | if (RuleChainType.CORE.equals(ruleChain.getType())) { |
250 | tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED); | 251 | tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED); |
@@ -43,7 +43,7 @@ public interface RuleChainService { | @@ -43,7 +43,7 @@ public interface RuleChainService { | ||
43 | 43 | ||
44 | boolean setRootRuleChain(TenantId tenantId, RuleChainId ruleChainId); | 44 | boolean setRootRuleChain(TenantId tenantId, RuleChainId ruleChainId); |
45 | 45 | ||
46 | - RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData); | 46 | + boolean saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData); |
47 | 47 | ||
48 | RuleChainMetaData loadRuleChainMetaData(TenantId tenantId, RuleChainId ruleChainId); | 48 | RuleChainMetaData loadRuleChainMetaData(TenantId tenantId, RuleChainId ruleChainId); |
49 | 49 |
@@ -179,11 +179,28 @@ public class BaseRelationService implements RelationService { | @@ -179,11 +179,28 @@ public class BaseRelationService implements RelationService { | ||
179 | 179 | ||
180 | @Override | 180 | @Override |
181 | public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { | 181 | public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { |
182 | - try { | ||
183 | - deleteEntityRelationsAsync(tenantId, entityId).get(); | ||
184 | - } catch (InterruptedException | ExecutionException e) { | ||
185 | - throw new RuntimeException(e); | 182 | + log.trace("Executing deleteEntityRelations [{}]", entityId); |
183 | + validate(entityId); | ||
184 | + final Cache cache = cacheManager.getCache(RELATIONS_CACHE); | ||
185 | + List<EntityRelation> inboundRelations = new ArrayList<>(); | ||
186 | + for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { | ||
187 | + inboundRelations.addAll(relationDao.findAllByTo(tenantId, entityId, typeGroup)); | ||
188 | + } | ||
189 | + | ||
190 | + List<EntityRelation> outboundRelations = new ArrayList<>(); | ||
191 | + for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { | ||
192 | + outboundRelations.addAll(relationDao.findAllByFrom(tenantId, entityId, typeGroup)); | ||
193 | + } | ||
194 | + | ||
195 | + for (EntityRelation relation : inboundRelations){ | ||
196 | + delete(tenantId, cache, relation, true); | ||
186 | } | 197 | } |
198 | + | ||
199 | + for (EntityRelation relation : outboundRelations){ | ||
200 | + delete(tenantId, cache, relation, false); | ||
201 | + } | ||
202 | + | ||
203 | + relationDao.deleteOutboundRelations(tenantId, entityId); | ||
187 | } | 204 | } |
188 | 205 | ||
189 | @Override | 206 | @Override |
@@ -193,14 +210,14 @@ public class BaseRelationService implements RelationService { | @@ -193,14 +210,14 @@ public class BaseRelationService implements RelationService { | ||
193 | validate(entityId); | 210 | validate(entityId); |
194 | List<ListenableFuture<List<EntityRelation>>> inboundRelationsList = new ArrayList<>(); | 211 | List<ListenableFuture<List<EntityRelation>>> inboundRelationsList = new ArrayList<>(); |
195 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { | 212 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { |
196 | - inboundRelationsList.add(relationDao.findAllByTo(tenantId, entityId, typeGroup)); | 213 | + inboundRelationsList.add(relationDao.findAllByToAsync(tenantId, entityId, typeGroup)); |
197 | } | 214 | } |
198 | 215 | ||
199 | ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList); | 216 | ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList); |
200 | 217 | ||
201 | List<ListenableFuture<List<EntityRelation>>> outboundRelationsList = new ArrayList<>(); | 218 | List<ListenableFuture<List<EntityRelation>>> outboundRelationsList = new ArrayList<>(); |
202 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { | 219 | for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) { |
203 | - outboundRelationsList.add(relationDao.findAllByFrom(tenantId, entityId, typeGroup)); | 220 | + outboundRelationsList.add(relationDao.findAllByFromAsync(tenantId, entityId, typeGroup)); |
204 | } | 221 | } |
205 | 222 | ||
206 | ListenableFuture<List<List<EntityRelation>>> outboundRelations = Futures.allAsList(outboundRelationsList); | 223 | ListenableFuture<List<List<EntityRelation>>> outboundRelations = Futures.allAsList(outboundRelationsList); |
@@ -242,6 +259,15 @@ public class BaseRelationService implements RelationService { | @@ -242,6 +259,15 @@ public class BaseRelationService implements RelationService { | ||
242 | } | 259 | } |
243 | } | 260 | } |
244 | 261 | ||
262 | + boolean delete(TenantId tenantId, Cache cache, EntityRelation relation, boolean deleteFromDb) { | ||
263 | + cacheEviction(relation, cache); | ||
264 | + if (deleteFromDb) { | ||
265 | + return relationDao.deleteRelation(tenantId, relation); | ||
266 | + } else { | ||
267 | + return false; | ||
268 | + } | ||
269 | + } | ||
270 | + | ||
245 | private void cacheEviction(EntityRelation relation, Cache cache) { | 271 | private void cacheEviction(EntityRelation relation, Cache cache) { |
246 | List<Object> fromToTypeAndTypeGroup = new ArrayList<>(); | 272 | List<Object> fromToTypeAndTypeGroup = new ArrayList<>(); |
247 | fromToTypeAndTypeGroup.add(relation.getFrom()); | 273 | fromToTypeAndTypeGroup.add(relation.getFrom()); |
@@ -283,7 +309,7 @@ public class BaseRelationService implements RelationService { | @@ -283,7 +309,7 @@ public class BaseRelationService implements RelationService { | ||
283 | validate(from); | 309 | validate(from); |
284 | validateTypeGroup(typeGroup); | 310 | validateTypeGroup(typeGroup); |
285 | try { | 311 | try { |
286 | - return relationDao.findAllByFrom(tenantId, from, typeGroup).get(); | 312 | + return relationDao.findAllByFromAsync(tenantId, from, typeGroup).get(); |
287 | } catch (InterruptedException | ExecutionException e) { | 313 | } catch (InterruptedException | ExecutionException e) { |
288 | throw new RuntimeException(e); | 314 | throw new RuntimeException(e); |
289 | } | 315 | } |
@@ -306,7 +332,7 @@ public class BaseRelationService implements RelationService { | @@ -306,7 +332,7 @@ public class BaseRelationService implements RelationService { | ||
306 | if (fromCache != null) { | 332 | if (fromCache != null) { |
307 | return Futures.immediateFuture(fromCache); | 333 | return Futures.immediateFuture(fromCache); |
308 | } else { | 334 | } else { |
309 | - ListenableFuture<List<EntityRelation>> relationsFuture = relationDao.findAllByFrom(tenantId, from, typeGroup); | 335 | + ListenableFuture<List<EntityRelation>> relationsFuture = relationDao.findAllByFromAsync(tenantId, from, typeGroup); |
310 | Futures.addCallback(relationsFuture, | 336 | Futures.addCallback(relationsFuture, |
311 | new FutureCallback<List<EntityRelation>>() { | 337 | new FutureCallback<List<EntityRelation>>() { |
312 | @Override | 338 | @Override |
@@ -327,7 +353,7 @@ public class BaseRelationService implements RelationService { | @@ -327,7 +353,7 @@ public class BaseRelationService implements RelationService { | ||
327 | log.trace("Executing findInfoByFrom [{}][{}]", from, typeGroup); | 353 | log.trace("Executing findInfoByFrom [{}][{}]", from, typeGroup); |
328 | validate(from); | 354 | validate(from); |
329 | validateTypeGroup(typeGroup); | 355 | validateTypeGroup(typeGroup); |
330 | - ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByFrom(tenantId, from, typeGroup); | 356 | + ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByFromAsync(tenantId, from, typeGroup); |
331 | return Futures.transformAsync(relations, | 357 | return Futures.transformAsync(relations, |
332 | relations1 -> { | 358 | relations1 -> { |
333 | List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>(); | 359 | List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>(); |
@@ -365,7 +391,7 @@ public class BaseRelationService implements RelationService { | @@ -365,7 +391,7 @@ public class BaseRelationService implements RelationService { | ||
365 | validate(to); | 391 | validate(to); |
366 | validateTypeGroup(typeGroup); | 392 | validateTypeGroup(typeGroup); |
367 | try { | 393 | try { |
368 | - return relationDao.findAllByTo(tenantId, to, typeGroup).get(); | 394 | + return relationDao.findAllByToAsync(tenantId, to, typeGroup).get(); |
369 | } catch (InterruptedException | ExecutionException e) { | 395 | } catch (InterruptedException | ExecutionException e) { |
370 | throw new RuntimeException(e); | 396 | throw new RuntimeException(e); |
371 | } | 397 | } |
@@ -388,7 +414,7 @@ public class BaseRelationService implements RelationService { | @@ -388,7 +414,7 @@ public class BaseRelationService implements RelationService { | ||
388 | if (fromCache != null) { | 414 | if (fromCache != null) { |
389 | return Futures.immediateFuture(fromCache); | 415 | return Futures.immediateFuture(fromCache); |
390 | } else { | 416 | } else { |
391 | - ListenableFuture<List<EntityRelation>> relationsFuture = relationDao.findAllByTo(tenantId, to, typeGroup); | 417 | + ListenableFuture<List<EntityRelation>> relationsFuture = relationDao.findAllByToAsync(tenantId, to, typeGroup); |
392 | Futures.addCallback(relationsFuture, | 418 | Futures.addCallback(relationsFuture, |
393 | new FutureCallback<List<EntityRelation>>() { | 419 | new FutureCallback<List<EntityRelation>>() { |
394 | @Override | 420 | @Override |
@@ -409,7 +435,7 @@ public class BaseRelationService implements RelationService { | @@ -409,7 +435,7 @@ public class BaseRelationService implements RelationService { | ||
409 | log.trace("Executing findInfoByTo [{}][{}]", to, typeGroup); | 435 | log.trace("Executing findInfoByTo [{}][{}]", to, typeGroup); |
410 | validate(to); | 436 | validate(to); |
411 | validateTypeGroup(typeGroup); | 437 | validateTypeGroup(typeGroup); |
412 | - ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByTo(tenantId, to, typeGroup); | 438 | + ListenableFuture<List<EntityRelation>> relations = relationDao.findAllByToAsync(tenantId, to, typeGroup); |
413 | return Futures.transformAsync(relations, | 439 | return Futures.transformAsync(relations, |
414 | relations1 -> { | 440 | relations1 -> { |
415 | List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>(); | 441 | List<ListenableFuture<EntityRelationInfo>> futures = new ArrayList<>(); |
@@ -31,11 +31,15 @@ import java.util.List; | @@ -31,11 +31,15 @@ import java.util.List; | ||
31 | */ | 31 | */ |
32 | public interface RelationDao { | 32 | public interface RelationDao { |
33 | 33 | ||
34 | - ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup); | 34 | + ListenableFuture<List<EntityRelation>> findAllByFromAsync(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup); |
35 | + | ||
36 | + List<EntityRelation> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup); | ||
35 | 37 | ||
36 | ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup); | 38 | ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup); |
37 | 39 | ||
38 | - ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup); | 40 | + ListenableFuture<List<EntityRelation>> findAllByToAsync(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup); |
41 | + | ||
42 | + List<EntityRelation> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup); | ||
39 | 43 | ||
40 | ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup); | 44 | ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup); |
41 | 45 |
@@ -26,6 +26,7 @@ import org.hibernate.exception.ConstraintViolationException; | @@ -26,6 +26,7 @@ import org.hibernate.exception.ConstraintViolationException; | ||
26 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
27 | import org.springframework.context.annotation.Lazy; | 27 | import org.springframework.context.annotation.Lazy; |
28 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
29 | +import org.springframework.transaction.annotation.Transactional; | ||
29 | import org.thingsboard.server.common.data.BaseData; | 30 | import org.thingsboard.server.common.data.BaseData; |
30 | import org.thingsboard.server.common.data.EntityType; | 31 | import org.thingsboard.server.common.data.EntityType; |
31 | import org.thingsboard.server.common.data.Tenant; | 32 | import org.thingsboard.server.common.data.Tenant; |
@@ -96,23 +97,19 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -96,23 +97,19 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
96 | private TbTenantProfileCache tenantProfileCache; | 97 | private TbTenantProfileCache tenantProfileCache; |
97 | 98 | ||
98 | @Override | 99 | @Override |
100 | + @Transactional | ||
99 | public RuleChain saveRuleChain(RuleChain ruleChain) { | 101 | public RuleChain saveRuleChain(RuleChain ruleChain) { |
100 | ruleChainValidator.validate(ruleChain, RuleChain::getTenantId); | 102 | ruleChainValidator.validate(ruleChain, RuleChain::getTenantId); |
101 | RuleChain savedRuleChain = ruleChainDao.save(ruleChain.getTenantId(), ruleChain); | 103 | RuleChain savedRuleChain = ruleChainDao.save(ruleChain.getTenantId(), ruleChain); |
102 | if (ruleChain.isRoot() && ruleChain.getId() == null) { | 104 | if (ruleChain.isRoot() && ruleChain.getId() == null) { |
103 | - try { | ||
104 | - createRelation(ruleChain.getTenantId(), new EntityRelation(savedRuleChain.getTenantId(), savedRuleChain.getId(), | ||
105 | - EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | ||
106 | - } catch (Exception e) { | ||
107 | - log.warn("[{}] Failed to create tenant to root rule chain relation. from: [{}], to: [{}]", | ||
108 | - savedRuleChain.getTenantId(), savedRuleChain.getTenantId(), savedRuleChain.getId(), e); | ||
109 | - throw new RuntimeException(e); | ||
110 | - } | 105 | + createRelation(ruleChain.getTenantId(), new EntityRelation(savedRuleChain.getTenantId(), savedRuleChain.getId(), |
106 | + EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | ||
111 | } | 107 | } |
112 | return savedRuleChain; | 108 | return savedRuleChain; |
113 | } | 109 | } |
114 | 110 | ||
115 | @Override | 111 | @Override |
112 | + @Transactional | ||
116 | public boolean setRootRuleChain(TenantId tenantId, RuleChainId ruleChainId) { | 113 | public boolean setRootRuleChain(TenantId tenantId, RuleChainId ruleChainId) { |
117 | RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); | 114 | RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); |
118 | if (!ruleChain.isRoot()) { | 115 | if (!ruleChain.isRoot()) { |
@@ -145,11 +142,12 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -145,11 +142,12 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
145 | } | 142 | } |
146 | 143 | ||
147 | @Override | 144 | @Override |
148 | - public RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData) { | 145 | + @Transactional |
146 | + public boolean saveRuleChainMetaData(TenantId tenantId, RuleChainMetaData ruleChainMetaData) { | ||
149 | Validator.validateId(ruleChainMetaData.getRuleChainId(), "Incorrect rule chain id."); | 147 | Validator.validateId(ruleChainMetaData.getRuleChainId(), "Incorrect rule chain id."); |
150 | RuleChain ruleChain = findRuleChainById(tenantId, ruleChainMetaData.getRuleChainId()); | 148 | RuleChain ruleChain = findRuleChainById(tenantId, ruleChainMetaData.getRuleChainId()); |
151 | if (ruleChain == null) { | 149 | if (ruleChain == null) { |
152 | - return null; | 150 | + return false; |
153 | } | 151 | } |
154 | 152 | ||
155 | if (CollectionUtils.isNotEmpty(ruleChainMetaData.getConnections())) { | 153 | if (CollectionUtils.isNotEmpty(ruleChainMetaData.getConnections())) { |
@@ -184,14 +182,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -184,14 +182,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
184 | for (RuleNode node : toAddOrUpdate) { | 182 | for (RuleNode node : toAddOrUpdate) { |
185 | node.setRuleChainId(ruleChain.getId()); | 183 | node.setRuleChainId(ruleChain.getId()); |
186 | RuleNode savedNode = ruleNodeDao.save(tenantId, node); | 184 | RuleNode savedNode = ruleNodeDao.save(tenantId, node); |
187 | - try { | ||
188 | - createRelation(tenantId, new EntityRelation(ruleChainMetaData.getRuleChainId(), savedNode.getId(), | ||
189 | - EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | ||
190 | - } catch (Exception e) { | ||
191 | - log.warn("[{}] Failed to create rule chain to rule node relation. from: [{}], to: [{}]", | ||
192 | - ruleChainMetaData.getRuleChainId(), savedNode.getId()); | ||
193 | - throw new RuntimeException(e); | ||
194 | - } | 185 | + createRelation(tenantId, new EntityRelation(ruleChainMetaData.getRuleChainId(), savedNode.getId(), |
186 | + EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); | ||
195 | int index = nodes.indexOf(node); | 187 | int index = nodes.indexOf(node); |
196 | nodes.set(index, savedNode); | 188 | nodes.set(index, savedNode); |
197 | ruleNodeIndexMap.put(savedNode.getId(), index); | 189 | ruleNodeIndexMap.put(savedNode.getId(), index); |
@@ -213,12 +205,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -213,12 +205,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
213 | EntityId from = nodes.get(nodeConnection.getFromIndex()).getId(); | 205 | EntityId from = nodes.get(nodeConnection.getFromIndex()).getId(); |
214 | EntityId to = nodes.get(nodeConnection.getToIndex()).getId(); | 206 | EntityId to = nodes.get(nodeConnection.getToIndex()).getId(); |
215 | String type = nodeConnection.getType(); | 207 | String type = nodeConnection.getType(); |
216 | - try { | ||
217 | - createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE)); | ||
218 | - } catch (Exception e) { | ||
219 | - log.warn("[{}] Failed to create rule node relation. from: [{}], to: [{}]", from, to); | ||
220 | - throw new RuntimeException(e); | ||
221 | - } | 208 | + createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE)); |
222 | } | 209 | } |
223 | } | 210 | } |
224 | if (ruleChainMetaData.getRuleChainConnections() != null) { | 211 | if (ruleChainMetaData.getRuleChainConnections() != null) { |
@@ -226,16 +213,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -226,16 +213,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
226 | EntityId from = nodes.get(nodeToRuleChainConnection.getFromIndex()).getId(); | 213 | EntityId from = nodes.get(nodeToRuleChainConnection.getFromIndex()).getId(); |
227 | EntityId to = nodeToRuleChainConnection.getTargetRuleChainId(); | 214 | EntityId to = nodeToRuleChainConnection.getTargetRuleChainId(); |
228 | String type = nodeToRuleChainConnection.getType(); | 215 | String type = nodeToRuleChainConnection.getType(); |
229 | - try { | ||
230 | - createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE, nodeToRuleChainConnection.getAdditionalInfo())); | ||
231 | - } catch (Exception e) { | ||
232 | - log.warn("[{}] Failed to create rule node to rule chain relation. from: [{}], to: [{}]", from, to); | ||
233 | - throw new RuntimeException(e); | ||
234 | - } | 216 | + createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE, nodeToRuleChainConnection.getAdditionalInfo())); |
235 | } | 217 | } |
236 | } | 218 | } |
237 | 219 | ||
238 | - return loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId()); | 220 | + return true; |
239 | } | 221 | } |
240 | 222 | ||
241 | private void validateCircles(List<NodeConnectionInfo> connectionInfos) { | 223 | private void validateCircles(List<NodeConnectionInfo> connectionInfos) { |
@@ -410,6 +392,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -410,6 +392,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
410 | } | 392 | } |
411 | 393 | ||
412 | @Override | 394 | @Override |
395 | + @Transactional | ||
413 | public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) { | 396 | public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) { |
414 | Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request."); | 397 | Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request."); |
415 | RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); | 398 | RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); |
@@ -716,6 +699,15 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -716,6 +699,15 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
716 | ruleNodeDao.removeById(tenantId, entityId.getId()); | 699 | ruleNodeDao.removeById(tenantId, entityId.getId()); |
717 | } | 700 | } |
718 | 701 | ||
702 | + private void createRelation(TenantId tenantId, EntityRelation relation) { | ||
703 | + log.debug("Creating relation: {}", relation); | ||
704 | + relationService.saveRelation(tenantId, relation); | ||
705 | + } | ||
706 | + | ||
707 | + private void deleteRelation(TenantId tenantId, EntityRelation relation) { | ||
708 | + log.debug("Deleting relation: {}", relation); | ||
709 | + relationService.deleteRelation(tenantId, relation); | ||
710 | + } | ||
719 | 711 | ||
720 | private DataValidator<RuleChain> ruleChainValidator = | 712 | private DataValidator<RuleChain> ruleChainValidator = |
721 | new DataValidator<RuleChain>() { | 713 | new DataValidator<RuleChain>() { |
@@ -49,12 +49,17 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -49,12 +49,17 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
49 | private RelationInsertRepository relationInsertRepository; | 49 | private RelationInsertRepository relationInsertRepository; |
50 | 50 | ||
51 | @Override | 51 | @Override |
52 | - public ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { | ||
53 | - return service.submit(() -> DaoUtil.convertDataList( | 52 | + public ListenableFuture<List<EntityRelation>> findAllByFromAsync(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { |
53 | + return service.submit(() -> findAllByFrom(tenantId, from, typeGroup)); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public List<EntityRelation> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { | ||
58 | + return DaoUtil.convertDataList( | ||
54 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( | 59 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( |
55 | from.getId(), | 60 | from.getId(), |
56 | from.getEntityType().name(), | 61 | from.getEntityType().name(), |
57 | - typeGroup.name()))); | 62 | + typeGroup.name())); |
58 | } | 63 | } |
59 | 64 | ||
60 | @Override | 65 | @Override |
@@ -68,12 +73,17 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -68,12 +73,17 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
68 | } | 73 | } |
69 | 74 | ||
70 | @Override | 75 | @Override |
71 | - public ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { | ||
72 | - return service.submit(() -> DaoUtil.convertDataList( | 76 | + public ListenableFuture<List<EntityRelation>> findAllByToAsync(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { |
77 | + return service.submit(() -> findAllByTo(tenantId, to, typeGroup)); | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public List<EntityRelation> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { | ||
82 | + return DaoUtil.convertDataList( | ||
73 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( | 83 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( |
74 | to.getId(), | 84 | to.getId(), |
75 | to.getEntityType().name(), | 85 | to.getEntityType().name(), |
76 | - typeGroup.name()))); | 86 | + typeGroup.name())); |
77 | } | 87 | } |
78 | 88 | ||
79 | @Override | 89 | @Override |
@@ -292,7 +292,8 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { | @@ -292,7 +292,8 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { | ||
292 | 292 | ||
293 | ruleNodes.set(name3Index, ruleNode4); | 293 | ruleNodes.set(name3Index, ruleNode4); |
294 | 294 | ||
295 | - RuleChainMetaData updatedRuleChainMetaData = ruleChainService.saveRuleChainMetaData(tenantId, savedRuleChainMetaData); | 295 | + Assert.assertTrue(ruleChainService.saveRuleChainMetaData(tenantId, savedRuleChainMetaData)); |
296 | + RuleChainMetaData updatedRuleChainMetaData = ruleChainService.loadRuleChainMetaData(tenantId, savedRuleChainMetaData.getRuleChainId()); | ||
296 | 297 | ||
297 | Assert.assertEquals(3, updatedRuleChainMetaData.getNodes().size()); | 298 | Assert.assertEquals(3, updatedRuleChainMetaData.getNodes().size()); |
298 | Assert.assertEquals(3, updatedRuleChainMetaData.getConnections().size()); | 299 | Assert.assertEquals(3, updatedRuleChainMetaData.getConnections().size()); |
@@ -404,7 +405,8 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { | @@ -404,7 +405,8 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { | ||
404 | ruleChainMetaData.addConnectionInfo(0,2,"fail"); | 405 | ruleChainMetaData.addConnectionInfo(0,2,"fail"); |
405 | ruleChainMetaData.addConnectionInfo(1,2,"success"); | 406 | ruleChainMetaData.addConnectionInfo(1,2,"success"); |
406 | 407 | ||
407 | - return ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData); | 408 | + Assert.assertTrue(ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData)); |
409 | + return ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId()); | ||
408 | } | 410 | } |
409 | 411 | ||
410 | private RuleChainMetaData createRuleChainMetadataWithCirclingRelation() throws Exception { | 412 | private RuleChainMetaData createRuleChainMetadataWithCirclingRelation() throws Exception { |