Search in sources :

Example 1 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class GroupGenerator method create.

public static Group create(int groupID, String name) {
    Group group = new Group();
    group.setApprovalModes(1);
    group.setBadge(Badge.FEATURED);
    group.setCategoriesEnabled(PostCategory.DISCUSSION);
    group.setCategoriesForModeratorsOnly(PostCategory.DISCUSSION);
    group.setCategory(1);
    group.setContactability(Contactability.CONTACTABLE);
    group.setContactEmail("bob@example.com");
    group.setCreatedTimestamp(System.currentTimeMillis());
    group.setDescription("long description long description long description long description long description long description long description long description long description long description long description long description long description long description long description ");
    group.setDirectoryPresence(DirectoryPresence.PUBLIC);
    group.setHasEmailExport(true);
    group.setHasMemberInvites(false);
    group.setHasMemberRoster(true);
    group.setHasNetworkUpdates(true);
    group.setHasSettings(true);
    group.setHideSubgroups(false);
    group.setHomeSiteUrl("http://www.example.com");
    group.setId(groupID);
    group.setIsOpenToNonMembers(true);
    group.setLargeLogoMediaUrl("/0/0/1/skafhdsjahiuewh");
    group.setLastModifiedTimestamp(System.currentTimeMillis());
    group.setLocale("en_US");
    Location location = new Location();
    location.setCountryCode("us");
    StringArray geoPlaceCodes = new StringArray();
    geoPlaceCodes.add("1-2-3-4-5");
    location.setGeoPlaceCodes(geoPlaceCodes);
    location.setGeoPostalCode("94043");
    location.setGmtOffset(-8f);
    location.setLatitude(122.1f);
    location.setLongitude(37.4f);
    location.setPostalCode("94043");
    location.setRegionCode(37);
    location.setUsesDaylightSavings(true);
    group.setLocation(location);
    group.setMaxFeeds(100);
    group.setMaxIdentityChanges(5);
    group.setMaxMembers(2000);
    group.setMaxModerators(10);
    group.setMaxSubgroups(20);
    group.setName(name);
    group.setNewsFormat(NewsFormat.RECENT);
    group.setNonMemberPermissions(NonMemberPermissions.COMMENT_AND_POST_WITH_MODERATION);
    group.setNumIdentityChanges(5);
    group.setNumMemberFlagsToDelete(3);
    group.setOpenedToNonMembersTimestamp(System.currentTimeMillis());
    group.setOtherCategory(3);
    // group.setParentGroupId();
    StringArray preApprovedEmailDomains = new StringArray();
    preApprovedEmailDomains.add("example.com");
    preApprovedEmailDomains.add("linkedin.com");
    group.setPreApprovedEmailDomains(preApprovedEmailDomains);
    group.setPreModerateMembersWithLowConnections(true);
    group.setPreModerateNewMembersPeriodInDays(3);
    group.setPreModeration(PreModerationType.COMMENTS);
    group.setPreModerationCategories(PostCategory.JOB);
    group.setRules("No spam, please");
    group.setSharingKey("HJFD3JH98JKH3");
    group.setShortDescription("short description");
    group.setSmallLogoMediaUrl("/0/0/1/skafhdsjahiuewh");
    group.setState(State.ACTIVE);
    group.setVanityUrl(name.toLowerCase().replace(' ', '-'));
    group.setVisibility(Visibility.PUBLIC);
    return group;
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) StringArray(com.linkedin.data.template.StringArray) Location(com.linkedin.restli.examples.groups.api.Location)

Example 2 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestPatchGeneration method testDiffFromNullNested.

@Test
public void testDiffFromNullNested() throws Exception {
    Group g1 = new Group();
    Group g2 = new Group(g1.data().copy());
    Location loc = new Location();
    loc.setLatitude(42.0f);
    loc.setLongitude(17.0f);
    g2.setLocation(loc);
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{$set={location={longitude=17.0, latitude=42.0}}}"
    final DataMap setMap = new DataMap();
    final DataMap latLongMap = new DataMap();
    latLongMap.put("longitude", 17.0f);
    latLongMap.put("latitude", 42.0f);
    final DataMap locationMap = new DataMap();
    locationMap.put("location", latLongMap);
    setMap.put(PatchConstants.SET_COMMAND, locationMap);
    assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Location(com.linkedin.restli.examples.groups.api.Location) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 3 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestPatchGeneration method testRoundtripDeleteField.

@Test
void testRoundtripDeleteField() throws Exception {
    Group g1 = new Group();
    g1.setId(17);
    g1.setDescription("Some description");
    Group g2 = new Group(g1.data().copy());
    g2.removeDescription();
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{$delete=[description]}"
    final DataMap deleteMap = new DataMap();
    final DataList descriptionList = new DataList();
    descriptionList.add("description");
    deleteMap.put(PatchConstants.DELETE_COMMAND, descriptionList);
    assertEquals(update.getDataMap(), deleteMap, "PatchTree DataMap should be correct");
    assertFalse(g1.equals(g2));
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
    processor.run(false);
    assertEquals(g1, g2);
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) DataList(com.linkedin.data.DataList) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) Patch(com.linkedin.data.transform.patch.Patch) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 4 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestGroupsRequestBuilders method requestGroupsBuilderDataProviderEntityWithFields.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderEntityWithFields")
private static Object[][] requestGroupsBuilderDataProviderEntityWithFields() {
    // Sample URIs:
    // "groups/1?fields=badge"
    // "groups/1?fields=badge"
    final Set<String> fieldSet = new HashSet<>();
    fieldSet.add("badge");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groups/1", null, null, fieldSet);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groups/1", null, null, fieldSet);
    return new Object[][] { { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsBuilders()), uriDetails2 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<Integer, Group>(new GroupsRequestBuilders()), uriDetails2 } };
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) GroupsBuilders(com.linkedin.restli.examples.groups.client.GroupsBuilders) HashSet(java.util.HashSet) DataProvider(org.testng.annotations.DataProvider)

Example 5 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestGroupsRequestBuilders method testEntityCreateId.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderNonEntity")
public void testEntityCreateId(URIDetails expectedURIDetails) throws IOException, RestException {
    CreateIdRequest<Integer, Group> request = new GroupsRequestBuilders().create().input(new Group()).build();
    checkRequestBuilder(request, ResourceMethod.CREATE, IdResponseDecoder.class, expectedURIDetails, new Group());
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) GroupsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupsRequestBuilders) Test(org.testng.annotations.Test)

Aggregations

Group (com.linkedin.restli.examples.groups.api.Group)28 Test (org.testng.annotations.Test)14 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)13 GroupsBuilders (com.linkedin.restli.examples.groups.client.GroupsBuilders)11 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)10 DataProvider (org.testng.annotations.DataProvider)10 DataMap (com.linkedin.data.DataMap)9 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 HashMap (java.util.HashMap)7 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)4 Patch (com.linkedin.data.transform.patch.Patch)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 Location (com.linkedin.restli.examples.groups.api.Location)3 DataList (com.linkedin.data.DataList)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 IdResponse (com.linkedin.restli.common.IdResponse)2 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)2 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2