@Test public void testAddNodeRoleDimension() throws IOException { String container = "someContainer"; Main.getWorkMgr().initNetwork(container, null); NodeRoleDimensionBean dimBean = new NodeRoleDimensionBean( NodeRoleDimension.builder("dimension1") .setRoleDimensionMappings(ImmutableList.of(new RoleDimensionMapping("(.*)"))) .build(), null); try (Response response = getNodeRolesTarget(container).post(Entity.entity(dimBean, MediaType.APPLICATION_JSON))) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); NodeRolesData nrData = Main.getWorkMgr().getNetworkNodeRoles(container); assertThat(nrData.nodeRoleDimensionFor("dimension1").isPresent(), equalTo(true)); } try (Response response = getNodeRolesTarget(container).post(Entity.entity(dimBean, MediaType.APPLICATION_JSON))) { assertThat(response.getStatus(), equalTo(BAD_REQUEST.getStatusCode())); } }
@Deprecated @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.nodeRoleDimensionFor(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleMappings( ImmutableList.<RoleMapping>builder() .addAll(nodeRolesData.getRoleMappings()) .addAll(dimBean.toNodeRoleDimension().toRoleMappings()) .build()) .setRoleDimensionOrder(nodeRolesData.getRoleDimensionOrder().orElse(null)) .setType(nodeRolesData.getType()) .build(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); }
NetworkNodeRolesResource { @Deprecated @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.nodeRoleDimensionFor(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleMappings( ImmutableList.<RoleMapping>builder() .addAll(nodeRolesData.getRoleMappings()) .addAll(dimBean.toNodeRoleDimension().toRoleMappings()) .build()) .setRoleDimensionOrder(nodeRolesData.getRoleDimensionOrder().orElse(null)) .setType(nodeRolesData.getType()) .build(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); } }
NetworkNodeRolesResource { @Deprecated @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.nodeRoleDimensionFor(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleMappings( ImmutableList.<RoleMapping>builder() .addAll(nodeRolesData.getRoleMappings()) .addAll(dimBean.toNodeRoleDimension().toRoleMappings()) .build()) .setRoleDimensionOrder(nodeRolesData.getRoleDimensionOrder().orElse(null)) .setType(nodeRolesData.getType()) .build(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); } NetworkNodeRolesResource(String network); }
NetworkNodeRolesResource { @Deprecated @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.nodeRoleDimensionFor(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleMappings( ImmutableList.<RoleMapping>builder() .addAll(nodeRolesData.getRoleMappings()) .addAll(dimBean.toNodeRoleDimension().toRoleMappings()) .build()) .setRoleDimensionOrder(nodeRolesData.getRoleDimensionOrder().orElse(null)) .setType(nodeRolesData.getType()) .build(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); } NetworkNodeRolesResource(String network); @Deprecated @POST Response addNodeRoleDimension(NodeRoleDimensionBean dimBean); @Path("/{dimension}") NetworkNodeRoleDimensionResource getNodeRoleDimensionResource(
      @PathParam("dimension") String dimension); @GET Response getNodeRoles(); @Consumes(MediaType.APPLICATION_JSON) @PUT Response putNodeRoles(NodeRolesDataBean nodeRolesDataBean); }
NetworkNodeRolesResource { @Deprecated @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.nodeRoleDimensionFor(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleMappings( ImmutableList.<RoleMapping>builder() .addAll(nodeRolesData.getRoleMappings()) .addAll(dimBean.toNodeRoleDimension().toRoleMappings()) .build()) .setRoleDimensionOrder(nodeRolesData.getRoleDimensionOrder().orElse(null)) .setType(nodeRolesData.getType()) .build(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); } NetworkNodeRolesResource(String network); @Deprecated @POST Response addNodeRoleDimension(NodeRoleDimensionBean dimBean); @Path("/{dimension}") NetworkNodeRoleDimensionResource getNodeRoleDimensionResource(
      @PathParam("dimension") String dimension); @GET Response getNodeRoles(); @Consumes(MediaType.APPLICATION_JSON) @PUT Response putNodeRoles(NodeRolesDataBean nodeRolesDataBean);  }