Search in sources :

Example 1 with AddResourceRequest

use of dk.dbc.search.solrdocstore.request.AddResourceRequest in project solr-document-store by DBCDK.

the class ResourceBean method addResource.

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("add")
@Operation(operationId = "add-resource", summary = "Adds a resource to an item", description = "This operation sets the resource and connect" + " it to a number of manifestations item, if possible.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response addResource(String jsonContent) throws JSONBException {
    try (LogWith logWith = track(UUID.randomUUID().toString())) {
        AddResourceRequest request = jsonbContext.unmarshall(jsonContent, AddResourceRequest.class);
        // Add resource
        BibliographicResourceEntity resource = request.asBibliographicResource();
        log.debug("POST resource: {}", resource);
        return storeResource(resource);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 2 with AddResourceRequest

use of dk.dbc.search.solrdocstore.request.AddResourceRequest in project solr-document-store by DBCDK.

the class BibliographicResourceIT method testAddSchoolCommonResourceEnqueue.

@Test
public void testAddSchoolCommonResourceEnqueue() {
    System.out.println("testAddSchoolCommonResourceEnqueue");
    AddResourceRequest request = new AddResourceRequest(300000, "12121212", "hasCoverUrl", true);
    runCommonEnqueueTest(request);
}
Also used : AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Test(org.junit.Test)

Example 3 with AddResourceRequest

use of dk.dbc.search.solrdocstore.request.AddResourceRequest in project solr-document-store by DBCDK.

the class BibliographicResourceIT method testAddResourceOntoDeleted.

@Test(timeout = 2_000L)
public void testAddResourceOntoDeleted() throws Exception {
    System.out.println("testAddResourceOntoDeleted");
    AddResourceRequest request = new AddResourceRequest(890890, "45454545", "hasCoverUrl", true);
    jpa(em -> {
        em.merge(new OpenAgencyEntity(890890, LibraryType.NonFBS, false, false, false));
        em.merge(new BibliographicEntity(890890, "classifier1", "45454545", "repo", null, null, true, null, "track:1"));
        bean.addResource(jsonbContext.marshall(request));
    });
    assertThat(queueContentAndClear(), empty());
}
Also used : BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Example 4 with AddResourceRequest

use of dk.dbc.search.solrdocstore.request.AddResourceRequest in project solr-document-store by DBCDK.

the class BibliographicResourceIT method testAddFBSSchoolResourceEnqueue.

@Test
public void testAddFBSSchoolResourceEnqueue() {
    System.out.println("testAddFBSSchoolResourceEnqueue");
    AddResourceRequest request = new AddResourceRequest(312000, "12121212", "hasCoverUrl", true);
    runCommonEnqueueTest(request);
}
Also used : AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Test(org.junit.Test)

Example 5 with AddResourceRequest

use of dk.dbc.search.solrdocstore.request.AddResourceRequest in project solr-document-store by DBCDK.

the class BibliographicResourceIT method testAddNonFBSdResourceEnqueue.

@Test
public void testAddNonFBSdResourceEnqueue() {
    System.out.println("testAddNonFBSdResourceEnqueue");
    AddResourceRequest request = new AddResourceRequest(890890, "45454545", "hasCoverUrl", true);
    jpa(em -> {
        em.merge(new OpenAgencyEntity(890890, LibraryType.NonFBS, false, false, false));
        em.merge(new BibliographicEntity(890890, "classifier1", "45454545", "repo", "work:1", "unit:1", false, null, "track:1"));
        em.merge(new BibliographicEntity(890890, "classifier2", "45454545", "repo", "work:1", "unit:1", false, null, "track:1"));
        em.merge(new BibliographicEntity(890890, "classifier3", "45454545", "repo", "work:1", "unit:1", false, null, "track:1"));
        em.merge(new BibliographicResourceEntity(890890, "45454545", "hasCoverUrl", true));
        bean.addResource(jsonbContext.marshall(request));
    });
    // Only enqueues its own items
    assertThat(queueContentAndClear(), containsInAnyOrder(queueItem(890890, "classifier1", "45454545"), queueItem(890890, "classifier2", "45454545"), queueItem(890890, "classifier3", "45454545"), queueItem("work:1")));
}
Also used : BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Aggregations

AddResourceRequest (dk.dbc.search.solrdocstore.request.AddResourceRequest)8 Test (org.junit.Test)7 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)3 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)2 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)2 LogWith (dk.dbc.log.LogWith)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Operation (org.eclipse.microprofile.openapi.annotations.Operation)1 RequestBody (org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)1 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)1