public NodeRolesDataBean( @Nonnull NodeRolesData nodeRolesData, @Nullable String snapshot, @Nonnull Set<String> nodes) { defaultDimension = nodeRolesData.getDefaultDimension(); roleDimensions = nodeRolesData.getNodeRoleDimensions().stream() .map(dim -> new NodeRoleDimensionBean(dim, snapshot, nodes)) .collect(Collectors.toSet()); }
/** * Get some "reasonable" {@link NodeRoleDimension} object for analysis. Preference order: the * default dimension if set and exists, the auto-inferred primary dimension if it exists, the * dimension that is lexicographically first, and null if no dimensions exist. * * @throws IOException If the contents of the file could not be cast to {@link NodeRolesData} */ @Nonnull private Optional<NodeRoleDimension> getNodeRoleDimension() throws IOException { // check default if (getDefaultDimension() != null) { Optional<NodeRoleDimension> opt = getNodeRoleDimension(getDefaultDimension()); if (opt.isPresent()) { return opt; } } // check auto primary Optional<NodeRoleDimension> optAuto = getNodeRoleDimension(NodeRoleDimension.AUTO_DIMENSION_PRIMARY); if (optAuto.isPresent()) { return optAuto; } // check first return getNodeRoleDimensions().stream().min(Comparator.comparing(NodeRoleDimension::getName)); }
@DELETE public Response delNodeRoleDimension() throws IOException { NodeRolesData nodeRolesData = Main.getWorkMgr().getNetworkNodeRoles(_network); if (nodeRolesData == null) { return Response.status(Status.NOT_FOUND).build(); } Optional<NodeRoleDimension> dimension = nodeRolesData.getNodeRoleDimension(_dimension); if (!dimension.isPresent()) { return Response.status(Status.NOT_FOUND).build(); } if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleDimensions( nodeRolesData.getNodeRoleDimensions().stream() .filter(dim -> !dim.getName().equalsIgnoreCase(dimension.get().getName())) .collect( ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder()))) .build(), _network)) { // if network was deleted while we were working return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); }
String roleDimension = parts[1]; Optional<NodeRoleDimension> optDimension = nodeRoleData.getNodeRoleDimensions().stream() .filter(dim -> dim.getName().equals(roleDimension)) .findAny(); String roleDimPrefix = finalQuery.equalsIgnoreCase("ROLE:") ? "" : parts[1]; suggestions.addAll( nodeRoleData.getNodeRoleDimensions().stream() .filter(dim -> dim.getName().startsWith(roleDimPrefix)) .map(
@POST public Response addNodeRoleDimension(NodeRoleDimensionBean dimBean) throws IOException { checkClientArgument(dimBean.name != null, "Node role dimension must have a name"); NodeRolesData nodeRolesData = Main.getWorkMgr().getNetworkNodeRoles(_network); if (nodeRolesData == null) { return Response.status(Status.NOT_FOUND).build(); } Optional<NodeRoleDimension> dimension = nodeRolesData.getNodeRoleDimension(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleDimensions( ImmutableSortedSet.<NodeRoleDimension>naturalOrder() .addAll(nodeRolesData.getNodeRoleDimensions()) .add(dimBean.toNodeRoleDimension()) .build()) .build(), _network)) { // if network was deleted while we were working return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); }
PropertySpecifier.baseAutoComplete( query, getNetworkNodeRoles(network).getNodeRoleDimensions().stream() .map(NodeRoleDimension::getName) .collect(Collectors.toSet()));