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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations