guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmuehl...@apache.org
Subject [09/24] incubator-guacamole-client git commit: GUACAMOLE-5: Refactor HistoryRESTService as a resource.
Date Wed, 13 Jul 2016 05:09:47 GMT
GUACAMOLE-5: Refactor HistoryRESTService as a resource.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/3658b91f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/3658b91f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/3658b91f

Branch: refs/heads/master
Commit: 3658b91fe18e386b10d251922610c03075cc55a3
Parents: 3f7f6e6
Author: Michael Jumper <mjumper@apache.org>
Authored: Tue Jul 12 13:43:37 2016 -0700
Committer: Michael Jumper <mjumper@apache.org>
Committed: Tue Jul 12 21:23:46 2016 -0700

----------------------------------------------------------------------
 .../guacamole/rest/RESTServiceModule.java       |   2 -
 .../rest/history/HistoryRESTService.java        | 144 -------------------
 .../guacamole/rest/history/HistoryResource.java | 122 ++++++++++++++++
 .../rest/session/UserContextResource.java       |  14 ++
 4 files changed, 136 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3658b91f/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
index dbdcaba..c6de0dc 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTServiceModule.java
@@ -36,7 +36,6 @@ import org.apache.guacamole.rest.auth.SecureRandomAuthTokenGenerator;
 import org.apache.guacamole.rest.auth.TokenSessionMap;
 import org.apache.guacamole.rest.connection.ConnectionModule;
 import org.apache.guacamole.rest.connectiongroup.ConnectionGroupModule;
-import org.apache.guacamole.rest.history.HistoryRESTService;
 import org.apache.guacamole.rest.language.LanguageRESTService;
 import org.apache.guacamole.rest.patch.PatchRESTService;
 import org.apache.guacamole.rest.schema.SchemaRESTService;
