1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.authoring;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import javax.jcr.Node;
26
27 import org.exoplatform.commons.utils.LazyPageList;
28 import org.exoplatform.commons.utils.ListAccess;
29 import org.exoplatform.commons.utils.ListAccessImpl;
30 import org.exoplatform.portal.application.PortalRequestContext;
31 import org.exoplatform.portal.webui.util.Util;
32 import org.exoplatform.services.cms.drives.ManageDriveService;
33 import org.exoplatform.services.wcm.core.NodeLocation;
34 import org.exoplatform.services.wcm.extensions.publication.PublicationManager;
35 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
36 import org.exoplatform.wcm.webui.Utils;
37 import org.exoplatform.webui.application.WebuiRequestContext;
38 import org.exoplatform.webui.application.portlet.PortletRequestContext;
39 import org.exoplatform.webui.config.annotation.ComponentConfig;
40 import org.exoplatform.webui.config.annotation.EventConfig;
41 import org.exoplatform.webui.core.UIComponent;
42 import org.exoplatform.webui.core.UIContainer;
43 import org.exoplatform.webui.core.lifecycle.Lifecycle;
44 import org.exoplatform.webui.event.Event;
45 import org.exoplatform.webui.event.EventListener;
46
47
48
49
50
51
52
53 @ComponentConfig(lifecycle = Lifecycle.class,
54 template = "app:/groovy/authoring/UIDashboardForm.gtmpl",
55 events = {
56 @EventConfig(listeners = UIDashboardForm.ShowDocumentActionListener.class),
57 @EventConfig(listeners = UIDashboardForm.RefreshActionListener.class) })
58 public class UIDashboardForm extends UIContainer {
59
60 private int pageSize_ = 10;
61
62 public UIDashboardForm() throws Exception {
63 addChild(UIDashBoardColumn.class, null, "UIDashboardDraft").setLabel("UIDashboardForm.label.mydraft");
64 addChild(UIDashBoardColumn.class, null, "UIDashboardWaiting").setLabel("UIDashboardForm.label.waitingapproval");
65 addChild(UIDashBoardColumn.class, null, "UIDashboardPublish").setLabel("UIDashboardForm.label.publishedtomorrow");
66 refreshData();
67 }
68
69 public List<Node> getContents(String fromstate) {
70 return getContents(fromstate, null, null);
71 }
72
73 public List<Node> getContents(String fromstate, String tostate) {
74 return getContents(fromstate, tostate, null);
75 }
76
77 public List<Node> getContents(String fromstate, String tostate, String date) {
78 PublicationManager manager = WCMCoreUtils.getService(PublicationManager.class);
79 String user = PortalRequestContext.getCurrentInstance().getRemoteUser();
80 String lang = Util.getPortalRequestContext().getLocale().getLanguage();
81 List<Node> nodes = new ArrayList<Node>();
82 List<Node> temp = new ArrayList<Node>();
83 try {
84 nodes = manager.getContents(fromstate, tostate, date, user, lang,
85 WCMCoreUtils.getRepository().getConfiguration().getDefaultWorkspaceName());
86 Set<String> uuidList = new HashSet<String>();
87 for(Node node : nodes) {
88 String currentState = null;
89 if(node.hasProperty("publication:currentState"))
90 currentState = node.getProperty("publication:currentState").getString();
91 if(currentState == null || !currentState.equals("published")) {
92 if(!org.exoplatform.services.cms.impl.Utils.isInTrash(node) &&
93 !uuidList.contains(node.getSession().getWorkspace().getName() + node.getUUID())) {
94 uuidList.add(node.getSession().getWorkspace().getName() + node.getUUID());
95 temp.add(node);
96 }
97 }
98 }
99 } catch (Exception e) {
100 temp = new ArrayList<Node>();
101 }
102 return temp;
103 }
104
105 private void refreshData() {
106 List<UIDashBoardColumn> children = new ArrayList<UIDashBoardColumn>();
107 for (UIComponent component : getChildren()) {
108 if (component instanceof UIDashBoardColumn) {
109 children.add((UIDashBoardColumn)component);
110 }
111 }
112 ListAccess<NodeLocation> draftNodes = new ListAccessImpl<NodeLocation>(NodeLocation.class,
113 NodeLocation.getLocationsByNodeList(getContents("draft")));
114 children.get(0).getUIPageIterator().setPageList(
115 new LazyPageList<NodeLocation>(draftNodes, pageSize_));
116
117 ListAccess<NodeLocation> waitingNodes = new ListAccessImpl<NodeLocation>(NodeLocation.class,
118 NodeLocation.getLocationsByNodeList(getContents("pending")));
119 children.get(1).getUIPageIterator().setPageList(
120 new LazyPageList<NodeLocation>(waitingNodes, pageSize_));
121
122 ListAccess<NodeLocation> publishedNodes = new ListAccessImpl<NodeLocation>(NodeLocation.class,
123 NodeLocation.getLocationsByNodeList(getContents("staged", null, "2")));
124 children.get(2).getUIPageIterator().setPageList(
125 new LazyPageList<NodeLocation>(publishedNodes, pageSize_));
126
127 }
128
129 public void processRender(WebuiRequestContext context) throws Exception
130 {
131 refreshData();
132 super.processRender(context);
133 }
134
135
136
137
138
139
140
141
142
143
144
145 public static class ShowDocumentActionListener extends EventListener<UIDashboardForm> {
146
147
148
149
150 public void execute(Event<UIDashboardForm> event) throws Exception {
151 PortalRequestContext context = Util.getPortalRequestContext();
152 String path = event.getRequestContext().getRequestParameter(OBJECTID);
153 HashMap<String, String> map = new HashMap<String, String>();
154 ManageDriveService driveService = WCMCoreUtils.getService(ManageDriveService.class);
155 map.put("repository", "repository");
156 map.put("drive", driveService.getDriveOfDefaultWorkspace());
157 map.put("path", path);
158 context.setAttribute("jcrexplorer-show-document", map);
159 Utils.updatePortal((PortletRequestContext) event.getRequestContext());
160
161 }
162 }
163
164
165
166
167
168
169
170
171
172
173 public static class RefreshActionListener extends EventListener<UIDashboardForm> {
174
175
176
177
178 public void execute(Event<UIDashboardForm> event) throws Exception {
179 UIDashboardForm src = event.getSource();
180 Utils.updatePortal((PortletRequestContext) event.getRequestContext());
181 }
182 }
183
184 }