1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.admin.unlock;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.exoplatform.commons.utils.LazyPageList;
24 import org.exoplatform.commons.utils.ListAccess;
25 import org.exoplatform.commons.utils.ListAccessImpl;
26 import org.exoplatform.ecm.webui.core.UIPagingGridDecorator;
27 import org.exoplatform.ecm.utils.lock.LockUtil;
28 import org.exoplatform.services.cms.lock.LockService;
29 import org.exoplatform.web.application.ApplicationMessage;
30 import org.exoplatform.webui.config.annotation.ComponentConfig;
31 import org.exoplatform.webui.config.annotation.EventConfig;
32 import org.exoplatform.webui.core.UIApplication;
33 import org.exoplatform.webui.event.Event;
34 import org.exoplatform.webui.event.EventListener;
35
36
37
38
39
40
41
42
43 @ComponentConfig(
44 template = "app:/groovy/webui/component/admin/unlock/UILockHolderList.gtmpl",
45 events = {
46 @EventConfig(listeners = UILockHolderList.DeleteLockActionListener.class)
47 }
48 )
49 public class UILockHolderList extends UIPagingGridDecorator {
50 final static public String[] ACTIONS = {};
51 final static public String ST_EDIT = "EditUnLockForm";
52
53 public UILockHolderList() throws Exception {
54 getUIPageIterator().setId("LockHolderListIterator");
55 }
56
57 public String[] getActions() { return ACTIONS ; }
58
59 public void refresh(int currentPage) throws Exception {
60 ListAccess<String> groupsAndUsersForLockList = new ListAccessImpl<String>(String.class,
61 getAllGroupsOrUsersForLock());
62 LazyPageList<String> pageList = new LazyPageList<String>(groupsAndUsersForLockList,
63 getUIPageIterator().getItemsPerPage());
64 getUIPageIterator().setPageList(pageList);
65 if (currentPage > getUIPageIterator().getAvailablePage())
66 getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage());
67 else
68 getUIPageIterator().setCurrentPage(currentPage);
69 }
70
71
72 public List getGroupsOrUsersForLock() throws Exception {
73 return getUIPageIterator().getCurrentPageData();
74 }
75
76 public List<String> getAllGroupsOrUsersForLock() throws Exception {
77 LockService lockService = getApplicationComponent(LockService.class);
78
79 return lockService.getAllGroupsOrUsersForLock();
80 }
81
82 static public class DeleteLockActionListener extends EventListener<UILockHolderList> {
83 public void execute(Event<UILockHolderList> event) throws Exception {
84 UILockHolderList uiLockHolderList = event.getSource();
85 UILockHolderContainer uiLockHolderContainer = uiLockHolderList.getAncestorOfType(UILockHolderContainer.class);
86 String removedLockSetting = event.getRequestContext().getRequestParameter(OBJECTID);
87 LockService lockService = uiLockHolderContainer.getApplicationComponent(LockService.class);
88 if (!lockService.getPreSettingLockList().contains(removedLockSetting)) {
89 lockService.removeGroupsOrUsersForLock(removedLockSetting);
90
91
92 List<String> ignoredList = new ArrayList<String>();
93 if (removedLockSetting.startsWith("*")) {
94 String groupOfRemovedLockSetting = StringUtils.substringAfter(removedLockSetting, ":");
95 List<String> allLockSettings = lockService.getAllGroupsOrUsersForLock();
96 for (String lockSetting : allLockSettings) {
97 if (groupOfRemovedLockSetting.equals(StringUtils.substringAfter(lockSetting, ":"))) {
98 ignoredList.add(lockSetting);
99 }
100 }
101 }
102 LockUtil.removeLockCache(removedLockSetting, ignoredList);
103
104 } else {
105 Object[] args = {removedLockSetting};
106 UIApplication uiApp = uiLockHolderList.getAncestorOfType(UIApplication.class);
107 uiApp.addMessage(new ApplicationMessage("UILockHolderList.msg.can-not-delete-lock-holder", args,
108 ApplicationMessage.WARNING));
109
110 event.getRequestContext().addUIComponentToUpdateByAjax(uiLockHolderContainer.getParent());
111 }
112 UILockHolderList uiHolderList = uiLockHolderContainer.getChild(UILockHolderList.class);
113 uiHolderList.refresh(uiHolderList.getUIPageIterator().getCurrentPage());
114 UIUnLockManager uiUnLockManager = uiLockHolderContainer.getParent();
115 uiUnLockManager.getChild(UILockNodeList.class).setRendered(false);
116 uiLockHolderContainer.setRendered(true);
117 event.getRequestContext().addUIComponentToUpdateByAjax(uiLockHolderContainer.getParent());
118 }
119 }
120 }