/** * Backwards compatibility. * * @param jsonId JSON string value of a GroupId * @return GroupId * @throws IllegalArgumentException */ public static GroupId fromJson(String jsonId) throws IllegalArgumentException { return new GroupId(jsonId); }
@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()); }
/** * Get the type of the given objectId. * * @return GroupId.Type */ private Type getType(Object objectId) { String type = parseType(objectId); if(type.equals("self")) { return Type.self; } else if(type.equals("friends")) { return Type.friends; } else if(type.equals("all")) { return Type.all; } else if(objectId instanceof String && ((String)objectId).startsWith("@")) { // Could be a custom @ id, and it certainly is not an object id // return null we don't know the type return Type.custom; } else { return Type.objectId; } }
switch (group.getType()) { case all: case friends: if (db.getJSONObject(GROUP_MEMBERS_TABLE).has(group.toString())) { JSONArray groupMembers = db.getJSONObject(GROUP_MEMBERS_TABLE).getJSONArray(group.toString()); for (int i = 0; i < groupMembers.length(); i++) { returnVal.add(groupMembers.getString(i));
@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()); } }
/** * Get the type of the stored objectId. * * @return GroupId.Type */ public Type getType() { return getType(this.objectId); }
@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()); }
public GroupId getGroup() { return GroupId.fromJson(getParameter(GROUP_ID, "@self")); }
/** {@inheritDoc} */ public String getId() { return this.id.toString(); } }
/** * Backwards Compatibility. * * @param type * @param objectId * @throws IllegalArgumentException when the provided objectId is not valid */ public GroupId(Type type, String objectId) throws IllegalArgumentException { // If Type is an objectId, convert objectId to ObjectId and store if(type.equals(Type.objectId)) { this.objectId = new ObjectId(objectId); // Else store the string representation of the type } else if(Type.custom.equals(type)){ //Custom @ id this.objectId = objectId; } else { this.objectId = typeToString(type); } }
if (groupId.getType() == GroupId.Type.self) { optionalUserIds, new GroupId(GroupId.Type.self, null), options, fields, request.getToken()); return FutureUtil.getFirstFromCollection(people); return personService.getPeople(personIds.build(), new GroupId(GroupId.Type.self, null), options, fields, request.getToken());
/** * Get the type of the stored objectId. * * @return GroupId.Type */ public Type getType() { return getType(this.objectId); }
@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()); }
switch (group.getType()) { case all: case friends: if (db.getJSONObject(GROUP_MEMBERS_TABLE).has(group.toString())) { JSONArray groupMembers = db.getJSONObject(GROUP_MEMBERS_TABLE).getJSONArray(group.toString()); for (int i = 0; i < groupMembers.length(); i++) { returnVal.add(groupMembers.getString(i));
public GroupId getGroup() { return GroupId.fromJson(getParameter(GROUP_ID, "@self")); }
/** {@inheritDoc} */ public String getId() { return this.id.toString(); } }
/** * Backwards Compatibility. * * @param type * @param objectId * @throws IllegalArgumentException when the provided objectId is not valid */ public GroupId(Type type, String objectId) throws IllegalArgumentException { // If Type is an objectId, convert objectId to ObjectId and store if(type.equals(Type.objectId)) { this.objectId = new ObjectId(objectId); // Else store the string representation of the type } else if(Type.custom.equals(type)){ //Custom @ id this.objectId = objectId; } else { this.objectId = typeToString(type); } }
/** * Backwards compatibility. * * @param jsonId JSON string value of a GroupId * @return GroupId * @throws IllegalArgumentException */ public static GroupId fromJson(String jsonId) throws IllegalArgumentException { return new GroupId(jsonId); }