root/head/ambra/webapp/src/main/java/org/topazproject/ambra/admin/action/IngestArchivesAction.java @ 7472

Revision 7472, 4.1 KB (checked in by wtoconnor, 18 months ago)

The forced ingest of articles does not work because the action is not Transactional.

Addresses #1185

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id HeadURL Revision
Line 
1/* $$HeadURL::                                                                            $$
2 * $$Id$$
3 *
4 * Copyright (c) 2006-2009 by Topaz, Inc.
5 * http://topazproject.org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.topazproject.ambra.admin.action;
21
22import java.io.File;
23
24import org.apache.commons.logging.Log;
25import org.apache.commons.logging.LogFactory;
26
27import org.springframework.beans.factory.annotation.Required;
28import org.springframework.transaction.annotation.Transactional;
29
30import org.topazproject.ambra.admin.service.DocumentManagementService;
31import org.topazproject.ambra.admin.service.AdminService;
32import org.topazproject.ambra.admin.service.AdminService.JournalInfo;
33import org.topazproject.ambra.article.service.DuplicateArticleIdException;
34import org.topazproject.ambra.article.service.Ingester;
35import org.topazproject.ambra.models.Article;
36
37import org.topazproject.otm.Session;
38
39@SuppressWarnings("serial")
40public class IngestArchivesAction extends BaseAdminActionSupport {
41  private static final Log log = LogFactory.getLog(IngestArchivesAction.class);
42
43  // Fields Used by template
44  private String[] filesToIngest;
45  private boolean  force = false;
46  private Session session;
47  private JournalInfo journalInfo;
48
49  // Necessary Services
50  private AdminService adminService;
51
52  public void setFilesToIngest(String[] files) {
53    filesToIngest = files;
54  }
55
56  public void setForce(boolean flag) {
57    force = flag;
58  }
59
60  @Required
61  public void setOtmSession(Session session) {
62    this.session = session;
63  }
64
65  @Override
66  @Transactional(rollbackFor = { Throwable.class })
67  public String execute() {
68    if (filesToIngest != null) {
69      DocumentManagementService dms = getDocumentManagementService();
70      for (String filename : filesToIngest) {
71        filename = filename.trim();
72        try {
73          File file = new File(dms.getDocumentDirectory(), filename);
74          log.info("Creating ingester for " + file);
75          Ingester ingester = dms.createIngester(file);
76          log.info("Preparing ingester for " + file);
77          ingester.prepare(configuration);
78          log.info("Starting ingest for " + file);
79          Article article = dms.ingest(ingester, force);
80          log.info("Finished ingest for " + file);
81          addActionMessage("Ingested: " + filename);
82
83          session.evict(article);  // purely for performance. Subsequent flush()es will be faster.
84          getDocumentManagementService().generateIngestedData(file, article);
85        } catch (DuplicateArticleIdException de) {
86          addActionError("Error ingesting: " + filename + " - " + getMessages(de));
87          log.error("Error ingesting article: " + filename , de);
88        } catch (Exception e) {
89          addActionError("Error ingesting: " + filename + " - " + getMessages(e));
90          log.error("Error ingesting article: " + filename, e);
91        }
92      }
93    }
94
95    // create a faux journal object for template
96    journalInfo = adminService.createJournalInfo();
97    return base();
98  }
99
100  private static String getMessages(Throwable t) {
101    StringBuilder msg = new StringBuilder();
102    while (t != null) {
103      msg.append(t.toString());
104      t = t.getCause();
105      if (t != null)
106        msg.append("<br/>\n");
107    }
108    return msg.toString();
109  }
110
111  /**
112   * Gets the JournalInfo value object for access in the view.
113   *
114   * @return Current virtual Journal value object.
115   */
116  public AdminService.JournalInfo getJournal() {
117    return journalInfo;
118  }
119
120  /**
121   * Sets the AdminService.
122   *
123   * @param  adminService The adminService to set.
124   */
125  @Required
126  public void setAdminService(AdminService adminService) {
127    this.adminService = adminService;
128  }
129}
Note: See TracBrowser for help on using the browser.