OrganizationResourcesDistributionService extends Service { @POST @Path("/{suborganizationId}/cap") @Consumes(APPLICATION_JSON) @ApiOperation( value = "Cap usage of shared resources.", notes = "By default suborganization is able to use all parent organization resources." + "Cap allow to limit usage of shared resources by suborganization.") @ApiResponses({ @ApiResponse(code = 204, message = "Resources successfully capped"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "Specified organization was not found"), @ApiResponse(code = 409, message = "Specified organization is root organization"), @ApiResponse(code = 409, message = "Suborganization is using shared resources"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void capResources( @ApiParam("Suborganization id") @PathParam("suborganizationId") String suborganizationId, @ApiParam("Resources to cap") List<ResourceDto> resourcesCap) throws BadRequestException, NotFoundException, ConflictException, ServerException { checkArgument(resourcesCap != null, "Missed resources caps."); Set<String> resourcesToSet = new HashSet<>(); for (ResourceDto resource : resourcesCap) { if (!resourcesToSet.add(resource.getType())) { throw new BadRequestException( format( "Resources to cap must contain only one resource with type '%s'.", resource.getType())); } resourceValidator.validate(resource); } resourcesDistributor.capResources(suborganizationId, resourcesCap); } @Inject  OrganizationResourcesDistributionService(
      OrganizationResourcesDistributor resourcesDistributor, ResourceValidator resourceValidator); @POST @Path("/{suborganizationId}/cap") @Consumes(APPLICATION_JSON) @ApiOperation( value = "Cap usage of shared resources.", notes = "By default suborganization is able to use all parent organization resources." + "Cap allow to limit usage of shared resources by suborganization.") @ApiResponses({ @ApiResponse(code = 204, message = "Resources successfully capped"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "Specified organization was not found"), @ApiResponse(code = 409, message = "Specified organization is root organization"), @ApiResponse(code = 409, message = "Suborganization is using shared resources"), @ApiResponse(code = 500, message = "Internal server error occurred") }) void capResources(
      @ApiParam("Suborganization id") @PathParam("suborganizationId") String suborganizationId,
      @ApiParam("Resources to cap") List<ResourceDto> resourcesCap); @GET @Path("/{suborganizationId}/cap") @Produces(APPLICATION_JSON) @ApiOperation( value = "Get resources cap of specified suborganization.", response = OrganizationDistributedResourcesDto.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 200, message = "Resources caps successfully fetched"), @ApiResponse(code = 404, message = "Specified organization was not found"), @ApiResponse(code = 409, message = "Specified organization is root organization"), @ApiResponse(code = 500, message = "Internal server error occurred") }) List<ResourceDto> getResourcesCap(
      @ApiParam("Suborganization id") @PathParam("suborganizationId") String suborganization); @GET @Path("/{organizationId}") @Produces(APPLICATION_JSON) @ApiOperation( value = "Get resources which are distributed by specified parent.", response = OrganizationDistributedResourcesDto.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 200, message = "Resources caps successfully fetched"), @ApiResponse(code = 500, message = "Internal server error occurred") }) Response getDistributedResources(
      @ApiParam("Organization id") @PathParam("organizationId") String organizationId,
      @ApiParam(value = "Max items") @QueryParam("maxItems") @DefaultValue("30") int maxItems,
      @ApiParam(value = "Skip count") @QueryParam("skipCount") @DefaultValue("0") long skipCount);  }
@Test public void shouldCapOrganizationResources() throws Exception { ResourceDto resource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1020).withUnit("unit"); List<ResourceDto> resources = singletonList(resource); given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(resources) .when() .expect() .statusCode(204) .post(SECURE_PATH + "/organization/resource/organization123/cap"); verify(organizationResourcesManager).capResources("organization123", resources); verify(resourceValidator).validate(resource); }