@@ -88,7 +87,6 @@ public class RESTServiceModule extends ServletModule {
         bind(ObjectRetrievalService.class);
 
         // Set up the API endpoints
-        bind(HistoryRESTService.class);
         bind(LanguageRESTService.class);
         bind(PatchRESTService.class);
         bind(SchemaRESTService.class);

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3658b91f/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryRESTService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryRESTService.java
b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryRESTService.java
deleted file mode 100644
index fd3738e..0000000
--- a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryRESTService.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.guacamole.rest.history;
-
-import com.google.inject.Inject;
-import java.util.ArrayList;
-import java.util.List;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.net.auth.ConnectionRecord;
-import org.apache.guacamole.net.auth.ConnectionRecordSet;
-import org.apache.guacamole.net.auth.UserContext;
-import org.apache.guacamole.GuacamoleSession;
-import org.apache.guacamole.rest.ObjectRetrievalService;
-import org.apache.guacamole.rest.auth.AuthenticationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A REST Service for retrieving and managing the history records of Guacamole
- * objects.
- *
- * @author Michael Jumper
- */
-@Path("/data/{dataSource}/history")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class HistoryRESTService {
-
-    /**
-     * Logger for this class.
-     */
-    private static final Logger logger = LoggerFactory.getLogger(HistoryRESTService.class);
-
-    /**
-     * The maximum number of history records to return in any one response.
-     */
-    private static final int MAXIMUM_HISTORY_SIZE = 1000;
-
-    /**
-     * A service for authenticating users from auth tokens.
-     */
-    @Inject
-    private AuthenticationService authenticationService;
-
-    /**
-     * Service for convenient retrieval of objects.
-     */
-    @Inject
-    private ObjectRetrievalService retrievalService;
-
-    /**
-     * Retrieves the usage history for all connections, restricted by optional
-     * filter parameters.
-     *
-     * @param authToken
-     *     The authentication token that is used to authenticate the user
-     *     performing the operation.
-     *
-     * @param authProviderIdentifier
-     *     The unique identifier of the AuthenticationProvider associated with
-     *     the UserContext containing the connection whose history is to be
-     *     retrieved.
-     *
-     * @param requiredContents
-     *     The set of strings that each must occur somewhere within the
-     *     returned connection records, whether within the associated username,
-     *     the name of the associated connection, or any associated date. If
-     *     non-empty, any connection record not matching each of the strings
-     *     within the collection will be excluded from the results.
-     *
-     * @param sortPredicates
-     *     A list of predicates to apply while sorting the resulting connection
-     *     records, describing the properties involved and the sort order for
-     *     those properties.
-     *
-     * @return
-     *     A list of connection records, describing the start and end times of
-     *     various usages of this connection.
-     *
-     * @throws GuacamoleException
-     *     If an error occurs while retrieving the connection history.
-     */
-    @GET
-    @Path("/connections")
-    public List<APIConnectionRecord> getConnectionHistory(@QueryParam("token") String
authToken,
-            @PathParam("dataSource") String authProviderIdentifier,
-            @QueryParam("contains") List<String> requiredContents,
-            @QueryParam("order") List<APIConnectionRecordSortPredicate> sortPredicates)
-            throws GuacamoleException {
-
-        GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
-        UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
-
-        // Retrieve overall connection history
-        ConnectionRecordSet history = userContext.getConnectionHistory();
-
-        // Restrict to records which contain the specified strings
-        for (String required : requiredContents) {
-            if (!required.isEmpty())
-                history = history.contains(required);
-        }
-
-        // Sort according to specified ordering
-        for (APIConnectionRecordSortPredicate predicate : sortPredicates)
-            history = history.sort(predicate.getProperty(), predicate.isDescending());
-
-        // Limit to maximum result size
-        history = history.limit(MAXIMUM_HISTORY_SIZE);
-
-        // Convert record set to collection of API connection records
-        List<APIConnectionRecord> apiRecords = new ArrayList<APIConnectionRecord>();
-        for (ConnectionRecord record : history.asCollection())
-            apiRecords.add(new APIConnectionRecord(record));
-
-        // Return the converted history
-        return apiRecords;
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3658b91f/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java
b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java
new file mode 100644
index 0000000..d71d445
--- /dev/null
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.rest.history;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.ConnectionRecord;
+import org.apache.guacamole.net.auth.ConnectionRecordSet;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * A REST resource for retrieving and managing the history records of Guacamole
+ * objects.
+ *
+ * @author Michael Jumper
+ */
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class HistoryResource {
+
+    /**
+     * The maximum number of history records to return in any one response.
+     */
+    private static final int MAXIMUM_HISTORY_SIZE = 1000;
+
+    /**
+     * The UserContext whose associated connection history is being exposed.
+     */
+    private final UserContext userContext;
+
+    /**
+     * Creates a new HistoryResource which exposes the connection history
+     * associated with the given UserContext.
+     *
+     * @param userContext
+     *     The UserContext whose connection history should be exposed.
+     */
+    public HistoryResource(UserContext userContext) {
+        this.userContext = userContext;
+    }
+
+    /**
+     * Retrieves the usage history for all connections, restricted by optional
+     * filter parameters.
+     *
+     * @param requiredContents
+     *     The set of strings that each must occur somewhere within the
+     *     returned connection records, whether within the associated username,
+     *     the name of the associated connection, or any associated date. If
+     *     non-empty, any connection record not matching each of the strings
+     *     within the collection will be excluded from the results.
+     *
+     * @param sortPredicates
+     *     A list of predicates to apply while sorting the resulting connection
+     *     records, describing the properties involved and the sort order for
+     *     those properties.
+     *
+     * @return
+     *     A list of connection records, describing the start and end times of
+     *     various usages of this connection.
+     *
+     * @throws GuacamoleException
+     *     If an error occurs while retrieving the connection history.
+     */
+    @GET
+    @Path("connections")
+    public List<APIConnectionRecord> getConnectionHistory(
+            @QueryParam("contains") List<String> requiredContents,
+            @QueryParam("order") List<APIConnectionRecordSortPredicate> sortPredicates)
+            throws GuacamoleException {
+
+        // Retrieve overall connection history
+        ConnectionRecordSet history = userContext.getConnectionHistory();
+
+        // Restrict to records which contain the specified strings
+        for (String required : requiredContents) {
+            if (!required.isEmpty())
+                history = history.contains(required);
+        }
+
+        // Sort according to specified ordering
+        for (APIConnectionRecordSortPredicate predicate : sortPredicates)
+            history = history.sort(predicate.getProperty(), predicate.isDescending());
+
+        // Limit to maximum result size
+        history = history.limit(MAXIMUM_HISTORY_SIZE);
+
+        // Convert record set to collection of API connection records
+        List<APIConnectionRecord> apiRecords = new ArrayList<APIConnectionRecord>();
+        for (ConnectionRecord record : history.asCollection())
+            apiRecords.add(new APIConnectionRecord(record));
+
+        // Return the converted history
+        return apiRecords;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3658b91f/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
index c9ff670..81344c6 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/session/UserContextResource.java
@@ -37,6 +37,7 @@ import org.apache.guacamole.net.auth.UserContext;
 import org.apache.guacamole.rest.activeconnection.APIActiveConnection;
 import org.apache.guacamole.rest.connection.APIConnection;
 import org.apache.guacamole.rest.connectiongroup.APIConnectionGroup;
+import org.apache.guacamole.rest.history.HistoryResource;
 import org.apache.guacamole.rest.user.APIUser;
 
 /**
@@ -169,4 +170,17 @@ public class UserContextResource {
                 userContext.getUserDirectory());
     }
 
+    /**
+     * Returns a new resource which represents historical data contained
+     * within the UserContext exposed by this UserContextResource.
+     *
+     * @return
+     *     A new resource which represents the historical data contained within
+     *     the UserContext exposed by this UserContextResource.
+     */
+    @Path("history")
+    public HistoryResource getHistoryResource() {
+        return new HistoryResource(userContext);
+    }
+
 }


Mime
View raw message