View Javadoc
1   /*
2    * Copyright (C) 2003-2011 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.wcm.webui.utils;
18  
19  import java.util.List;
20  
21  import javax.jcr.Node;
22  
23  import org.exoplatform.portal.webui.util.Util;
24  import org.exoplatform.services.wcm.extensions.publication.PublicationManager;
25  import org.exoplatform.services.wcm.extensions.publication.lifecycle.impl.LifecyclesConfig.Lifecycle;
26  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
27  
28  /**
29   * Created by The eXo Platform SAS
30   * Author : Dang Viet Ha
31   *          hadv@exoplatform.com
32   * 22-06-2011
33   */
34  public class Utils {
35  
36    /**
37     * This method check whether to show the publish button for the current node or not
38     * @param currentNode the input current node
39     * @return <code>true</code> if the current node can be published,
40     * otherwise <code>false</code>
41     * @throws Exception
42     */
43    public static boolean isShowFastPublish(Node currentNode) throws Exception {
44      if (currentNode.hasProperty("publication:currentState")
45          && currentNode.hasProperty("publication:lifecycle")) {
46        String currentState = currentNode.getProperty("publication:currentState").getString();
47  
48        if (!"published".equals(currentState)) {
49  
50          String userId;
51          try {
52            userId = Util.getPortalRequestContext().getRemoteUser();
53          } catch (Exception e) {
54            userId = currentNode.getSession().getUserID();
55          }
56  
57          String nodeLifecycle = currentNode.getProperty("publication:lifecycle").getString();
58  
59          PublicationManager publicationManager = WCMCoreUtils.getService(PublicationManager.class);
60          List<Lifecycle> lifecycles =
61            publicationManager.getLifecyclesFromUser(userId, "published");
62  
63          for (Lifecycle lifecycle : lifecycles) {
64            if (nodeLifecycle.equals(lifecycle.getName())) {
65              return true;
66            }
67          }
68        }
69  
70      }
71      return false;
72    }
73  }