@Test public void testIsPreviouslyIngested() { NeutralRecord originalRecord = createBaseNeutralRecord(); NeutralRecord recordClone = (NeutralRecord) originalRecord.clone(); TenantContext.setTenantId("tenantId"); Mockito.when(mockBatchJobMongoDA.findRecordHash(any(String.class), any(String.class))).thenReturn(null); Mockito.when(mockDIdStrategy.generateId(any(NaturalKeyDescriptor.class))).thenReturn(RECORD_DID); Mockito.when(mockDidResolver.getDidSchemaParser()).thenReturn(didSchemaParser); Mockito.when(didSchemaParser.getNaturalKeys()).thenReturn(createNaturalKeyMap()); Assert.assertFalse(SliDeltaManager.isPreviouslyIngested(originalRecord, mockBatchJobMongoDA, mockDIdStrategy, mockDidResolver, errorReport, reportStats)); confirmMetaDataUpdated(originalRecord); List<Map<String, String>> fData = (List<Map<String, String>>) originalRecord.getMetaData().get("rhData"); String fTenantId = (String) originalRecord.getMetaData().get("rhTenantId"); String fHash=fData.get(0).get("rhHash"); String fRhId=fData.get(0).get("rhId"); RecordHash hash = createRecordHash(fHash); Mockito.when(mockBatchJobMongoDA.findRecordHash(any(String.class), any(String.class))).thenReturn(hash); Assert.assertTrue(SliDeltaManager.isPreviouslyIngested(recordClone, mockBatchJobMongoDA, mockDIdStrategy, mockDidResolver, errorReport, reportStats)); confirmMetaDataUpdated(recordClone); List<Map<String, String>> sData = (List<Map<String, String>>) originalRecord.getMetaData().get("rhData"); String sTenantId = (String) originalRecord.getMetaData().get("rhTenantId"); String sHash=sData.get(0).get("rhHash"); String sRhId=sData.get(0).get("rhId"); Assert.assertEquals(fRhId, sRhId); Assert.assertEquals(fHash, sHash); Assert.assertEquals(fTenantId, sTenantId); }
public static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO, DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver, AbstractMessageReport report, ReportStats reportStats) { boolean isPrevIngested = false; String tenantId = TenantContext.getTenantId(); String sliEntityType = MapUtils.getString(n.getMetaData(), "sliEntityType"); if (sliEntityType == null) { sliEntityType = n.getRecordType(); } Map<String, String> populatedNaturalKeys = new HashMap<String, String>(); NeutralRecord neutralRecordResolved = null; neutralRecordResolved = (NeutralRecord) n.clone(); NeutralRecordEntity entity = new NeutralRecordEntity(neutralRecordResolved); didResolver.resolveInternalIds(entity, tenantId, report, reportStats); try { Map<String, List<DidNaturalKey>> naturalKeysMap = didResolver.getDidSchemaParser().getNaturalKeys(); String recordType = neutralRecordResolved.getRecordType(); List<DidNaturalKey> naturalKeys = naturalKeysMap.get(recordType); if ( null == naturalKeys ) { throw new NoNaturalKeysDefinedException("Natural keys not defined for record type '" + recordType + "'"); } populatedNaturalKeys = populateNaturalKeyValues(neutralRecordResolved, naturalKeys); NaturalKeyDescriptor nkd = new NaturalKeyDescriptor(populatedNaturalKeys, tenantId, sliEntityType, null); String recordId = dIdStrategy.generateId(nkd); String recordHashValues = neutralRecordResolved.generateRecordHash(tenantId); RecordHash record = batchJobDAO.findRecordHash(tenantId, recordId); List<Map<String, Object>> rhData = new ArrayList<Map<String, Object>>(); Map<String, Object> rhDataElement = new HashMap<String, Object>(); rhDataElement.put(RECORDHASH_ID, recordId); rhDataElement.put(RECORDHASH_HASH, recordHashValues); rhData.add(rhDataElement); n.addMetaData(RECORDHASH_DATA, rhData); isPrevIngested = !n.getActionVerb().doDelete() && (record != null && record.getHash().equals(recordHashValues)); if(record != null) { rhDataElement.put(RECORDHASH_CURRENT, record.exportToSerializableMap()); } } catch (NoNaturalKeysDefinedException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } catch (NaturalKeyValidationException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } return isPrevIngested; }
SliDeltaManager { public static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO, DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver, AbstractMessageReport report, ReportStats reportStats) { boolean isPrevIngested = false; String tenantId = TenantContext.getTenantId(); String sliEntityType = MapUtils.getString(n.getMetaData(), "sliEntityType"); if (sliEntityType == null) { sliEntityType = n.getRecordType(); } Map<String, String> populatedNaturalKeys = new HashMap<String, String>(); NeutralRecord neutralRecordResolved = null; neutralRecordResolved = (NeutralRecord) n.clone(); NeutralRecordEntity entity = new NeutralRecordEntity(neutralRecordResolved); didResolver.resolveInternalIds(entity, tenantId, report, reportStats); try { Map<String, List<DidNaturalKey>> naturalKeysMap = didResolver.getDidSchemaParser().getNaturalKeys(); String recordType = neutralRecordResolved.getRecordType(); List<DidNaturalKey> naturalKeys = naturalKeysMap.get(recordType); if ( null == naturalKeys ) { throw new NoNaturalKeysDefinedException("Natural keys not defined for record type '" + recordType + "'"); } populatedNaturalKeys = populateNaturalKeyValues(neutralRecordResolved, naturalKeys); NaturalKeyDescriptor nkd = new NaturalKeyDescriptor(populatedNaturalKeys, tenantId, sliEntityType, null); String recordId = dIdStrategy.generateId(nkd); String recordHashValues = neutralRecordResolved.generateRecordHash(tenantId); RecordHash record = batchJobDAO.findRecordHash(tenantId, recordId); List<Map<String, Object>> rhData = new ArrayList<Map<String, Object>>(); Map<String, Object> rhDataElement = new HashMap<String, Object>(); rhDataElement.put(RECORDHASH_ID, recordId); rhDataElement.put(RECORDHASH_HASH, recordHashValues); rhData.add(rhDataElement); n.addMetaData(RECORDHASH_DATA, rhData); isPrevIngested = !n.getActionVerb().doDelete() && (record != null && record.getHash().equals(recordHashValues)); if(record != null) { rhDataElement.put(RECORDHASH_CURRENT, record.exportToSerializableMap()); } } catch (NoNaturalKeysDefinedException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } catch (NaturalKeyValidationException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } return isPrevIngested; } }
SliDeltaManager { public static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO, DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver, AbstractMessageReport report, ReportStats reportStats) { boolean isPrevIngested = false; String tenantId = TenantContext.getTenantId(); String sliEntityType = MapUtils.getString(n.getMetaData(), "sliEntityType"); if (sliEntityType == null) { sliEntityType = n.getRecordType(); } Map<String, String> populatedNaturalKeys = new HashMap<String, String>(); NeutralRecord neutralRecordResolved = null; neutralRecordResolved = (NeutralRecord) n.clone(); NeutralRecordEntity entity = new NeutralRecordEntity(neutralRecordResolved); didResolver.resolveInternalIds(entity, tenantId, report, reportStats); try { Map<String, List<DidNaturalKey>> naturalKeysMap = didResolver.getDidSchemaParser().getNaturalKeys(); String recordType = neutralRecordResolved.getRecordType(); List<DidNaturalKey> naturalKeys = naturalKeysMap.get(recordType); if ( null == naturalKeys ) { throw new NoNaturalKeysDefinedException("Natural keys not defined for record type '" + recordType + "'"); } populatedNaturalKeys = populateNaturalKeyValues(neutralRecordResolved, naturalKeys); NaturalKeyDescriptor nkd = new NaturalKeyDescriptor(populatedNaturalKeys, tenantId, sliEntityType, null); String recordId = dIdStrategy.generateId(nkd); String recordHashValues = neutralRecordResolved.generateRecordHash(tenantId); RecordHash record = batchJobDAO.findRecordHash(tenantId, recordId); List<Map<String, Object>> rhData = new ArrayList<Map<String, Object>>(); Map<String, Object> rhDataElement = new HashMap<String, Object>(); rhDataElement.put(RECORDHASH_ID, recordId); rhDataElement.put(RECORDHASH_HASH, recordHashValues); rhData.add(rhDataElement); n.addMetaData(RECORDHASH_DATA, rhData); isPrevIngested = !n.getActionVerb().doDelete() && (record != null && record.getHash().equals(recordHashValues)); if(record != null) { rhDataElement.put(RECORDHASH_CURRENT, record.exportToSerializableMap()); } } catch (NoNaturalKeysDefinedException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } catch (NaturalKeyValidationException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } return isPrevIngested; } private  SliDeltaManager(); }
SliDeltaManager { public static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO, DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver, AbstractMessageReport report, ReportStats reportStats) { boolean isPrevIngested = false; String tenantId = TenantContext.getTenantId(); String sliEntityType = MapUtils.getString(n.getMetaData(), "sliEntityType"); if (sliEntityType == null) { sliEntityType = n.getRecordType(); } Map<String, String> populatedNaturalKeys = new HashMap<String, String>(); NeutralRecord neutralRecordResolved = null; neutralRecordResolved = (NeutralRecord) n.clone(); NeutralRecordEntity entity = new NeutralRecordEntity(neutralRecordResolved); didResolver.resolveInternalIds(entity, tenantId, report, reportStats); try { Map<String, List<DidNaturalKey>> naturalKeysMap = didResolver.getDidSchemaParser().getNaturalKeys(); String recordType = neutralRecordResolved.getRecordType(); List<DidNaturalKey> naturalKeys = naturalKeysMap.get(recordType); if ( null == naturalKeys ) { throw new NoNaturalKeysDefinedException("Natural keys not defined for record type '" + recordType + "'"); } populatedNaturalKeys = populateNaturalKeyValues(neutralRecordResolved, naturalKeys); NaturalKeyDescriptor nkd = new NaturalKeyDescriptor(populatedNaturalKeys, tenantId, sliEntityType, null); String recordId = dIdStrategy.generateId(nkd); String recordHashValues = neutralRecordResolved.generateRecordHash(tenantId); RecordHash record = batchJobDAO.findRecordHash(tenantId, recordId); List<Map<String, Object>> rhData = new ArrayList<Map<String, Object>>(); Map<String, Object> rhDataElement = new HashMap<String, Object>(); rhDataElement.put(RECORDHASH_ID, recordId); rhDataElement.put(RECORDHASH_HASH, recordHashValues); rhData.add(rhDataElement); n.addMetaData(RECORDHASH_DATA, rhData); isPrevIngested = !n.getActionVerb().doDelete() && (record != null && record.getHash().equals(recordHashValues)); if(record != null) { rhDataElement.put(RECORDHASH_CURRENT, record.exportToSerializableMap()); } } catch (NoNaturalKeysDefinedException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } catch (NaturalKeyValidationException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } return isPrevIngested; } private  SliDeltaManager(); static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO,
            DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver,
            AbstractMessageReport report, ReportStats reportStats); }
