use of org.kuali.kfs.krad.service.BusinessObjectService in project cu-kfs by CU-CommunityApps.
the class CUObjectCodeGlobal method setCode.
/**
* @param code the code to set
*/
public void setCode(String code) {
this.code = code;
this.cgReportingCode = code;
BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
HashMap<String, String> keys = new HashMap<String, String>();
keys.put("chartOfAccountsCode", this.chartOfAccountsCode);
// lookup table has class attribute defined as "code"
keys.put("code", this.code);
contractGrantReportingCode = (ContractGrantReportingCode) bos.findByPrimaryKey(ContractGrantReportingCode.class, keys);
}
use of org.kuali.kfs.krad.service.BusinessObjectService in project cu-kfs by CU-CommunityApps.
the class CuAccountDelegateGlobal method generateGlobalChangesToPersist.
/**
* @see org.kuali.kfs.krad.document.GlobalBusinessObject#applyGlobalChanges(org.kuali.rice.krad.bo.BusinessObject)
*/
@SuppressWarnings("deprecation")
public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class);
List<AccountDelegate> persistables = new ArrayList();
List<AccountDelegateGlobalDetail> changeDocuments = this.getDelegateGlobals();
List<AccountGlobalDetail> accountDetails = this.getAccountGlobalDetails();
for (AccountDelegateGlobalDetail changeDocument : changeDocuments) {
for (AccountGlobalDetail accountDetail : accountDetails) {
Account account = (Account) boService.findByPrimaryKey(Account.class, accountDetail.getPrimaryKeys());
// the busines rules for this document should have caught this.
if (account == null) {
throw new RuntimeException("Account [" + accountDetail.getChartOfAccountsCode() + "-" + accountDetail.getAccountNumber() + "] was not present in the database. " + "This should never happen under normal circumstances, as an invalid account should have " + "been caught by the Business Rules infrastructure.");
}
// attempt to load the existing Delegate from the DB, if it exists. we do this to avoid
// versionNumber conflicts if we tried to just insert a new record that already existed.
Map pkMap = new HashMap();
// chartOfAccountsCode & accountNumber
pkMap.putAll(accountDetail.getPrimaryKeys());
pkMap.put("financialDocumentTypeCode", changeDocument.getFinancialDocumentTypeCode());
pkMap.put("accountDelegateSystemId", changeDocument.getAccountDelegateUniversalId());
AccountDelegate delegate = (AccountDelegate) boService.findByPrimaryKey(AccountDelegate.class, pkMap);
// so lets populate it with the primary keys
if (delegate == null) {
delegate = new AccountDelegate();
delegate.setChartOfAccountsCode(accountDetail.getChartOfAccountsCode());
delegate.setAccountNumber(accountDetail.getAccountNumber());
delegate.setAccountDelegateSystemId(changeDocument.getAccountDelegateUniversalId());
delegate.setFinancialDocumentTypeCode(changeDocument.getFinancialDocumentTypeCode());
delegate.setActive(true);
} else {
delegate.setActive(true);
}
// APPROVAL FROM AMOUNT
delegate.setFinDocApprovalFromThisAmt(changeDocument.getApprovalFromThisAmount());
// APPROVAL TO AMOUNT
delegate.setFinDocApprovalToThisAmount(changeDocument.getApprovalToThisAmount());
// PRIMARY ROUTING
delegate.setAccountsDelegatePrmrtIndicator(changeDocument.getAccountDelegatePrimaryRoutingIndicator());
// START DATE
if (changeDocument.getAccountDelegateStartDate() != null) {
delegate.setAccountDelegateStartDate(new Date(changeDocument.getAccountDelegateStartDate().getTime()));
}
persistables.add(delegate);
}
}
return new ArrayList<PersistableBusinessObject>(persistables);
}
use of org.kuali.kfs.krad.service.BusinessObjectService in project cu-kfs by CU-CommunityApps.
the class ObjectCodeGlobalExtensionRule method checkContractGrantReportingCode.
/*
* Verify value has been entered for required attribute cgReportingCode
*/
protected boolean checkContractGrantReportingCode(CUObjectCodeGlobal ocg) {
boolean success = true;
String cgReportingCode = ocg.getCgReportingCode();
for (GlobalBusinessObjectDetail ocgd : ocg.getAllDetailObjects()) {
String chartOfAccountsCode = ((ObjectCodeGlobalDetail) ocgd).getChartOfAccountsCode();
if ((!StringUtils.isBlank(cgReportingCode)) && (!StringUtils.isBlank(cgReportingCode))) {
// have values for both table primary keys
HashMap<String, String> fieldValues = new HashMap<String, String>();
fieldValues.put("chartOfAccountsCode", chartOfAccountsCode);
// prompt table has attribute defined as "code" and we need to use it for the lookup
fieldValues.put("code", cgReportingCode);
BusinessObjectService bos = SpringContext.getBean(BusinessObjectService.class);
Collection<ContractGrantReportingCode> retVals = bos.findMatching(ContractGrantReportingCode.class, fieldValues);
if (retVals.isEmpty()) {
putFieldError("cgReportingCode", CUKFSKeyConstants.ERROR_DOCUMENT_OBJCDMAINT_CG_RPT_CAT_CODE_NOT_EXIST, new String[] { chartOfAccountsCode, cgReportingCode });
success = false;
} else {
// verify the value to be assigned is active
for (ContractGrantReportingCode sfp : retVals) {
if (!sfp.isActive()) {
putFieldError("cgReportingCode", KFSKeyConstants.ERROR_INACTIVE, getFieldLabel(CUObjectCodeGlobal.class, "cgReportingCode"));
success = false;
}
}
}
}
// implied else coa or cgReportingCode or both are blank, caught by maintenance doc having these fields defined as "required", else coding to report this causes double error messages
}
return success;
}
use of org.kuali.kfs.krad.service.BusinessObjectService in project cu-kfs by CU-CommunityApps.
the class CuBatchExtractServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
BusinessObjectService businessObjectService = buildMockBusinessObjectService();
DataDictionaryService dataDictionaryService = buildMockDataDictionaryService();
cuBatchExtractServiceImpl = new CuBatchExtractServiceImpl();
cuBatchExtractServiceImpl.setBusinessObjectService(businessObjectService);
cuBatchExtractServiceImpl.setDataDictionaryService(dataDictionaryService);
}
use of org.kuali.kfs.krad.service.BusinessObjectService in project cu-kfs by CU-CommunityApps.
the class CuBatchExtractServiceImplTest method buildMockBusinessObjectService.
@SuppressWarnings({ "rawtypes", "unchecked" })
private BusinessObjectService buildMockBusinessObjectService() {
BusinessObjectService businessObjectService = EasyMock.createMock(BusinessObjectService.class);
// Had to leave the boClassArg's inner type as a raw type, due to compiling problems from a bounded-type service method argument.
Capture<Class> boClassArg = EasyMock.newCapture();
Capture<Map<String, ?>> criteriaArg = EasyMock.newCapture();
EasyMock.expect(businessObjectService.findMatching(EasyMock.<Class>capture(boClassArg), EasyMock.capture(criteriaArg))).andStubAnswer(() -> findMatching(boClassArg.getValue(), criteriaArg.getValue()));
EasyMock.replay(businessObjectService);
return businessObjectService;
}
Aggregations