OrganizationService extends Service { @GET @Produces(APPLICATION_JSON) @Path("/{parent}/organizations") @ApiOperation( value = "Get child organizations", response = OrganizationDto.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 200, message = "The child organizations successfully fetched"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response getByParent( @ApiParam("Parent organization id") @PathParam("parent") String parent, @ApiParam(value = "Max items") @QueryParam("maxItems") @DefaultValue("30") int maxItems, @ApiParam(value = "Skip count") @QueryParam("skipCount") @DefaultValue("0") int skipCount) throws ServerException, BadRequestException { checkArgument(maxItems >= 0, "The number of items to return can't be negative."); checkArgument(skipCount >= 0, "The number of items to skip can't be negative."); final Page<? extends Organization> organizationsPage = organizationManager.getByParent(parent, maxItems, skipCount); return Response.ok() .entity( organizationsPage.getItems( organization -> linksInjector.injectLinks(asDto(organization), getServiceContext()))) .header("Link", createLinkHeader(organizationsPage)) .build(); } @Inject  OrganizationService(
      OrganizationManager organizationManager,
      OrganizationLinksInjector linksInjector,
      OrganizationValidator organizationValidator); @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Create new organization", response = OrganizationDto.class) @ApiResponses({ @ApiResponse(code = 201, message = "The organization successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse( code = 409, message = "Conflict error occurred during the organization creation" + "(e.g. The organization with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") }) Response create(
      @ApiParam(value = "Organization to create", required = true) OrganizationDto organization); @POST @Path("/{id}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Update organization", response = OrganizationDto.class) @ApiResponses({ @ApiResponse(code = 200, message = "The organization successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "The organization with given id was not found"), @ApiResponse( code = 409, message = "Conflict error occurred during the organization creation" + "(e.g. The organization with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") }) OrganizationDto update(
      @ApiParam("Organization id") @PathParam("id") String organizationId,
      @ApiParam(value = "Organization to update", required = true) OrganizationDto organization); @DELETE @Path("/{id}") @ApiOperation("Remove organization with given id") @ApiResponses({ @ApiResponse(code = 204, message = "The organization successfully removed"), @ApiResponse(code = 500, message = "Internal server error occurred") }) void remove(@ApiParam("Organization id") @PathParam("id") String organization); @GET @Produces(APPLICATION_JSON) @Path("/{organizationId}") @ApiOperation(value = "Get organization by id", response = OrganizationDto.class) @ApiResponses({ @ApiResponse(code = 200, message = "The organization successfully fetched"), @ApiResponse(code = 404, message = "The organization with given id was not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) OrganizationDto getById(
      @ApiParam("Organization id") @PathParam("organizationId") String organizationId); @GET @Produces(APPLICATION_JSON) @Path("/find") @ApiOperation(value = "Find organization by name", response = OrganizationDto.class) @ApiResponses({ @ApiResponse(code = 200, message = "The organization successfully fetched"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "The organization with given name was not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) OrganizationDto find(
      @ApiParam(value = "Organization name", required = true) @QueryParam("name")
          String organizationName); @GET @Produces(APPLICATION_JSON) @Path("/{parent}/organizations") @ApiOperation( value = "Get child organizations", response = OrganizationDto.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 200, message = "The child organizations successfully fetched"), @ApiResponse(code = 500, message = "Internal server error occurred") }) Response getByParent(
      @ApiParam("Parent organization id") @PathParam("parent") String parent,
      @ApiParam(value = "Max items") @QueryParam("maxItems") @DefaultValue("30") int maxItems,
      @ApiParam(value = "Skip count") @QueryParam("skipCount") @DefaultValue("0") int skipCount); @GET @Produces(APPLICATION_JSON) @ApiOperation( value = "Get user's organizations", notes = "When user parameter is missed then will be fetched current user's organizations", response = OrganizationDto.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 200, message = "The organizations successfully fetched"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 500, message = "Internal server error occurred") }) Response getOrganizations(
      @ApiParam(value = "User id") @QueryParam("user") String userId,
      @ApiParam(value = "Max items") @QueryParam("maxItems") @DefaultValue("30") int maxItems,
      @ApiParam(value = "Skip count") @QueryParam("skipCount") @DefaultValue("0") int skipCount);  }
@Test public void shouldGetChildOrganizations() throws Exception { final OrganizationDto toFetch = createOrganization(); doReturn(new Page<>(singletonList(toFetch), 0, 1, 1)) .when(orgManager) .getByParent(anyString(), anyInt(), anyLong()); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .when() .expect() .statusCode(200) .get(SECURE_PATH + "/organization/parentOrg123/organizations?skipCount=0&maxItems=1"); final List<OrganizationDto> organizationDtos = unwrapDtoList(response, OrganizationDto.class); assertEquals(organizationDtos.size(), 1); assertEquals(organizationDtos.get(0), toFetch); verify(orgManager).getByParent("parentOrg123", 1, 0); verify(linksInjector).injectLinks(any(), any()); }