@Override public void setUp() throws Exception { super.setUp(); String messageFileName = LaborTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/message.properties"; String propertiesFileName = LaborTestDataPropertyConstants.TEST_DATA_PACKAGE_NAME + "/laborGLLedgerEntryPoster.properties"; properties = TestDataPreparator.loadPropertiesFromClassPath(propertiesFileName); fieldNames = properties.getProperty("fieldNames"); deliminator = properties.getProperty("deliminator"); keyFieldList = Arrays.asList(StringUtils.split(fieldNames, deliminator)); laborGLLedgerEntryPoster = SpringContext.getBean(PostTransaction.class, "laborGLLedgerEntryPoster"); businessObjectService = SpringContext.getBean(BusinessObjectService.class); originEntryGroupService = SpringContext.getBean(LaborOriginEntryGroupService.class); laborGeneralLedgerEntryService = SpringContext.getBean(LaborGeneralLedgerEntryService.class); DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); // TODO:- commented out // group1 = originEntryGroupService.createGroup(dateTimeService.getCurrentSqlDate(), // LABOR_MAIN_POSTER_VALID, false, false, false); today = dateTimeService.getCurrentDate(); LaborGeneralLedgerEntry cleanup = new LaborGeneralLedgerEntry(); ObjectUtil.populateBusinessObject(cleanup, properties, "dataCleanup", fieldNames, deliminator); fieldValues = ObjectUtil.buildPropertyMap( cleanup, Arrays.asList(StringUtils.split(fieldNames, deliminator))); businessObjectService.deleteMatching(LaborGeneralLedgerEntry.class, fieldValues); }
/** * Populate the target object with the source object * * @param targetObject the target object * @param sourceObject the source object */ public static void buildObjectWithoutReferenceFields(Object targetObject, Object sourceObject) { DynaClass dynaClass = WrapDynaClass.createDynaClass(targetObject.getClass()); DynaProperty[] properties = dynaClass.getDynaProperties(); for (DynaProperty property : properties) { ObjectUtil.setProperty(targetObject, sourceObject, property, true); } }
/** * Populate the target object with the source object * * @param targetObject the target object * @param sourceObject the source object */ public static void buildObject(Object targetObject, Object sourceObject) { DynaClass dynaClass = WrapDynaClass.createDynaClass(targetObject.getClass()); DynaProperty[] properties = dynaClass.getDynaProperties(); for (DynaProperty property : properties) { ObjectUtil.setProperty(targetObject, sourceObject, property, false); } }
/** * Populate a business object with the given properities and information * * @param businessOjbject the business object to be populated * @param properties the given properties * @param propertyKey the property keys in the properties * @param fieldNames the names of the fields to be populated * @param deliminator the deliminator that separates the values to be used in a string */ public static void populateBusinessObject( Object businessOjbject, Properties properties, String propertyKey, int[] fieldLength, List<String> keyFields) { String data = properties.getProperty(propertyKey); ObjectUtil.convertLineToBusinessObject(businessOjbject, data, fieldLength, keyFields); }
/** * Populate a business object with the given properities and information * * @param businessOjbject the business object to be populated * @param properties the given properties * @param propertyKey the property keys in the properties * @param fieldNames the names of the fields to be populated * @param deliminator the deliminator that separates the values to be used in a string */ public static void populateBusinessObject( Object businessOjbject, Properties properties, String propertyKey, String fieldNames, String deliminator) { String data = properties.getProperty(propertyKey); ObjectUtil.convertLineToBusinessObject(businessOjbject, data, deliminator, fieldNames); }
/** * Tokenize the input line with the given deliminator and populate the given object with values of * the tokens * * @param targetObject the target object * @param line the input line * @param delim the deminator that separates the fields in the given line * @param keyFields the specified fields */ public static void convertLineToBusinessObject( Object targetObject, String line, int[] fieldLength, List<String> keyFields) { String[] tokens = new String[fieldLength.length]; int currentPosition = 0; for (int i = 0; i < fieldLength.length; i++) { currentPosition = i <= 0 ? 0 : fieldLength[i - 1] + currentPosition; tokens[i] = StringUtils.mid(line, currentPosition, fieldLength[i]).trim(); } ObjectUtil.buildObject(targetObject, tokens, keyFields); }
/** @see org.kuali.kfs.module.bc.service.PayrateImportService#importFile(java.io.InputStream) */ @Transactional public boolean importFile( InputStream fileImportStream, List<ExternalizedMessageWrapper> messageList, String principalId) { Map payRateHoldingPersonUniversalIdentifierKey = new HashMap(); payRateHoldingPersonUniversalIdentifierKey.put( KFSPropertyConstants.PERSON_UNIVERSAL_IDENTIFIER, principalId); this.businessObjectService.deleteMatching( BudgetConstructionPayRateHolding.class, payRateHoldingPersonUniversalIdentifierKey); BufferedReader fileReader = new BufferedReader(new InputStreamReader(fileImportStream)); this.importCount = 0; try { while (fileReader.ready()) { BudgetConstructionPayRateHolding budgetConstructionPayRateHolding = new BudgetConstructionPayRateHolding(); String line = fileReader.readLine(); ObjectUtil.convertLineToBusinessObject( budgetConstructionPayRateHolding, line, DefaultImportFileFormat.fieldLengths, Arrays.asList(DefaultImportFileFormat.fieldNames)); budgetConstructionPayRateHolding.setPrincipalId(principalId); budgetConstructionPayRateHolding.setAppointmentRequestedPayRate( budgetConstructionPayRateHolding.getAppointmentRequestedPayRate().movePointLeft(2)); businessObjectService.save(budgetConstructionPayRateHolding); this.importCount++; } } catch (Exception e) { this.businessObjectService.deleteMatching( BudgetConstructionPayRateHolding.class, payRateHoldingPersonUniversalIdentifierKey); messageList.add(new ExternalizedMessageWrapper(BCKeyConstants.ERROR_PAYRATE_IMPORT_ABORTED)); return false; } if (importCount == 0) messageList.add( new ExternalizedMessageWrapper(BCKeyConstants.MSG_PAYRATE_IMPORT_NO_IMPORT_RECORDS)); else messageList.add( new ExternalizedMessageWrapper( BCKeyConstants.MSG_PAYRATE_IMPORT_COUNT, String.valueOf(importCount))); return true; }
private List loadInputData( Class clazz, String propertyKeyPrefix, int numberOfInputData, List<String> keyFieldList, int[] fieldLength) { List inputDataList = new ArrayList(); for (int i = 1; i <= numberOfInputData; i++) { String propertyKey = propertyKeyPrefix + i; try { Object inputData = clazz.newInstance(); ObjectUtil.populateBusinessObject( inputData, properties, propertyKey, fieldLength, keyFieldList); inputDataList.add(inputData); } catch (Exception e) { e.printStackTrace(); } } return inputDataList; }
private int loadInputData( String propertyKeyPrefix, int numberOfInputData, List<String> keyFieldList, int[] fieldLength) { int count = 0; for (int i = 1; i <= numberOfInputData; i++) { String propertyKey = propertyKeyPrefix + i; PendingLedgerEntryForTesting inputData = new PendingLedgerEntryForTesting(); ObjectUtil.populateBusinessObject( inputData, properties, propertyKey, fieldLength, keyFieldList); if (businessObjectService.countMatching( LaborLedgerPendingEntry.class, inputData.getPrimaryKeyMap()) <= 0) { inputData.setFinancialDocumentApprovedCode( KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED); businessObjectService.save(inputData); count++; } } return count; }
/** * determine whether the given accounting line has already been in the given document * * @param accountingDocument the given document * @param accountingLine the given accounting line * @return true if the given accounting line has already been in the given document; otherwise, * false */ protected boolean isDuplicateSourceAccountingLine( AccountingDocument accountingDocument, AccountingLine accountingLine) { // only check source accounting lines if (!(accountingLine instanceof ExpenseTransferSourceAccountingLine)) { return false; } LaborExpenseTransferDocumentBase expenseTransferDocument = (LaborExpenseTransferDocumentBase) accountingDocument; List<ExpenseTransferSourceAccountingLine> sourceAccountingLines = expenseTransferDocument.getSourceAccountingLines(); List<String> key = defaultKeyOfExpenseTransferAccountingLine(); int counter = 0; for (AccountingLine sourceAccountingLine : sourceAccountingLines) { boolean isExisting = ObjectUtil.equals(accountingLine, sourceAccountingLine, key); counter = isExisting ? counter + 1 : counter; if (counter > 1) { return true; } } return false; }
/** * Tokenize the input line with the given deliminator and populate the given object with values of * the tokens * * @param targetObject the target object * @param line the input line * @param delim the deminator that separates the fields in the given line * @param keyFields the specified fields */ public static void convertLineToBusinessObject( Object targetObject, String line, String delim, String fieldNames) { List<String> tokens = split(line, delim); List<String> keyFields = Arrays.asList(StringUtils.split(fieldNames, delim)); ObjectUtil.buildObject(targetObject, tokens.toArray(), keyFields); }
/** * Tokenize the input line with the given deliminator and populate the given object with values of * the tokens * * @param targetObject the target object * @param line the input line * @param delim the deminator that separates the fields in the given line * @param keyFields the specified fields */ public static void convertLineToBusinessObject( Object targetObject, String line, String delim, List<String> keyFields) { String[] tokens = StringUtils.split(line, delim); ObjectUtil.buildObject(targetObject, tokens, keyFields); }
/** * update a given collection entry with the pending entry obtained from the given field values and * isApproved * * @param entryCollection the given entry collection * @param fieldValues the given field values * @param isApproved indicate if the resulting pending entry has been approved * @param isConsolidated indicate if the collection entries have been consolidated */ protected void updateCollection( Collection entryCollection, Map fieldValues, boolean isApproved, boolean isConsolidated, Class clazz) { // go through the pending entries to update the balance collection Iterator<LaborLedgerPendingEntry> pendingEntryIterator = laborLedgerPendingEntryService.findPendingLedgerEntriesForLedgerBalance( fieldValues, isApproved); while (pendingEntryIterator.hasNext()) { LaborLedgerPendingEntry pendingEntry = pendingEntryIterator.next(); // if consolidated, change the following fields into the default values for consolidation if (isConsolidated) { pendingEntry.setSubAccountNumber(Constant.CONSOLIDATED_SUB_ACCOUNT_NUMBER); pendingEntry.setFinancialSubObjectCode(Constant.CONSOLIDATED_SUB_OBJECT_CODE); pendingEntry.setFinancialObjectTypeCode(Constant.CONSOLIDATED_OBJECT_TYPE_CODE); } if (LedgerBalance.class.isAssignableFrom(clazz)) { try { LedgerBalance ledgerBalance = laborLedgerBalanceService.findLedgerBalance(entryCollection, pendingEntry); if (ledgerBalance == null) { Object newLedgerBalance = clazz.newInstance(); ObjectUtil.buildObject(newLedgerBalance, pendingEntry); ledgerBalance = (LedgerBalance) newLedgerBalance; entryCollection.add(ledgerBalance); } laborLedgerBalanceService.updateLedgerBalance(ledgerBalance, pendingEntry); ledgerBalance .getDummyBusinessObject() .setConsolidationOption(isConsolidated ? Constant.CONSOLIDATION : Constant.DETAIL); ledgerBalance .getDummyBusinessObject() .setPendingEntryOption( isApproved ? Constant.APPROVED_PENDING_ENTRY : Constant.ALL_PENDING_ENTRY); } catch (Exception e) { LOG.error("cannot create a new object of type: " + clazz.getName() + "/n" + e); } } else if (LedgerEntry.class.isAssignableFrom(clazz)) { LedgerEntry ledgerEntry = new LedgerEntry(); ObjectUtil.buildObject(ledgerEntry, pendingEntry); ledgerEntry .getDummyBusinessObject() .setConsolidationOption(isConsolidated ? Constant.CONSOLIDATION : Constant.DETAIL); ledgerEntry .getDummyBusinessObject() .setPendingEntryOption( isApproved ? Constant.APPROVED_PENDING_ENTRY : Constant.ALL_PENDING_ENTRY); entryCollection.add(ledgerEntry); } else { LOG.warn("The class, " + clazz.getName() + ", is unregistered with the method."); return; } } }