Search in sources :

Example 16 with MessageMap

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;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PersonService(org.kuali.rice.kim.api.identity.PersonService) DisbursementVoucherPayeeDetail(org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail) Person(org.kuali.rice.kim.api.identity.Person) MessageMap(org.kuali.kfs.krad.util.MessageMap) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService)

Example 17 with MessageMap

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;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) CuDisbursementVoucherPayeeDetail(edu.cornell.kfs.fp.businessobject.CuDisbursementVoucherPayeeDetail) Person(org.kuali.rice.kim.api.identity.Person) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 18 with MessageMap

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);
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) MaintenanceDocument(org.kuali.kfs.krad.maintenance.MaintenanceDocument) VendorMaintainableImpl(org.kuali.kfs.vnd.document.VendorMaintainableImpl) MessageMap(org.kuali.kfs.krad.util.MessageMap) ValidationException(org.kuali.kfs.krad.exception.ValidationException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException)

Example 19 with MessageMap

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);
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) MaintenanceDocument(org.kuali.kfs.krad.maintenance.MaintenanceDocument) VendorMaintainableImpl(org.kuali.kfs.vnd.document.VendorMaintainableImpl) MessageMap(org.kuali.kfs.krad.util.MessageMap) ValidationException(org.kuali.kfs.krad.exception.ValidationException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException)

Example 20 with MessageMap

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);
    }
}
Also used : PurapService(org.kuali.kfs.module.purap.document.service.PurapService) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Aggregations

MessageMap (org.kuali.kfs.krad.util.MessageMap)25 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)5 UserSession (org.kuali.kfs.krad.UserSession)4 Person (org.kuali.rice.kim.api.identity.Person)4 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)3 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)3 ValidationException (org.kuali.kfs.krad.exception.ValidationException)3 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)3 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)3 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)2 CuVendorCreditMemoDocument (edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DisbursementVoucherPayeeDetail (org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail)2 MaintenanceDocument (org.kuali.kfs.krad.maintenance.MaintenanceDocument)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)2 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)2 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)2 ParseException (org.kuali.kfs.sys.exception.ParseException)2