Search in sources :

Example 16 with Source

use of com.ibm.watson.discovery.v1.model.Source in project data-transfer-project by google.

the class GoogleContactsExportConversionTest method testConversionToVCardNames.

@Test
public void testConversionToVCardNames() {
    // Set up Person with a primary name and two secondary names
    String primaryGivenName = "Mark";
    String primaryFamilyName = "Twain";
    Name primaryName = new Name().setGivenName(primaryGivenName).setFamilyName(primaryFamilyName).setMetadata(PRIMARY_FIELD_METADATA);
    String alternateGivenName1 = "Samuel";
    String alternateFamilyName1 = "Clemens";
    String alternateSourceType1 = "PROFILE";
    Name alternateName1 = new Name().setGivenName(alternateGivenName1).setFamilyName(alternateFamilyName1).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType1)));
    String alternateGivenName2 = "Louis";
    String alternateFamilyName2 = "de Conte";
    String alternateSourceType2 = "PEN_NAME";
    Name alternateName2 = new Name().setGivenName(alternateGivenName2).setFamilyName(alternateFamilyName2).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType2)));
    // Order shouldn't matter
    Person person = new Person().setNames(Arrays.asList(alternateName2, alternateName1, primaryName));
    // Run test
    VCard vCard = GoogleContactsExporter.convert(person);
    // Check name conversion correctness
    List<StructuredName> structuredNames = vCard.getStructuredNames();
    assertThat(structuredNames.size()).isEqualTo(3);
    // Check primary (non-alternate) names
    List<StructuredName> actualPrimaryNames = structuredNames.stream().filter(n -> n.getAltId() == null).collect(Collectors.toList());
    List<Pair<String, String>> actualPrimaryNamesValues = actualPrimaryNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
    assertThat(actualPrimaryNamesValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
    List<String> actualPrimarySourceValues = actualPrimaryNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
    assertThat(actualPrimarySourceValues).containsExactly(DEFAULT_SOURCE_TYPE);
    // Check alternate names
    List<StructuredName> actualAlternateNames = structuredNames.stream().filter(n -> n.getAltId() != null).collect(Collectors.toList());
    List<Pair<String, String>> actualAlternateNamesValues = actualAlternateNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
    assertThat(actualAlternateNamesValues).containsExactly(Pair.of(alternateGivenName1, alternateFamilyName1), Pair.of(alternateGivenName2, alternateFamilyName2));
    List<String> actualAlternateSourceValues = actualAlternateNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
    assertThat(actualAlternateSourceValues).containsExactly(alternateSourceType1, alternateSourceType2);
}
Also used : VCard(ezvcard.VCard) Arrays(java.util.Arrays) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) VCardProperty(ezvcard.property.VCardProperty) Telephone(ezvcard.property.Telephone) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Address(ezvcard.property.Address) StructuredName(ezvcard.property.StructuredName) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) Email(ezvcard.property.Email) VCardParameters(ezvcard.parameter.VCardParameters) VCARD_PRIMARY_PREF(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.VCARD_PRIMARY_PREF) Name(com.google.api.services.people.v1.model.Name) TextProperty(ezvcard.property.TextProperty) Collections(java.util.Collections) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Source(com.google.api.services.people.v1.model.Source) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name) Pair(com.google.gdata.util.common.base.Pair) Test(org.junit.Test)

Example 17 with Source

use of com.ibm.watson.discovery.v1.model.Source in project data-transfer-project by google.

the class GoogleContactsImporter method convertToGoogleName.

private static Name convertToGoogleName(StructuredName vCardName) {
    Name name = new Name();
    name.setFamilyName(vCardName.getFamily());
    name.setGivenName(vCardName.getGiven());
    FieldMetadata fieldMetadata = new FieldMetadata();
    boolean isPrimary = (vCardName.getAltId() == null);
    fieldMetadata.setPrimary(isPrimary);
    String vCardNameSource = vCardName.getParameter(SOURCE_PARAM_NAME_TYPE);
    if (CONTACT_SOURCE_TYPE.equals(vCardNameSource)) {
        Source source = new Source().setType(vCardNameSource);
        fieldMetadata.setSource(source);
    }
    name.setMetadata(fieldMetadata);
    return name;
}
Also used : FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name)

Example 18 with Source

use of com.ibm.watson.discovery.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotificationsTest method testUpdateSourceWOptions.

// Test the updateSource operation with a valid options model parameter
@Test
public void testUpdateSourceWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"id\": \"id\", \"name\": \"name\", \"description\": \"description\", \"enabled\": false, \"type\": \"type\", \"updated_at\": \"2019-01-01T12:00:00.000Z\", \"topic_count\": 10, \"topic_names\": [\"topicNames\"]}";
    String updateSourcePath = "/v1/instances/testString/sources/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateSourceOptions model
    UpdateSourceOptions updateSourceOptionsModel = new UpdateSourceOptions.Builder().instanceId("testString").id("testString").name("testString").description("testString").enabled(true).build();
    // Invoke updateSource() with a valid options model and verify the result
    Response<Source> response = eventNotificationsService.updateSource(updateSourceOptionsModel).execute();
    assertNotNull(response);
    Source responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PATCH");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateSourcePath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : UpdateSourceOptions(com.ibm.cloud.eventnotifications.event_notifications.v1.model.UpdateSourceOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with Source

use of com.ibm.watson.discovery.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotifications method getSource.

/**
 * Get a Source.
 *
 * Get a Sources.
 *
 * @param getSourceOptions the {@link GetSourceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Source}
 */
public ServiceCall<Source> getSource(GetSourceOptions getSourceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSourceOptions, "getSourceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", getSourceOptions.instanceId());
    pathParamsMap.put("id", getSourceOptions.id());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources/{id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getSource");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Source> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Source>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)

Example 20 with Source

use of com.ibm.watson.discovery.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class EventNotifications method updateSource.

/**
 * Update details of a Source.
 *
 * Update details of a Source.
 *
 * @param updateSourceOptions the {@link UpdateSourceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Source}
 */
public ServiceCall<Source> updateSource(UpdateSourceOptions updateSourceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateSourceOptions, "updateSourceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("instance_id", updateSourceOptions.instanceId());
    pathParamsMap.put("id", updateSourceOptions.id());
    RequestBuilder builder = RequestBuilder.patch(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/sources/{id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "updateSource");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (updateSourceOptions.name() != null) {
        contentJson.addProperty("name", updateSourceOptions.name());
    }
    if (updateSourceOptions.description() != null) {
        contentJson.addProperty("description", updateSourceOptions.description());
    }
    if (updateSourceOptions.enabled() != null) {
        contentJson.addProperty("enabled", updateSourceOptions.enabled());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Source> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Source>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 HashMap (java.util.HashMap)8 Test (org.testng.annotations.Test)7 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 Name (com.google.api.services.people.v1.model.Name)6 Source (com.google.api.services.people.v1.model.Source)6 StructuredName (ezvcard.property.StructuredName)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 JsonObject (com.google.gson.JsonObject)5 Configuration (com.ibm.watson.discovery.v1.model.Configuration)5 Source (com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)4 SourceOptionsWebCrawl (com.ibm.watson.discovery.v1.model.SourceOptionsWebCrawl)4 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)3 Person (com.google.api.services.people.v1.model.Person)3 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Pair (com.google.gdata.util.common.base.Pair)3 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3