/******************************************************************************************************************* * * Loads the {@link Accounting} at initialization. * ******************************************************************************************************************/ @PostConstruct @VisibleForTesting void initialize() { try { log.info("initialize()"); accounting = Accounting.createNew().as(Loadable).load(); messageBus.publish(new AccountingOpenedEvent(accounting)); } catch (IOException e) { throw new RuntimeException(e); } }
public AccountingXml (final @Nonnull Accounting accounting) { customersXml = accounting.getCustomerRegistry().findCustomers().stream().map(customer -> new CustomerXml(customer)) .collect(toList()); projectsXml = accounting.getProjectRegistry().findProjects().stream().map(project -> new ProjectXml(project)) .collect(toList()); invoicesxml = accounting.getInvoiceRegistry().findInvoices().stream().map(invoice -> new InvoiceXml(invoice)) .collect(toList()); }
nextId = 1; final Accounting accounting = Accounting.createNew(); final CustomerRegistry customerRegistry = accounting.getCustomerRegistry(); final ProjectRegistry projectRegistry = accounting.getProjectRegistry(); final InvoiceRegistry invoiceRegistry = accounting.getInvoiceRegistry();
@Nonnull public static Accounting createEmptyAccounting() { AsDelegateProvider.Locator.set(new EmptyAsDelegateProvider()); final Accounting accounting = Accounting.createNew(); return accounting; }
/******************************************************************************************************************* * * Reacts to the notification that an {@link Accounting} has been opened by populating the presentation with * the customers. * * @param event the notification event * ******************************************************************************************************************/ @VisibleForTesting void onAccountingOpenedEvent (final @Nonnull @ListensTo AccountingOpenedEvent event) { log.info("onAccountingOpenedEvent({})", event); presentation.populate(event.getAccounting().getCustomerRegistry().findCustomers().stream() .map(customer -> (CustomerSpi)customer) .sorted(comparing(CustomerSpi::getName)) .map(customer -> createPresentationModelFor(customer)) .collect(toCompositePresentationModel())); }
@DataProvider(name = "projects") public static Object[][] projectProvider() { return ScenarioFactory.createScenarios().entrySet().stream() .flatMap(entry -> entry.getValue().getProjectRegistry().findProjects().stream() .map(project -> new Object[] { entry.getKey(), project })) .collect(Collectors.toList()) .toArray(new Object[0][0]); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public Accounting load() throws IOException { final Path dataFile = getDataFile(); log.info(">>>> loading data from {}...", dataFile); try (final InputStream is = new FileInputStream(dataFile.toFile())) { return accounting.as(Unmarshallable).unmarshal(is); } }
@Test(dataProvider = "scenarios") public void must_properly_unmarshall (final @Nonnull String scenarioName) throws Exception { final Path expectedResultsFolder = Paths.get("src/test/resources/expected-results"); final Path testFolder = Paths.get("target/test-results"); Files.createDirectories(testFolder); final Path importFile = Paths.get("src/test/resources/scenarios").resolve(scenarioName + ".xml"); final Path actualResult = testFolder.resolve(scenarioName + ".txt"); final Path expectedResult = expectedResultsFolder.resolve(scenarioName + ".txt"); final Accounting accounting = Accounting.createNew(); final AccountingXmlUnmarshallable fixture = new AccountingXmlUnmarshallable(accounting); try (final InputStream is = new FileInputStream(importFile.toFile())) { fixture.unmarshal(is); } try (final PrintWriter pw = new PrintWriter(actualResult.toFile())) { new Dumper(accounting, pw).dumpAll(); } FileComparisonUtils.assertSameContents(expectedResult.toFile(), actualResult.toFile()); }
@Nonnull public Project.Builder toBuilder (final @Nonnull Accounting accounting) { try { final Customer customer = accounting.getCustomerRegistry().findCustomers().withId(customerXml.getId()).result(); return new Project.Builder().withId(id) .withCustomer(customer) .withName(name) .withNumber(number) .withDescription(description) .withNotes(notes) .withStatus(status) .withHourlyRate(hourlyRate) .withBudget(budget) .withStartDate(startDate) .withEndDate(endDate) .withEvents(JobEventXml.toJobEvents(jobEventsXml)); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
@Nonnull public Invoice.Builder toBuilder (final @Nonnull Accounting accounting) { try { final Project customer = accounting.getProjectRegistry().findProjects().withId(projectXml.getId()).result(); return new Invoice.Builder().withId(id) .withNumber(number) .withProject(customer) .withDate(date) .withDueDate(dueDate) .withEarnings(earnings) .withTax(tax) .withJobEvents(JobEventXml.toJobEvents(jobEventsXml)); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public void save() throws IOException { final Path dataFile = getDataFile(); log.info(">>>> saving data to {}...", dataFile); try (final OutputStream os = new FileOutputStream(dataFile.toFile())) { accounting.as(Marshallable).marshal(os); } }
public void fill (final @Nonnull Accounting accounting) { final CustomerRegistry customerRegistry = accounting.getCustomerRegistry(); final ProjectRegistry projectRegistry = accounting.getProjectRegistry(); final InvoiceRegistry invoiceRegistry = accounting.getInvoiceRegistry(); customersXml.forEach(customer -> customerRegistry.addCustomer().with(customer.toBuilder()).create()); projectsXml.forEach(project -> projectRegistry.addProject().with(project.toBuilder(accounting)).create()); invoicesxml.forEach(invoice -> invoiceRegistry.addInvoice().with(invoice.toBuilder(accounting)).create()); } }
@Test public void must_properly_unmarshall_iBiz() throws Exception { final Path expectedResultsFolder = Paths.get("/Users/fritz/Business/Tidalwave/Projects/WorkAreas/blueHour/private"); if (Files.exists(expectedResultsFolder)) { final Path testFolder = Paths.get("target/test-results"); Files.createDirectories(testFolder); final Path actualResult = testFolder.resolve("unmarshalledDump.txt"); final Path expectedResult = expectedResultsFolder.resolve("iBizImportDump.txt"); final Path importFile = expectedResultsFolder.resolve("iBizImportMarshalled.xml"); final Accounting accounting = Accounting.createNew(); final AccountingXmlUnmarshallable fixture = new AccountingXmlUnmarshallable(accounting); try (final InputStream is = new FileInputStream(importFile.toFile())) { fixture.unmarshal(is); } try (final PrintWriter pw = new PrintWriter(actualResult.toFile())) { new Dumper(accounting, pw).dumpAll(); } FileComparisonUtils.assertSameContents(expectedResult.toFile(), actualResult.toFile()); } }
public void dumpAll() throws IOException { dumpCustomers(accounting.getCustomerRegistry().findCustomers()); dumpProjects(accounting.getProjectRegistry().findProjects()); dumpInvoices(accounting.getInvoiceRegistry().findInvoices()); }