@Override public Set<ChildEdge> getChildEdges() { return m_entity.getChildEdges() .stream() .map(edge -> new ChildEdgeImpl(m_manager, edge)) .collect(Collectors.toSet()); }
private boolean checkDescendantForLoop(final BusinessServiceEntity parent, final BusinessServiceEntity descendant) { if (parent.equals(descendant)) { return true; } for (BusinessServiceChildEdgeEntity eachChildEdge : descendant.getChildEdges()) { return this.checkDescendantForLoop(parent, eachChildEdge.getChild()); } return false; }
@Override public void setChildEdges(BusinessService parentService, Set<ChildEdge> childEdges) { final BusinessServiceEntity parentEntity = getBusinessServiceEntity(parentService); for (final BusinessServiceChildEdgeEntity e : parentEntity.getChildEdges()) { parentEntity.removeEdge(e); } childEdges.forEach(e -> parentEntity.addEdge(((ChildEdgeImpl) e).getEntity())); }
@Override public void deleteBusinessService(BusinessService businessService) { BusinessServiceEntity entity = getBusinessServiceEntity(businessService); // remove all parent -> child associations for(BusinessServiceEntity parent : getDao().findParents(entity)) { List<BusinessServiceChildEdgeEntity> collect = parent.getChildEdges().stream().filter(e -> entity.equals(e.getChild())).collect(Collectors.toList()); collect.forEach(x -> { parent.removeEdge(x); edgeDao.delete(x); // we need to delete this edge manually as they cannot be deleted automatically }); } // edges of the entity are deleted automatically by hibernate getDao().delete(entity); }
public static BusinessServiceResponseDTO toResponseDto(BusinessServiceEntity input) { Objects.requireNonNull(input); BusinessServiceResponseDTO response = new BusinessServiceResponseDTO(); response.setId(input.getId()); response.setName(input.getName()); response.setReduceFunction(transform(input.getReductionFunction())); response.setOperationalStatus(Status.INDETERMINATE); // we assume INDETERMINATE response.setAttributes(input.getAttributes()); response.setLocation(ResourceLocationFactory.createBusinessServiceLocation(input.getId().toString())); response.setReductionKeys(input.getReductionKeyEdges().stream().map(BsmTestUtils::toResponseDTO).collect(Collectors.toList())); response.setIpServices(input.getIpServiceEdges().stream().map(BsmTestUtils::toResponseDTO).collect(Collectors.toList())); response.setChildren(input.getChildEdges().stream().map(BsmTestUtils::toResponseDTO).collect(Collectors.toList())); response.setParentServices(Sets.newHashSet()); // do not know that here return response; }
@Override public boolean addChildEdge(BusinessService parentService, BusinessService childService, MapFunction mapFunction, int weight) { // verify that exists final BusinessServiceEntity parentEntity = getBusinessServiceEntity(parentService); final BusinessServiceEntity childEntity = getBusinessServiceEntity(childService); // Create the edge ChildEdge childEdge = createEdge(ChildEdge.class, parentService, mapFunction, weight); childEdge.setChild(childService); // Verify no loop if (this.checkDescendantForLoop(parentEntity, childEntity)) { throw new IllegalArgumentException("Service will form a loop"); } // if already exists, no update final BusinessServiceChildEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(childEdge); long count = parentEntity.getChildEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count(); if (count > 0) { return false; } parentEntity.addEdge(((ChildEdgeImpl)childEdge).getEntity()); return true; }