use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class CuRequisitionServiceImpl method checkAutomaticPurchaseOrderRules.
/**
* Checks the rule for Automatic Purchase Order eligibility of the requisition and return a String containing the reason why the
* requisition was not eligible to become an APO if it was not eligible, or return an empty String if the requisition is
* eligible to become an APO
*
* @param requisition the requisition document to be checked for APO eligibility.
* @return String containing the reason why the requisition was not eligible to become an APO if it was not eligible, or an
* empty String if the requisition is eligible to become an APO.
*/
protected String checkAutomaticPurchaseOrderRules(RequisitionDocument requisition) {
String requisitionSource = requisition.getRequisitionSourceCode();
KualiDecimal reqTotal = requisition.getTotalDollarAmount();
KualiDecimal apoLimit = purapService.getApoLimit(requisition.getVendorContractGeneratedIdentifier(), requisition.getChartOfAccountsCode(), requisition.getOrganizationCode());
requisition.setOrganizationAutomaticPurchaseOrderLimit(apoLimit);
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() reqId = " + requisition.getPurapDocumentIdentifier() + "; apoLimit = " + apoLimit + "; reqTotal = " + reqTotal);
}
if (apoLimit == null) {
return "APO limit is empty.";
} else {
if (reqTotal.compareTo(apoLimit) == 1) {
return "Requisition total is greater than the APO limit.";
}
}
if (reqTotal.compareTo(KualiDecimal.ZERO) <= 0) {
return "Requisition total is not greater than zero.";
}
if (LOG.isDebugEnabled()) {
LOG.debug("isAPO() vendor #" + requisition.getVendorHeaderGeneratedIdentifier() + "-" + requisition.getVendorDetailAssignedIdentifier());
}
if (requisition.getVendorHeaderGeneratedIdentifier() == null || requisition.getVendorDetailAssignedIdentifier() == null) {
return "Vendor was not selected from the vendor database.";
} else {
VendorDetail vendorDetail = vendorService.getVendorDetail(requisition.getVendorHeaderGeneratedIdentifier(), requisition.getVendorDetailAssignedIdentifier());
if (vendorDetail == null) {
return "Error retrieving vendor from the database.";
}
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode())) {
return "Requisition does not have all of the vendor address fields that are required for Purchase Order.";
}
requisition.setVendorRestrictedIndicator(vendorDetail.getVendorRestrictedIndicator());
if (requisition.getVendorRestrictedIndicator() != null && requisition.getVendorRestrictedIndicator()) {
return "Selected vendor is marked as restricted.";
}
if (vendorDetail.isVendorDebarred()) {
return "Selected vendor is marked as a debarred vendor";
}
requisition.setVendorDetail(vendorDetail);
if ((!PurapConstants.RequisitionSources.B2B.equals(requisitionSource)) && ObjectUtils.isNull(requisition.getVendorContractGeneratedIdentifier())) {
Person initiator = getPersonService().getPerson(requisition.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
VendorContract b2bContract = vendorService.getVendorB2BContract(vendorDetail, initiator.getCampusCode());
if (b2bContract != null) {
return "Standard requisition with no contract selected but a B2B contract exists for the selected vendor.";
}
}
// if the vendor is selected through vendor contract is selected
if (StringUtils.isNotBlank(requisition.getVendorContractName())) {
boolean routeToCM = parameterService.getParameterValueAsBoolean(RequisitionDocument.class, CUPurapParameterConstants.ROUTE_REQS_WITH_EXPIRED_CONTRACT_TO_CM, Boolean.FALSE);
if (routeToCM && vendorService.isVendorContractExpired(requisition, requisition.getVendorContractGeneratedIdentifier(), vendorDetail)) {
return "Contracted Vendor used where the contract end date is expired.";
}
}
}
// if vendor address isn't complete, no APO
if (StringUtils.isBlank(requisition.getVendorLine1Address()) || StringUtils.isBlank(requisition.getVendorCityName()) || StringUtils.isBlank(requisition.getVendorCountryCode()) || !postalCodeValidationService.validateAddress(requisition.getVendorCountryCode(), requisition.getVendorStateCode(), requisition.getVendorPostalCode(), "", "")) {
return "Requistion does not contain a complete vendor address";
}
// These are needed for commodity codes. They are put in here so that
// we don't have to loop through items too many times.
String purchaseOrderRequiresCommodityCode = parameterService.getParameterValueAsString(PurchaseOrderDocument.class, PurapRuleConstants.ITEMS_REQUIRE_COMMODITY_CODE_IND);
boolean commodityCodeRequired = purchaseOrderRequiresCommodityCode.equals("Y");
for (Iterator iter = requisition.getItems().iterator(); iter.hasNext(); ) {
RequisitionItem item = (RequisitionItem) iter.next();
if (item.isItemRestrictedIndicator()) {
return "Requisition contains an item that is marked as restricted.";
}
// We only need to check the commodity codes if this is an above the line item.
if (item.getItemType().isLineItemIndicator()) {
String commodityCodesReason = "";
List<VendorCommodityCode> vendorCommodityCodes = commodityCodeRequired ? requisition.getVendorDetail().getVendorCommodities() : null;
commodityCodesReason = checkAPORulesPerItemForCommodityCodes(item, vendorCommodityCodes, commodityCodeRequired);
if (StringUtils.isNotBlank(commodityCodesReason)) {
return commodityCodesReason;
}
}
if (PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE.equals(item.getItemType().getItemTypeCode()) || PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE.equals(item.getItemType().getItemTypeCode())) {
if ((item.getItemUnitPrice() != null) && ((BigDecimal.ZERO.compareTo(item.getItemUnitPrice())) != 0)) {
// discount or trade-in item has unit price that is not empty or zero
return "Requisition contains a " + item.getItemType().getItemTypeDescription() + " item, so it does not qualify as an APO.";
}
}
}
if (StringUtils.isNotEmpty(requisition.getRecurringPaymentTypeCode())) {
return "Payment type is marked as recurring.";
}
if ((requisition.getPurchaseOrderTotalLimit() != null) && (KualiDecimal.ZERO.compareTo(requisition.getPurchaseOrderTotalLimit()) != 0)) {
LOG.debug("isAPO() po total limit is not null and not equal to zero; return false.");
return "The 'PO not to exceed' amount has been entered.";
}
if (StringUtils.isNotEmpty(requisition.getAlternate1VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate2VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate3VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate4VendorName()) || StringUtils.isNotEmpty(requisition.getAlternate5VendorName())) {
LOG.debug("isAPO() alternate vendor name exists; return false.");
return "Requisition contains additional suggested vendor names.";
}
if (requisition.isPostingYearNext() && !purapService.isTodayWithinApoAllowedRange()) {
return "Requisition is set to encumber next fiscal year and approval is not within APO allowed date range.";
}
return "";
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method setCollegeAndDepartmentBasedOnPrimaryDepartment.
/**
* Sets the College and Department based on the initiator primary department.
*
* @param documentForm
*/
private void setCollegeAndDepartmentBasedOnPrimaryDepartment(IWantDocumentForm documentForm) {
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
String primaryDeptOrg = null;
IWantDocument iWantDocument = null;
if (documentForm != null && documentForm.getDocument() != null) {
iWantDocument = (IWantDocument) documentForm.getDocument();
}
if (iWantDocument != null && StringUtils.isEmpty(iWantDocument.getCollegeLevelOrganization())) {
Person currentUser = GlobalVariables.getUserSession().getPerson();
Entity entityInfo = KimApiServiceLocator.getIdentityService().getEntityByPrincipalId(currentUser.getPrincipalId());
if (ObjectUtils.isNotNull(entityInfo)) {
if (ObjectUtils.isNotNull(entityInfo.getEmploymentInformation()) && entityInfo.getEmploymentInformation().size() > 0) {
EntityEmployment employmentInformation = entityInfo.getEmploymentInformation().get(0);
String primaryDepartment = employmentInformation.getPrimaryDepartmentCode();
primaryDeptOrg = primaryDepartment.substring(primaryDepartment.lastIndexOf('-') + 1, primaryDepartment.length());
String cLevelOrg = iWantDocumentService.getCLevelOrganizationForDLevelOrg(primaryDepartment);
((IWantDocument) documentForm.getDocument()).setCollegeLevelOrganization(cLevelOrg);
}
}
}
if (iWantDocument != null && StringUtils.isNotEmpty(iWantDocument.getCollegeLevelOrganization())) {
String cLevelOrg = iWantDocument.getCollegeLevelOrganization();
documentForm.getDeptOrgKeyLabels().clear();
documentForm.getDeptOrgKeyLabels().add(new ConcreteKeyValue("", "Please Select"));
List<LevelOrganization> dLevelOrgs = iWantDocumentService.getDLevelOrganizations(cLevelOrg);
for (LevelOrganization levelOrganization : dLevelOrgs) {
documentForm.getDeptOrgKeyLabels().add(new ConcreteKeyValue(levelOrganization.getCode(), levelOrganization.getCodeAndDescription()));
}
if (primaryDeptOrg != null) {
iWantDocument.setDepartmentLevelOrganization(primaryDeptOrg);
}
}
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method getPersonData.
/**
* @see edu.cornell.kfs.module.purap.document.service.IWantDocumentService#getPersonData(java.lang.String)
*/
public PersonData getPersonData(String principalName) {
PersonData personData = new PersonData();
Person person = personService.getPersonByPrincipalName(principalName);
personData.setPersonName(person.getNameUnmasked());
personData.setNetID(principalName);
personData.setEmailAddress(person.getEmailAddressUnmasked());
personData.setPhoneNumber(person.getPhoneNumberUnmasked());
personData.setCampusAddress(getPersonCampusAddress(principalName));
return personData;
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class AccountGlobalRule method checkGeneralRules.
/**
* This method checks some of the general business rules associated with this document Such as: valid user for fiscal officer,
* supervisor or account manager (and not the same individual) are they trying to use an expired continuation account
*
* @param maintenanceDocument
* @return false on rules violation
*/
protected boolean checkGeneralRules(MaintenanceDocument maintenanceDocument) {
LOG.info("checkGeneralRules called");
Person fiscalOfficer = newAccountGlobal.getAccountFiscalOfficerUser();
Person accountManager = newAccountGlobal.getAccountManagerUser();
Person accountSupervisor = newAccountGlobal.getAccountSupervisoryUser();
boolean success = true;
if (isNonSystemSupervisorEditingAClosedAccount(maintenanceDocument, GlobalVariables.getUserSession().getPerson())) {
success &= false;
putFieldError(KFSPropertyConstants.ACCOUNT_CHANGE_DETAILS, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ONLY_SUPERVISORS_CAN_EDIT);
}
if (StringUtils.isNotBlank(newAccountGlobal.getAccountFiscalOfficerSystemIdentifier()) && (ObjectUtils.isNull(fiscalOfficer) || StringUtils.isEmpty(fiscalOfficer.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, KFSConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.namespace, KFSConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.name, fiscalOfficer.getPrincipalId()))) {
final String fiscalOfficerName = fiscalOfficer != null ? fiscalOfficer.getName() : newAccountGlobal.getAccountFiscalOfficerSystemIdentifier();
super.putFieldError(KFSPropertyConstants.ACCOUNT_FISCAL_OFFICER_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] { fiscalOfficerName, KFSConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.namespace, KFSConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.name });
success = false;
} else if ((ObjectUtils.isNotNull(fiscalOfficer) && StringUtils.isNotBlank(fiscalOfficer.getPrincipalName()) && ObjectUtils.isNull(fiscalOfficer.getPrincipalId()))) {
super.putFieldError(KFSPropertyConstants.ACCOUNT_FISCAL_OFFICER_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_PRINCPAL_NAME_FISCAL_OFFICER_SUPER_INVALID);
success = false;
}
if (StringUtils.isNotBlank(newAccountGlobal.getAccountsSupervisorySystemsIdentifier()) && (ObjectUtils.isNull(accountSupervisor) || StringUtils.isEmpty(accountSupervisor.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.namespace, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.name, accountSupervisor.getPrincipalId()))) {
final String accountSupervisorName = accountSupervisor != null ? accountSupervisor.getName() : newAccountGlobal.getAccountsSupervisorySystemsIdentifier();
super.putFieldError(KFSPropertyConstants.ACCOUNT_SUPERVISORY_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] { accountSupervisorName, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.namespace, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.name });
success = false;
} else if (ObjectUtils.isNotNull(accountSupervisor) && StringUtils.isNotBlank(accountSupervisor.getPrincipalName()) && ObjectUtils.isNull(accountSupervisor.getPrincipalId())) {
super.putFieldError(KFSPropertyConstants.ACCOUNT_SUPERVISORY_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_PRINCPAL_NAME_ACCOUNT_SUPER_INVALID);
success = false;
}
if (StringUtils.isNotBlank(newAccountGlobal.getAccountManagerSystemIdentifier()) && (ObjectUtils.isNull(accountManager) || StringUtils.isEmpty(accountManager.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.namespace, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.name, accountManager.getPrincipalId()))) {
final String accountManagerName = accountManager != null ? accountManager.getName() : newAccountGlobal.getAccountManagerSystemIdentifier();
super.putFieldError(KFSPropertyConstants.ACCOUNT_MANAGER_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] { accountManagerName, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.namespace, KFSConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.name });
success = false;
} else if (ObjectUtils.isNotNull(accountManager) && StringUtils.isNotBlank(accountManager.getPrincipalName()) && ObjectUtils.isNull(accountManager.getPrincipalId())) {
super.putFieldError(KFSPropertyConstants.ACCOUNT_MANAGER_USER + "." + KFSPropertyConstants.KUALI_USER_PERSON_USER_IDENTIFIER, KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_PRINCPAL_NAME_ACCOUNT_MANAGER_INVALID);
success = false;
}
// check FringeBenefit account rules
success &= checkFringeBenefitAccountRule(newAccountGlobal);
// the supervisor cannot be the same as the fiscal officer or account manager.
if (isSupervisorSameAsFiscalOfficer(newAccountGlobal)) {
success &= false;
putFieldError(KFSPropertyConstants.ACCOUNTS_SUPERVISORY_SYSTEMS_IDENTIFIER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_BE_FISCAL_OFFICER);
}
if (isSupervisorSameAsManager(newAccountGlobal)) {
success &= false;
putFieldError(KFSPropertyConstants.ACCOUNT_MANAGER_SYSTEM_IDENTIFIER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_BE_ACCT_MGR);
}
// disallow continuation account being expired
if (isContinuationAccountExpired(newAccountGlobal)) {
success &= false;
putFieldError(KFSPropertyConstants.CONTINUATION_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCOUNT_EXPIRED_CONTINUATION);
}
// only need to do this check if the entered information does not already violate the rules
if (!isSupervisorSameAsFiscalOfficer(newAccountGlobal) && !isSupervisorSameAsManager(newAccountGlobal)) {
success &= checkAllAccountUsers(newAccountGlobal, fiscalOfficer, accountManager, accountSupervisor);
}
success &= checkCfda(newAccountGlobal.getAccountCfdaNumber());
return success;
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class DisbursementVoucherAction method hasFullEdit.
/**
* Determines if the current user has full edit permissions on the document, which would allow them to repopulate the payee
*
* @param document the document to check for full edit permissions on
* @return true if full edit is allowed on the document, false otherwise
*/
protected boolean hasFullEdit(DisbursementVoucherDocument document) {
final Person user = GlobalVariables.getUserSession().getPerson();
final TransactionalDocumentPresentationController documentPresentationController = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(document);
final TransactionalDocumentAuthorizer documentAuthorizer = (TransactionalDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(document);
Set<String> documentActions = documentPresentationController.getDocumentActions(document);
documentActions = documentAuthorizer.getDocumentActions(document, user, documentActions);
Set<String> editModes = documentPresentationController.getEditModes(document);
editModes = documentAuthorizer.getEditModes(document, user, editModes);
return documentActions.contains(KRADConstants.KUALI_ACTION_CAN_EDIT) && editModes.contains("fullEntry");
}
Aggregations