org.apache.shindig.social.opensocial.spi.UserId类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.apache.shindig.social.opensocial.spi.UserId类的一些代码示例,展示了UserId类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UserId类的具体详情如下:
包路径:org.apache.shindig.social.opensocial.spi.UserId
类名称:UserId

UserId介绍

[英]Data structure representing a userid
[中]表示用户ID的数据结构

代码示例

代码示例来源:origin: org.apache.shindig/shindig-social-api

public static UserId fromJson(String jsonId) {
 Type idSpecEnum = Type.jsonValueOf(jsonId);
 if (idSpecEnum != null) {
  return new UserId(idSpecEnum, null);
 }
 return new UserId(Type.userId, jsonId);
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

/** {@inheritDoc} */
public Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId,
  Set<String> fields, Map<String, Object> values, SecurityToken token)
  throws ProtocolException {
 // TODO: this seems redundant. No need to pass both fields and a map of
 // field->value
 // TODO: According to rest, yes there is. If a field is in the param list
 // but not in the map
 // that means it is a delete
 try {
  JSONObject personData = db.getJSONObject(DATA_TABLE).getJSONObject(userId.getUserId(token));
  if (personData == null) {
   personData = new JSONObject();
   db.getJSONObject(DATA_TABLE).put(userId.getUserId(token), personData);
  }
  for (Map.Entry<String, Object> entry : values.entrySet()) {
   personData.put(entry.getKey(), entry.getValue());
  }
  return Futures.immediateFuture(null);
 } catch (JSONException je) {
  throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
    je);
 }
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

@Test
 public void testFromJson() throws Exception {
  UserId owner = UserId.fromJson("@owner");
  assertEquals(UserId.Type.owner, owner.getType());

  UserId viewer = UserId.fromJson("@viewer");
  assertEquals(UserId.Type.viewer, viewer.getType());

  UserId me = UserId.fromJson("@me");
  assertEquals(UserId.Type.me, me.getType());

  UserId user = UserId.fromJson("john.doe");
  assertEquals(UserId.Type.userId, user.getType());
  assertEquals("john.doe", user.getUserId());
 }
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

