root/head/ambra/webapp/src/main/java/org/topazproject/ambra/admin/action/PublishArchivesAction.java @ 7438

Revision 7438, 4.7 KB (checked in by wtoconnor, 18 months ago)

Prevent Cross Publishing into current journal.

After and ingest the admin is presented with a matrix of journals that articles can be cross published in. Included in the current journal the article will be published in if 'Publish' check box is chosen. Articles should not be crossed published in the journal they are published in. Remove it form the adminTop.ftl but several xxxxAction.java files were affect so they were changed also.

Addresses #1149

  • 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.util.HashMap;
23import java.util.HashSet;
24import java.util.List;
25import java.util.Map;
26import java.util.Set;
27
28import org.apache.commons.logging.Log;
29import org.apache.commons.logging.LogFactory;
30
31import org.springframework.transaction.annotation.Transactional;
32import org.springframework.transaction.interceptor.TransactionAspectSupport;
33import org.springframework.beans.factory.annotation.Required;
34import org.topazproject.ambra.admin.service.AdminService;
35import org.topazproject.ambra.admin.service.AdminService.JournalInfo;
36
37@SuppressWarnings("serial")
38public class PublishArchivesAction extends BaseAdminActionSupport {
39  private static final Log log = LogFactory.getLog(PublishArchivesAction.class);
40
41  // Fields Used by template
42  private String[] articlesToPublish;
43  private String[] articlesInVirtualJournals;
44  private String[] articlesToDelete;
45  private JournalInfo journalInfo;
46
47  // Necessary Services
48  private AdminService adminService;
49
50  /**
51   * Deletes and publishes checked articles from the admin console.  Note that delete has priority
52   * over publish.
53   */
54  @Override
55  @Transactional(rollbackFor = { Throwable.class })
56  public String execute() {
57    try {
58      deleteArticles();
59      publishArticles();
60    } catch (Exception e) {
61      addActionError("Exception: " + e);
62      log.error(e);
63      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
64      return ERROR;
65    }
66
67    // create a faux journal object for template
68    journalInfo = adminService.createJournalInfo();
69    return base();
70  }
71
72  /**
73   * Publishes articles from the admin console.
74   */
75  private void publishArticles() {
76    if (articlesToPublish == null)
77      return;
78
79    Map<String, Set<String>> vjMap = new HashMap<String, Set<String>>();
80    if (articlesInVirtualJournals != null) {
81      for (String articleInVirtualJournal : articlesInVirtualJournals) {
82        // form builds checkbox value as "article" + "::" + "virtualJournal"
83        String[] parts = articleInVirtualJournal.split("::");
84        Set<String> vjList = vjMap.get(parts[0]);
85        if (vjList == null)
86          vjMap.put(parts[0], vjList = new HashSet<String>());
87        vjList.add(parts[1]);
88      }
89    }
90
91    List<String> msgs = getDocumentManagementService().publish(articlesToPublish, vjMap);
92    for (String msg : msgs)
93      addActionMessage(msg);
94  }
95
96  /**
97   * Deletes the checked articles from the admin console.
98   */
99  private void deleteArticles() {
100    if (articlesToDelete == null)
101      return;
102
103    List<String> msgs = getDocumentManagementService().delete(articlesToDelete);
104    for (String msg : msgs)
105      addActionMessage(msg);
106
107    for (String article : articlesToDelete) {
108      try {
109        getDocumentManagementService().revertIngestedQueue(article);
110      } catch (Exception ioe) {
111        log.warn("Error cleaning up spool directories for '" + article +
112                 "' - manual cleanup required", ioe);
113        addActionMessage("Failed to move " + article + " back to ingestion queue: " + ioe);
114      }
115    }
116  }
117
118  /**
119   *
120   * @param articles array of articles to publish
121   */
122  public void setArticlesToPublish(String[] articles) {
123    articlesToPublish = articles;
124  }
125
126  /**
127   *
128   * @param articlesInVirtualJournals array of ${virtualJournal} + "::" + ${article} to publish.
129   */
130  public void setArticlesInVirtualJournals(String[] articlesInVirtualJournals) {
131    this.articlesInVirtualJournals = articlesInVirtualJournals;
132  }
133
134  /**
135   *
136   * @param articles array of articles to delete
137   */
138  public void setArticlesToDelete(String[] articles) {
139    articlesToDelete= articles;
140  }
141
142  /**
143   * Gets the JournalInfo value object for access in the view.
144   *
145   * @return Current virtual Journal value object.
146   */
147  public AdminService.JournalInfo getJournal() {
148    return journalInfo;
149  }
150
151  /**
152   * Sets the AdminService.
153   *
154   * @param  adminService The adminService to set.
155   */
156  @Required
157  public void setAdminService(AdminService adminService) {
158    this.adminService = adminService;
159  }
160}
Note: See TracBrowser for help on using the browser.