use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.
the class CuDisbursementVoucherEmployeeInformationValidation method validate.
public boolean validate(AttributedDocumentEvent event) {
LOG.debug("validate start");
boolean isValid = true;
CuDisbursementVoucherDocument document = (CuDisbursementVoucherDocument) getAccountingDocumentForValidation();
DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
if (!payeeDetail.isEmployee() || payeeDetail.isVendor() || !(document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isSaved())) {
return true;
}
String employeeId = payeeDetail.getDisbVchrPayeeIdNumber();
Person employee = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(employeeId);
MessageMap errors = GlobalVariables.getMessageMap();
errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
boolean stateIsInitiated = workflowDocument.isInitiated() || workflowDocument.isSaved();
if (ObjectUtils.isNull(employee)) {
employee = SpringContext.getBean(PersonService.class).getPerson(employeeId);
} else {
if (!KFSConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode()) && !CUKFSConstants.EMPLOYEE_RETIRED_STATUS.equals(employee.getEmployeeStatusCode())) {
// If employee is found, then check that employee is active or retired if the doc has not already been routed.
if (stateIsInitiated) {
String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_INACTIVE, label);
isValid = false;
}
}
}
// check existence of employee
if (employee == null) {
// If employee is not found, report existence error
String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_EXISTENCE, label);
isValid = false;
}
errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
return isValid;
}
use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.
the class CuDisbursementVoucherPayeeInitiatorValidation method validate.
public boolean validate(AttributedDocumentEvent event) {
LOG.debug("validate start");
boolean isValid = true;
CuDisbursementVoucherDocument document = (CuDisbursementVoucherDocument) accountingDocumentForValidation;
CuDisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
MessageMap errors = GlobalVariables.getMessageMap();
errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
String uuid = null;
// If payee is a vendor, then look up SSN and look for SSN in the employee table
if (payeeDetail.isVendor() && StringUtils.isNotBlank(payeeDetail.getDisbVchrVendorHeaderIdNumber())) {
VendorDetail dvVendor = retrieveVendorDetail(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger(), payeeDetail.getDisbVchrVendorDetailAssignedIdNumberAsInteger());
// if the vendor tax type is SSN, then check the tax number
if (dvVendor != null && TAX_TYPE_SSN.equals(dvVendor.getVendorHeader().getVendorTaxTypeCode())) {
// check ssn against employee table
Person user = retrieveEmployeeBySSN(dvVendor.getVendorHeader().getVendorTaxNumber());
if (user != null) {
uuid = user.getPrincipalId();
}
}
} else if (payeeDetail.isEmployee()) {
Person employee = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeDetail.getDisbVchrEmployeeIdNumber());
uuid = employee.getPrincipalId();
} else if (payeeDetail.isStudent() || payeeDetail.isAlumni()) {
uuid = payeeDetail.getDisbVchrPayeeIdNumber();
}
// If a uuid was found for payee, check it against the initiator uuid
if (StringUtils.isNotBlank(uuid)) {
Person initUser = getInitiator(document);
if (uuid.equals(initUser.getPrincipalId())) {
errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_PAYEE_INITIATOR);
isValid = false;
}
}
errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
return isValid;
}
use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method addVendor.
/*
* create vendor document and route
*/
private String addVendor(VendorBatchDetail vendorBatch) {
GlobalVariables.setMessageMap(new MessageMap());
// create and route doc as system user
// GlobalVariables.setUserSession(new UserSession("kfs"));
LOG.info("addVendor " + vendorBatch.getLogData());
try {
MaintenanceDocument vendorDoc = (MaintenanceDocument) documentService.getNewDocument(VENDOR_DOCUMENT_TYPE_NAME);
vendorDoc.getDocumentHeader().setDocumentDescription(getDocumentDescription(vendorBatch, true));
VendorMaintainableImpl vImpl = (VendorMaintainableImpl) vendorDoc.getNewMaintainableObject();
vImpl.setMaintenanceAction(KFSConstants.MAINTENANCE_NEW_ACTION);
VendorDetail vDetail = (VendorDetail) vImpl.getBusinessObject();
setupVendorDetailFields(vDetail, vendorBatch);
setupInsuranceTracking((VendorDetailExtension) vDetail.getExtension(), vendorBatch);
vDetail.setVendorAddresses(getVendorAddresses(vendorBatch.getVendorAddresses(), vDetail));
vDetail.setVendorContacts(getVendorContacts(vendorBatch.getVendorContacts()));
VendorHeader vHeader = vDetail.getVendorHeader();
setupVendorHeaderFields(vHeader, vendorBatch);
vHeader.setVendorSupplierDiversities(getVendorSupplierDiversities(vendorBatch.getVendorSupplierDiversities()));
vDetail.setVendorHeader(vHeader);
vImpl.setBusinessObject(vDetail);
vendorDoc.setNewMaintainableObject(vImpl);
addNotes(vendorDoc, vendorBatch);
if (StringUtils.isNotBlank(vendorBatch.getAttachmentFiles())) {
loadDocumentAttachments(vendorDoc, Arrays.asList(vendorBatch.getAttachmentFiles().split(COLLECTION_FIELD_DELIMITER)));
}
documentService.routeDocument(vendorDoc, KFSConstants.EMPTY_STRING, null);
return vendorDoc.getDocumentNumber();
} catch (Exception e) {
LOG.info("addVendor STE " + e.getStackTrace() + e.toString());
return getFailRequestMessage(e);
}
}
use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method updateVendor.
/*
* update vendor record. vendor number must be valid.
*/
private String updateVendor(VendorBatchDetail vendorBatch) {
GlobalVariables.setMessageMap(new MessageMap());
try {
MaintenanceDocument vendorDoc = (MaintenanceDocument) documentService.getNewDocument(VENDOR_DOCUMENT_TYPE_NAME);
vendorDoc.getDocumentHeader().setDocumentDescription(getDocumentDescription(vendorBatch, false));
LOG.info("updateVendor " + vendorBatch.getLogData());
VendorDetail vendor = cuVendorService.getByVendorNumber(vendorBatch.getVendorNumber());
if (vendor != null) {
// Vendor does not eist
VendorMaintainableImpl oldVendorImpl = (VendorMaintainableImpl) vendorDoc.getOldMaintainableObject();
oldVendorImpl.setBusinessObject(vendor);
} else {
// Vendor does not eist
return "Failed request : Vendor " + vendorBatch.getVendorNumber() + " Not Found.";
}
VendorMaintainableImpl vImpl = (VendorMaintainableImpl) vendorDoc.getNewMaintainableObject();
vImpl.setMaintenanceAction(KFSConstants.MAINTENANCE_EDIT_ACTION);
vendorDoc.getNewMaintainableObject().setDocumentNumber(vendorDoc.getDocumentNumber());
vImpl.setBusinessObject((VendorDetail) ObjectUtils.deepCopy(vendor));
VendorDetail vDetail = (VendorDetail) vImpl.getBusinessObject();
setupVendorDetailFields(vDetail, vendorBatch);
setupInsuranceTracking((VendorDetailExtension) vDetail.getExtension(), vendorBatch);
updateVendorAddresses(vendorBatch.getVendorAddresses(), vendor, vDetail);
updateVendorContacts(vendorBatch.getVendorContacts(), vendor, vDetail);
updateVendorSupplierDiversitys(vendorBatch.getVendorSupplierDiversities(), vendor, vDetail);
setupVendorHeaderFields(vDetail.getVendorHeader(), vendorBatch);
vImpl.setBusinessObject(vDetail);
vendorDoc.setNewMaintainableObject(vImpl);
addNotes(vendorDoc, vendorBatch);
// attachment
if (StringUtils.isNotBlank(vendorBatch.getAttachmentFiles())) {
loadDocumentAttachments(vendorDoc, Arrays.asList(vendorBatch.getAttachmentFiles().split(COLLECTION_FIELD_DELIMITER)));
}
// end attachment
documentService.routeDocument(vendorDoc, KFSConstants.EMPTY_STRING, null);
return vendorDoc.getDocumentNumber();
} catch (Exception e) {
LOG.info("updateVendor STE " + e.getStackTrace() + e.toString());
return getFailRequestMessage(e);
}
}
use of org.kuali.kfs.krad.util.MessageMap in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method saveDocumentNoValidationUsingClearErrorMap.
/**
* Sets the error map to a new, empty error map before calling saveDocumentNoValidation to save the document.
*
* @param document The purchase order document to be saved.
*/
protected void saveDocumentNoValidationUsingClearErrorMap(PurchasingDocument document) {
MessageMap errorHolder = GlobalVariables.getMessageMap();
GlobalVariables.setMessageMap(new MessageMap());
try {
SpringContext.getBean(PurapService.class).saveDocumentNoValidation(document);
} finally {
GlobalVariables.setMessageMap(errorHolder);
}
}
Aggregations