@Test
public void testGetUserId() throws Exception {
 UserId owner = new UserId(UserId.Type.owner, "hello");
 assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner")));
 UserId viewer = new UserId(UserId.Type.viewer, "hello");
 assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId me = new UserId(UserId.Type.me, "hello");
 assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId user = new UserId(UserId.Type.userId, "hello");
 assertEquals("hello", user.getUserId(new FakeGadgetToken()));
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

public Set<UserId> getUsers() {
 List<String> ids = getListParameter(USER_ID);
 if (ids.isEmpty()) {
  Preconditions.checkArgument(token.getViewerId() != null, "No userId provided and viewer not available");
  // Assume @me
  return ImmutableSet.of(UserId.fromJson("@me"));
 }
 ImmutableSet.Builder<UserId> userIds = ImmutableSet.builder();
 for (String id : ids) {
  userIds.add(UserId.fromJson(id));
 }
 return userIds.build();
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

@Test
public void testGetUser() throws Exception {
 request.setParameter("userId", "@owner");
 assertEquals(UserId.Type.owner, request.getUsers().iterator().next().getType());
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

@Test
public void testGetUserId() throws Exception {
 UserId owner = new UserId(UserId.Type.owner, "hello");
 assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner")));
 UserId viewer = new UserId(UserId.Type.viewer, "hello");
 assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId me = new UserId(UserId.Type.me, "hello");
 assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId user = new UserId(UserId.Type.userId, "hello");
 assertEquals("hello", user.getUserId(new FakeGadgetToken()));
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

public Set<UserId> getUsers() {
 List<String> ids = getListParameter(USER_ID);
 if (ids.isEmpty()) {
  Preconditions.checkArgument(token.getViewerId() != null, "No userId provided and viewer not available");
  // Assume @me
  return ImmutableSet.of(UserId.fromJson("@me"));
 }
 ImmutableSet.Builder<UserId> userIds = ImmutableSet.builder();
 for (String id : ids) {
  userIds.add(UserId.fromJson(id));
 }
 return userIds.build();
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

@Test
public void testGetUser() throws Exception {
 request.setParameter("userId", "@owner");
 assertEquals(UserId.Type.owner, request.getUsers().iterator().next().getType());
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

/** {@inheritDoc} */
public Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId,
  Set<String> fields, Map<String, Object> values, SecurityToken token)
  throws ProtocolException {
 // TODO: this seems redundant. No need to pass both fields and a map of
 // field->value
 // TODO: According to rest, yes there is. If a field is in the param list
 // but not in the map
 // that means it is a delete
 try {
  JSONObject personData = db.getJSONObject(DATA_TABLE).getJSONObject(userId.getUserId(token));
  if (personData == null) {
   personData = new JSONObject();
   db.getJSONObject(DATA_TABLE).put(userId.getUserId(token), personData);
  }
  for (Map.Entry<String, Object> entry : values.entrySet()) {
   personData.put(entry.getKey(), entry.getValue());
  }
  return Futures.immediateFuture(null);
 } catch (JSONException je) {
  throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
    je);
 }
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

public static UserId fromJson(String jsonId) {
 Type idSpecEnum = Type.jsonValueOf(jsonId);
 if (idSpecEnum != null) {
  return new UserId(idSpecEnum, null);
 }
 return new UserId(Type.userId, jsonId);
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

@Test
 public void testFromJson() throws Exception {
  UserId owner = UserId.fromJson("@owner");
  assertEquals(UserId.Type.owner, owner.getType());

  UserId viewer = UserId.fromJson("@viewer");
  assertEquals(UserId.Type.viewer, viewer.getType());

  UserId me = UserId.fromJson("@me");
  assertEquals(UserId.Type.me, me.getType());

  UserId user = UserId.fromJson("john.doe");
  assertEquals(UserId.Type.userId, user.getType());
  assertEquals("john.doe", user.getUserId());
 }
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

@Test
public void testGetUserId() throws Exception {
 UserId owner = new UserId(UserId.Type.owner, "hello");
 assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner")));
 UserId viewer = new UserId(UserId.Type.viewer, "hello");
 assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId me = new UserId(UserId.Type.me, "hello");
 assertEquals("viewer", me.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 UserId user = new UserId(UserId.Type.userId, "hello");
 assertEquals("hello", user.getUserId(new FakeGadgetToken()));
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

public Set<UserId> getUsers() {
 List<String> ids = getListParameter(USER_ID);
 if (ids.isEmpty()) {
  Preconditions.checkArgument(token.getViewerId() != null, "No userId provided and viewer not available");
  // Assume @me
  return ImmutableSet.of(UserId.fromJson("@me"));
 }
 ImmutableSet.Builder<UserId> userIds = ImmutableSet.builder();
 for (String id : ids) {
  userIds.add(UserId.fromJson(id));
 }
 return userIds.build();
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-social-api

@Test
public void testGetUser() throws Exception {
 request.setParameter("userId", "@owner");
 assertEquals(UserId.Type.owner, request.getUsers().iterator().next().getType());
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

/** {@inheritDoc} */
public Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId,
  Set<String> fields, Map<String, String> values, SecurityToken token)
  throws ProtocolException {
 // TODO: this seems redundant. No need to pass both fields and a map of
 // field->value
 // TODO: According to rest, yes there is. If a field is in the param list
 // but not in the map
 // that means it is a delete
 try {
  JSONObject personData = db.getJSONObject(DATA_TABLE).getJSONObject(userId.getUserId(token));
  if (personData == null) {
   personData = new JSONObject();
   db.getJSONObject(DATA_TABLE).put(userId.getUserId(token), personData);
  }
  for (Map.Entry<String, String> entry : values.entrySet()) {
   personData.put(entry.getKey(), entry.getValue());
  }
  return ImmediateFuture.newInstance(null);
 } catch (JSONException je) {
  throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
    je);
 }
}

代码示例来源:origin: com.lmco.shindig/shindig-social-api

public static UserId fromJson(String jsonId) {
 Type idSpecEnum = Type.jsonValueOf(jsonId);
 if (idSpecEnum != null) {
  return new UserId(idSpecEnum, null);
 }
 return new UserId(Type.userId, jsonId);
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

@Test
 public void testFromJson() throws Exception {
  UserId owner = UserId.fromJson("@owner");
  assertEquals(UserId.Type.owner, owner.getType());

  UserId viewer = UserId.fromJson("@viewer");
  assertEquals(UserId.Type.viewer, viewer.getType());

  UserId me = UserId.fromJson("@me");
  assertEquals(UserId.Type.me, me.getType());

  UserId user = UserId.fromJson("john.doe");
  assertEquals(UserId.Type.userId, user.getType());
  assertEquals("john.doe", user.getUserId());
 }
}

代码示例来源:origin: org.apache.shindig/shindig-social-api

/** {@inheritDoc} */
public Future<Void> deletePersonData(UserId userId, GroupId groupId, String appId,
  Set<String> fields, SecurityToken token) throws ProtocolException {
 try {
  String user = userId.getUserId(token);
  if (!db.getJSONObject(DATA_TABLE).has(user)) {
   return null;
  }
  JSONObject newPersonData = new JSONObject();
  JSONObject oldPersonData = db.getJSONObject(DATA_TABLE).getJSONObject(user);
  // JSONObject keys are always strings
  @SuppressWarnings("unchecked")
  Iterator<String> keys = oldPersonData.keys();
  while (keys.hasNext()) {
   String key = keys.next();
   if (!fields.contains(key)) {
    newPersonData.put(key, oldPersonData.getString(key));
   }
  }
  db.getJSONObject(DATA_TABLE).put(user, newPersonData);
  return Futures.immediateFuture(null);
 } catch (JSONException je) {
  throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
    je);
 }
}

代码示例来源:origin: org.apache.shindig/shindig-samples

public static Set<UserId> buildUserIds(String... userIds) {
 // Set user id list
 Set<UserId> userIdSet = Sets.newHashSet();
 for (String userId: userIds) {
  userIdSet.add(new UserId(Type.userId, userId));
 }
 return userIdSet;
}

相关文章