public BusinessServiceEntity addReductionKeyEdge(String reductionKey, AbstractMapFunctionEntity mapFunction, int weight, String friendlyName) { SingleReductionKeyEdgeEntity edge = new SingleReductionKeyEdgeEntity(); edge.setBusinessService(this); edge.setReductionKey(Objects.requireNonNull(reductionKey)); edge.setWeight(weight); edge.setMapFunction(Objects.requireNonNull(mapFunction)); edge.setFriendlyName(friendlyName); addEdge(edge); return this; } }
private static AlarmWrapper createAlarmWrapper(final OnmsAlarm alarm) { return new AlarmWrapper() { @Override public String getReductionKey() { return alarm.getReductionKey(); } @Override public Status getStatus() { return SeverityMapper.toStatus(alarm.getSeverity()); } }; }
public static ReductionKeyEdgeResponseDTO toResponseDTO(SingleReductionKeyEdgeEntity input) { ReductionKeyEdgeResponseDTO edge = new ReductionKeyEdgeResponseDTO(); edge.setLocation(ResourceLocationFactory.createBusinessServiceEdgeLocation(input.getBusinessService().getId(), input.getId())); edge.setReductionKeys(input.getReductionKeys()); edge.setReductionKey(input.getReductionKey()); edge.setMapFunction(transform(input.getMapFunction())); edge.setId(input.getId()); edge.setWeight(input.getWeight()); edge.setFriendlyName(input.getFriendlyName()); edge.setOperationalStatus(Status.INDETERMINATE); // we assume INDETERMINATE return edge; }
@Override public void setFriendlyName(String friendlyName) { getEntity().setFriendlyName(friendlyName); }
@Override public String getFriendlyName() { return getEntity().getFriendlyName(); }
@Override public Set<String> getReductionKeys() { return getEntity().getReductionKeys(); }
@Override public void setReductionKey(String reductionKey) { getEntity().setReductionKey(reductionKey); }
@SuppressWarnings("unchecked") private <T extends Edge> T createEdge(Class<T> type, BusinessService source, MapFunction mapFunction, int weight) { T edge = null; if (type == IpServiceEdge.class) { edge = (T) new IpServiceEdgeImpl(this, new IPServiceEdgeEntity()); } if (type == ChildEdge.class) { edge = (T) new ChildEdgeImpl(this, new BusinessServiceChildEdgeEntity()); } if (type == ReductionKeyEdge.class) { edge = (T) new ReductionKeyEdgeImpl(this, new SingleReductionKeyEdgeEntity()); } if (type == ApplicationEdge.class) { edge = (T) new ApplicationEdgeImpl(this, new ApplicationEdgeEntity()); } if (edge != null) { edge.setSource(source); edge.setMapFunction(mapFunction); edge.setWeight(weight); return edge; } throw new IllegalArgumentException("Could not create edge for type " + type); }
@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; }
@Override public String getReductionKey() { return getEntity().getReductionKey(); }