001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.purap.document.web.struts;
017
018 import javax.servlet.http.HttpServletRequest;
019 import javax.servlet.http.HttpServletResponse;
020
021 import org.apache.struts.action.ActionForm;
022 import org.apache.struts.action.ActionForward;
023 import org.apache.struts.action.ActionMapping;
024 import org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument;
025 import org.kuali.kfs.sys.KFSConstants;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase;
028 import org.kuali.rice.kns.bo.Note;
029 import org.kuali.rice.kns.bo.PersistableBusinessObject;
030 import org.kuali.rice.kns.service.DocumentService;
031 import org.kuali.rice.kns.util.GlobalVariables;
032 import org.kuali.rice.kns.util.ObjectUtils;
033
034 /**
035 * Struts Action for Electronic invoice document.
036 */
037 public class ElectronicInvoiceRejectAction extends FinancialSystemTransactionalDocumentActionBase {
038
039 public ActionForward startResearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
040
041 ElectronicInvoiceRejectForm electronicInvoiceRejectForm = (ElectronicInvoiceRejectForm) form;
042 ElectronicInvoiceRejectDocument eirDocument = (ElectronicInvoiceRejectDocument) electronicInvoiceRejectForm.getDocument();
043 eirDocument.setInvoiceResearchIndicator(true);
044
045 Note noteObj = SpringContext.getBean(DocumentService.class).createNoteFromDocument(eirDocument, "Research started by: " + GlobalVariables.getUserSession().getPerson().getName());
046 PersistableBusinessObject noteParent = getNoteParent(eirDocument, noteObj);
047 noteParent.addNote(noteObj);
048 this.getNoteService().save(noteObj);
049 getDocumentService().saveDocument(eirDocument);
050
051 return mapping.findForward(KFSConstants.MAPPING_BASIC);
052 }
053
054 public ActionForward completeResearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
055
056 ElectronicInvoiceRejectForm electronicInvoiceRejectForm = (ElectronicInvoiceRejectForm) form;
057 ElectronicInvoiceRejectDocument eirDocument = (ElectronicInvoiceRejectDocument) electronicInvoiceRejectForm.getDocument();
058 eirDocument.setInvoiceResearchIndicator(false);
059
060 Note noteObj = SpringContext.getBean(DocumentService.class).createNoteFromDocument(eirDocument, "Research completed by: " + GlobalVariables.getUserSession().getPerson().getName());
061 PersistableBusinessObject noteParent = getNoteParent(eirDocument, noteObj);
062 noteParent.addNote(noteObj);
063 this.getNoteService().save(noteObj);
064 getDocumentService().saveDocument(eirDocument);
065
066 return mapping.findForward(KFSConstants.MAPPING_BASIC);
067
068 }
069
070 protected PersistableBusinessObject getNoteParent(ElectronicInvoiceRejectDocument document, Note newNote) {
071 //get the property name to set (this assumes this is a document type note)
072 String propertyName = getNoteService().extractNoteProperty(newNote);
073 //get BO to set
074 PersistableBusinessObject noteParent = (PersistableBusinessObject)ObjectUtils.getPropertyValue(document, propertyName);
075 return noteParent;
076 }
077
078 }
079