public async Task Update(DishonourLetter letter, bool updateFile = false) { Log.Debug("Updating dishonour letter '{@letter}', {@updateFile} in Documentum", letter, updateFile); var dataObject = await GetLetterDataObject(letter.Name, letter.ProcessingDate); dataObject.Properties.Set(DishonourLetterAttributes.DishonourStatus, letter.Status.Value); if (updateFile) { using (var stream = letter.FileInfo.OpenRead()) { if (stream.Length > MaxDishonourLetterFileSize) { throw new InvalidOperationException( string.Format("File is bigger than maximum dishonours letter file size ({0}KB)", MaxDishonourLetterFileSize/1024)); } var buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int) stream.Length); dataObject.Contents.Add(new BinaryContent(buffer, DocumentumFormats.Pdf)); } } await Task.Run(() => objectRepository.Update(dataObject)); }
public void DoThis() { const string AuxiliaryDomestic = "000001029"; const string Bsb = "012468"; const string AccountNumber = "999999999"; const string Amount = "77440"; var processingDate = new DateTime(2015, 02, 10); var fileName = DishonourLetter.GetFileName(AuxiliaryDomestic, Bsb, AccountNumber, Amount, processingDate); var dishonourLetter = new DishonourLetter(fileName, DishonourLetterStatus.LetterIssued, processingDate); string output = JsonConvert.SerializeObject(dishonourLetter); var t = 5; }
public async Task<DishonourLetter> CreateLetterForVoucher(Voucher voucher, DateTime processingDate) { Log.Debug("Creating dishonours letter in Documentum"); Guard.IsNotNull(voucher, "voucher"); var fileName = DishonourLetter.GetFileName( voucher.AuxiliaryDomestic, voucher.Bsb, voucher.AccountNumber, voucher.Amount, voucher.ProcessingDate); var letter = new DishonourLetter( fileName, DishonourLetterStatus.LetterRaised, processingDate); var letterPath = await Create(letter); LinkLetterToVoucher(letterPath, voucher, processingDate); return letter; }
private async Task<string> Create(DishonourLetter letter) { Log.Debug("Creating dishonour letter {@letter} in Documentum", letter); var letterPath = GetLetterPath(letter.ProcessingDate); var path = string.Format("{0}/{1}", letterPath, letter.Name); var properties = new Dictionary<string, string> { {DocumentumAttributes.ObjectName, letter.Name}, {DocumentumAttributes.Title, letter.Name}, {DishonourLetterAttributes.DishonourStatus, DishonourLetterStatus.LetterRaised.Value} }; await Task.Run(() => objectRepository.CreateDataObject( letterPath, letter.Name, DocumentumTypes.FxaDishonourLetter, DocumentumFormats.Pdf, properties, false)); Log.Debug("Dishonour letter created : '{0}'", path); return path; }
public async Task WhenUpdate_AndBufferIsTooBig_ThenThrow() { var fileName = "xxx"; var processingDate = new DateTime(2015, 12, 25); var letterObject = new DataObject() { Properties = new PropertySet( new StringProperty(DocumentumAttributes.ObjectName, fileName), new StringProperty(DishonourLetterAttributes.DishonourStatus, DishonourLetterStatus.LetterRaised.Value)) }; var expectedPath = string.Format("{0}/{1:yyyy}/{1:MM}/{1:dd}/{2}", LetterPath, processingDate, fileName); var letter = new DishonourLetter(fileName, DishonourLetterStatus.LetterIssued, processingDate) { FileInfo = GetMockFileInfo(new string(new char[1048577])) }; ExpectConfig(letterPath: true); ExpectObjectRepositoryToGetObjectByPath(expectedPath, letterObject); ExpectObjectRepositoryToUpdateWithContent(letterObject); var sut = CreateRepository(); await sut.Update(letter, true); }
public async Task WhenUpdate_ThenEverythingIsOk() { var fileName = "xxx"; var processingDate = new DateTime(2015, 12, 25); var letterObject = new DataObject() { Properties = new PropertySet( new StringProperty(DocumentumAttributes.ObjectName, fileName), new StringProperty(DishonourLetterAttributes.DishonourStatus, DishonourLetterStatus.LetterRaised.Value)) }; var expectedPath = string.Format("{0}/{1:yyyy}/{1:MM}/{1:dd}/{2}", LetterPath, processingDate, fileName); var letter = new DishonourLetter(fileName, DishonourLetterStatus.LetterIssued, processingDate) { FileInfo = GetMockFileInfo("aaa") }; ExpectConfig(letterPath: true); ExpectObjectRepositoryToGetObjectByPath(expectedPath, letterObject); ExpectObjectRepositoryToUpdateWithContent(letterObject); var sut = CreateRepository(); await sut.Update(letter, true); Assert.AreEqual(3, letterObject.Contents[0].GetAsByteArray().Length); Assert.AreEqual(DocumentumFormats.Pdf, letterObject.Contents[0].Format); dfsConfiguration.VerifyAll(); objectRepository.VerifyAll(); }