001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: /*
017: * Created on Jul 9, 2004
018: *
019: */
020: package org.kuali.module.pdp.action.upload;
021:
022: import java.io.File;
023: import java.io.FileOutputStream;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.struts.action.ActionForm;
029: import org.apache.struts.action.ActionForward;
030: import org.apache.struts.action.ActionMapping;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.module.pdp.action.BaseAction;
033: import org.kuali.module.pdp.exception.PaymentLoadException;
034: import org.kuali.module.pdp.form.upload.UploadForm;
035: import org.kuali.module.pdp.service.LoadPaymentStatus;
036: import org.kuali.module.pdp.service.PaymentFileService;
037: import org.kuali.module.pdp.service.SecurityRecord;
038:
039: /**
040: * @author jsissom
041: */
042: public class ManualUploadFileAction extends BaseAction {
043: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(ManualUploadFileAction.class);
045:
046: private PaymentFileService paymentFileService;
047: private String tmpDir = "/tmp";
048:
049: public ManualUploadFileAction() {
050: setPaymentFileService(SpringContext
051: .getBean(PaymentFileService.class));
052: }
053:
054: // TODO Fix this
055: public void setTmpDir(String t) {
056: LOG.debug("setTmpDir() setting tmp dir to " + t);
057: tmpDir = t;
058: }
059:
060: protected boolean isAuthorized(ActionMapping mapping,
061: ActionForm form, HttpServletRequest request,
062: HttpServletResponse response) {
063: SecurityRecord sr = getSecurityRecord(request);
064: return sr.isSubmitRole();
065: }
066:
067: protected ActionForward executeLogic(ActionMapping mapping,
068: ActionForm form, HttpServletRequest request,
069: HttpServletResponse response) throws Exception {
070: LOG.debug("executeLogic() starting");
071:
072: UploadForm uForm = (UploadForm) form;
073:
074: String filename = tmpDir + "/" + request.getSession().getId()
075: + ".xml";
076: LOG.debug("executeLogic() Filename: " + filename);
077: File outputFile = new File(filename);
078:
079: FileOutputStream out = new FileOutputStream(outputFile);
080: out.write(uForm.getFile().getFileData());
081: out.close();
082:
083: try {
084: LoadPaymentStatus status = paymentFileService.loadPayments(
085: filename, getUser(request));
086: if (status.getWarnings().size() > 0) {
087: LOG
088: .debug("executeLogic() There were warnings when loading "
089: + filename);
090: request.setAttribute("errors", status.getWarnings());
091: }
092: // Save the status in the request so we can print info from it
093: request.setAttribute("status", status);
094: } catch (PaymentLoadException e1) {
095: LOG.error("executeLogic() Exception when parsing XML", e1);
096:
097: request.setAttribute("errors", e1.getErrors());
098: return mapping.findForward("hard_errors");
099: }
100:
101: // Delete the file because we're done with it
102: outputFile.delete();
103:
104: LOG.debug("executeLogic() File load was successful");
105: return mapping.findForward("successful");
106: }
107:
108: public void setPaymentFileService(PaymentFileService p) {
109: this.paymentFileService = p;
110: }
111: }
|