use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class CuRequisitionDocument method toCopyFromGateway.
/**
* toCopyFromGateway
*/
public void toCopyFromGateway() throws WorkflowException, ValidationException {
// no validation for the KFS copy requisition rules:
String sourceDocumentHeaderId = getDocumentNumber();
setNewDocumentHeader();
getDocumentHeader().setDocumentTemplateNumber(sourceDocumentHeaderId);
// Clear out existing notes.
if (getNotes() != null) {
getNotes().clear();
}
addCopyErrorDocumentNote("copied from document " + sourceDocumentHeaderId);
// --- LedgerPostingDocumentBase:
setAccountingPeriod(retrieveCurrentAccountingPeriod());
// --GeneralLedgerPostingDocumentBase:
getGeneralLedgerPendingEntries().clear();
// --AccountingDocumentBase:
copyAccountingLines(false);
updatePostingYearForAccountingLines(getSourceAccountingLines());
updatePostingYearForAccountingLines(getTargetAccountingLines());
// --RequisitionDocument:
// Clear related views
this.setAccountsPayablePurchasingDocumentLinkIdentifier(null);
this.setRelatedViews(null);
Person currentUser = GlobalVariables.getUserSession().getPerson();
ChartOrgHolder purapChartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
this.setPurapDocumentIdentifier(null);
// Set req status to INPR.
// for app doc status
updateAndSaveAppDocStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
// Set fields from the user.
if (ObjectUtils.isNotNull(purapChartOrg)) {
this.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
this.setOrganizationCode(purapChartOrg.getOrganizationCode());
}
this.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
boolean activeVendor = true;
boolean activeContract = true;
Date today = SpringContext.getBean(DateTimeService.class).getCurrentDate();
VendorContract vendorContract = new VendorContract();
vendorContract.setVendorContractGeneratedIdentifier(this.getVendorContractGeneratedIdentifier());
Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(vendorContract);
vendorContract = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorContract.class, keys);
if (!(vendorContract != null && today.after(vendorContract.getVendorContractBeginningDate()) && today.before(vendorContract.getVendorContractEndDate()))) {
activeContract = false;
}
VendorDetail vendorDetail = SpringContext.getBean(VendorService.class).getVendorDetail(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier());
if (!(vendorDetail != null && vendorDetail.isActiveIndicator())) {
activeVendor = false;
}
// KFSPTS-916 : need vendor address key for business rules and only way to get it is to retrieve the default PO address for the vendor.
if (vendorDetail != null) {
VendorAddress vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(this.getVendorHeaderGeneratedIdentifier(), this.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.PURCHASE_ORDER, "");
if (vendorAddress != null) {
super.templateVendorAddress(vendorAddress);
}
}
// B2B - only copy if contract and vendor are both active (throw separate errors to print to screen)
if (this.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
if (!activeContract) {
// -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_EXPIRED_CONTRACT);
}
if (!activeVendor) {
// -- throw new ValidationException(PurapKeyConstants.ERROR_REQ_COPY_INACTIVE_VENDOR);
}
}
if (!activeVendor) {
this.setVendorContractGeneratedIdentifier(null);
}
if (!activeContract) {
this.setVendorContractGeneratedIdentifier(null);
}
// These fields should not be set in this method; force to be null
this.setOrganizationAutomaticPurchaseOrderLimit(null);
this.setPurchaseOrderAutomaticIndicator(false);
for (Iterator iter = this.getItems().iterator(); iter.hasNext(); ) {
RequisitionItem item = (RequisitionItem) iter.next();
item.setPurapDocumentIdentifier(null);
item.setItemIdentifier(null);
for (Iterator acctIter = item.getSourceAccountingLines().iterator(); acctIter.hasNext(); ) {
RequisitionAccount account = (RequisitionAccount) acctIter.next();
account.setAccountIdentifier(null);
account.setItemIdentifier(null);
}
}
if (!PurapConstants.RequisitionSources.B2B.equals(this.getRequisitionSourceCode())) {
SpringContext.getBean(PurapService.class).addBelowLineItems(this);
}
this.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(this.getVendorContractGeneratedIdentifier(), this.getChartOfAccountsCode(), this.getOrganizationCode()));
clearCapitalAssetFields();
SpringContext.getBean(PurapService.class).clearTax(this, this.isUseTaxIndicator());
this.refreshNonUpdateableReferences();
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method setUpDeliverToSectionOfReqDoc.
/**
* Sets up the deliver to section of the Requisition document based on the information
* on the I Want Document.
*
* @param requisitionDocument
* @param iWantDocument
*/
private void setUpDeliverToSectionOfReqDoc(RequisitionDocument requisitionDocument, IWantDocument iWantDocument, PurapService purapService) {
Person deliverTo = null;
if (StringUtils.isNotBlank(iWantDocument.getDeliverToNetID())) {
requisitionDocument.setDeliveryBuildingRoomNumber(KFSConstants.NOT_AVAILABLE_STRING);
requisitionDocument.setDeliveryCountryCode(KFSConstants.COUNTRY_CODE_UNITED_STATES);
requisitionDocument.setDeliveryBuildingOtherIndicator(true);
deliverTo = personService.getPersonByPrincipalName(iWantDocument.getDeliverToNetID());
if (ObjectUtils.isNotNull(deliverTo)) {
Person currentUser = GlobalVariables.getUserSession().getPerson();
ChartOrgHolder purapChartOrg = financialSystemUserService.getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
if (ObjectUtils.isNotNull(purapChartOrg)) {
requisitionDocument.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
requisitionDocument.setOrganizationCode(purapChartOrg.getOrganizationCode());
}
requisitionDocument.setDeliveryCampusCode(deliverTo.getCampusCode());
requisitionDocument.setDeliveryToName(iWantDocument.getDeliverToName());
requisitionDocument.setDeliveryToEmailAddress(iWantDocument.getDeliverToEmailAddress());
requisitionDocument.setDeliveryToPhoneNumber(iWantDocument.getDeliverToPhoneNumber());
requisitionDocument.setRequestorPersonName(iWantDocument.getInitiatorName());
requisitionDocument.setRequestorPersonEmailAddress(iWantDocument.getInitiatorEmailAddress());
requisitionDocument.setRequestorPersonPhoneNumber(iWantDocument.getInitiatorPhoneNumber());
parseAndSetRequestorAddress(iWantDocument.getDeliverToAddress(), requisitionDocument);
requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(purapService.getApoLimit(requisitionDocument.getVendorContractGeneratedIdentifier(), requisitionDocument.getChartOfAccountsCode(), requisitionDocument.getOrganizationCode()));
// populate billing address
BillingAddress billingAddress = new BillingAddress();
billingAddress.setBillingCampusCode(requisitionDocument.getDeliveryCampusCode());
@SuppressWarnings("unchecked") Map<String, ?> keys = persistenceService.getPrimaryKeyFieldValues(billingAddress);
billingAddress = businessObjectService.findByPrimaryKey(BillingAddress.class, keys);
requisitionDocument.templateBillingAddress(billingAddress);
}
}
if (StringUtils.isBlank(iWantDocument.getDeliverToNetID()) || ObjectUtils.isNull(deliverTo)) {
// populate requisition fields from I Want doc initiator
deliverTo = personService.getPerson(iWantDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
if (ObjectUtils.isNotNull(deliverTo)) {
Person currentUser = GlobalVariables.getUserSession().getPerson();
ChartOrgHolder purapChartOrg = financialSystemUserService.getPrimaryOrganization(currentUser, PurapConstants.PURAP_NAMESPACE);
if (ObjectUtils.isNotNull(purapChartOrg)) {
requisitionDocument.setChartOfAccountsCode(purapChartOrg.getChartOfAccountsCode());
requisitionDocument.setOrganizationCode(purapChartOrg.getOrganizationCode());
}
requisitionDocument.setDeliveryCampusCode(deliverTo.getCampusCode());
requisitionDocument.setDeliveryToName(deliverTo.getName());
requisitionDocument.setDeliveryToEmailAddress(deliverTo.getEmailAddressUnmasked());
requisitionDocument.setDeliveryToPhoneNumber(SpringContext.getBean(PhoneNumberService.class).formatNumberIfPossible(deliverTo.getPhoneNumber()));
requisitionDocument.setRequestorPersonName(deliverTo.getName());
requisitionDocument.setRequestorPersonEmailAddress(deliverTo.getEmailAddressUnmasked());
requisitionDocument.setRequestorPersonPhoneNumber(SpringContext.getBean(PhoneNumberService.class).formatNumberIfPossible(deliverTo.getPhoneNumber()));
DefaultPrincipalAddress defaultPrincipalAddress = new DefaultPrincipalAddress(deliverTo.getPrincipalId());
@SuppressWarnings("unchecked") Map<String, ?> addressKeys = persistenceService.getPrimaryKeyFieldValues(defaultPrincipalAddress);
defaultPrincipalAddress = (DefaultPrincipalAddress) businessObjectService.findByPrimaryKey(DefaultPrincipalAddress.class, addressKeys);
if (ObjectUtils.isNotNull(defaultPrincipalAddress) && ObjectUtils.isNotNull(defaultPrincipalAddress.getBuilding())) {
if (defaultPrincipalAddress.getBuilding().isActive()) {
requisitionDocument.setDeliveryCampusCode(defaultPrincipalAddress.getCampusCode());
requisitionDocument.templateBuildingToDeliveryAddress(defaultPrincipalAddress.getBuilding());
requisitionDocument.setDeliveryBuildingRoomNumber(defaultPrincipalAddress.getBuildingRoomNumber());
} else {
// since building is now inactive, delete default building record
businessObjectService.delete(defaultPrincipalAddress);
}
}
// set the APO limit
requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(purapService.getApoLimit(requisitionDocument.getVendorContractGeneratedIdentifier(), requisitionDocument.getChartOfAccountsCode(), requisitionDocument.getOrganizationCode()));
// populate billing address
BillingAddress billingAddress = new BillingAddress();
billingAddress.setBillingCampusCode(requisitionDocument.getDeliveryCampusCode());
@SuppressWarnings("unchecked") Map<String, ?> keys = persistenceService.getPrimaryKeyFieldValues(billingAddress);
billingAddress = (BillingAddress) businessObjectService.findByPrimaryKey(BillingAddress.class, keys);
requisitionDocument.templateBillingAddress(billingAddress);
}
}
}
use of org.kuali.rice.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.
the class IWantDocumentServiceImpl method buildDocumentFinalizedMessage.
/**
* Builds an email message to be sent when the input document has been finalized.
*
* @param iWantDocument
* @return an email message to be sent when the input document has been finalized
*/
private BodyMailMessage buildDocumentFinalizedMessage(IWantDocument iWantDocument) {
WorkflowDocument workflowDocument = iWantDocument.getDocumentHeader().getWorkflowDocument();
String initiator = workflowDocument.getInitiatorPrincipalId();
String documentNumber = iWantDocument.getDocumentNumber();
Person initiatorPerson = personService.getPerson(initiator);
String initiatorEmail = initiatorPerson.getEmailAddressUnmasked();
BodyMailMessage message = new BodyMailMessage();
message.addToAddress(initiatorEmail);
message.setFromAddress(initiatorEmail);
message.setSubject("I Want document: " + documentNumber + " has been finalized");
StringBuilder emailBody = new StringBuilder();
String vendorName = iWantDocument.getVendorName();
if (vendorName == null) {
vendorName = StringUtils.EMPTY;
}
emailBody.append("This is a message to inform you that the I Want document ").append(iWantDocument.getDocumentNumber()).append(" has been finalized: ").append(KRADConstants.NEWLINE).append(KRADConstants.NEWLINE);
emailBody.append("From: ").append(initiatorPerson.getNameUnmasked()).append(KRADConstants.NEWLINE);
emailBody.append("Title: ").append(iWantDocument.getDocumentTitle()).append(KRADConstants.NEWLINE);
emailBody.append("Type: ").append(workflowDocument.getDocumentTypeName()).append(KRADConstants.NEWLINE);
emailBody.append("Id: ").append(documentNumber).append(KRADConstants.NEWLINE);
emailBody.append("Vendor Name: ").append(vendorName).append("\n\n");
String docUrl = getDocumentURL(documentNumber, workflowDocument);
emailBody.append(" Go here to view this item: ").append(docUrl).append(KRADConstants.NEWLINE);
message.setMessage(emailBody.toString());
return message;
}
use of org.kuali.rice.kim.api.identity.Person 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;
}
Aggregations