Source Code Cross Referenced for IngesterAction.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » batch » web » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.batch.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package edu.iu.uis.eden.batch.web;
018:
019:        import java.io.File;
020:        import java.io.FileOutputStream;
021:        import java.io.IOException;
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Iterator;
025:        import java.util.List;
026:
027:        import javax.servlet.http.HttpServletRequest;
028:        import javax.servlet.http.HttpServletResponse;
029:
030:        import org.apache.log4j.Logger;
031:        import org.apache.struts.action.Action;
032:        import org.apache.struts.action.ActionForm;
033:        import org.apache.struts.action.ActionForward;
034:        import org.apache.struts.action.ActionMapping;
035:        import org.apache.struts.upload.FormFile;
036:
037:        import edu.iu.uis.eden.KEWServiceLocator;
038:        import edu.iu.uis.eden.batch.CompositeXmlDocCollection;
039:        import edu.iu.uis.eden.batch.FileXmlDocCollection;
040:        import edu.iu.uis.eden.batch.XmlDoc;
041:        import edu.iu.uis.eden.batch.XmlDocCollection;
042:        import edu.iu.uis.eden.batch.ZipXmlDocCollection;
043:        import edu.iu.uis.eden.util.Utilities;
044:        import edu.iu.uis.eden.web.UserLoginFilter;
045:
046:        /**
047:         * Struts action that accepts uploaded files and feeds them to the XmlIngesterService
048:         * @see edu.iu.uis.eden.batch.XmlIngesterService
049:         * @see edu.iu.uis.eden.batch.web.IngesterForm
050:         * @author Aaron Hamid (arh14 at cornell dot edu)
051:         */
052:        public class IngesterAction extends Action {
053:            private static final Logger LOG = Logger
054:                    .getLogger(IngesterAction.class);
055:
056:            public ActionForward execute(ActionMapping mapping,
057:                    ActionForm form, HttpServletRequest request,
058:                    HttpServletResponse response) throws Exception {
059:
060:                LOG.debug(request.getMethod());
061:                if (!"post".equals(request.getMethod().toLowerCase())) {
062:                    LOG.debug("returning to view");
063:                    return mapping.findForward("view");
064:                }
065:
066:                IngesterForm iform = (IngesterForm) form;
067:
068:                List messages = new ArrayList();
069:                List tempFiles = new ArrayList();
070:                try {
071:                    Collection files = iform.getFiles();
072:                    List collections = new ArrayList(files.size());
073:                    LOG.debug(files);
074:                    LOG.debug("" + files.size());
075:
076:                    Iterator it = files.iterator();
077:                    while (it.hasNext()) {
078:                        FormFile file = (FormFile) it.next();
079:                        if (file.getFileName() == null
080:                                || file.getFileName().length() == 0)
081:                            continue;
082:                        if (file.getFileData() == null) {
083:                            messages.add("File '" + file.getFileName()
084:                                    + "' contained no data");
085:                            continue;
086:                        }
087:                        LOG.debug("Processing file: " + file.getFileName());
088:                        // ok, we have to copy it to *another* file because Struts doesn't give us a File
089:                        // reference (which itself is not a bad abstraction) and XmlDocs based on ZipFile
090:                        // can't be constructed without a file reference.
091:                        FileOutputStream fos = null;
092:                        File temp = null;
093:                        try {
094:                            temp = File.createTempFile("ingester", null);
095:                            tempFiles.add(temp);
096:                            fos = new FileOutputStream(temp);
097:                            fos.write(file.getFileData());
098:                        } catch (IOException ioe) {
099:                            messages.add("Error copying file data for '"
100:                                    + file.getFileName() + "': " + ioe);
101:                            continue;
102:                        } finally {
103:                            if (fos != null)
104:                                try {
105:                                    fos.close();
106:                                } catch (IOException ioe) {
107:                                    LOG.error(
108:                                            "Error closing temp file output stream: "
109:                                                    + temp, ioe);
110:                                }
111:                        }
112:                        if (file.getFileName().toLowerCase().endsWith(".zip")) {
113:                            try {
114:                                collections.add(new ZipXmlDocCollection(temp));
115:                            } catch (IOException ioe) {
116:                                String message = "Unable to load file: " + file;
117:                                LOG.error(message);
118:                                messages.add(message);
119:                            }
120:                        } else if (file.getFileName().endsWith(".xml")) {
121:                            collections.add(new FileXmlDocCollection(temp, file
122:                                    .getFileName()));
123:                        } else {
124:                            messages.add("Ignoring extraneous file: "
125:                                    + file.getFileName());
126:                        }
127:                    }
128:
129:                    if (collections.size() == 0) {
130:                        String message = "No valid files to ingest";
131:                        LOG.debug(message);
132:                        messages.add(message);
133:                    } else {
134:                        // wrap in composite collection to make transactional
135:                        CompositeXmlDocCollection compositeCollection = new CompositeXmlDocCollection(
136:                                collections);
137:                        int totalProcessed = 0;
138:                        List<XmlDocCollection> c = new ArrayList<XmlDocCollection>(
139:                                1);
140:                        c.add(compositeCollection);
141:                        try {
142:                            Collection failed = KEWServiceLocator
143:                                    .getXmlIngesterService().ingest(
144:                                            c,
145:                                            UserLoginFilter.getUserSession(
146:                                                    request).getWorkflowUser());
147:                            boolean txFailed = failed.size() > 0;
148:                            if (txFailed) {
149:                                messages.add("Ingestion failed");
150:                            }
151:                            it = collections.iterator();
152:                            while (it.hasNext()) {
153:                                XmlDocCollection collection = (XmlDocCollection) it
154:                                        .next();
155:                                List docs = collection.getXmlDocs();
156:                                Iterator docIt = docs.iterator();
157:                                while (docIt.hasNext()) {
158:                                    XmlDoc doc = (XmlDoc) docIt.next();
159:                                    if (doc.isProcessed()) {
160:                                        if (!txFailed) {
161:                                            totalProcessed++;
162:                                            messages
163:                                                    .add("Ingested xml doc: "
164:                                                            + doc.getName()
165:                                                            + (doc
166:                                                                    .getProcessingMessage() == null ? ""
167:                                                                    : "\n"
168:                                                                            + doc
169:                                                                                    .getProcessingMessage()));
170:                                        } else {
171:                                            messages
172:                                                    .add("Rolled back doc: "
173:                                                            + doc.getName()
174:                                                            + (doc
175:                                                                    .getProcessingMessage() == null ? ""
176:                                                                    : "\n"
177:                                                                            + doc
178:                                                                                    .getProcessingMessage()));
179:                                        }
180:                                    } else {
181:                                        messages
182:                                                .add("Failed to ingest xml doc: "
183:                                                        + doc.getName()
184:                                                        + (doc
185:                                                                .getProcessingMessage() == null ? ""
186:                                                                : "\n"
187:                                                                        + doc
188:                                                                                .getProcessingMessage()));
189:                                    }
190:                                }
191:                            }
192:                        } catch (Exception e) {
193:                            String message = "Error during ingest";
194:                            LOG.error(message, e);
195:                            messages.add(message + ": " + e + ":\n"
196:                                    + Utilities.collectStackTrace(e));
197:                        }
198:                        if (totalProcessed == 0) {
199:                            String message = "No xml docs ingested";
200:                            LOG.debug(message);
201:                            messages.add(message);
202:                        }
203:                    }
204:                } finally {
205:                    if (tempFiles.size() > 0) {
206:                        Iterator it = tempFiles.iterator();
207:                        while (it.hasNext()) {
208:                            File temp = (File) it.next();
209:                            if (!temp.delete()) {
210:                                LOG.warn("Error deleting temp file: " + temp);
211:                            }
212:                        }
213:                    }
214:                }
215:
216:                request.setAttribute("messages", messages);
217:                return mapping.findForward("view");
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.