SliDeltaManager { public static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO, DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver, AbstractMessageReport report, ReportStats reportStats) { boolean isPrevIngested = false; String tenantId = TenantContext.getTenantId(); String sliEntityType = MapUtils.getString(n.getMetaData(), "sliEntityType"); if (sliEntityType == null) { sliEntityType = n.getRecordType(); } Map<String, String> populatedNaturalKeys = new HashMap<String, String>(); NeutralRecord neutralRecordResolved = null; neutralRecordResolved = (NeutralRecord) n.clone(); NeutralRecordEntity entity = new NeutralRecordEntity(neutralRecordResolved); didResolver.resolveInternalIds(entity, tenantId, report, reportStats); try { Map<String, List<DidNaturalKey>> naturalKeysMap = didResolver.getDidSchemaParser().getNaturalKeys(); String recordType = neutralRecordResolved.getRecordType(); List<DidNaturalKey> naturalKeys = naturalKeysMap.get(recordType); if ( null == naturalKeys ) { throw new NoNaturalKeysDefinedException("Natural keys not defined for record type '" + recordType + "'"); } populatedNaturalKeys = populateNaturalKeyValues(neutralRecordResolved, naturalKeys); NaturalKeyDescriptor nkd = new NaturalKeyDescriptor(populatedNaturalKeys, tenantId, sliEntityType, null); String recordId = dIdStrategy.generateId(nkd); String recordHashValues = neutralRecordResolved.generateRecordHash(tenantId); RecordHash record = batchJobDAO.findRecordHash(tenantId, recordId); List<Map<String, Object>> rhData = new ArrayList<Map<String, Object>>(); Map<String, Object> rhDataElement = new HashMap<String, Object>(); rhDataElement.put(RECORDHASH_ID, recordId); rhDataElement.put(RECORDHASH_HASH, recordHashValues); rhData.add(rhDataElement); n.addMetaData(RECORDHASH_DATA, rhData); isPrevIngested = !n.getActionVerb().doDelete() && (record != null && record.getHash().equals(recordHashValues)); if(record != null) { rhDataElement.put(RECORDHASH_CURRENT, record.exportToSerializableMap()); } } catch (NoNaturalKeysDefinedException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } catch (NaturalKeyValidationException e) { LOG.warn(e.getMessage()); isPrevIngested = false; } return isPrevIngested; } private  SliDeltaManager(); static boolean isPreviouslyIngested(NeutralRecord n, BatchJobDAO batchJobDAO,
            DeterministicUUIDGeneratorStrategy dIdStrategy, DeterministicIdResolver didResolver,
            AbstractMessageReport report, ReportStats reportStats); static final String RECORDHASH_DATA; static final String RECORDHASH_HASH; static final String RECORDHASH_ID; static final String RECORDHASH_CURRENT; static final String NRKEYVALUEFIELDNAMES; static final String OPTIONALNRKEYVALUEFIELDNAMES; }