View Javadoc
1   /*
2    * Copyright (C) 2003-2013 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (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 Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.jcrext.activity;
18  
19  import javax.jcr.Node;
20  
21  import org.apache.commons.chain.Context;
22  import org.exoplatform.services.command.action.Action;
23  import org.exoplatform.services.listener.ListenerService;
24  import org.exoplatform.services.wcm.core.NodetypeConstant;
25  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
26  
27  /**
28   * Created by The eXo Platform SAS
29   * Author : Nguyen The Vinh From ECM Of eXoPlatform
30   *          vinh_nguyen@exoplatform.com
31   * 14 Jan 2013  
32   */
33  public class AddNodeActivityAction implements Action{
34    
35    private ListenerService listenerService=null;
36    private ActivityCommonService activityService = null;
37    public AddNodeActivityAction() {
38      listenerService =  WCMCoreUtils.getService(ListenerService.class);
39      activityService = WCMCoreUtils.getService(ActivityCommonService.class);
40    }
41    public boolean execute(Context context) throws Exception {
42      if (listenerService ==null) return false;
43      Object item = context.get("currentItem");
44      if (item instanceof Node) {
45        Node node = (Node)item;
46        if (node.getPrimaryNodeType().getName().equals((NodetypeConstant.NT_FILE))) {
47          Node parent = node.getParent();
48          if (activityService.isAcceptedNode(parent) && !activityService.isCreating(parent)) {
49            listenerService.broadcast(ActivityCommonService.ATTACH_ADDED_ACTIVITY, parent, node);
50          }
51        }
52      }
53      return false;
54    }
55  }