Search in sources :

Example 1 with UserSession

use of org.kuali.kfs.krad.UserSession in project cu-kfs by CU-CommunityApps.

the class VendorDetailInquiryPresentationController method getConditionallyHiddenPropertyNames.

/**
 * Implement this method to hide fields based on specific data in the record being inquired into
 *
 * @return Set of property names that should be hidden
 */
@Override
public Set<String> getConditionallyHiddenPropertyNames(BusinessObject businessObject) {
    Set<String> retVal = new HashSet<String>();
    IdentityManagementService idService = SpringContext.getBean(IdentityManagementService.class);
    UserSession uSession = GlobalVariables.getUserSession();
    Map<String, String> permissionDetails = new HashMap<String, String>();
    permissionDetails.put(KewApiConstants.DOCUMENT_TYPE_NAME_DETAIL, "PVEN");
    boolean canViewAttachments = idService.isAuthorizedByTemplateName(uSession.getPrincipalId(), KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.VIEW_NOTE_ATTACHMENT, permissionDetails, null);
    if (!canViewAttachments) {
        VendorDetail detail = (VendorDetail) businessObject;
        VendorService vendorService = SpringContext.getBean(VendorService.class);
        List<Note> boNotes = vendorService.getVendorNotes(detail);
        for (int i = 0; i < boNotes.size(); i++) retVal.add("boNotes[" + i + "].attachmentLink");
    }
    return retVal;
}
Also used : HashMap(java.util.HashMap) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) IdentityManagementService(org.kuali.rice.kim.api.services.IdentityManagementService) UserSession(org.kuali.kfs.krad.UserSession) Note(org.kuali.kfs.krad.bo.Note) HashSet(java.util.HashSet)

Example 2 with UserSession

use of org.kuali.kfs.krad.UserSession in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method buildDisbursementVoucher.

/**
 * @param dvDescription
 * @param dvExplanation
 * @param tripNumber
 * @param travelerNetId
 * @param initiatorNetId
 * @param totalAmount
 * @param checkStubText
 * @return
 * @throws Exception
 */
private String buildDisbursementVoucher(String dvDescription, String dvExplanation, String tripNumber, String travelerNetId, String initiatorNetId, double totalAmount, String checkStubText) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISBURSEMENT_VOUCHER)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DV.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DV.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDisbursementVoucherDocument dvDoc = null;
    try {
        dvDoc = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dvDoc != null) {
        dvDoc.getDocumentHeader().setDocumentDescription(dvDescription);
        dvDoc.getDocumentHeader().setExplanation(dvExplanation);
        dvDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        dvDoc.initiateDocument();
        // Set vendor to traveler using netID provided
        Person traveler = SpringContext.getBean(PersonService.class).getPersonByPrincipalName(travelerNetId);
        for (EntityAffiliationContract entityAffiliation : ((PersonImpl) traveler).getAffiliations()) {
            if (entityAffiliation.isDefaultValue()) {
                if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STUDENT)) {
                    dvDoc.templateStudent(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.ALUMNI)) {
                    dvDoc.templateAlumni(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.FACULTY) || StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STAFF)) {
                    dvDoc.templateEmployee(traveler);
                }
            }
        }
        dvDoc.setPayeeAssigned(true);
        dvDoc.getDvPayeeDetail().setDisbVchrPaymentReasonCode("J");
        dvDoc.setDisbVchrCheckTotalAmount(new KualiDecimal(totalAmount));
        dvDoc.setDisbVchrPaymentMethodCode("P");
        dvDoc.setDisbVchrCheckStubText(checkStubText);
        dvDoc.setTripId(tripNumber);
        dvDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(dvDoc);
        return dvDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : EntityAffiliationContract(org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) PersonImpl(org.kuali.rice.kim.impl.identity.PersonImpl) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) PersonService(org.kuali.rice.kim.api.identity.PersonService) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Person(org.kuali.rice.kim.api.identity.Person) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 3 with UserSession

use of org.kuali.kfs.krad.UserSession in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method submitTrip.

/**
 */
public String submitTrip(String dvDescription, String dvExplanation, String tripNumber, String travelerNetId, String initiatorNetId, double totalAmount, String checkStubText) throws Exception {
    UserSession actualUserSession = GlobalVariables.getUserSession();
    MessageMap globalErrorMap = GlobalVariables.getMessageMap();
    try {
        if (totalAmount > 0.00) {
            return buildDisbursementVoucher(dvDescription, dvExplanation, tripNumber, travelerNetId, initiatorNetId, totalAmount, checkStubText);
        } else {
            return buildDistributionIncomeExpenseDocument(dvDescription, dvExplanation, tripNumber, initiatorNetId);
        }
    } finally {
        GlobalVariables.setUserSession(actualUserSession);
        GlobalVariables.setMessageMap(globalErrorMap);
    }
}
Also used : UserSession(org.kuali.kfs.krad.UserSession) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 4 with UserSession

use of org.kuali.kfs.krad.UserSession in project cu-kfs by CU-CommunityApps.

the class DisbursementVoucherDocumentBatchServiceImpl method loadDisbursementVouchers.

/**
 * @see com.rsmart.kuali.kfs.fp.batch.service.DisbursementVoucherDocumentBatchService#loadDisbursementVouchers(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchFeed,
 *      com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchStatus, java.lang.String,
 *      org.kuali.kfs.kns.util.MessageMap)
 */
