Search in sources :

Example 6 with UserSession

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

the class VendorInactivateConvertBatchServiceImpl method inactivateConvert.

/**
 */
public boolean inactivateConvert(String fileName, BatchInputFileType batchInputFileType) {
    boolean result = true;
    // load up the file into a byte array
    byte[] fileByteContent = safelyLoadFileBytes(fileName);
    LOG.info("Attempting to parse the file");
    Object parsedObject = null;
    try {
        parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
    } catch (ParseException e) {
        String errorMessage = "Error parsing batch file: " + e.getMessage();
        LOG.error(errorMessage, e);
        throw new RuntimeException(errorMessage);
    }
    // make sure we got the type we expected, then cast it
    if (!(parsedObject instanceof List)) {
        String errorMessage = "Parsed file was not of the expected type.  Expected [" + List.class + "] but got [" + parsedObject.getClass() + "].";
        criticalError(errorMessage);
    }
    List<VendorInactivateConvertBatch> vendors = ((List<VendorInactivateConvertBatch>) parsedObject);
    for (VendorInactivateConvertBatch vendor : vendors) {
        String[] vendorId = vendor.getVendorId().split("-");
        Collection<VendorDetail> vendorDets = businessObjectService.findMatching(VendorDetail.class, Collections.singletonMap("vendorHeaderGeneratedIdentifier", vendorId[0]));
        GlobalVariables.setUserSession(new UserSession("kfs"));
        VendorDetail vnd = cuVendorService.getByVendorNumber(vendor.getVendorId());
        if (ObjectUtils.isNull(vnd)) {
            LOG.info("Vendor with id: " + vendor.getVendorId() + " does not exist in the database.");
        }
        if ((ObjectUtils.isNotNull(vnd))) {
            VendorHeader vHead = businessObjectService.findBySinglePrimaryKey(VendorHeader.class, vnd.getVendorHeaderGeneratedIdentifier());
            if (vendor.getAction().equalsIgnoreCase("inactivate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                inactivateVendor(vnd, vendor.getNote(), vendor.getReason());
            } else if (vendor.getAction().equalsIgnoreCase("activate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                activateVendor(vnd, vendor.getNote(), vendor.getReason());
            } else if (vendor.getAction().equalsIgnoreCase("convert") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
                convertVendor(vHead, vnd, vendor.getNote(), vendor.getConvertType());
            } else if (vendorDets.size() > 1) {
                LOG.info("failed to process for " + vnd.getVendorNumber() + ", This vendor has child records. These must be processed through the application");
            } else {
                String errorMessage = "Failed to parse vendor action expected inactivate or convert but recevied " + vendor.getAction();
                criticalError(errorMessage);
            }
        }
    }
    return result;
}
Also used : VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) VendorInactivateConvertBatch(edu.cornell.kfs.vnd.businessobject.VendorInactivateConvertBatch) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) UserSession(org.kuali.kfs.krad.UserSession) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.kuali.kfs.sys.exception.ParseException)

Example 7 with UserSession

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

the class EzraServiceImpl method routeProposalDocument.

private void routeProposalDocument(Proposal proposal) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    MaintenanceDocument proposalDoc = null;
    try {
        proposalDoc = (MaintenanceDocument) documentService.getNewDocument("PRPL");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    proposalDoc.getDocumentHeader().setDocumentDescription("Auto creation of new proposal: " + proposal.getProposalNumber());
    proposalDoc.getNewMaintainableObject().setBusinessObject(proposal);
    try {
        documentService.saveDocument(proposalDoc);
        proposalDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 8 with UserSession

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

the class EzraServiceImpl method routeAgencyDocument.

private void routeAgencyDocument(Agency agency, Agency oldAgency) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    // DocumentService docService = SpringContext.getBean(DocumentService.class);
    MaintenanceDocument agencyDoc = null;
    try {
        agencyDoc = (MaintenanceDocument) documentService.getNewDocument("AGCY");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    agencyDoc.getDocumentHeader().setDocumentDescription("Auto creation of new agency: " + agency.getAgencyNumber());
    if (ObjectUtils.isNotNull(oldAgency)) {
        agencyDoc.getOldMaintainableObject().setBusinessObject(oldAgency);
        agencyDoc.getDocumentHeader().setDocumentDescription(agency.getAgencyNumber() + " by auto edit");
    }
    Maintainable agencyMaintainable = agencyDoc.getNewMaintainableObject();
    agencyMaintainable.setBusinessObject(agency);
    agencyDoc.setNewMaintainableObject(agencyMaintainable);
    try {
        documentService.saveDocument(agencyDoc);
        agencyDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Example 9 with UserSession

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

the class EzraServiceImpl method routeAwardDocument.

private void routeAwardDocument(Award award, Award oldAward) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    // DocumentService docService = SpringContext.getBean(DocumentService.class);
    MaintenanceDocument awardDoc = null;
    try {
        awardDoc = (MaintenanceDocument) documentService.getNewDocument("AWRD");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    LOG.info("Created a new Award doc. " + award.getProposalNumber());
    awardDoc.getDocumentHeader().setDocumentDescription("Auto creation of new award : " + award.getProposalNumber());
    if (ObjectUtils.isNotNull(oldAward)) {
        awardDoc.getOldMaintainableObject().setBusinessObject(oldAward);
        award.setVersionNumber(oldAward.getVersionNumber());
        awardDoc.getDocumentHeader().setDocumentDescription(award.getProposalNumber() + " by auto edit");
    }
    awardDoc.getNewMaintainableObject().setBusinessObject(award);
    ;
    try {
        documentService.saveDocument(awardDoc);
        // documentService.routeDocument(awardDoc, "Automatically created and routed", null);
        awardDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    } catch (RuntimeException rte) {
        LOG.error(rte);
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 10 with UserSession

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

the class MockPersonUtil method createMockUserSession.

public static UserSession createMockUserSession(Person person) {
    UserSession userSession = EasyMock.createMock(UserSession.class);
    EasyMock.expect(userSession.getPrincipalId()).andStubReturn(person.getPrincipalId());
    EasyMock.expect(userSession.getPrincipalName()).andStubReturn(person.getPrincipalName());
    EasyMock.expect(userSession.getLoggedInUserPrincipalName()).andStubReturn(person.getPrincipalName());
    EasyMock.expect(userSession.getPerson()).andStubReturn(person);
    EasyMock.expect(userSession.getActualPerson()).andStubReturn(person);
    EasyMock.replay(userSession);
    return userSession;
}
Also used : UserSession(org.kuali.kfs.krad.UserSession)

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