@Override public Long getId() { return m_entity.getId(); }
@Transient public Set<BusinessServiceChildEdgeEntity> getChildEdges() { return getEdges(BusinessServiceChildEdgeEntity.class); }
public BusinessServiceEntity toEntity() { BusinessServiceEntity entity = new BusinessServiceEntity(); entity.setName(name); entity.setId(id); entity.setAttributes(attributes); if (reduceFunction != null) { entity.setReductionFunction(reduceFunction); } ipServices.forEach(e -> entity.addIpServiceEdge(e.value, e.mapFunction, e.weight, e.friendlyName)); children.forEach(e -> entity.addChildServiceEdge(e.value, e.mapFunction, e.weight)); reductionKeys.forEach(e -> entity.addReductionKeyEdge(e.value, e.mapFunction, e.weight, e.friendlyName)); return entity; }
@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 setIpServiceEdges(BusinessService businessService, Set<IpServiceEdge> ipServiceEdges) { final BusinessServiceEntity entity = getBusinessServiceEntity(businessService); for (final IPServiceEdgeEntity e : entity.getIpServiceEdges()) { entity.removeEdge(e); } ipServiceEdges.forEach(e -> entity.addEdge(((IpServiceEdgeImpl) e).getEntity())); }
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; }
public static BusinessServiceRequestDTO toRequestDto(BusinessServiceEntity input) { Objects.requireNonNull(input); BusinessServiceRequestDTO request = new BusinessServiceRequestDTO(); request.setName(input.getName()); request.setAttributes(new HashMap<>(input.getAttributes())); request.setReduceFunction(transform(input.getReductionFunction())); input.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeEntityVisitor<Void>() { @Override public Void visit(BusinessServiceChildEdgeEntity edgeEntity) {
@Override public void setReductionKeyEdges(BusinessService businessService, Set<ReductionKeyEdge> reductionKeyEdges) { final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService); for (final SingleReductionKeyEdgeEntity e : parentEntity.getReductionKeyEdges()) { parentEntity.removeEdge(e); } reductionKeyEdges.forEach(e -> parentEntity.addEdge(((ReductionKeyEdgeImpl) e).getEntity())); }
@Override public void setApplicationEdges(BusinessService businessService, Set<ApplicationEdge> applicationEdges) { final BusinessServiceEntity entity = getBusinessServiceEntity(businessService); for (final ApplicationEdgeEntity e : entity.getApplicationEdges()) { entity.removeEdge(e); } applicationEdges.forEach(e -> entity.addEdge(((ApplicationEdgeImpl) e).getEntity())); }
@Override public boolean deleteEdge(BusinessService source, Edge edge) { BusinessServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge); BusinessServiceEntity businessServiceEntity = getBusinessServiceEntity(source); // does not exist, no update necessary if (!businessServiceEntity.getEdges().contains(edgeEntity)) { return false; } // remove and update businessServiceEntity.removeEdge(edgeEntity); return true; }
@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); }
@Override public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) { final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService); // Create the edge final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight); edge.setIpService(ipService); edge.setFriendlyName(friendlyName); // if already exists, no update final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge); long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count(); if (count > 0) { return false; } parentEntity.addEdge(((IpServiceEdgeImpl)edge).getEntity()); return true; }
@Override public boolean addReductionKeyEdge(BusinessService businessService, String reductionKey, MapFunction mapFunction, int weight, String friendlyName) { final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService); // Create the edge final ReductionKeyEdgeImpl edge = (ReductionKeyEdgeImpl) createEdge(ReductionKeyEdge.class, businessService, mapFunction, weight); edge.setReductionKey(reductionKey); edge.setFriendlyName(friendlyName); // if already exists, no update final SingleReductionKeyEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge); long count = parentEntity.getReductionKeyEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count(); if (count > 0) { return false; } parentEntity.addEdge(edge.getEntity()); return true; }
public IPServiceEdgeEntity getServiceChild1() { return getChild1().getIpServiceEdges().iterator().next(); }
@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; }
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; }
public BusinessServiceEntity addChildServiceEdge(BusinessServiceEntity child, AbstractMapFunctionEntity mapFunction, int weight) { BusinessServiceChildEdgeEntity edge = new BusinessServiceChildEdgeEntity(); edge.setBusinessService(this); edge.setChild(Objects.requireNonNull(child)); edge.setWeight(weight); edge.setMapFunction(Objects.requireNonNull(mapFunction)); addEdge(edge); return this; }
@Override public boolean addApplicationEdge(BusinessService businessService, Application application, MapFunction mapFunction, int weight) { final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService); // Create the edge final ApplicationEdge edge = createEdge(ApplicationEdge.class, businessService, mapFunction, weight); edge.setApplication(application); // if already exists, no update final ApplicationEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge); long count = parentEntity.getApplicationEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count(); if (count > 0) { return false; } parentEntity.addEdge(((ApplicationEdgeImpl)edge).getEntity()); return true; }
public BusinessServiceEntity addChildServiceEdge(BusinessServiceEntity child, AbstractMapFunctionEntity mapFunction) { return addChildServiceEdge(child, mapFunction, 1); }
public BusinessServiceEntity addIpServiceEdge(OnmsMonitoredService ipService, AbstractMapFunctionEntity mapFunction) { return addIpServiceEdge(ipService, mapFunction, 1, null); }