This is an automated email from the ASF dual-hosted git repository.
sblackmon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/streams.git
The following commit(s) were added to refs/heads/master by this push:
new e4b2d2d resolves STREAMS-650
e4b2d2d is described below
commit e4b2d2de4329d43600d058467167cd334bb03c4d
Author: sblackmon <[email protected]>
AuthorDate: Wed Dec 11 15:20:34 2019 -0600
resolves STREAMS-650
---
.../org/apache/streams/fullcontact/FullContact.java | 19 +++++++++++--------
.../streams/fullcontact/PersonEnrichment.java | 4 ++--
.../fullcontact/api/EnrichPersonResponse.json | 21 +++++++++++++++++++++
.../streams/fullcontact/test/FullContactIT.java | 14 ++++++++++++++
.../test/resources/FullContactIT/FullContactIT.conf | 3 +++
5 files changed, 51 insertions(+), 10 deletions(-)
diff --git
a/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/FullContact.java
b/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/FullContact.java
index 0d0eff8..933337f 100644
---
a/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/FullContact.java
+++
b/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/FullContact.java
@@ -18,9 +18,11 @@
package org.apache.streams.fullcontact;
+import org.apache.juneau.rest.client.RestCallException;
import org.apache.streams.config.ComponentConfigurator;
import org.apache.streams.fullcontact.api.EnrichCompanyRequest;
import org.apache.streams.fullcontact.api.EnrichPersonRequest;
+import org.apache.streams.fullcontact.api.EnrichPersonResponse;
import org.apache.streams.fullcontact.config.FullContactConfiguration;
import org.apache.streams.fullcontact.pojo.CompanySummary;
import org.apache.streams.fullcontact.pojo.PersonSummary;
@@ -120,20 +122,21 @@ public class FullContact implements CompanyEnrichment,
PersonEnrichment {
}
@Override
- public PersonSummary enrichPerson(EnrichPersonRequest request) {
+ public EnrichPersonResponse enrichPerson(EnrichPersonRequest request) {
try {
String requestJson = serializer.serialize(request);
RestCall call = restClient
- .doPost(baseUrl() + "person.enrich")
- .accept("application/json")
- .contentType("application/json")
- .body(new StringReader(requestJson));
+ .doPost(baseUrl() + "person.enrich")
+ .accept("application/json")
+ .contentType("application/json")
+ .ignoreErrors()
+ .body(new StringReader(requestJson));
String responseJson = call.getResponseAsString();
- PersonSummary result = parser.parse(responseJson, PersonSummary.class);
- return result;
+ EnrichPersonResponse response = parser.parse(responseJson,
EnrichPersonResponse.class);
+ return response;
} catch( Exception e ) {
LOGGER.error("Exception", e);
- return new PersonSummary();
+ return new EnrichPersonResponse().withMessage(e.getMessage());
} finally {
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
}
diff --git
a/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/PersonEnrichment.java
b/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/PersonEnrichment.java
index d3ad2f5..d4202ac 100644
---
a/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/PersonEnrichment.java
+++
b/streams-contrib/streams-processor-fullcontact/src/main/java/org/apache/streams/fullcontact/PersonEnrichment.java
@@ -19,7 +19,7 @@
package org.apache.streams.fullcontact;
import org.apache.streams.fullcontact.api.EnrichPersonRequest;
-import org.apache.streams.fullcontact.pojo.PersonSummary;
+import org.apache.streams.fullcontact.api.EnrichPersonResponse;
import org.apache.juneau.http.annotation.Body;
import org.apache.juneau.remote.RemoteInterface;
@@ -29,6 +29,6 @@ import org.apache.juneau.rest.client.remote.RemoteMethod;
public interface PersonEnrichment {
@RemoteMethod(method ="POST")
- public PersonSummary enrichPerson(@Body EnrichPersonRequest request);
+ public EnrichPersonResponse enrichPerson(@Body EnrichPersonRequest request);
}
\ No newline at end of file
diff --git
a/streams-contrib/streams-processor-fullcontact/src/main/jsonschema/org/apache/streams/fullcontact/api/EnrichPersonResponse.json
b/streams-contrib/streams-processor-fullcontact/src/main/jsonschema/org/apache/streams/fullcontact/api/EnrichPersonResponse.json
new file mode 100644
index 0000000..b96e2f1
--- /dev/null
+++
b/streams-contrib/streams-processor-fullcontact/src/main/jsonschema/org/apache/streams/fullcontact/api/EnrichPersonResponse.json
@@ -0,0 +1,21 @@
+{
+ "type": "object",
+ "$schema": "http://json-schema.org/draft-03/schema",
+ "$license": [
+ "http://www.apache.org/licenses/LICENSE-2.0"
+ ],
+ "id": "#",
+ "javaType": "org.apache.streams.fullcontact.api.EnrichPersonResponse",
+ "extends": {
+ "$ref": "../pojo/PersonSummary.json"
+ },
+ "properties": {
+ "message": {
+ "type": "string",
+ "description": "Error message if error occurred."
+ },
+ "status": {
+ "type": "integer"
+ }
+ }
+}
\ No newline at end of file
diff --git
a/streams-contrib/streams-processor-fullcontact/src/test/java/org/apache/streams/fullcontact/test/FullContactIT.java
b/streams-contrib/streams-processor-fullcontact/src/test/java/org/apache/streams/fullcontact/test/FullContactIT.java
index 715539e..1d5eccb 100644
---
a/streams-contrib/streams-processor-fullcontact/src/test/java/org/apache/streams/fullcontact/test/FullContactIT.java
+++
b/streams-contrib/streams-processor-fullcontact/src/test/java/org/apache/streams/fullcontact/test/FullContactIT.java
@@ -245,4 +245,18 @@ public class FullContactIT {
assertThat("response contains a non-empty fullName",
StringUtils.isNotBlank(response.getFullName()));
}
+ @Test
+ public void testHandlesMissCorrectly() throws Exception {
+ PersonEnrichment personEnrichment = FullContact.getInstance(config);
+ String email =
StreamsConfigurator.getConfig().getString("org.apache.streams.fullcontact.test.FullContactIT.testHandlesMissCorrectly.emailHash");
+ EnrichPersonRequest req = new EnrichPersonRequest()
+ .withEmail(email);
+ EnrichPersonResponse response = personEnrichment.enrichPerson(req);
+ nonNull(response);
+ nonNull(response.getStatus());
+ assertEquals(response.getStatus(), new Long(404));
+ nonNull(response.getMessage());
+ assertEquals(response.getMessage(), "Profile not found");
+ }
+
}
\ No newline at end of file
diff --git
a/streams-contrib/streams-processor-fullcontact/src/test/resources/FullContactIT/FullContactIT.conf
b/streams-contrib/streams-processor-fullcontact/src/test/resources/FullContactIT/FullContactIT.conf
index 8689528..6dcecb3 100644
---
a/streams-contrib/streams-processor-fullcontact/src/test/resources/FullContactIT/FullContactIT.conf
+++
b/streams-contrib/streams-processor-fullcontact/src/test/resources/FullContactIT/FullContactIT.conf
@@ -39,4 +39,7 @@ org.apache.streams.fullcontact.test.FullContactIT {
postalCode = "10022"
}
}
+ testHandlesMissCorrectly {
+
emailHash="61824ffeb4ca171b6bb10db99eefb8a4b1c5f270eb74e35d5469d0c55a346c12"
+ }
}
\ No newline at end of file