Search in sources :

Example 1 with Instance

use of org.folio.Instance in project mod-inventory by folio-org.

the class InstanceUtilTest method shouldMergeInstances.

@Test
public void shouldMergeInstances() {
    Set<AlternativeTitle> alternativeTitles = new HashSet<>();
    alternativeTitles.add(new AlternativeTitle().withAlternativeTitle("alt1").withAlternativeTitleTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19"));
    List<Contributor> contributors = new ArrayList<>();
    contributors.add(new Contributor().withName("contributor1").withContributorNameTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeText("text").withPrimary(true));
    Instance mapped = new Instance().withId("30773a27-b485-4dab-aeb6-b8c04fa3cb17").withHrid("in000000001").withModeOfIssuanceId("30773a27-b485-4dab-aeb6-b8c04fa3cb18").withAlternativeTitles(alternativeTitles).withContributors(contributors);
    List<String> statisticalCodeIds = new ArrayList<>();
    statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb19");
    statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb18");
    List<String> natureOfContentTermIds = new ArrayList<>();
    statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb21");
    statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb22");
    List<InstanceRelationshipToParent> parents = new ArrayList<>();
    parents.add(new InstanceRelationshipToParent("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
    List<InstanceRelationshipToChild> children = new ArrayList<>();
    children.add(new InstanceRelationshipToChild("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
    List<String> tagList = new ArrayList<>();
    tagList.add("Tag1");
    tagList.add("Tag2");
    org.folio.inventory.domain.instances.Instance existing = new org.folio.inventory.domain.instances.Instance("30773a27-b485-4dab-aeb6-b8c04fa3cb17", "7", "in000000001", "source", "title", "30773a27-b485-4dab-aeb6-b8c04fa3cb19");
    existing.setStatisticalCodeIds(statisticalCodeIds);
    existing.setDiscoverySuppress(true);
    existing.setStaffSuppress(true);
    existing.setPreviouslyHeld(true);
    existing.setCatalogedDate("");
    existing.setStatusId("30773a27-b485-4dab-aeb6-b8c04fa3cb26");
    existing.setNatureOfContentTermIds(natureOfContentTermIds);
    existing.setParentInstances(parents);
    existing.setChildInstances(children);
    existing.setTags(tagList);
    org.folio.inventory.domain.instances.Instance instance = InstanceUtil.mergeFieldsWhichAreNotControlled(existing, mapped);
    assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb17", instance.getId());
    assertEquals("in000000001", instance.getHrid());
    assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb18", instance.getModeOfIssuanceId());
    assertEquals(contributors.get(0).getName(), instance.getContributors().get(0).name);
    assertEquals(statisticalCodeIds, instance.getStatisticalCodeIds());
    assertTrue(instance.getDiscoverySuppress());
    assertTrue(instance.getStaffSuppress());
    assertTrue(instance.getPreviouslyHeld());
    assertEquals("", instance.getCatalogedDate());
    assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb26", instance.getStatusId());
    assertEquals(natureOfContentTermIds, instance.getNatureOfContentTermIds());
    assertNotNull(instance.getTags());
    assertEquals(tagList, instance.getTags());
    assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getParentInstances().get(0).getId());
    assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getChildInstances().get(0).getId());
}
Also used : Instance(org.folio.Instance) ArrayList(java.util.ArrayList) Contributor(org.folio.Contributor) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) AlternativeTitle(org.folio.AlternativeTitle) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Instance

use of org.folio.Instance in project mod-inventory by folio-org.

the class MatchHoldingEventHandlerUnitTest method shouldMatchWithSubMatchByInstanceOnHandleEventPayload.

@Test
public void shouldMatchWithSubMatchByInstanceOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
        Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(singletonList(createHolding()), 1));
        callback.accept(result);
        return null;
    }).when(holdingCollection).findByCql(eq(format("hrid == \"%s\" AND instanceId == \"%s\"", HOLDING_HRID, INSTANCE_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(EntityType.INSTANCE.value(), JsonObject.mapFrom(new Instance().withId(INSTANCE_ID)).encode());
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
        testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_HOLDING_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) Instance(org.folio.Instance) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Aggregations

Instance (org.folio.Instance)2 Test (org.junit.Test)2 Async (io.vertx.ext.unit.Async)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Consumer (java.util.function.Consumer)1 AlternativeTitle (org.folio.AlternativeTitle)1 Contributor (org.folio.Contributor)1 DataImportEventPayload (org.folio.DataImportEventPayload)1 HoldingsRecord (org.folio.HoldingsRecord)1 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)1 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)1 Success (org.folio.inventory.common.domain.Success)1 MatchHoldingEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler)1 MatchItemEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler)1 InstanceRelationshipToChild (org.folio.inventory.domain.instances.InstanceRelationshipToChild)1 InstanceRelationshipToParent (org.folio.inventory.domain.instances.InstanceRelationshipToParent)1 EventHandler (org.folio.processing.events.services.handler.EventHandler)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1