resolves STREAMS-652
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PeopleDataLabs.java b/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PeopleDataLabs.java
index 6604c0f..6f32cce 100755
--- a/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PeopleDataLabs.java
+++ b/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PeopleDataLabs.java
@@ -18,6 +18,10 @@
package org.apache.streams.peopledatalabs;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.util.EntityUtils;
+import org.apache.juneau.ObjectMap;
+import org.apache.juneau.rest.client.RestCallException;
import org.apache.streams.config.ComponentConfigurator;
import com.google.common.util.concurrent.Uninterruptibles;
@@ -27,6 +31,7 @@
import org.apache.juneau.rest.client.RestClient;
import org.apache.juneau.rest.client.RestClientBuilder;
import org.apache.streams.peopledatalabs.api.BulkEnrichPersonRequest;
+import org.apache.streams.peopledatalabs.api.BulkEnrichPersonResponseItem;
import org.apache.streams.peopledatalabs.api.EnrichPersonRequest;
import org.apache.streams.peopledatalabs.api.EnrichPersonResponse;
import org.apache.streams.peopledatalabs.config.PeopleDataLabsConfiguration;
@@ -103,12 +108,18 @@
@Override
public EnrichPersonResponse enrichPerson(EnrichPersonRequest request) {
try {
- PersonEnrichment personEnrichment = restClient.getRemoteResource(PersonEnrichment.class);
-// RestCall call = restClient
-// .doGet(baseUrl() + "person")
-// .body(request);
- //String responseJson = call.getResponseAsString();
- EnrichPersonResponse result = personEnrichment.enrichPerson(request);
+ // TODO: use juneau remoting here once upgraded and tested
+ // PersonEnrichment personEnrichment = restClient.getRemoteResource(PersonEnrichment.class);
+ String requestJson = serializer.serialize(request);
+ ObjectMap requestParams = new ObjectMap(requestJson);
+ RestCall call = restClient
+ .doGet(baseUrl() + "person")
+ .accept("application/json")
+ .contentType("application/json")
+ .ignoreErrors()
+ .queryIfNE(requestParams);
+ String responseJson = call.getResponseAsString();
+ EnrichPersonResponse result = parser.parse(responseJson, EnrichPersonResponse.class);
return result;
} catch( Exception e ) {
LOGGER.error("Exception", e);
@@ -120,18 +131,20 @@
}
@Override
- public List<EnrichPersonResponse> bulkEnrichPerson(BulkEnrichPersonRequest request) {
+ public List<BulkEnrichPersonResponseItem> bulkEnrichPerson(BulkEnrichPersonRequest request) {
try {
- //PersonEnrichment personEnrichment = restClient.getRemoteResource(PersonEnrichment.class);
- //List<EnrichPersonResponse> result = personEnrichment.bulkEnrichPerson(request);
+ // TODO: use juneau remoting here once upgraded and tested
+ // PersonEnrichment personEnrichment = restClient.getRemoteResource(PersonEnrichment.class);
+ // List<EnrichPersonResponse> result = personEnrichment.bulkEnrichPerson(request);
String requestJson = serializer.serialize(request);
RestCall call = restClient
.doPost(baseUrl() + "person/bulk")
.accept("application/json")
.contentType("application/json")
+ .ignoreErrors()
.body(new StringReader(requestJson));
String responseJson = call.getResponseAsString();
- List<EnrichPersonResponse> result = parser.parse(responseJson, List.class, EnrichPersonResponse.class);
+ List<BulkEnrichPersonResponseItem> result = parser.parse(responseJson, List.class, BulkEnrichPersonResponseItem.class);
return result;
} catch( Exception e ) {
LOGGER.error("Exception", e);
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PersonEnrichment.java b/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PersonEnrichment.java
index 5ec911f..4d42c31 100755
--- a/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PersonEnrichment.java
+++ b/streams-contrib/streams-processor-peopledatalabs/src/main/java/org/apache/streams/peopledatalabs/PersonEnrichment.java
@@ -18,6 +18,8 @@
package org.apache.streams.peopledatalabs;
+import org.apache.juneau.rest.client.RestCallException;
+import org.apache.streams.peopledatalabs.api.BulkEnrichPersonResponseItem;
import org.apache.streams.peopledatalabs.api.EnrichPersonRequest;
import org.apache.streams.peopledatalabs.api.BulkEnrichPersonRequest;
import org.apache.streams.peopledatalabs.api.EnrichPersonResponse;
@@ -36,6 +38,6 @@
public EnrichPersonResponse enrichPerson(@Query(name = "*", skipIfEmpty = true) EnrichPersonRequest request);
@RemoteMethod(method ="POST", path="/person/bulk")
- public List<EnrichPersonResponse> bulkEnrichPerson(@Body(required = true) BulkEnrichPersonRequest request);
+ public List<BulkEnrichPersonResponseItem> bulkEnrichPerson(@Body(required = true) BulkEnrichPersonRequest request);
}
\ No newline at end of file
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/BulkEnrichPersonResponseItem.json b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/BulkEnrichPersonResponseItem.json
new file mode 100755
index 0000000..9efdf85
--- /dev/null
+++ b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/BulkEnrichPersonResponseItem.json
@@ -0,0 +1,29 @@
+{
+ "type": "object",
+ "$schema": "http://json-schema.org/draft-03/schema",
+ "$license": [
+ "http://www.apache.org/licenses/LICENSE-2.0"
+ ],
+ "id": "#",
+ "javaType": "org.apache.streams.peopledatalabs.api.BulkEnrichPersonResponseItem",
+ "properties": {
+ "status": {
+ "type": "integer"
+ },
+ "metadata": {
+ "type": "object",
+ "javaType": "org.apache.streams.peopledatalabs.api.EnrichPersonResponseMetadata",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "request_id": {
+ "type": "string"
+ }
+ }
+ },
+ "data": {
+ "$ref": "../pojo/Person.json"
+ }
+ }
+}
\ No newline at end of file
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonRequest.json b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonRequest.json
index ea6aa1b..c59c86a 100755
--- a/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonRequest.json
+++ b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonRequest.json
@@ -42,6 +42,13 @@
"Medford, OR USA"
]
},
+ "street_address": {
+ "type": "string",
+ "description": "A street address in which the person lives",
+ "examples": [
+ "1234 Main Street"
+ ]
+ },
"locality": {
"type": "string",
"description": "A locality in which the person lives",
@@ -49,6 +56,13 @@
"Boise"
]
},
+ "postal_code": {
+ "type": "string",
+ "description": "The postal code in which the person lives, must be used with either a country or a region.",
+ "examples": [
+ "83701"
+ ]
+ },
"region": {
"type": "string",
"description": "A state or region in which the person lives",
@@ -100,7 +114,24 @@
},
"profile": {
"type": "string",
- "description": "A social profile the person has used."
+ "description": "A social profile the person has used. \nList of supported profiles: linkedin\ntwitter\nfacebook\ngithub\nxing\ngravatar\nindeed\nklout\nmeetup\nfoursquare\nangellist\nquora\npinterest\nflickr\naboutme\nyoutube\nvimeo\ngoogle\nwordpress\ninstagram\ncrunchbase\ndribbble\nmyspace\nbehance\nmedium\nsoundcloud\nreddit\ngitlab",
+ "examples": [
+ "https://linkedin.com/in/seanthorne"
+ ]
+ },
+ "lid": {
+ "type": "string",
+ "description": "A LinkedIn numerical ID.",
+ "examples": [
+ "145991517"
+ ]
+ },
+ "birth_date": {
+ "type": "string",
+ "description": "The person's birth date. Either the year, or a full birth date",
+ "examples": [
+ "1996-10-01"
+ ]
}
}
}
\ No newline at end of file
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonResponse.json b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonResponse.json
index e8a6a18..91a4c78 100755
--- a/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonResponse.json
+++ b/streams-contrib/streams-processor-peopledatalabs/src/main/jsonschema/org/apache/streams/peopledatalabs/api/EnrichPersonResponse.json
@@ -24,6 +24,18 @@
},
"data": {
"$ref": "../pojo/Person.json"
+ },
+ "error": {
+ "type": "object",
+ "javaType": "org.apache.streams.peopledatalabs.api.EnrichPersonResponseError",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "message": {
+ "type": "string"
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/test/java/org/apache/streams/peopledatalabs/test/PeopleDataLabsIT.java b/streams-contrib/streams-processor-peopledatalabs/src/test/java/org/apache/streams/peopledatalabs/test/PeopleDataLabsIT.java
index 28b4487..2f11445 100644
--- a/streams-contrib/streams-processor-peopledatalabs/src/test/java/org/apache/streams/peopledatalabs/test/PeopleDataLabsIT.java
+++ b/streams-contrib/streams-processor-peopledatalabs/src/test/java/org/apache/streams/peopledatalabs/test/PeopleDataLabsIT.java
@@ -18,6 +18,7 @@
package org.apache.streams.peopledatalabs.test;
+import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.streams.config.ComponentConfigurator;
import org.apache.streams.config.StreamsConfigurator;
@@ -46,10 +47,12 @@
private static final Logger LOGGER = LoggerFactory.getLogger(PeopleDataLabsIT.class);
- private static String configfile = "target/test-classes/PeopleDataLabsIT.conf";
+ private static String configfile = "target/test-classes/PeopleDataLabsIT/PeopleDataLabsIT.conf";
private static PeopleDataLabsConfiguration config;
+ private static Config testsconfig;
+
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
File conf = new File(configfile);
@@ -58,12 +61,13 @@
Assert.assertTrue (conf.isFile());
StreamsConfigurator.addConfig(ConfigFactory.parseFileAnySyntax(conf));
config = new ComponentConfigurator<>(PeopleDataLabsConfiguration.class).detectConfiguration();
+ testsconfig = StreamsConfigurator.getConfig().getConfig("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT");
}
@Test
public void testSearchByEmail() throws Exception {
PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
- String email = StreamsConfigurator.getConfig().getString("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testSearchByEmail.email");
+ String email = testsconfig.getString("testSearchByEmail.email");
EnrichPersonRequest req = new EnrichPersonRequest()
.withEmail(email);
EnrichPersonResponse response = personEnrichment.enrichPerson(req);
@@ -76,9 +80,24 @@
}
@Test
+ public void testSearchByEmailHash() throws Exception {
+ PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
+ String emailHash = testsconfig.getString("testSearchByEmailHash.emailHash");
+ EnrichPersonRequest req = new EnrichPersonRequest()
+ .withEmailHash(emailHash);
+ EnrichPersonResponse response = personEnrichment.enrichPerson(req);
+ nonNull(response);
+ nonNull(response.getStatus());
+ nonNull(response.getMetadata());
+ nonNull(response.getData());
+ assertEquals(response.getStatus(), new Long(200));
+ assertThat("response contains at least one email address", response.getData().getEmails().size() >= 1);
+ }
+
+ @Test
public void testSearchByLinkedinUrl() throws Exception {
PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
- String profile = StreamsConfigurator.getConfig().getString("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testSearchByLinkedinUrl.profile");
+ String profile = testsconfig.getString("testSearchByLinkedinUrl.profile");
EnrichPersonRequest req = new EnrichPersonRequest()
.withProfile(profile);
EnrichPersonResponse response = personEnrichment.enrichPerson(req);
@@ -93,9 +112,10 @@
@Test
public void testSearchByNameLocationCompany() throws Exception {
PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
- String name = StreamsConfigurator.getConfig().getString("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testSearchByNameLocationCompany.name");
- String location = StreamsConfigurator.getConfig().getString("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testSearchByNameLocationCompany.location");
- String company = StreamsConfigurator.getConfig().getString("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testSearchByNameLocationCompany.company");
+ Config testconfig = testsconfig.getConfig("testSearchByNameLocationCompany");
+ String name = testconfig.getString("name");
+ String location = testconfig.getString("location");
+ String company = testconfig.getString("company");
EnrichPersonRequest req = new EnrichPersonRequest()
.withName(name)
.withLocation(location)
@@ -112,7 +132,7 @@
@Test
public void testBulkEnrichment() throws Exception {
PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
- List<String> emails = StreamsConfigurator.getConfig().getStringList("org.apache.streams.peopledatalabs.test.PeopleDataLabsIT.testBulkEnrichment.emails");
+ List<String> emails = testsconfig.getStringList("testBulkEnrichment.emails");
BulkEnrichPersonRequestItem item1 = new BulkEnrichPersonRequestItem()
.withParams(new Params().withEmail(Lists.newArrayList(emails.get(0))));
BulkEnrichPersonRequestItem item2 = new BulkEnrichPersonRequestItem()
@@ -121,8 +141,27 @@
.withParams(new Params().withEmail(Lists.newArrayList(emails.get(2))));
List<BulkEnrichPersonRequestItem> reqList = Lists.newArrayList(item1, item2, item3);
BulkEnrichPersonRequest bulkRequest = new BulkEnrichPersonRequest().withRequests(reqList);
- List<EnrichPersonResponse> response = personEnrichment.bulkEnrichPerson(bulkRequest);
+ List<BulkEnrichPersonResponseItem> response = personEnrichment.bulkEnrichPerson(bulkRequest);
nonNull(response);
assertThat("response contains three response items", response.size() == 3);
}
+
+ @Test
+ public void testHandlesMissCorrectly() throws Exception {
+ PersonEnrichment personEnrichment = PeopleDataLabs.getInstance(config);
+ Config testconfig = testsconfig.getConfig("testHandlesMissCorrectly");
+ String emailHash = testconfig.getString("emailHash");
+ EnrichPersonRequest req = new EnrichPersonRequest()
+ .withEmailHash(emailHash);
+ EnrichPersonResponse response = personEnrichment.enrichPerson(req);
+ nonNull(response);
+ nonNull(response.getStatus());
+ nonNull(response.getMetadata());
+ nonNull(response.getData());
+ assertEquals(response.getStatus(), new Long(404));
+ nonNull(response.getError());
+ assertEquals(response.getError().getType(), "not_found");
+ nonNull(response.getError().getMessage());
+ }
+
}
\ No newline at end of file
diff --git a/streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT.conf b/streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT/PeopleDataLabsIT.conf
similarity index 82%
rename from streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT.conf
rename to streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT/PeopleDataLabsIT.conf
index fe0f1bf..ba01a9e 100644
--- a/streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT.conf
+++ b/streams-contrib/streams-processor-peopledatalabs/src/test/resources/PeopleDataLabsIT/PeopleDataLabsIT.conf
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-include "../../../../peopledatalabs.conf"
+include "../../../../../peopledatalabs.conf"
org.apache.streams.peopledatalabs.test.PeopleDataLabsIT {
testSearchByEmail.email="sean@peopledatalabs.com"
+ testSearchByEmailHash.emailHash="138ea1a7076bb01889af2309de02e8b826c27f022b21ea8cf11aca9285d5a04e"
testSearchByLinkedinUrl.profile="linkedin.com/in/seanthorne"
testSearchByNameLocationCompany {
name="Sean Thorne"
@@ -28,4 +29,7 @@
"smarthi@apache.org"
"jfrazee@apache.org"
]
+ testHandlesMissCorrectly {
+ emailHash="61824ffeb4ca171b6bb10db99eefb8a4b1c5f270eb74e35d5469d0c55a346c12"
+ }
}
\ No newline at end of file