/** * Allowed endpoints /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set on the person object. If there are no fields vars then all of the data will be * overridden. */ @Operation(httpMethods = "DELETE") public Future<?> delete(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); return service.deletePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * /appdata/{userId}+/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app */ @Operation(httpMethods = "GET") public Future<?> get(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); // Preconditions HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); return service.getPersonData(userIds, request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set. If there are no fields vars then all of the data will be overridden. */ @Operation(httpMethods = "POST", bodyParam = "data") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); @SuppressWarnings("unchecked") // As of today, this is the only format supported by the AppData protocol Map<String, Object> values = request.getTypedParameter("data", Map.class); for (String key : values.keySet()) { if (!isValidKey(key)) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "One or more of the app data keys are invalid: " + key); } } return service.updatePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), values, request.getToken()); }
/** * /appdata/{userId}+/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app */ @Operation(httpMethods = "GET") public Future<?> get(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); // Preconditions HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); return service.getPersonData(userIds, request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * Allowed endpoints /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set on the person object. If there are no fields vars then all of the data will be * overridden. */ @Operation(httpMethods = "DELETE") public Future<?> delete(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); return service.deletePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set. If there are no fields vars then all of the data will be overridden. */ @Operation(httpMethods = "POST", bodyParam = "data") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); @SuppressWarnings("unchecked") // As of today, this is the only format supported by the AppData protocol Map<String, Object> values = request.getTypedParameter("data", Map.class); for (String key : values.keySet()) { if (!isValidKey(key)) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "One or more of the app data keys are invalid: " + key); } } return service.updatePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), values, request.getToken()); }
/** * /appdata/{userId}+/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app */ @Operation(httpMethods = "GET") public Future<?> get(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); // Preconditions HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); return service.getPersonData(userIds, request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * Allowed endpoints /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set on the person object. If there are no fields vars then all of the data will be * overridden. */ @Operation(httpMethods = "DELETE") public Future<?> delete(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); return service.deletePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), request.getToken()); }
/** * /appdata/{userId}/{groupId}/{appId} - fields={field1, field2} * * examples: /appdata/john.doe/@friends/app?fields=count /appdata/john.doe/@self/app * * The post data should be a regular json object. All of the fields vars will be pulled from the * values and set. If there are no fields vars then all of the data will be overridden. */ @Operation(httpMethods = "POST", bodyParam = "data") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); @SuppressWarnings("unchecked") // As of today, this is the only format supported by the AppData protocol Map<String, String> values = request.getTypedParameter("data", Map.class); for (String key : values.keySet()) { if (!isValidKey(key)) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "One or more of the app data keys are invalid: " + key); } } return service.updatePersonData(userIds.iterator().next(), request.getGroup(), request.getAppId(), request.getFields(), values, request.getToken()); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleDelete() throws Exception { Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "DELETE"); EasyMock.expect(appDataService.deletePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(token))) .andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(params, null, token, converter).get()); verify(); } }
private Future<?> setupPostData(String method) throws ProtocolException { String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, method); String jsonAppData = "{pandas: 'are fuzzy'}"; Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); HashMap<String, Object> values = Maps.newHashMap(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class))) .andReturn(values); org.easymock.EasyMock.expect(appDataService.updatePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(values), eq(token))) .andReturn(Futures.immediateFuture((Void) null)); replay(); return operation.execute(params, new StringReader(jsonAppData), token, converter); }
@Test public void testHandleGetWithoutFields() throws Exception { String path = "/appdata/john.doe/@friends/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(GroupId.Type.friends, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(params, null, token, converter).get()); verify(); }
@Test public void testHandleDelete() throws Exception { Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "DELETE"); EasyMock.expect(appDataService.deletePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(token))) .andReturn(Futures.immediateFuture((Void) null)); replay(); assertNull(operation.execute(params, null, token, converter).get()); verify(); } }
private Future<?> setupPostData(String method) throws ProtocolException { String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, method); String jsonAppData = "{pandas: 'are fuzzy'}"; Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); HashMap<String, Object> values = Maps.newHashMap(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class))) .andReturn(values); org.easymock.EasyMock.expect(appDataService.updatePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(values), eq(token))) .andReturn(Futures.immediateFuture((Void) null)); replay(); return operation.execute(params, new StringReader(jsonAppData), token, converter); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleDelete() throws Exception { Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "DELETE"); EasyMock.expect(appDataService.deletePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(token))) .andReturn(ImmediateFuture.newInstance((Void) null)); replay(); assertNull(operation.execute(params, null, token, converter).get()); verify(); } }
private Future<?> setupPostData(String method) throws ProtocolException { String path = "/appdata/john.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, method); String jsonAppData = "{pandas: 'are fuzzy'}"; Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); HashMap<String, String> values = Maps.newHashMap(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class))) .andReturn(values); org.easymock.EasyMock.expect(appDataService.updatePersonData(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(values), eq(token))) .andReturn(ImmediateFuture.newInstance((Void) null)); replay(); return operation.execute(params, new StringReader(jsonAppData), token, converter); }
@Test public void testHandleGetPlural() throws Exception { String path = "/appdata/john.doe,jane.doe/@self/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE); userIdSet.add(new UserId(UserId.Type.userId, "jane.doe")); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(userIdSet), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
@Test public void testHandleGetWithoutFields() throws Exception { String path = "/appdata/john.doe/@friends/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); Map<String, String[]> params = Maps.newHashMap(); params.put("fields", new String[]{"pandas"}); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(GroupId.Type.friends, null)), eq("appId"), eq(ImmutableSet.of("pandas")), eq(token))) .andReturn(Futures.immediateFuture(data)); replay(); assertEquals(data, operation.execute(params, null, token, converter).get()); verify(); }