You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2012/04/13 14:39:56 UTC

svn commit: r1325739 - in /shindig/trunk/java: common/src/main/java/org/apache/shindig/protocol/ social-api/src/main/java/org/apache/shindig/social/opensocial/spi/ social-api/src/test/java/org/apache/shindig/social/opensocial/spi/

Author: rbaxter85
Date: Fri Apr 13 12:39:55 2012
New Revision: 1325739

URL: http://svn.apache.org/viewvc?rev=1325739&view=rev
Log:
SHINDIG-1698
Committed For Yao Zhang
Need to support query parameter for Social REST API

Added:
    shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java   (with props)
Modified:
    shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RequestItem.java
    shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java?rev=1325739&r1=1325738&r2=1325739&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java Fri Apr 13 12:39:55 2012
@@ -325,4 +325,8 @@ public class BaseRequestItem implements 
       getAttributeMap().put(val, obj);
     }
   }
+
+  public Set<String> getParameterNames() {
+    return this.parameters.keySet();
+  }
 }

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RequestItem.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RequestItem.java?rev=1325739&r1=1325738&r2=1325739&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RequestItem.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RequestItem.java Fri Apr 13 12:39:55 2012
@@ -183,4 +183,10 @@ public interface RequestItem {
    * @param obj an object
    */
   void setAttribute(String val, Object obj);
+
+  /**
+   * Get the list of parameter names for this request object.
+   * @return A set of Parameter Names.
+   */
+   Set<String> getParameterNames();
 }

Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java?rev=1325739&r1=1325738&r2=1325739&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/CollectionOptions.java Fri Apr 13 12:39:55 2012
@@ -17,13 +17,19 @@
  */
 package org.apache.shindig.social.opensocial.spi;
 
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.shindig.protocol.RequestItem;
 import org.apache.shindig.protocol.model.FilterOperation;
 import org.apache.shindig.protocol.model.SortOrder;
 
 import com.google.common.base.Objects;
-
-import java.util.Date;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 /**
  * Data structure representing many of the RPC/REST requests we receive.
@@ -38,6 +44,19 @@ public class CollectionOptions {
   private int max;
   private Date updatedSince;
 
+  private Map<String, String> optionalParameters;
+  private static final String[] predefinedParameters= {
+      RequestItem.COUNT,
+      RequestItem.FIELDS,
+      RequestItem.FILTER_BY,
+      RequestItem.FILTER_OPERATION,
+      RequestItem.FILTER_VALUE,
+      RequestItem.SORT_BY,
+      RequestItem.SORT_ORDER,
+      RequestItem.START_INDEX,
+      "userId",
+      "groupId"
+    };
   public CollectionOptions() {}
 
   public CollectionOptions(RequestItem request) {
@@ -49,6 +68,13 @@ public class CollectionOptions {
     this.setFirst(request.getStartIndex());
     this.setMax(request.getCount());
     this.setUpdatedSince(request.getUpdatedSince());
+    Set<String> parameterNames = Sets.newHashSet(request.getParameterNames());
+    parameterNames.removeAll(Arrays.asList(predefinedParameters));
+    Map<String, String> optionalParameters = Maps.newHashMap();
+    for (String parameter : parameterNames) {
+      optionalParameters.put(parameter, request.getParameter(parameter));
+    }
+    this.setOptionalParameters(optionalParameters);
   }
   /**
    * This sortBy can be any field of the object being sorted or the special js sort of topFriends.
@@ -185,4 +211,13 @@ public class CollectionOptions {
     return Objects.hashCode(this.sortBy, this.sortOrder, this.filter,
         this.filterOperation, this.filterValue, this.first, this.max);
   }
+
+  public Map<String, String> getOptionalParameter() {
+    return this.optionalParameters;
+  }
+
+  private void setOptionalParameters(Map<String, String> optionalParameters) {
+    this.optionalParameters = optionalParameters;
+  }
+
 }

Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java?rev=1325739&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java Fri Apr 13 12:39:55 2012
@@ -0,0 +1,65 @@
+/*
+ * 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.shindig.social.opensocial.spi;
+
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
+import org.apache.shindig.common.testing.FakeGadgetToken;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.social.opensocial.service.SocialRequestItem;
+
+import com.google.common.collect.Maps;
+import com.google.inject.Guice;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CollectionOptionsTest extends Assert {
+
+	private static final FakeGadgetToken FAKE_TOKEN = new FakeGadgetToken();
+
+	protected SocialRequestItem request;
+	protected BeanJsonConverter converter;
+
+	@Before
+	public void setUp() throws Exception {
+		FAKE_TOKEN.setAppId("12345");
+		FAKE_TOKEN.setOwnerId("someowner");
+		FAKE_TOKEN.setViewerId("someowner");
+		converter = new BeanJsonConverter(Guice.createInjector());
+		Map<String, String[]> optionalParameters = Maps.newHashMap();
+		String[] cvalue1 = {"cvalue1"};
+		String[] cvalue2 = {"cvalue2"};
+		optionalParameters.put("condition1",cvalue1);
+		optionalParameters.put("condition2",cvalue2);
+		request = new SocialRequestItem(
+				optionalParameters,
+				FAKE_TOKEN, converter, converter);
+	}
+
+	@Test
+	public void testOptionalParams() throws Exception {
+		CollectionOptions op = new CollectionOptions(request);
+		Map<String, String> optionalParams = op.getOptionalParameter();
+		Map<String, String> optionalParams1 = Maps.newHashMap();
+		optionalParams1.put("condition1","cvalue1");
+		optionalParams1.put("condition2","cvalue2");
+		assertEquals(optionalParams, optionalParams1);
+	}
+}
\ No newline at end of file

Propchange: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/CollectionOptionsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain