1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.exoplatform.social.service.rest;
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import javax.ws.rs.GET;
25 import javax.ws.rs.Path;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.WebApplicationException;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
32 import javax.xml.bind.annotation.XmlRootElement;
33
34 import org.exoplatform.application.registry.Application;
35 import org.exoplatform.application.registry.ApplicationCategory;
36 import org.exoplatform.application.registry.ApplicationRegistryService;
37 import org.exoplatform.container.PortalContainer;
38 import org.exoplatform.portal.config.model.ApplicationType;
39 import org.exoplatform.services.rest.resource.ResourceContainer;
40
41
42
43
44
45
46
47
48 @Path("social/apps")
49 public class AppsRestService implements ResourceContainer {
50
51 private ApplicationRegistryService _applicationRegistryService;
52
53
54
55 public AppsRestService() {}
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @GET
73 @Path("show.{format}")
74 public Response showApps(@Context UriInfo uriInfo, @PathParam("format") String format) throws Exception {
75
76 MediaType mediaType = Util.getMediaType(format);
77 AppList appList = showApps();
78 return Util.getResponse(appList, uriInfo, mediaType, Response.Status.OK);
79 }
80
81
82
83
84
85 static public class App {
86 private String _appId;
87 private String _appName;
88
89
90
91
92 public void setAppId(String appId) { _appId = appId; }
93
94
95
96
97 public String getAppId() { return _appId; }
98
99
100
101
102 public void setAppName(String appName) { _appName = appName; }
103
104
105
106
107 public String getAppName() {return _appName ;}
108 }
109
110
111
112
113
114 @XmlRootElement
115 static public class AppList {
116 private List<App> _apps;
117
118
119
120
121 public void setApps(List<App> apps) { _apps = apps; }
122
123
124
125
126 public List<App> getApps() { return _apps; }
127
128
129
130
131
132 public void addApp(App app) {
133 if (_apps == null) {
134 _apps = new ArrayList<App>();
135 }
136 _apps.add(app);
137 }
138 }
139
140
141
142
143
144
145 private AppList showApps() {
146 AppList appList = new AppList();
147 ApplicationRegistryService applicationRegistryService = getApplicationRegistryService();
148
149 try {
150 List<ApplicationCategory> applicationCategoryList = applicationRegistryService.getApplicationCategories("root");
151 Iterator<ApplicationCategory> applicationCategoryItr = applicationCategoryList.iterator();
152 ApplicationCategory applicationCategory;
153 while (applicationCategoryItr.hasNext()) {
154 applicationCategory = applicationCategoryItr.next();
155 ApplicationType<org.exoplatform.portal.pom.spi.portlet.Portlet> portletType = ApplicationType.PORTLET;
156 List<Application> applications = applicationRegistryService.getApplications(applicationCategory, portletType);
157 Iterator<Application> applicationItr = applications.iterator();
158 Application application;
159 while (applicationItr.hasNext()) {
160 App app = new App();
161 application = applicationItr.next();
162 app.setAppId(application.getId());
163 app.setAppName(application.getDisplayName());
164 appList.addApp(app);
165 }
166 }
167 } catch (Exception ex) {
168 throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
169 }
170 return appList;
171 }
172
173
174
175
176
177
178 private ApplicationRegistryService getApplicationRegistryService() {
179 if (_applicationRegistryService == null) {
180 PortalContainer portalContainer = PortalContainer.getInstance();
181 _applicationRegistryService = (ApplicationRegistryService) portalContainer.
182 getComponentInstanceOfType(ApplicationRegistryService.class);
183 }
184 return _applicationRegistryService;
185 }
186 }