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.Item;
20  import javax.jcr.Node;
21  import javax.jcr.Property;
22  
23  import org.apache.commons.chain.Context;
24  import org.exoplatform.services.command.action.Action;
25  import org.exoplatform.services.listener.ListenerService;
26  import org.exoplatform.services.security.ConversationState;
27  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
28  
29  /**
30   * Created by The eXo Platform SAS
31   * Author : Nguyen The Vinh From ECM Of eXoPlatform
32   *          vinh_nguyen@exoplatform.com
33   * 11 Jan 2013  
34   */
35  public class EditPropertyActivityAction implements Action{
36    private ListenerService listenerService=null;
37    private ActivityCommonService activityService = null;
38    public EditPropertyActivityAction() {
39      listenerService =  WCMCoreUtils.getService(ListenerService.class);
40      activityService = WCMCoreUtils.getService(ActivityCommonService.class);
41    }
42    @Override
43    public boolean execute(Context context) throws Exception {
44      Object item = context.get("currentItem");
45      Node node = (item instanceof Property) ?((Property)item).getParent():(Node)item;
46      Node nodeTemp = activityService.isSpecialContentNodeType((Item) item);
47      String propertyName = (item instanceof Property) ?((Property)item).getName():((Node)item).getName();
48      if (nodeTemp !=null) {
49        if (!activityService.isCreating(nodeTemp)) { 
50          //Consider this special case as changing of content
51          String itemPath = ((Item) item).getPath();
52          String nodePath = nodeTemp.getPath();
53          String referencePath = itemPath.substring(nodePath.length());
54          if (referencePath.startsWith("/")) {
55            referencePath = referencePath.substring(1);
56          }
57          listenerService.broadcast(ActivityCommonService.EDIT_ACTIVITY, nodeTemp, referencePath);
58        }
59      }
60      nodeTemp = node;
61      // Do not create / update activity for bellow cases
62      if (!activityService.isAcceptedProperties(propertyName)) return false;
63      if (ConversationState.getCurrent() == null) return false;
64      
65      if(node.isNodeType("nt:resource")) node = node.getParent();
66      //filter node type
67      if (activityService.isAcceptedNode(node)) {
68        //Notify to update activity
69        if (!activityService.isCreating(node)) {
70          listenerService.broadcast(ActivityCommonService.EDIT_ACTIVITY, node, propertyName);
71        }      
72      }
73      return false;
74    }
75  
76  }