Skip to content

Commit cb7fa2a

Browse files
Merge pull request #24 from sovren/fix/various-customer-issues
Fixing issue with PaginationSettings and other debugging issues
2 parents e688eeb + 2dddbdc commit cb7fa2a

File tree

10 files changed

+115
-23
lines changed

10 files changed

+115
-23
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.sovren</groupId>
55
<artifactId>sovren-java</artifactId>
66

7-
<version>1.1.0</version>
7+
<version>1.1.1</version>
88

99
<packaging>jar</packaging>
1010
<name>Sovren Java SDK</name>

src/main/java/com/sovren/ApiEndpoints.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ class ApiEndpoints {
1414
_dataCenter = dataCenter;
1515
}
1616

17+
private String versionSuffix() {
18+
String versionSuffix = "";
19+
if (_dataCenter.Version != null && !_dataCenter.Version.trim().isEmpty()){
20+
versionSuffix = "/" + _dataCenter.Version;
21+
}
22+
return versionSuffix;
23+
}
24+
1725
private String prefix() {
18-
return _dataCenter.Root + "/" + _dataCenter.Version;
26+
return _dataCenter.Root + versionSuffix();
1927
}
2028

2129
private String prefix(boolean isMatchUI) {
@@ -24,7 +32,7 @@ private String prefix(boolean isMatchUI) {
2432
//do not throw this for now, it will just be a 404
2533
}
2634

27-
return _dataCenter.Root + "/" + (isMatchUI ? _matchUIPrefix : "") + "/" + _dataCenter.Version;
35+
return _dataCenter.Root + "/" + (isMatchUI ? _matchUIPrefix : "") + versionSuffix();
2836
}
2937

