SitemapResource implements RESTResource, SitemapSubscriptionCallback, SseBroadcaster.Listener<SseSinkInfo> { @GET @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Get all available sitemaps.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SitemapDTO.class)))) }) public Response getSitemaps() { logger.debug("Received HTTP GET request from IP {} at '{}'", request.getRemoteAddr(), uriInfo.getPath()); Object responseObject = getSitemapBeans(uriInfo.getAbsolutePathBuilder().build()); return Response.ok(responseObject).build(); } @Activate  SitemapResource( //
            final @Reference ItemUIRegistry itemUIRegistry, //
            final @Reference LocaleService localeService, //
            final @Reference SitemapSubscriptionService subscriptions); @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void addSitemapProvider(SitemapProvider provider); void removeSitemapProvider(SitemapProvider provider); @GET @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Get all available sitemaps.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SitemapDTO.class)))) }) Response getSitemaps(); @GET @Path("/{sitemapname: [a-zA-Z_0-9]+}") @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Get sitemap by name.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SitemapDTO.class))) }) Response getSitemapData(@Context HttpHeaders headers,
            @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
            @PathParam("sitemapname") @Parameter(description = "sitemap name") String sitemapname,
            @QueryParam("type") String type, @QueryParam("jsoncallback") @DefaultValue("callback") String callback,
            @QueryParam("includeHidden") @Parameter(description = "include hidden widgets") boolean includeHiddenWidgets); @GET @Path("/{sitemapname: [a-zA-Z_0-9]+}/{pageid: [a-zA-Z_0-9]+}") @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Polls the data for a sitemap.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PageDTO.class))), @ApiResponse(responseCode = "404", description = "Sitemap with requested name does not exist or page does not exist, or page refers to a non-linkable widget"), @ApiResponse(responseCode = "400", description = "Invalid subscription id has been provided.") }) Response getPageData(@Context HttpHeaders headers,
            @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language,
            @PathParam("sitemapname") @Parameter(description = "sitemap name") String sitemapname,
            @PathParam("pageid") @Parameter(description = "page id") String pageId,
            @QueryParam("subscriptionid") @Parameter(description = "subscriptionid") @Nullable String subscriptionId,
            @QueryParam("includeHidden") @Parameter(description = "include hidden widgets") boolean includeHiddenWidgets); @POST @Path(SEGMENT_EVENTS + "/subscribe") @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Creates a sitemap event subscription.", responses = { @ApiResponse(responseCode = "201", description = "Subscription created."), @ApiResponse(responseCode = "503", description = "Subscriptions limit reached.") }) Object createEventSubscription(); @GET @Path(SEGMENT_EVENTS + "/{subscriptionid: [a-zA-Z_0-9-]+}") @Produces(MediaType.SERVER_SENT_EVENTS) @Operation(summary = "Get sitemap events.", responses = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Page not linked to the subscription."), @ApiResponse(responseCode = "404", description = "Subscription not found.") }) void getSitemapEvents(@Context final SseEventSink sseEventSink, @Context final HttpServletResponse response,
            @PathParam("subscriptionid") @Parameter(description = "subscription id") String subscriptionId,
            @QueryParam("sitemap") @Parameter(description = "sitemap name") @Nullable String sitemapname,
            @QueryParam("pageid") @Parameter(description = "page id") @Nullable String pageId); Collection<SitemapDTO> getSitemapBeans(URI uri); @Override void onEvent(SitemapEvent event); @Override void onRelease(String subscriptionId); @Override void sseEventSinkRemoved(SseEventSink sink, SseSinkInfo info); static final String PATH_SITEMAPS; }
@Test public void whenSitemapsAreProvidedShouldReturnSitemapBeans() { Response sitemaps = sitemapResource.getSitemaps(); assertThat((Collection<?>) sitemaps.getEntity(), hasSize(1)); @SuppressWarnings("unchecked") SitemapDTO dto = ((Collection<SitemapDTO>) sitemaps.getEntity()).iterator().next(); assertThat(dto.name, is(SITEMAP_MODEL_NAME)); assertThat(dto.link, is(SITEMAP_PATH + "/" + SITEMAP_MODEL_NAME)); }