private void initTestContext(String testFile) throws Exception { // testPM = new HsqldbMemoryPersistenceManager(); // System.setProperty("riena.test", "true"); // PersistenceManager.reset(testPM); initSampleDairy(); if (testFile != null) { System.err.println("importing " + testFile); final ScaleImporter importer = new ScaleImporter(new File(testFile)); importer.readRecords(); final List<ScaleRecord> results = importer.getResults(); for (final ScaleRecord record : results) { final CollectionJournalLine line = DairyFactory.eINSTANCE.createCollectionJournalLine(); line.setRecordedMember(record.getMemberNumber()); line.setValidatedMember(getMembership(record.getMemberNumber())); line.setQuantity(new BigDecimal(record.getQuantity())); final CollectionGroup group = getCollectionGroup( record.getRouteNumber(), record.getSessionCode(), record.getValidDate()); group.getEntries().add(line); group.setEntryCount(group.getEntryCount() + 1); group.setRecordTotal(group.getRecordTotal().add(line.getQuantity())); } for (final CollectionGroup group : groups.values()) { repo.save(group); } } }
private CollectionGroup getCollectionGroup(String routeNumber, String sessionCode, Date date) { if (date == null) { throw new IllegalArgumentException("date cannot be null"); } final String key = String.format("%5s-%2s-%tF", routeNumber, sessionCode, date); CollectionGroup group = groups.get(key); if (group == null) { group = DairyFactory.eINSTANCE.createCollectionGroup(); group.setReferenceNumber(key); group.setCollectionDate(date); group.setStatus(JournalStatus.COMPLETE); group.setDriver(DEFAULT_DRIVER); group.setType(CollectionGroupType.JOURNAL_GROUP); group.setCollectionCenter(getCenter(routeNumber)); groups.put(key, group); } return group; }