3038
private String sanitize(String indexOrDocId) throws IllegalArgumentException {

src/main/java/com/sovren/SovrenClient.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,15 @@ private <T extends ApiResponse> HttpResponse<T> executeRequest(Request apiReques
122122
rawResponse = _client.newCall(apiRequest).execute();
123123
apiResponse = new HttpResponse(rawResponse, classOfT);
124124

125-
if (apiResponse != null && apiResponse.getResponse() != null && apiResponse.getResponse().code() == 413) {
125+
if (rawResponse != null && rawResponse.code() == 413) {
126126
errorInfo.Message = "Request body was too large.";
127127
throw new SovrenException(requestBody, rawResponse, errorInfo, null);
128128
}
129+
130+
if (rawResponse != null && apiResponse.getData() == null && rawResponse.code() != 200) {
131+
//something went wrong, a non-200 status code
132+
errorInfo.Message = rawResponse.code() + " - " + rawResponse.message();
133+
}
129134

130135
if (apiResponse == null || apiResponse.getData() == null) throw new SovrenException(requestBody, rawResponse, errorInfo, null);
131136
}
@@ -177,7 +182,15 @@ private GenerateUIResponse executeUIRequest(Request apiRequest, String requestBo
177182
private String getBodyIfDebug(Request request) {
178183

179184
if (ShowFullRequestBodyInExceptions) {
180-
return request.body().toString();
185+
try {
186+
final Request copy = request.newBuilder().build();
187+
final okio.Buffer buffer = new okio.Buffer();
188+
copy.body().writeTo(buffer);
189+
return buffer.readUtf8();
190+
}
191+
catch (IOException e) {
192+
return null;
193+
}
181194
}
182195

183196
return null;

src/main/java/com/sovren/models/api/matching/request/LocationCriteria.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.sovren.models.api.matching.request;
77

88
import java.util.List;
9-
import java.util.Optional;
109
import com.sovren.models.Location;
1110
import com.sovren.models.api.geocoding.GeocodeProvider;
1211

@@ -19,7 +18,7 @@ public class LocationCriteria {
1918
public List<Location> Locations;
2019

2120
/** The distance from {@link #Locations} within which to find results.*/
22-
public Optional<Integer> Distance;
21+
public Integer Distance;
2322

2423
/** The units for the specified distance. */
2524
public DistanceUnit DistanceUnit;

src/main/java/com/sovren/models/api/matching/request/MatchRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package com.sovren.models.api.matching.request;
77

8-
import java.util.Optional;
98
import com.sovren.models.api.matching.CategoryWeights;
109
import com.sovren.models.api.matching.BaseScoredResponseValue;
1110

src/main/java/com/sovren/models/api/matching/request/PaginationSettings.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55

66
package com.sovren.models.api.matching.request;
77

8-
import java.util.Optional;
9-
108
/**
119
* Settings for pagination of results
1210
*/
1311
public class PaginationSettings {
1412

1513
/** How many results to return*/
16-
public Optional<Integer> Take;
14+
public Integer Take;
1715

1816
/** How many results to skip. For example: (skip 5, take 10) means return results 6-15*/
19-
public Optional<Integer> Skip;
17+
public Integer Skip;
2018
}

src/main/java/com/sovren/models/api/matching/request/SkillFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package com.sovren.models.api.matching.request;
77

8-
import java.util.Optional;
9-
108
/**
119
* Filter for a specific skill
1210
*/
@@ -19,7 +17,7 @@ public class SkillFilter {
1917
public String SkillName;
2018

2119
/** The experience level of the skill*/
22-
public Optional<SkillExperienceLevel> ExperienceLevel;
20+
public SkillExperienceLevel ExperienceLevel;
2321

2422
/** Whether or not the skill must be a current skill*/
2523
public boolean IsCurrent;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright © 2020 Sovren Group, Inc. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Sovren licensees
3+
// within the terms of their license of Sovren products or Sovren customers
4+
// within the Terms of Service pertaining to the Sovren SaaS products.
5+
6+
package com.sovren;
7+
8+
import com.sovren.exceptions.SovrenException;
9+
import com.sovren.models.api.matching.request.FilterCriteria;
10+
import java.util.ArrayList;
11+
import static org.junit.jupiter.api.Assertions.*;
12+
import org.junit.jupiter.api.Test;
13+
14+
public class SDKTests extends TestBase {
15+
16+
@Test
17+
public void test404Message(){
18+
DataCenter fakeDC = new DataCenter("https://rest.resumeparsing.com/v9/fake");
19+
SovrenClient client = new SovrenClient("1234", "1234", fakeDC);
20+
21+
try {
22+
client.getAccountInfo();
23+
}
24+
catch (SovrenException e){
25+
assertEquals(404, e.HttpStatusCode);
26+
assertEquals("404 - Not Found", e.getMessage());
27+
}
28+
}
29+
30+
@Test
31+
public void test500Message(){
32+
DataCenter fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/");
33+
SovrenClient client = new SovrenClient("1234", "1234", fakeDC);
34+
35+
try {
36+
client.getAccountInfo();
37+
}
38+
catch (SovrenException e){
39+
assertEquals(500, e.HttpStatusCode);
40+
assertEquals("connect timed out", e.getMessage().toLowerCase());
41+
}
42+
}
43+
44+
@Test
45+
public void testSelfHostedDataCenter(){
46+
String url = "https://selfhosted.customer.com";
47+
DataCenter fakeDC = new DataCenter(url);
48+
ApiEndpoints endpoints = new ApiEndpoints(fakeDC);
49+
50+
assertEquals(url + "/account", endpoints.account());
51+
}
52+
53+
@Test
54+
public void testDebugRequestBody(){
55+
DataCenter fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/");
56+
SovrenClient client = new SovrenClient("1234", "1234", fakeDC);
57+
client.ShowFullRequestBodyInExceptions = true;
58+
59+
try {
60+
ArrayList<String> index = new ArrayList<>();
61+
index.add("testIndex");
62+
client.search(index, new FilterCriteria(), null, null);
63+
}
64+
catch (SovrenException e){
65+
String expectedRequest = "{\"IndexIdsToSearchInto\":[\"testIndex\"],\"FilterCriteria\":{\"UserDefinedTagsMustAllExist\":false,\"HasPatents\":false,\"HasSecurityCredentials\":false,\"IsAuthor\":false,\"IsPublicSpeaker\":false,\"IsMilitary\":false,\"EmployersMustAllBeCurrentEmployer\":false,\"SkillsMustAllExist\":false,\"IsTopStudent\":false,\"IsCurrentStudent\":false,\"IsRecentGraduate\":false,\"LanguagesKnownMustAllExist\":false}}";
66+
assertEquals(expectedRequest, e.RequestBody);
67+
}
68+
}
69+
}

src/test/java/com/sovren/integration/AIMatchingTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.sovren.models.api.matching.MatchResponseValue;
1212
import com.sovren.models.api.matching.SearchResponseValue;
1313
import com.sovren.models.api.matching.request.FilterCriteria;
14+
import com.sovren.models.api.matching.request.PaginationSettings;
1415
import com.sovren.models.api.matching.ui.GenerateUIResponse;
1516
import com.sovren.models.matching.IndexType;
1617
import okhttp3.OkHttpClient;
@@ -99,7 +100,9 @@ public void testSearch(String indexId, String validSearchTerm) {
99100

100101
filterCritera.SearchExpression = validSearchTerm;
101102
assertDoesNotThrow(() -> {
102-
SearchResponseValue response = Client.search(indexesToQuery, filterCritera, null, null).Value;
103+
PaginationSettings pageSettings = new PaginationSettings();
104+
pageSettings.Take = 10;
105+
SearchResponseValue response = Client.search(indexesToQuery, filterCritera, null, pageSettings).Value;
103106
assertEquals(1, response.CurrentCount);
104107
assertEquals(1, response.TotalCount);
105108
});

src/test/java/com/sovren/integration/ParsingTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public void testSkillsData() throws SovrenException {
363363
}
364364

365365
@Test
366-
public void testPersonalInfoAndResumeQuality() throws SovrenException {
366+
public void testPersonalInfo() throws SovrenException {
367367
ParseResumeResponseValue response = Client.parseResume(new ParseRequest(TestData.ResumePersonalInformation, null)).Value;
368368

369369
assertNotNull(response.ResumeData.PersonalAttributes.Birthplace);
@@ -373,21 +373,26 @@ public void testPersonalInfoAndResumeQuality() throws SovrenException {
373373
assertNotNull(response.ResumeData.PersonalAttributes.FathersName);
374374
assertNotNull(response.ResumeData.PersonalAttributes.Gender);
375375
assertNotNull(response.ResumeData.PersonalAttributes.MaritalStatus);
376-
assertNotNull(response.ResumeData.PersonalAttributes.MotherTongue);
376+
//assertNotNull(response.ResumeData.PersonalAttributes.MotherTongue);
377377
assertNotNull(response.ResumeData.PersonalAttributes.Nationality);
378378
assertNotNull(response.ResumeData.PersonalAttributes.PassportNumber);
379+
}
380+
381+
@Test
382+
public void testResumeQuality() throws SovrenException, IOException {
383+
Document document = getTestFileAsDocument("resume.docx");
384+
ParseResumeResponseValue response = Client.parseResume(new ParseRequest(document, null)).Value;
379385

380-
//fatal 413
381386
assertHasItems(response.ResumeData.ResumeMetadata.ResumeQuality);
382387
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Level);
383-
assertEquals(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Level, ResumeQualityLevel.FatalProblem.Value);
388+
assertEquals(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Level, ResumeQualityLevel.SuggestedImprovement.Value);
384389
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings);
385390
assertHasItems(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings);
386391
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(0).Message);
387392
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(0).QualityCode);
388-
assertEquals("413", response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(0).QualityCode);
389-
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(2).Findings.get(1).SectionIdentifiers);
390-
assertHasItems(response.ResumeData.ResumeMetadata.ResumeQuality.get(2).Findings.get(1).SectionIdentifiers);
393+
assertEquals("227", response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(0).QualityCode);
394+
assertNotNull(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(3).SectionIdentifiers);
395+
assertHasItems(response.ResumeData.ResumeMetadata.ResumeQuality.get(0).Findings.get(3).SectionIdentifiers);
391396
}
392397

393398
@Test

0 commit comments

Comments
 (0)