use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.
the class IWantDocumentFeedServiceImpl method populateIWantDocument.
/**
* Populates an I Want document based on the input data.
*
* @param batchIWantDocument
*/
private void populateIWantDocument(BatchIWantDocument batchIWantDocument, String incomingFileName) {
boolean noErrors = true;
List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
LOG.info("Creating I Want document from data related to source number: " + batchIWantDocument.getSourceNumber());
try {
if (StringUtils.isBlank(batchIWantDocument.getInitiator())) {
LOG.error("Initiator net ID cannot be empty: " + batchIWantDocument.getInitiator());
noErrors = false;
}
// if initiator is blank we cannot create the I Want doc
if (noErrors) {
Person initiator = personService.getPersonByPrincipalName(batchIWantDocument.getInitiator());
if (ObjectUtils.isNull(initiator)) {
LOG.error("Initiator net ID is not valid: " + batchIWantDocument.getInitiator());
noErrors = false;
}
// if initiator is not valid we cannot create the I Want doc
if (noErrors) {
IWantDocument iWantDocument = (IWantDocument) documentService.getNewDocument(CUPurapConstants.IWNT_DOC_TYPE, batchIWantDocument.getInitiator());
iWantDocumentService.setUpIWantDocDefaultValues(iWantDocument, initiator);
if (StringUtils.isNotBlank(batchIWantDocument.getInitiatorNetID())) {
iWantDocument.setInitiatorNetID(batchIWantDocument.getInitiatorNetID());
}
iWantDocument.getDocumentHeader().setExplanation(batchIWantDocument.getBusinessPurpose());
iWantDocument.setExplanation(batchIWantDocument.getBusinessPurpose());
if (StringUtils.isNotBlank(batchIWantDocument.getCollegeLevelOrganization())) {
iWantDocument.setCollegeLevelOrganization(batchIWantDocument.getCollegeLevelOrganization());
}
if (StringUtils.isNotBlank(batchIWantDocument.getDepartmentLevelOrganization())) {
iWantDocument.setDepartmentLevelOrganization(batchIWantDocument.getDepartmentLevelOrganization());
}
iWantDocument.getDocumentHeader().setOrganizationDocumentNumber(batchIWantDocument.getSourceNumber());
// populate requester fields
populateIWantDocRequestorSection(initiator, batchIWantDocument, iWantDocument);
// populate deliver to section
populateIWantDocDeliverToSection(batchIWantDocument, iWantDocument);
// populate vendor data
if (StringUtils.isNotBlank(batchIWantDocument.getVendorNumber())) {
String[] vendorNumbers = batchIWantDocument.getVendorNumber().split("-");
if (vendorNumbers.length == 2) {
try {
Integer vendorHeaderId = new Integer(vendorNumbers[0]);
Integer vendorId = new Integer(vendorNumbers[1]);
String phoneNumber = "Phone: ";
Map<String, Object> fieldValues = new HashMap<String, Object>();
fieldValues.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
fieldValues.put("vendorDetailAssignedIdentifier", vendorId);
fieldValues.put("vendorPhoneTypeCode", "PH");
Collection<VendorPhoneNumber> vendorPhoneNumbers = businessObjectService.findMatching(VendorPhoneNumber.class, fieldValues);
if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
}
Map<String, Object> fieldValuesVendorDetail = new HashMap<String, Object>();
fieldValuesVendorDetail.put("vendorHeaderGeneratedIdentifier", vendorHeaderId);
fieldValuesVendorDetail.put("vendorDetailAssignedIdentifier", vendorId);
VendorDetail vendorDetail = businessObjectService.findByPrimaryKey(VendorDetail.class, fieldValuesVendorDetail);
if (ObjectUtils.isNotNull(vendorDetail)) {
iWantDocument.setVendorHeaderGeneratedIdentifier(vendorHeaderId);
iWantDocument.setVendorDetailAssignedIdentifier(vendorId);
iWantDocument.setVendorName(vendorDetail.getVendorName());
updateDefaultVendorAddress(vendorDetail);
// populate vendor info
String addressLine1 = vendorDetail.getDefaultAddressLine1() != null ? vendorDetail.getDefaultAddressLine1() : StringUtils.EMPTY;
String addressLine2 = vendorDetail.getDefaultAddressLine2() != null ? vendorDetail.getDefaultAddressLine2() : StringUtils.EMPTY;
String cityName = vendorDetail.getDefaultAddressCity() != null ? vendorDetail.getDefaultAddressCity() : StringUtils.EMPTY;
String stateCode = vendorDetail.getDefaultAddressStateCode() != null ? vendorDetail.getDefaultAddressStateCode() : StringUtils.EMPTY;
String countryCode = vendorDetail.getDefaultAddressCountryCode() != null ? vendorDetail.getDefaultAddressCountryCode() : StringUtils.EMPTY;
String postalCode = vendorDetail.getDefaultAddressPostalCode() != null ? vendorDetail.getDefaultAddressPostalCode() : StringUtils.EMPTY;
String faxNumber = "Fax: " + (vendorDetail.getDefaultFaxNumber() != null ? vendorDetail.getDefaultFaxNumber() : StringUtils.EMPTY);
String url = "URL: " + (vendorDetail.getVendorUrlAddress() != null ? vendorDetail.getVendorUrlAddress() : StringUtils.EMPTY);
String vendorInfo = new StringBuilder(100).append(addressLine1).append('\n').append(addressLine2).append('\n').append(cityName).append(", ").append(postalCode).append(", ").append(stateCode).append(", ").append(countryCode).append('\n').append(faxNumber).append('\n').append(phoneNumber).append(" \n").append(url).toString();
iWantDocument.setVendorDescription(vendorInfo);
} else {
// Invalid vendor number
LOG.error("Vendor with id: " + batchIWantDocument.getVendorNumber() + " does not exist.");
noErrors = false;
}
} catch (NumberFormatException e) {
LOG.error("Vendor id: " + batchIWantDocument.getVendorNumber() + " is not valid.");
noErrors = false;
}
} else {
// Invalid vendor number
LOG.error("Vendor ID is not valid: " + batchIWantDocument.getVendorNumber());
noErrors = false;
}
} else {
if (StringUtils.isNotEmpty(batchIWantDocument.getVendorName())) {
iWantDocument.setVendorName(batchIWantDocument.getVendorName());
}
if (StringUtils.isNotEmpty(batchIWantDocument.getVendorDescription())) {
iWantDocument.setVendorDescription(batchIWantDocument.getVendorDescription());
}
}
// add items
noErrors &= populateIWantDocItems(batchIWantDocument, iWantDocument);
// add accounts
noErrors &= populateIWantDocAccounts(batchIWantDocument, iWantDocument);
// account Description
if (StringUtils.isNotBlank(batchIWantDocument.getAccountDescriptionTxt())) {
iWantDocument.setAccountDescriptionTxt(batchIWantDocument.getAccountDescriptionTxt());
}
if (StringUtils.isNotBlank(batchIWantDocument.getCommentsAndSpecialInstructions())) {
iWantDocument.setCommentsAndSpecialInstructions(batchIWantDocument.getCommentsAndSpecialInstructions());
}
iWantDocument.setGoods(batchIWantDocument.isGoods());
if (StringUtils.isNotBlank(batchIWantDocument.getServicePerformedOnCampus())) {
iWantDocument.setServicePerformedOnCampus(batchIWantDocument.getServicePerformedOnCampus());
}
if (StringUtils.isNotBlank(batchIWantDocument.getCurrentRouteToNetId())) {
Person adHocRouteTo = personService.getPersonByPrincipalName(batchIWantDocument.getCurrentRouteToNetId());
if (ObjectUtils.isNull(adHocRouteTo)) {
LOG.error("Ad Hoc Route to net ID is not valid: " + batchIWantDocument.getCurrentRouteToNetId());
noErrors = false;
} else {
iWantDocument.setCurrentRouteToNetId(batchIWantDocument.getCurrentRouteToNetId());
AdHocRoutePerson recipient = new AdHocRoutePerson();
recipient.setId(iWantDocument.getCurrentRouteToNetId());
recipient.setActionRequested(KewApiConstants.ACTION_REQUEST_APPROVE_REQ);
adHocRoutePersons.add(recipient);
iWantDocument.setAdHocRoutePersons(adHocRoutePersons);
}
}
iWantDocumentService.setIWantDocumentDescription(iWantDocument);
// add notes
addNotes(iWantDocument, batchIWantDocument);
// add attachments
loadDocumentAttachments(iWantDocument, batchIWantDocument.getAttachments(), incomingFileName);
boolean rulePassed = true;
// call business rules
rulePassed &= ruleService.applyRules(new SaveDocumentEvent("", iWantDocument));
if (!rulePassed) {
LOG.error("I Want document " + iWantDocument.getDocumentNumber() + "not saved due to errors");
logErrorMessages();
} else if (noErrors) {
documentService.saveDocument(iWantDocument);
}
}
}
} catch (Exception e) {
LOG.error("error while creating I Want document: " + e.getMessage(), e);
throw new RuntimeException("Error encountered while attempting to create I Want document " + e.getMessage(), e);
}
}
use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.
the class IWantDocumentPresentationController method getEditModes.
@Override
public Set<String> getEditModes(Document document) {
Set<String> editModes = super.getEditModes(document);
WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
IWantDocument iWantDocument = (IWantDocument) document;
if (SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(workflowDocument, GlobalVariables.getUserSession().getPrincipalId())) {
editModes.add("completeOrder");
}
if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
editModes.add("wizard");
}
if (CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
editModes.add(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
// remove all others
editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
}
if (CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
editModes.add(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
// remove all others
editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
}
if (CUPurapConstants.IWantDocumentSteps.VENDOR_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
editModes.add(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
// remove all others
editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
}
if (CUPurapConstants.IWantDocumentSteps.ROUTING_STEP.equalsIgnoreCase(iWantDocument.getStep())) {
editModes.add(CUPurapConstants.IWantDocumentSteps.ROUTING_STEP);
// remove all others
editModes.remove(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.ITEMS_AND_ACCT_DATA_STEP);
editModes.remove(CUPurapConstants.IWantDocumentSteps.VENDOR_STEP);
}
// KFSPTS-2527 only display create req and create DV buttons if neither REQ not DV has been created from I Want doc
if ((StringUtils.isBlank(iWantDocument.getReqsDocId()) && StringUtils.isBlank(iWantDocument.getDvDocId())) && !workflowDocument.isInitiated() && !workflowDocument.isSaved()) {
editModes.add(CUPurapConstants.IWNT_DOC_CREATE_REQ);
editModes.add(CUPurapConstants.IWNT_DOC_CREATE_DV);
}
editModes.add(CUPurapConstants.IWNT_DOC_USE_LOOKUPS);
return editModes;
}
use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.
the class CuDisbursementVoucherAction method createDVFromIWantDoc.
/**
* Creates a DV document based on information on an I Want document.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward createDVFromIWantDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String iWantDocumentNumber = request.getParameter("docId");
CuDisbursementVoucherForm disbursementVoucherForm = (CuDisbursementVoucherForm) form;
IWantDocument iWantDocument = (IWantDocument) getDocumentService().getByDocumentHeaderId(iWantDocumentNumber);
// Do not allow the DV to be created if the IWNT doc is already associated with another DV.
if (iWantDocument != null && (StringUtils.isNotBlank(iWantDocument.getReqsDocId()) || StringUtils.isNotBlank(iWantDocument.getDvDocId()))) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUPurapKeyConstants.ERROR_DV_OR_REQ_ALREADY_CREATED_FROM_IWNT, iWantDocumentNumber);
return mapping.findForward("error");
}
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
createDocument(disbursementVoucherForm);
CuDisbursementVoucherDocument disbursementVoucherDocument = (CuDisbursementVoucherDocument) disbursementVoucherForm.getDocument();
iWantDocumentService.setUpDVDetailsFromIWantDoc(iWantDocument, disbursementVoucherDocument, disbursementVoucherForm);
// Set the DV doc ID reference on the IWantDocument.
iWantDocument.setDvDocId(disbursementVoucherDocument.getDocumentNumber());
SpringContext.getBean(PurapService.class).saveDocumentNoValidation(iWantDocument);
return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method deleteAccount.
/**
* Deletes the selected account
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward deleteAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
IWantDocumentForm iWantForm = (IWantDocumentForm) form;
IWantDocument iWantDocument = (IWantDocument) iWantForm.getDocument();
iWantDocument.deleteAccount(getSelectedLine(request));
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of edu.cornell.kfs.module.purap.document.IWantDocument in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method continueToCustomerData.
/**
* Takes the user to next page
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward continueToCustomerData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
IWantDocumentForm iWantForm = (IWantDocumentForm) form;
IWantDocument iWantDocument = iWantForm.getIWantDocument();
iWantForm.setStep(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
iWantDocument.setStep(CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Aggregations