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());
}
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)));
}
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;
}
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();
}
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;
}
Aggregations