/** * Get the type of the stored objectId. * * @return GroupId.Type */ public Type getType() { return getType(this.objectId); }
/** * Get the type of the stored objectId. * * @return GroupId.Type */ public Type getType() { return getType(this.objectId); }
private Set<String> getIdSet(UserId user, GroupId group, SecurityToken token) throws JSONException { String userId = user.getUserId(token); if (group == null) { return ImmutableSortedSet.of(userId); } Set<String> returnVal = Sets.newLinkedHashSet(); switch (group.getType()) { case all: case friends: case groupId: if (db.getJSONObject(FRIEND_LINK_TABLE).has(userId)) { JSONArray friends = db.getJSONObject(FRIEND_LINK_TABLE).getJSONArray(userId); for (int i = 0; i < friends.length(); i++) { returnVal.add(friends.getString(i)); } } break; case self: returnVal.add(userId); break; } return returnVal; }
/** * Set the objectId with a String * * @param objectId String * @throws IllegalArgumentException */ public void setObjectId(String objectId) throws IllegalArgumentException { if(getType(objectId).equals(Type.objectId)) { this.objectId = new ObjectId(objectId); } else { this.objectId = objectId; } }
/** * Set the objectId with a String * * @param objectId String * @throws IllegalArgumentException */ public void setObjectId(String objectId) throws IllegalArgumentException { if(getType(objectId).equals(Type.objectId)) { this.objectId = new ObjectId(objectId); } else { this.objectId = objectId; } }
switch (group.getType()) { case all: case friends:
switch (group.getType()) { case all: case friends:
/** * If the given object is an objectId, create and store * Else we need the string representation to store, including the "@" * * @param objectId Object * @throws IllegalArgumentException */ public GroupId(Object objectId) throws IllegalArgumentException { if(objectId == null) { this.objectId = new ObjectId(""); // If it is an objectId, store as is } else if(objectId instanceof ObjectId) { this.objectId = (ObjectId) objectId; // Else it must be a string, store as such } else { if(Type.objectId.equals(getType(objectId))) { this.objectId = new ObjectId(objectId.toString()); } else { this.objectId = objectId.toString(); } } }
/** * If the given object is an objectId, create and store * Else we need the string representation to store, including the "@" * * @param objectId Object * @throws IllegalArgumentException */ public GroupId(Object objectId) throws IllegalArgumentException { if(objectId == null) { this.objectId = new ObjectId(""); // If it is an objectId, store as is } else if(objectId instanceof ObjectId) { this.objectId = (ObjectId) objectId; // Else it must be a string, store as such } else { if(Type.objectId.equals(getType(objectId))) { this.objectId = new ObjectId(objectId.toString()); } else { this.objectId = objectId.toString(); } } }
if (GroupId.Type.self == groupId.getType() && result.isEmpty()) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "People '" + idSet + "' not found");
if (GroupId.Type.self == groupId.getType() && result.isEmpty()) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "People '" + idSet + "' not found");
if (GroupId.Type.self == groupId.getType() && result.isEmpty()) { throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "People '" + idSet + "' not found");
@Test public void testFromJson() throws Exception { GroupId all = GroupId.fromJson("@all"); assertEquals(GroupId.Type.all, all.getType()); GroupId friends = GroupId.fromJson("@friends"); assertEquals(GroupId.Type.friends, friends.getType()); GroupId self = GroupId.fromJson("@self"); assertEquals(GroupId.Type.self, self.getType()); GroupId group = GroupId.fromJson("superbia"); assertEquals(GroupId.Type.groupId, group.getType()); assertEquals("superbia", group.getGroupId()); } }
@Test public void testFromJson() { GroupId all = GroupId.fromJson("@all"); assertEquals(GroupId.Type.all, all.getType()); GroupId friends = GroupId.fromJson("@friends"); assertEquals(GroupId.Type.friends, friends.getType()); GroupId self = GroupId.fromJson("@self"); assertEquals(GroupId.Type.self, self.getType()); GroupId group = GroupId.fromJson("superbia"); assertEquals(GroupId.Type.objectId, group.getType()); assertEquals("superbia", group.getObjectId().toString()); GroupId unknown = GroupId.fromJson("@foo"); assertEquals(Type.custom, unknown.getType()); assertEquals("@foo", unknown.getObjectId().toString()); }
@Test public void testFromJson() { GroupId all = GroupId.fromJson("@all"); assertEquals(GroupId.Type.all, all.getType()); GroupId friends = GroupId.fromJson("@friends"); assertEquals(GroupId.Type.friends, friends.getType()); GroupId self = GroupId.fromJson("@self"); assertEquals(GroupId.Type.self, self.getType()); GroupId group = GroupId.fromJson("superbia"); assertEquals(GroupId.Type.objectId, group.getType()); assertEquals("superbia", group.getObjectId().toString()); GroupId unknown = GroupId.fromJson("@foo"); assertEquals(Type.custom, unknown.getType()); assertEquals("@foo", unknown.getObjectId().toString()); }
@Test public void testGetGroup() throws Exception { request.setParameter("groupId", "@self"); assertEquals(GroupId.Type.self, request.getGroup().getType()); } }
@Test public void testGetGroup() throws Exception { request.setParameter("groupId", "@self"); assertEquals(GroupId.Type.self, request.getGroup().getType()); } }
@Test public void testGetGroup() throws Exception { request.setParameter("groupId", "@self"); assertEquals(GroupId.Type.self, request.getGroup().getType()); } }
@Test public void testGroupId() { DomainName dn1 = new DomainName("example.com"); LocalId l1 = new LocalId("195mg90a39v"); GlobalId gl1 = new GlobalId(dn1, l1); GroupId g1 = new GroupId("example.com:195mg90a39v"); GroupId g2 = new GroupId(gl1); assertEquals(g1.getType(), g2.getType()); assertEquals(g1.getObjectId().toString(), g2.getObjectId().toString()); GroupId g3 = new GroupId("@foo"); assertEquals(Type.custom, g3.getType()); assertEquals("@foo", g3.getObjectId().toString()); GroupId g4 = new GroupId(Type.objectId, "example.com:195mg90a39v"); assertEquals(Type.objectId, g4.getType()); assertEquals("example.com:195mg90a39v", g4.getObjectId().toString()); GroupId g5 = new GroupId(Type.custom, "@foo"); assertEquals(Type.custom, g5.getType()); assertEquals("@foo", g5.getObjectId().toString()); GroupId g6 = new GroupId(Type.all, "something"); assertEquals(Type.all, g6.getType()); assertEquals("@all", g6.getObjectId().toString()); GroupId g7 = new GroupId(Type.self, null); assertEquals(Type.self, g7.getType()); assertEquals("@self", g7.getObjectId().toString()); GroupId g8 = new GroupId(Type.friends, "bar"); assertEquals(Type.friends, g8.getType()); assertEquals("@friends", g8.getObjectId().toString()); }
@Test public void testGroupId() { DomainName dn1 = new DomainName("example.com"); LocalId l1 = new LocalId("195mg90a39v"); GlobalId gl1 = new GlobalId(dn1, l1); GroupId g1 = new GroupId("example.com:195mg90a39v"); GroupId g2 = new GroupId(gl1); assertEquals(g1.getType(), g2.getType()); assertEquals(g1.getObjectId().toString(), g2.getObjectId().toString()); GroupId g3 = new GroupId("@foo"); assertEquals(Type.custom, g3.getType()); assertEquals("@foo", g3.getObjectId().toString()); GroupId g4 = new GroupId(Type.objectId, "example.com:195mg90a39v"); assertEquals(Type.objectId, g4.getType()); assertEquals("example.com:195mg90a39v", g4.getObjectId().toString()); GroupId g5 = new GroupId(Type.custom, "@foo"); assertEquals(Type.custom, g5.getType()); assertEquals("@foo", g5.getObjectId().toString()); GroupId g6 = new GroupId(Type.all, "something"); assertEquals(Type.all, g6.getType()); assertEquals("@all", g6.getObjectId().toString()); GroupId g7 = new GroupId(Type.self, null); assertEquals(Type.self, g7.getType()); assertEquals("@self", g7.getObjectId().toString()); GroupId g8 = new GroupId(Type.friends, "bar"); assertEquals(Type.friends, g8.getType()); assertEquals("@friends", g8.getObjectId().toString()); }