]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
85ddf090eb553d746ac171a3ba61f21a8e818d1d
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.systeminfo;
2
3 import java.nio.charset.Charset;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.List;
7 import java.util.Locale;
8 import java.util.Properties;
9 import java.util.TimeZone;
10
11 import javax.ws.rs.Consumes;
12 import javax.ws.rs.GET;
13 import javax.ws.rs.Path;
14 import javax.ws.rs.Produces;
15 import javax.ws.rs.core.Context;
16 import javax.ws.rs.core.Response;
17 import javax.ws.rs.core.UriInfo;
18 import javax.ws.rs.HttpMethod;
19
20 import org.collectionspace.services.authorization.AuthZ;
21 import org.collectionspace.services.authorization.CSpaceAction;
22 import org.collectionspace.services.authorization.CSpaceResource;
23 import org.collectionspace.services.authorization.URIResourceImpl;
24 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
25 import org.collectionspace.services.common.CSWebApplicationException;
26 import org.collectionspace.services.common.ServiceMain;
27 import org.collectionspace.services.common.UriInfoWrapper;
28 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
29 import org.collectionspace.services.common.context.ServiceContext;
30 import org.collectionspace.services.common.context.ServiceContextFactory;
31 import org.collectionspace.services.common.security.UnauthorizedException;
32 import org.nuxeo.runtime.api.Framework;
33
34 @Path(SystemInfoClient.SERVICE_PATH)
35 @Produces({"application/xml"})
36 @Consumes({"application/xml"})
37 public class SystemInfoResource extends AbstractCollectionSpaceResourceImpl<SystemInfoCommon, SystemInfoCommon> {
38
39         @Override
40         public Class<?> getCommonPartClass() {
41                 // TODO Auto-generated method stub
42                 return null;
43         }
44
45         @Override
46         public String getServiceName() {
47                 return SystemInfoClient.SERVICE_NAME;
48         }
49
50         @Override
51         protected String getVersionString() {
52                 // TODO Auto-generated method stub
53                 return null;
54         }
55
56         //
57         // API Endpoints
58         //
59
60     @GET
61     public SystemInfoCommon get(@Context UriInfo ui) {
62         SystemInfoCommon result = null;
63
64         try {
65                 result = new SystemInfoCommon();
66                 result.setInstanceId(ServiceMain.getInstance().getCspaceInstanceId());
67                 result.setDisplayName("CollectionSpace Services v5.1");
68                 Version ver = new Version();
69                 ver.setMajor("5");
70                 ver.setMinor("1");
71                 ver.setPatch("0");
72                 ver.setBuild("1");
73                 result.setVersion(ver);
74
75                 result.setHostTimezone(TimeZone.getDefault().getID());
76                 result.setHostLocale(Locale.getDefault().toLanguageTag());
77                 result.setHostCharset(Charset.defaultCharset().name());
78                 //
79                 // To get the full set of the system information, we required the user be authenticated *and* have "DELETE" privs on the "systeminfo" resource
80                 //
81                 try {
82                         ServiceContext<SystemInfoCommon, SystemInfoCommon> ctx = createServiceContext(getServiceName(), ui);
83                         CSpaceResource res = new URIResourceImpl(ctx.getTenantId(), SystemInfoClient.SERVICE_NAME, HttpMethod.DELETE);
84                         if (AuthZ.get().isAccessAllowed(res)) {
85                                                 // TODO: Stop hardcoding this!
86                                                 // result.setNuxeoVersionString("7.10-HF17");
87                                                 result.setHost(String.format("Architecture:%s Name:%s Version:%s",
88                                                                 System.getProperty("os.arch"), System.getProperty("os.name"), System.getProperty("os.version")));
89                                                 result.setJavaVersionString(System.getProperty("java.version"));
90
91                                                 // TODO: Stop hardcoding this!
92                                                 // result.setPostgresVersionString("9.5.7");
93
94                                                 Properties properties = Framework.getProperties();
95                                                 List<String> names = new ArrayList<String>(properties.stringPropertyNames());
96                                                 PropertyList nuxeoPropertyList = new PropertyList();
97
98                                                 Collections.sort(names);
99
100                                                 for (String name : names) {
101                                                         Property p = new Property();
102                                                         p.setKey(name);
103                                                         p.setValue(properties.getProperty(name));
104
105                                                         nuxeoPropertyList.getProperty().add(p);
106                                                 }
107
108                                                 result.setNuxeoPropertyList(nuxeoPropertyList);
109                         }
110                 } catch (UnauthorizedException e) {
111                         e.printStackTrace();
112                 }
113
114         } catch(Exception e) {
115                 Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).type("text/plain").build();
116             throw new CSWebApplicationException(response);
117         }
118
119         return result;
120     }
121
122         @Override
123         public ServiceContextFactory<SystemInfoCommon, SystemInfoCommon> getServiceContextFactory() {
124         return (ServiceContextFactory<SystemInfoCommon, SystemInfoCommon>) RemoteServiceContextFactory.get();
125         }
126 }