@Test void testInitializeoNoLdpResource() throws Exception { final ResourceService mockService = mock(ResourceService.class); when(mockBundler.getResourceService()).thenReturn(mockService); when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); when(mockService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler); matcher.initialize(); verify(mockService, description("Re-create a missing root resource on initialization")) .create(any(Metadata.class), any(Dataset.class)); verify(mockService, never().description("Don't try to replace a non-existent root on initialization")) .replace(any(Metadata.class), any(Dataset.class)); verify(mockService, description("Verify that the root resource is fetched only once")).get(root); }
@PostConstruct public void initialize() { final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX); try (final Dataset dataset = rdf.createDataset()) { LOGGER.debug("Preparing to initialize Trellis at {}", root); trellis.getResourceService().get(root).thenCompose(res -> initialize(root, res, dataset)) .exceptionally(err -> { LOGGER.warn("Unable to auto-initialize Trellis: {}. See DEBUG log for more info", err.getMessage()); LOGGER.debug("Error auto-initializing Trellis", err); return null; }).toCompletableFuture().join(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Trellis HTTP layer", ex); } }
TrellisHttpResource { @PostConstruct public void initialize() { final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX); try (final Dataset dataset = rdf.createDataset()) { LOGGER.debug("Preparing to initialize Trellis at {}", root); trellis.getResourceService().get(root).thenCompose(res -> initialize(root, res, dataset)) .exceptionally(err -> { LOGGER.warn("Unable to auto-initialize Trellis: {}. See DEBUG log for more info", err.getMessage()); LOGGER.debug("Error auto-initializing Trellis", err); return null; }).toCompletableFuture().join(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Trellis HTTP layer", ex); } } }
TrellisHttpResource { @PostConstruct public void initialize() { final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX); try (final Dataset dataset = rdf.createDataset()) { LOGGER.debug("Preparing to initialize Trellis at {}", root); trellis.getResourceService().get(root).thenCompose(res -> initialize(root, res, dataset)) .exceptionally(err -> { LOGGER.warn("Unable to auto-initialize Trellis: {}. See DEBUG log for more info", err.getMessage()); LOGGER.debug("Error auto-initializing Trellis", err); return null; }).toCompletableFuture().join(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Trellis HTTP layer", ex); } } @Inject  TrellisHttpResource(final ServiceBundler trellis);  TrellisHttpResource(); private  TrellisHttpResource(final ServiceBundler trellis, final Config config);  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); private  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl,
            final Config config); }
TrellisHttpResource { @PostConstruct public void initialize() { final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX); try (final Dataset dataset = rdf.createDataset()) { LOGGER.debug("Preparing to initialize Trellis at {}", root); trellis.getResourceService().get(root).thenCompose(res -> initialize(root, res, dataset)) .exceptionally(err -> { LOGGER.warn("Unable to auto-initialize Trellis: {}. See DEBUG log for more info", err.getMessage()); LOGGER.debug("Error auto-initializing Trellis", err); return null; }).toCompletableFuture().join(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Trellis HTTP layer", ex); } } @Inject  TrellisHttpResource(final ServiceBundler trellis);  TrellisHttpResource(); private  TrellisHttpResource(final ServiceBundler trellis, final Config config);  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); private  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl,
            final Config config); @PostConstruct void initialize(); @GET @Timed @Operation(summary = "Get a linked data resource") @APIResponses( value = { @APIResponse( responseCode = "404", description = "Missing resource"), @APIResponse( responseCode = "200", description = "The linked data resource, serialized as Turtle", content = @Content(mediaType = "text/turtle")), @APIResponse( responseCode = "200", description = "The linked data resource, serialized as JSON-LD", content = @Content(mediaType = "application/ld+json"))}) CompletionStage<Response> getResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @HEAD @Timed @Operation(summary = "Get the headers for a linked data resource") @APIResponse(description = "The headers for a linked data resource") CompletionStage<Response> getResourceHeaders(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @OPTIONS @Timed @Operation(summary = "Get the interaction options for a linked data resource") @APIResponse(description = "The interaction options for a linked data resource") CompletionStage<Response> options(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @PATCH @Timed @Operation(summary = "Update a linked data resource") CompletionStage<Response> updateResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The update request for RDF resources, typically as SPARQL-Update",
                         required = true,
                         content = @Content(mediaType = "application/sparql-update")) final String body); @DELETE @Timed @Operation(summary = "Delete a linked data resource") CompletionStage<Response> deleteResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext); @POST @Timed @Operation(summary = "Create a linked data resource") CompletionStage<Response> createResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The new resource") final InputStream body); @PUT @Timed @Operation(summary = "Create or update a linked data resource") CompletionStage<Response> setResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The updated resource") final InputStream body); }
TrellisHttpResource { @PostConstruct public void initialize() { final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX); try (final Dataset dataset = rdf.createDataset()) { LOGGER.debug("Preparing to initialize Trellis at {}", root); trellis.getResourceService().get(root).thenCompose(res -> initialize(root, res, dataset)) .exceptionally(err -> { LOGGER.warn("Unable to auto-initialize Trellis: {}. See DEBUG log for more info", err.getMessage()); LOGGER.debug("Error auto-initializing Trellis", err); return null; }).toCompletableFuture().join(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Trellis HTTP layer", ex); } } @Inject  TrellisHttpResource(final ServiceBundler trellis);  TrellisHttpResource(); private  TrellisHttpResource(final ServiceBundler trellis, final Config config);  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); private  TrellisHttpResource(final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl,
            final Config config); @PostConstruct void initialize(); @GET @Timed @Operation(summary = "Get a linked data resource") @APIResponses( value = { @APIResponse( responseCode = "404", description = "Missing resource"), @APIResponse( responseCode = "200", description = "The linked data resource, serialized as Turtle", content = @Content(mediaType = "text/turtle")), @APIResponse( responseCode = "200", description = "The linked data resource, serialized as JSON-LD", content = @Content(mediaType = "application/ld+json"))}) CompletionStage<Response> getResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @HEAD @Timed @Operation(summary = "Get the headers for a linked data resource") @APIResponse(description = "The headers for a linked data resource") CompletionStage<Response> getResourceHeaders(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @OPTIONS @Timed @Operation(summary = "Get the interaction options for a linked data resource") @APIResponse(description = "The interaction options for a linked data resource") CompletionStage<Response> options(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers); @PATCH @Timed @Operation(summary = "Update a linked data resource") CompletionStage<Response> updateResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The update request for RDF resources, typically as SPARQL-Update",
                         required = true,
                         content = @Content(mediaType = "application/sparql-update")) final String body); @DELETE @Timed @Operation(summary = "Delete a linked data resource") CompletionStage<Response> deleteResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext); @POST @Timed @Operation(summary = "Create a linked data resource") CompletionStage<Response> createResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The new resource") final InputStream body); @PUT @Timed @Operation(summary = "Create or update a linked data resource") CompletionStage<Response> setResource(@Context final Request request, @Context final UriInfo uriInfo,
            @Context final HttpHeaders headers, @Context final SecurityContext secContext,
            @RequestBody(description = "The updated resource") final InputStream body);  }