use of org.folio.Authority in project mod-inventory by folio-org.
the class ExternalStorageModuleAuthorityRecordCollectionExamples method shouldRetrieveId.
@Test
public void shouldRetrieveId() {
String authorityId = UUID.randomUUID().toString();
Authority authority = new Authority().withId(authorityId);
assertEquals(authorityId, storage.getId(authority));
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class UpdateAuthorityQuickMarcEventHandlerTest method shouldProcessEvent.
@Test
public void shouldProcessEvent() {
HashMap<String, String> eventPayload = new HashMap<>();
eventPayload.put("RECORD_TYPE", "MARC_AUTHORITY");
eventPayload.put("MARC_AUTHORITY", record.encode());
eventPayload.put("MAPPING_RULES", mappingRules.encode());
eventPayload.put("MAPPING_PARAMS", new JsonObject().encode());
eventPayload.put("RELATED_RECORD_VERSION", AUTHORITY_VERSION.toString());
Future<Authority> future = updateAuthorityQuickMarcEventHandler.handle(eventPayload);
Authority updatedAuthority = future.result();
Assert.assertNotNull(updatedAuthority);
Assert.assertEquals(AUTHORITY_ID, updatedAuthority.getId());
Assert.assertEquals(AUTHORITY_VERSION, updatedAuthority.getVersion());
Assert.assertNotNull(updatedAuthority.getIdentifiers());
Assert.assertEquals(4, updatedAuthority.getIdentifiers().size());
Assert.assertNotNull(updatedAuthority.getNotes());
ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
verify(authorityUpdateDelegate).handle(any(), any(), argument.capture());
Assert.assertEquals("token", argument.getValue().getToken());
Assert.assertEquals("dummy", argument.getValue().getTenantId());
Assert.assertEquals("http://localhost", argument.getValue().getOkapiLocation());
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class UpdateAuthorityQuickMarcEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
existingAuthority = new JsonObject(TestUtil.readFileFromPath(AUTHORITY_PATH)).mapTo(Authority.class);
authorityUpdateDelegate = Mockito.spy(new AuthorityUpdateDelegate(storage));
updateAuthorityQuickMarcEventHandler = new UpdateAuthorityQuickMarcEventHandler(authorityUpdateDelegate, context);
when(storage.getAuthorityRecordCollection(any())).thenReturn(authorityRecordCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingAuthority));
return null;
}).when(authorityRecordCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Authority authority = invocationOnMock.getArgument(0);
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(authority));
return null;
}).when(authorityRecordCollection).update(any(), any(), any());
when(context.getTenantId()).thenReturn("dummy");
when(context.getToken()).thenReturn("token");
when(context.getOkapiLocation()).thenReturn("http://localhost");
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
record = new JsonObject(TestUtil.readFileFromPath(RECORD_PATH));
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class AuthorityUpdateDelegate method mergeRecords.
private Future<Authority> mergeRecords(Authority existingRecord, Authority mappedRecord) {
try {
mappedRecord.setId(existingRecord.getId());
JsonObject existing = JsonObject.mapFrom(existingRecord);
JsonObject mapped = JsonObject.mapFrom(mappedRecord);
JsonObject merged = existing.mergeIn(mapped);
Authority mergedAuthorityRecord = merged.mapTo(Authority.class);
return Future.succeededFuture(mergedAuthorityRecord);
} catch (Exception e) {
LOGGER.error("Error updating authority", e);
return Future.failedFuture(e);
}
}
use of org.folio.Authority in project mod-inventory by folio-org.
the class AuthorityUpdateDelegate method handle.
public Future<Authority> handle(Map<String, String> eventPayload, Record marcRecord, Context context) {
try {
JsonObject mappingRules = new JsonObject(eventPayload.get(MAPPING_RULES_KEY));
MappingParameters mappingParameters = new JsonObject(eventPayload.get(MAPPING_PARAMS_KEY)).mapTo(MappingParameters.class);
JsonObject parsedRecord = retrieveParsedContent(marcRecord.getParsedRecord());
String authorityId = marcRecord.getExternalIdsHolder().getAuthorityId();
RecordMapper<Authority> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
var mappedAuthority = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
AuthorityRecordCollection authorityRecordCollection = storage.getAuthorityRecordCollection(context);
return getAuthorityRecordById(authorityId, authorityRecordCollection).onSuccess(existingAuthorityRecord -> fillVersion(existingAuthorityRecord, eventPayload)).compose(existingAuthorityRecord -> mergeRecords(existingAuthorityRecord, mappedAuthority)).compose(updatedAuthorityRecord -> updateAuthorityRecord(updatedAuthorityRecord, authorityRecordCollection));
} catch (Exception e) {
LOGGER.error("Error updating Authority", e);
return Future.failedFuture(e);
}
}
Aggregations