public void loadDisbursementVouchers(DisbursementVoucherBatchFeed batchFeed, DisbursementVoucherBatchStatus batchStatus, String incomingFileName, MessageMap MessageMap) {
    // get new batch record for the load
    DisbursementVoucherBatch disbursementVoucherBatch = getNewDisbursementVoucherBatch();
    businessObjectService.save(disbursementVoucherBatch);
    batchStatus.setUnitCode(batchFeed.getUnitCode());
    boolean batchHasErrors = false;
    for (BatchDisbursementVoucherDocument batchDisbursementVoucherDocument : batchFeed.getBatchDisbursementVoucherDocuments()) {
        batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_READ, 1);
        batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_READ, batchDisbursementVoucherDocument.getSourceAccountingLines().size());
        // get defaults for DV chart/org
        DisbursementVoucherBatchDefault batchDefault = null;
        if (StringUtils.isNotBlank(batchFeed.getUnitCode())) {
            batchDefault = getDisbursementVoucherBatchDefault(batchFeed.getUnitCode());
        }
        MessageMap documentMessageMap = new MessageMap();
        batchFeedHelperService.performForceUppercase(DisbursementVoucherDocument.class.getName(), batchDisbursementVoucherDocument);
        // create and route doc as system user
        // create and route doc as system user
        UserSession actualUserSession = GlobalVariables.getUserSession();
        GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
        MessageMap globalMessageMap = GlobalVariables.getMessageMap();
        GlobalVariables.setMessageMap(documentMessageMap);
        DisbursementVoucherDocument disbursementVoucherDocument = null;
        try {
            disbursementVoucherDocument = populateDisbursementVoucherDocument(disbursementVoucherBatch, batchDisbursementVoucherDocument, batchDefault, documentMessageMap);
            // if the document is valid create GLPEs, Save and Approve
            if (documentMessageMap.hasNoErrors()) {
                businessObjectService.save(disbursementVoucherDocument.getExtension());
                documentService.routeDocument(disbursementVoucherDocument, "", null);
                if (documentMessageMap.hasNoErrors()) {
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_WRITTEN, 1);
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_WRITTEN, disbursementVoucherDocument.getSourceAccountingLines().size());
                    batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_GLPE_RECORDS_WRITTEN, disbursementVoucherDocument.getGeneralLedgerPendingEntries().size());
                    batchStatus.getBatchDisbursementVoucherDocuments().add(disbursementVoucherDocument);
                }
            }
        } catch (WorkflowException e) {
            LOG.error("Unable to route DV: " + e.getMessage());
            throw new RuntimeException("Unable to route DV: " + e.getMessage(), e);
        } catch (ValidationException e1) {
        // will be reported in audit report
        } finally {
            GlobalVariables.setUserSession(actualUserSession);
            GlobalVariables.setMessageMap(globalMessageMap);
        }
        if (documentMessageMap.hasErrors()) {
            batchHasErrors = true;
        }
        // populate summary line and add to report
        DisbursementVoucherBatchSummaryLine batchSummaryLine = populateBatchSummaryLine(disbursementVoucherDocument, documentMessageMap);
        batchStatus.getBatchSummaryLines().add(batchSummaryLine);
    }
    // indicate in global map there were errors (for batch upload screen)
    if (batchHasErrors) {
        MessageMap.putError(KFSConstants.GLOBAL_ERRORS, FPKeyConstants.ERROR_BATCH_DISBURSEMENT_VOUCHER_ERRORS_NOTIFICATION);
    }
    batchFeedHelperService.removeDoneFile(incomingFileName);
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherBatchDefault(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DisbursementVoucherBatch(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatch) DisbursementVoucherBatchSummaryLine(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchSummaryLine) MessageMap(org.kuali.kfs.krad.util.MessageMap) BatchDisbursementVoucherDocument(com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 5 with UserSession

use of org.kuali.kfs.krad.UserSession in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method buildDistributionIncomeExpenseDocument.

/**
 * @param diDescription
 * @param diExplanation
 * @param tripNumber
 * @param initiatorNetId
 * @return
 * @throws Exception
 */
private String buildDistributionIncomeExpenseDocument(String diDescription, String diExplanation, String tripNumber, String initiatorNetId) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISTRIBUTION_INCOME_EXPENSE)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DI.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DI.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDistributionOfIncomeAndExpenseDocument diDoc = null;
    try {
        diDoc = (CuDistributionOfIncomeAndExpenseDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DistributionOfIncomeAndExpenseDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (diDoc != null) {
        diDoc.getDocumentHeader().setDocumentDescription(diDescription);
        diDoc.getDocumentHeader().setExplanation(diExplanation);
        diDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        diDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        diDoc.setTripId(tripNumber);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(diDoc);
        return diDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService) CuDistributionOfIncomeAndExpenseDocument(edu.cornell.kfs.fp.document.CuDistributionOfIncomeAndExpenseDocument)

Aggregations

UserSession (org.kuali.kfs.krad.UserSession)11 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)6 MessageMap (org.kuali.kfs.krad.util.MessageMap)4 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)3 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)2 DisbursementVoucherBatch (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatch)1 DisbursementVoucherBatchDefault (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault)1 DisbursementVoucherBatchSummaryLine (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchSummaryLine)1 BatchDisbursementVoucherDocument (com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument)1 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)1 CuDistributionOfIncomeAndExpenseDocument (edu.cornell.kfs.fp.document.CuDistributionOfIncomeAndExpenseDocument)1 VendorInactivateConvertBatch (edu.cornell.kfs.vnd.businessobject.VendorInactivateConvertBatch)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)1 Maintainable (org.kuali.kfs.kns.maintenance.Maintainable)1 Note (org.kuali.kfs.krad.bo.Note)1