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;
}
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();
}
}
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();
}
}
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();
}
}
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;
}
Aggregations