Search in sources :

Example 1 with OpenAgencyEntity

use of dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity 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 2 with OpenAgencyEntity

use of dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity in project solr-document-store by DBCDK.

the class BibliographicResourceRetrieveBeanIT method testCase.

@Test(timeout = 2_000L)
public void testCase() throws Exception {
    System.out.println("testCase");
    jpa(em -> {
        em.merge(new OpenAgencyEntity(888888, LibraryType.NonFBS, true, true, true));
        em.merge(new OpenAgencyEntity(710100, LibraryType.FBS, true, true, true));
        em.merge(new OpenAgencyEntity(310100, LibraryType.FBSSchool, true, true, true));
        em.merge(new BibliographicResourceEntity(888888, "a", "foo", true));
        em.merge(new BibliographicResourceEntity(710100, "a", "foo", true));
        em.merge(new BibliographicResourceEntity(710100, "a", "bar", false));
        em.merge(new BibliographicResourceEntity(710100, "no", "bar", false));
        em.merge(new BibliographicResourceEntity(310100, "a", "foo", false));
    });
    List<BibliographicResourceEntity> resourcesFor = bean.getResourcesFor(710100, "a");
    System.out.println("resourcesFor = " + resourcesFor);
    assertThat(resourcesFor, containsInAnyOrder(new BibliographicResourceEntity(710100, "a", "foo", true), new BibliographicResourceEntity(710100, "a", "bar", false)));
    List<BibliographicResourceEntity> resourcesForCommon = bean.getResourcesForCommon("a");
    System.out.println("resourcesForCommon = " + resourcesForCommon);
    assertThat(resourcesForCommon, containsInAnyOrder(new BibliographicResourceEntity(710100, "a", "foo", true), new BibliographicResourceEntity(710100, "a", "bar", false), new BibliographicResourceEntity(310100, "a", "foo", false)));
}
Also used : BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Example 3 with OpenAgencyEntity

use of dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity in project solr-document-store by DBCDK.

the class OpenAgencyBean method lookup.

public OpenAgencyEntity lookup(int agencyId, boolean fail_missing) {
    OpenAgencyEntity entity = entityManager.find(OpenAgencyEntity.class, agencyId);
    // If someone keeps hammering with an unknown agencyid, multiple requests
    if (entity == null || entity.getLibraryType() == LibraryType.Missing && entity.getFetchedAgeMs() > MISSING_AGENCY_TIMEOUT) {
        entity = proxy.loadOpenAgencyEntry(agencyId);
        entityManager.persist(entity);
    }
    if (entity.getLibraryType() == LibraryType.Missing) {
        log.warn("Agency is missing");
        if (fail_missing) {
            throw new EJBException("Cannot find openagency entry for: " + agencyId);
        }
        return null;
    }
    return entity;
}
Also used : OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) EJBException(javax.ejb.EJBException)

Example 4 with OpenAgencyEntity

use of dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity in project solr-document-store by DBCDK.

the class ResourceBean method storeResource.

private Response storeResource(BibliographicResourceEntity resource) {
    // Verify agency exists, throws exception if not exist
    LibraryType libraryType;
    try {
        OpenAgencyEntity oaEntity = openAgency.lookup(resource.getAgencyId());
        libraryType = oaEntity.getLibraryType();
    } catch (EJBException ex) {
        return Response.ok().entity(new StatusResponse("Unknown agency")).build();
    }
    if (resource.getValue()) {
        entityManager.merge(resource);
    } else {
        BibliographicResourceEntity entity = entityManager.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(resource.getAgencyId(), resource.getBibliographicRecordId(), resource.getField()));
        if (entity != null)
            entityManager.remove(entity);
    }
    // Enqueue all related bib items
    List<BibliographicEntity> bibliographicEntities;
    if (LibraryType.COMMON_AGENCY == resource.getAgencyId() || LibraryType.SCHOOL_COMMON_AGENCY == resource.getAgencyId() || libraryType == LibraryType.FBS || libraryType == LibraryType.FBSSchool) {
        bibliographicEntities = commonRelatedBibEntities(resource);
    } else {
        bibliographicEntities = nonFBSBibEntries(resource);
    }
    try {
        EnqueueCollector enqueue = enqueueSupplier.getEnqueueCollector();
        bibliographicEntities.forEach(e -> {
            if (!e.isDeleted()) {
                enqueue.add(e, QueueType.RESOURCE, QueueType.UNITRESOURCE, QueueType.WORKRESOURCE);
            }
        });
        enqueue.commit();
    } catch (SQLException ex) {
        log.error("Unable to commit queue entries: {}", ex.getMessage());
        log.debug("Unable to commit queue entries: ", ex);
        return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponse("Unable to commit queue entries")).build();
    }
    return Response.ok().entity(new StatusResponse()).build();
}
Also used : SQLException(java.sql.SQLException) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EJBException(javax.ejb.EJBException) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)

Example 5 with OpenAgencyEntity

use of dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity in project solr-document-store by DBCDK.

the class HoldingsToBibliographicBeanIT method mockToReturn.

private OpenAgencyBean mockToReturn(LibraryType libraryType) {
    OpenAgencyBean mock = Mockito.mock(OpenAgencyBean.class);
    Mockito.when(mock.lookup(Mockito.anyInt())).thenReturn(new OpenAgencyEntity(-1, libraryType, true, true, true));
    return mock;
}
Also used : OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)

Aggregations

OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)25 Test (org.junit.Test)15 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)8 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)8 AgencyItemFieldKey (dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey)4 EJBException (javax.ejb.EJBException)4 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)3 OpenAgencyStatusResponse (dk.dbc.search.solrdocstore.response.OpenAgencyStatusResponse)3 Response (javax.ws.rs.core.Response)3 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)2 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)2 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)2 AddResourceRequest (dk.dbc.search.solrdocstore.request.AddResourceRequest)2 Timed (org.eclipse.microprofile.metrics.annotation.Timed)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 OpenAgencyException (dk.dbc.openagency.http.OpenAgencyException)1 AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)1 DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)1 StatusResponse (dk.dbc.search.solrdocstore.response.StatusResponse)1 LibraryRules (dk.dbc.vipcore.marshallers.LibraryRules)1