@Test public void shouldThrowExceptionIfModifiedDateOfExistingRecordIsSameAsCurrentTimeStamp() throws Exception { final Date currentTimestamp = new Date(); AuditFields auditFields = new AuditFields(1L, currentTimestamp); Importable currentRecord = new TestImportable(); BaseModel existing = new BaseModel() { }; existing.setId(2L); existing.setModifiedDate(currentTimestamp); handler = instantiateHandler(existing); handler.messageService = messageService; when(messageService.message("duplicate.record.error.code")).thenReturn("Duplicate Record"); when(messageService.message("upload.record.error", "Duplicate Record", "1")).thenReturn("Upload error, Duplicate Record in row 1"); expectedEx.expect(DataException.class); expectedEx.expectMessage("Upload error, Duplicate Record in row 1"); handler.execute(currentRecord, 2, auditFields); }
@Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } } }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  @Override void execute(Importable importable, int rowNumber, AuditFields auditFields); @Override void postProcess(AuditFields auditFields); }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  @Override void execute(Importable importable, int rowNumber, AuditFields auditFields); @Override void postProcess(AuditFields auditFields);  }