use of edu.cornell.kfs.module.purap.document.service.IWantDocumentService in project cu-kfs by CU-CommunityApps.
the class CuRequisitionAction method createReqFromIWantDoc.
/**
* Creates a requisition document based on information from an I Want document.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
@SuppressWarnings("deprecation")
public ActionForward createReqFromIWantDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String iWantDocumentNumber = request.getParameter(KRADConstants.PARAMETER_DOC_ID);
RequisitionForm requisitionForm = (RequisitionForm) form;
IWantDocument iWantDocument = (IWantDocument) getDocumentService().getByDocumentHeaderId(iWantDocumentNumber);
if (iWantDocument == null) {
throw new WorkflowException("Could not find IWantDocument with ID '" + iWantDocumentNumber + "'");
}
// Make sure the user is authorized to create the req in this manner.
TransactionalDocumentPresentationController pControl = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(iWantDocument);
TransactionalDocumentAuthorizer authorizer = (TransactionalDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(iWantDocument);
Set<String> iwntEditModes = authorizer.getEditModes(iWantDocument, GlobalVariables.getUserSession().getPerson(), pControl.getEditModes(iWantDocument));
if (!iwntEditModes.contains(CUPurapConstants.IWNT_DOC_CREATE_REQ)) {
throw new AuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), CUPurapConstants.IWNT_DOC_CREATE_REQ, CuRequisitionDocument.class.getSimpleName(), "user is not authorized to create requisitions from IWantDocument '" + iWantDocumentNumber + "'", Collections.<String, Object>emptyMap());
}
// Do not allow the req to be created if the IWNT doc is already associated with another req.
if (iWantDocument != null && (StringUtils.isNotBlank(iWantDocument.getReqsDocId()) || StringUtils.isNotBlank(iWantDocument.getDvDocId()))) {
throw new WorkflowException("Cannot create requisition from IWantDocument '" + iWantDocumentNumber + "' because a DV or Requisition has already been created from that document");
}
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
createDocument(requisitionForm);
RequisitionDocument requisitionDocument = requisitionForm.getRequisitionDocument();
iWantDocumentService.setUpRequisitionDetailsFromIWantDoc(iWantDocument, requisitionDocument, requisitionForm);
// Set the requisition doc ID reference on the IWantDocument.
iWantDocument.setReqsDocId(requisitionDocument.getDocumentNumber());
SpringContext.getBean(PurapService.class).saveDocumentNoValidation(iWantDocument);
return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
use of edu.cornell.kfs.module.purap.document.service.IWantDocumentService in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method docHandler.
/**
* @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#docHandler(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward docHandler(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward actionForward = super.docHandler(mapping, form, request, response);
IWantDocumentForm iWantForm = (IWantDocumentForm) form;
IWantDocument iWantDocument = iWantForm.getIWantDocument();
String command = iWantForm.getCommand();
String step = request.getParameter(CUPurapConstants.IWNT_STEP_PARAMETER);
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
if (step != null) {
iWantForm.setStep(step);
}
if (iWantDocument != null) {
if (iWantDocument.getDocumentHeader().getWorkflowDocument().isSaved()) {
step = CUPurapConstants.IWantDocumentSteps.CUSTOMER_DATA_STEP;
}
iWantDocument.setStep(step);
if (KewApiConstants.INITIATE_COMMAND.equalsIgnoreCase(command)) {
iWantForm.setDocument(iWantDocument);
if (iWantDocument != null) {
String principalId = iWantDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
Principal initiator = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
String initiatorPrincipalID = initiator.getPrincipalId();
String initiatorNetID = initiator.getPrincipalName();
iWantDocument.setInitiatorNetID(initiatorNetID);
Person currentUser = GlobalVariables.getUserSession().getPerson();
String initiatorName = currentUser.getNameUnmasked();
String initiatorPhoneNumber = currentUser.getPhoneNumberUnmasked();
String initiatorEmailAddress = currentUser.getEmailAddressUnmasked();
String address = iWantDocumentService.getPersonCampusAddress(initiatorNetID);
iWantDocument.setInitiatorName(initiatorName);
iWantDocument.setInitiatorPhoneNumber(initiatorPhoneNumber);
iWantDocument.setInitiatorEmailAddress(initiatorEmailAddress);
iWantDocument.setInitiatorAddress(address);
// check default user options
Map<String, String> primaryKeysCollegeOption = new HashMap<String, String>();
primaryKeysCollegeOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysCollegeOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_COLLEGE);
IWantDocUserOptions userOptionsCollege = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysCollegeOption);
Map<String, String> primaryKeysDepartmentOption = new HashMap<String, String>();
primaryKeysDepartmentOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysDepartmentOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DEPARTMENT);
IWantDocUserOptions userOptionsDepartment = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysDepartmentOption);
// check default deliver to address info
Map<String, String> primaryKeysdeliverToNetIDOption = new HashMap<String, String>();
primaryKeysdeliverToNetIDOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysdeliverToNetIDOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_NET_ID);
IWantDocUserOptions userOptionsDeliverToNetID = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysdeliverToNetIDOption);
Map<String, String> primaryKeysDeliverToNameOption = new HashMap<String, String>();
primaryKeysDeliverToNameOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysDeliverToNameOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_NAME);
IWantDocUserOptions userOptionsDeliverToName = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysDeliverToNameOption);
Map<String, String> primaryKeysDeliverToEmailOption = new HashMap<String, String>();
primaryKeysDeliverToEmailOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysDeliverToEmailOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_EMAIL_ADDRESS);
IWantDocUserOptions userOptionsDeliverToEmail = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysDeliverToEmailOption);
Map<String, String> primaryKeysDeliverToPhnNbrOption = new HashMap<String, String>();
primaryKeysDeliverToPhnNbrOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysDeliverToPhnNbrOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_PHONE_NUMBER);
IWantDocUserOptions userOptionsDeliverToPhnNbr = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysDeliverToPhnNbrOption);
Map<String, String> primaryKeysDeliverToAddressOption = new HashMap<String, String>();
primaryKeysDeliverToAddressOption.put(CUPurapConstants.USER_OPTIONS_PRINCIPAL_ID, initiatorPrincipalID);
primaryKeysDeliverToAddressOption.put(CUPurapConstants.USER_OPTIONS_OPTION_ID, CUPurapConstants.USER_OPTIONS_DEFAULT_DELIVER_TO_ADDRESS);
IWantDocUserOptions userOptionsDeliverToAddress = (IWantDocUserOptions) getBusinessObjectService().findByPrimaryKey(IWantDocUserOptions.class, primaryKeysDeliverToAddressOption);
if (ObjectUtils.isNotNull(userOptionsCollege)) {
iWantDocument.setCollegeLevelOrganization(userOptionsCollege.getOptionValue());
}
if (ObjectUtils.isNotNull(userOptionsDepartment)) {
iWantDocument.setDepartmentLevelOrganization(userOptionsDepartment.getOptionValue());
}
// if no default user options check primary department
if (ObjectUtils.isNull(userOptionsCollege) && ObjectUtils.isNull(userOptionsDepartment)) {
// / set college and department based on primary id
setCollegeAndDepartmentBasedOnPrimaryDepartment(iWantForm);
}
if (ObjectUtils.isNotNull(userOptionsDeliverToNetID)) {
iWantDocument.setDeliverToNetID(userOptionsDeliverToNetID.getOptionValue());
}
if (ObjectUtils.isNotNull(userOptionsDeliverToName)) {
iWantDocument.setDeliverToName(userOptionsDeliverToName.getOptionValue());
}
if (ObjectUtils.isNotNull(userOptionsDeliverToEmail)) {
iWantDocument.setDeliverToEmailAddress(userOptionsDeliverToEmail.getOptionValue());
}
if (ObjectUtils.isNotNull(userOptionsDeliverToPhnNbr)) {
iWantDocument.setDeliverToPhoneNumber(userOptionsDeliverToPhnNbr.getOptionValue());
}
if (ObjectUtils.isNotNull(userOptionsDeliverToAddress)) {
iWantDocument.setDeliverToAddress(userOptionsDeliverToAddress.getOptionValue());
}
}
iWantDocumentService.setIWantDocumentDescription(iWantDocument);
}
}
return actionForward;
}
use of edu.cornell.kfs.module.purap.document.service.IWantDocumentService in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method execute.
/**
* @see org.kuali.kfs.kns.web.struts.action.KualiAction#execute(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward actionForward = super.execute(mapping, form, request, response);
IWantDocumentForm documentForm = (IWantDocumentForm) form;
IWantDocument iWantDoc = documentForm.getIWantDocument();
if (documentForm != null && documentForm.getDocument() != null) {
iWantDoc.setExplanation(iWantDoc.getDocumentHeader().getExplanation());
// populate department drop down
if (!documentForm.getPreviousSelectedOrg().equalsIgnoreCase(((IWantDocument) documentForm.getDocument()).getCollegeLevelOrganization())) {
String cLevelOrg = ((IWantDocument) documentForm.getDocument()).getCollegeLevelOrganization();
documentForm.getDeptOrgKeyLabels().clear();
documentForm.getDeptOrgKeyLabels().add(new ConcreteKeyValue("", "Please Select"));
if (StringUtils.isNotEmpty(cLevelOrg)) {
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
List<LevelOrganization> dLevelOrgs = iWantDocumentService.getDLevelOrganizations(cLevelOrg);
// Get the list of chart+org combos to forcibly exclude from the drop-down, if any.
String routingChart = ((IWantDocument) documentForm.getDocument()).getRoutingChart();
Collection<String> dLevelExcludesList = getParameterService().getParameterValuesAsString(PurapConstants.PURAP_NAMESPACE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, IWANT_DEPT_ORGS_TO_EXCLUDE_PARM);
Set<String> dLevelExcludes = new HashSet<String>((dLevelExcludesList != null) ? dLevelExcludesList : Collections.<String>emptyList());
for (LevelOrganization levelOrganization : dLevelOrgs) {
// Add each department-level org to the drop-down as long as it is not marked for exclusion.
if (!dLevelExcludes.contains(routingChart + "=" + levelOrganization.getCode())) {
documentForm.getDeptOrgKeyLabels().add(new ConcreteKeyValue(levelOrganization.getCode(), levelOrganization.getCodeAndDescription()));
}
}
}
}
setupDocumentMessages(documentForm.getStep());
}
return actionForward;
}
use of edu.cornell.kfs.module.purap.document.service.IWantDocumentService in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method save.
@Override
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
// Only recreate document description if in INITIATED or SAVED status.
WorkflowDocument workflowDocument = ((KualiDocumentFormBase) form).getDocument().getDocumentHeader().getWorkflowDocument();
if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
iWantDocumentService.setIWantDocumentDescription((IWantDocument) ((KualiDocumentFormBase) form).getDocument());
}
ActionForward actionForward = super.save(mapping, form, request, response);
IWantDocumentForm iWantDocForm = (IWantDocumentForm) form;
IWantDocument iWantDocument = iWantDocForm.getIWantDocument();
boolean added = true;
// add new item and new accounting line if not empty
IWantItem item = iWantDocForm.getNewIWantItemLine();
if (StringUtils.isNotBlank(item.getItemDescription()) || item.getItemUnitPrice() != null || item.getItemQuantity() != null) {
added &= addNewItem(iWantDocForm, iWantDocument, item);
}
added &= addNewFavoriteAccountIfNecessary(added, iWantDocument);
if (added) {
IWantAccount account = iWantDocForm.getNewSourceLine();
if (StringUtils.isNotBlank(account.getAccountNumber()) || StringUtils.isNotBlank(account.getSubAccountNumber()) || StringUtils.isNotBlank(account.getFinancialObjectCode()) || StringUtils.isNotBlank(account.getFinancialSubObjectCode()) || StringUtils.isNotBlank(account.getProjectCode()) || StringUtils.isNotBlank(account.getOrganizationReferenceId())) {
added &= addNewAccount(iWantDocForm, iWantDocument, account);
}
}
// Do not save if item or account additions failed.
if (!added) {
return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
iWantDocument.setExplanation(iWantDocument.getDocumentHeader().getExplanation());
if (StringUtils.isNotBlank(iWantDocForm.getNewAdHocRoutePerson().getId())) {
iWantDocument.setCurrentRouteToNetId(iWantDocForm.getNewAdHocRoutePerson().getId());
}
return actionForward;
}
use of edu.cornell.kfs.module.purap.document.service.IWantDocumentService in project cu-kfs by CU-CommunityApps.
the class IWantDocumentAction method refresh.
/**
* @see org.kuali.kfs.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
IWantDocumentForm iWantDocForm = (IWantDocumentForm) form;
IWantDocument iWantDocument = iWantDocForm.getIWantDocument();
ActionForward actionForward = super.refresh(mapping, form, request, response);
String refreshCaller = request.getParameter(KFSConstants.REFRESH_CALLER);
if (refreshCaller != null && refreshCaller.endsWith(KFSConstants.LOOKUPABLE_SUFFIX)) {
String deliverToNetID = iWantDocument.getDeliverToNetID();
if (StringUtils.isNotEmpty(deliverToNetID)) {
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
String address = iWantDocumentService.getPersonCampusAddress(deliverToNetID);
iWantDocument.setDeliverToAddress(address);
}
if ("iWantDocVendorLookupable".equalsIgnoreCase(refreshCaller)) {
Integer vendorHeaderId = iWantDocument.getVendorHeaderGeneratedIdentifier();
Integer vendorId = iWantDocument.getVendorDetailAssignedIdentifier();
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 = getBusinessObjectService().findMatching(VendorPhoneNumber.class, fieldValues);
if (ObjectUtils.isNotNull(vendorPhoneNumbers) && vendorPhoneNumbers.size() > 0) {
VendorPhoneNumber retrievedVendorPhoneNumber = vendorPhoneNumbers.toArray(new VendorPhoneNumber[1])[0];
phoneNumber += retrievedVendorPhoneNumber.getVendorPhoneNumber();
}
// populate vendor info
String addressLine1 = iWantDocument.getVendorLine1Address() != null ? iWantDocument.getVendorLine1Address() : StringUtils.EMPTY;
String addressLine2 = iWantDocument.getVendorLine2Address() != null ? iWantDocument.getVendorLine2Address() : StringUtils.EMPTY;
String cityName = iWantDocument.getVendorCityName() != null ? iWantDocument.getVendorCityName() : StringUtils.EMPTY;
String stateCode = iWantDocument.getVendorStateCode() != null ? iWantDocument.getVendorStateCode() : StringUtils.EMPTY;
String countryCode = iWantDocument.getVendorCountryCode() != null ? iWantDocument.getVendorCountryCode() : StringUtils.EMPTY;
String postalCode = iWantDocument.getVendorPostalCode() != null ? iWantDocument.getVendorPostalCode() : StringUtils.EMPTY;
String faxNumber = "Fax: " + (iWantDocument.getVendorFaxNumber() != null ? iWantDocument.getVendorFaxNumber() : StringUtils.EMPTY);
String url = "URL: " + (iWantDocument.getVendorWebURL() != null ? iWantDocument.getVendorWebURL() : 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);
}
}
return actionForward;
}
Aggregations