@SuppressWarnings("unchecked") @Test public void shouldResolveDidsInEmbeddedList() throws IOException { NeutralRecordEntity entity = createSourceEmbeddedEntity(); DidRefConfig refConfig = createRefConfig("Simple_DID_ref_config.json"); DidEntityConfig entityConfig = createEntityConfig("Embedded_DID_entity_config.json"); mockRefConfig(refConfig, ENTITY_TYPE); mockEntityConfig(entityConfig, ENTITY_TYPE); Mockito.when(schemaRepository.getSchema(ENTITY_TYPE)).thenReturn(null); Map<String, String> naturalKeys1 = new HashMap<String, String>(); naturalKeys1.put(SRC_KEY_FIELD, SRC_KEY_VALUE_1); String entityType = ENTITY_TYPE; String tenantId = TENANT; NaturalKeyDescriptor ndk1 = new NaturalKeyDescriptor(naturalKeys1, tenantId, entityType, null); Map<String, String> naturalKeys2 = new HashMap<String, String>(); naturalKeys2.put(SRC_KEY_FIELD, SRC_KEY_VALUE_2); NaturalKeyDescriptor ndk2 = new NaturalKeyDescriptor(naturalKeys2, tenantId, entityType, null); Mockito.when(didGenerator.generateId(Mockito.eq(ndk1))).thenReturn(DID_VALUE_1); Mockito.when(didGenerator.generateId(Mockito.eq(ndk2))).thenReturn(DID_VALUE_2); AbstractMessageReport errorReport = new DummyMessageReport(); ReportStats reportStats = new SimpleReportStats(); didResolver.resolveInternalIds(entity, TENANT, errorReport, reportStats); List<Object> embeddedList = (List<Object>) entity.getBody().get(EMBEDDED_LIST_FIELD); Assert.assertNotNull(embeddedList); Assert.assertEquals(2, embeddedList.size()); Map<String, Object> subObj1 = (Map<String, Object>) embeddedList.get(0); Map<String, Object> subObj2 = (Map<String, Object>) embeddedList.get(1); Assert.assertEquals(DID_VALUE_1, subObj1.get(REF_FIELD)); Assert.assertEquals(DID_VALUE_2, subObj2.get(REF_FIELD)); Assert.assertFalse("no errors should be reported from reference resolution ", reportStats.hasErrors()); }
public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } } }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }  }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }  void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report,
                                   ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName(); }
DeterministicIdResolver implements BatchJobStage { public void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report, ReportStats reportStats) { DidEntityConfig entityConfig = getEntityConfig(entity.getType()); if (entityConfig == null) { return; } if (entityConfig.getReferenceSources() == null || entityConfig.getReferenceSources().isEmpty()) { LOG.debug("Entity configuration contains no references --> returning..."); return; } for (DidRefSource didRefSource : entityConfig.getReferenceSources()) { String referenceEntityType = didRefSource.getEntityType(); String sourceRefPath = didRefSource.getSourceRefPath(); try { handleDeterministicIdForReference(entity, didRefSource, tenantId); } catch (IdResolutionException e) { handleException(entity, sourceRefPath, entity.getType(), referenceEntityType, e, report, reportStats); } } }  void resolveInternalIds(NeutralRecordEntity entity, String tenantId, AbstractMessageReport report,
                                   ReportStats reportStats); DidSchemaParser getDidSchemaParser(); void setDidSchemaParser(DidSchemaParser didSchemaParser); @Override String getStageName();  }