Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing fastfinds, searchForIdList, and findMultipleEntity #255

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 114 additions & 29 deletions src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,45 @@ public <T extends SearchEntity> List<T> searchForList(Class<T> type, String quer
* {@inheritDoc}
*/
@Override
public <T extends SearchEntity> IdListWrapper searchForIdList(Class<T> type,
String query,
SearchParams params) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForIdSearch(
BullhornEntityInfo.getTypesRestEntityName(type),
query,
params);

String url = restUrlFactory.assembleIdSearchUrl(getRestUrl(), params);
public <T extends SearchEntity> IdListWrapper searchForIdList(Class<T> type, String query, SearchParams params) {
if(MAX_URL_LENGTH > query.length()) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForIdSearch(
BullhornEntityInfo.getTypesRestEntityName(type), query, params);

String url = restUrlFactory.assembleIdSearchUrl(getRestUrl(), params);
if (Candidate.class == type) {
url = url + "&useV2=true";
}

IdListWrapper wrapper = performGetRequest(url, IdListWrapper.class, uriVariables);
if (wrapper == null) {
return new IdListWrapper<>();
}
return wrapper;
}
return searchForIdListPost(type,query,params);
}

/**
* {@inheritDoc}
*/
protected <T extends SearchEntity> IdListWrapper searchForIdListPost(Class<T> type, String query, SearchParams params) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForIdSearchPost(
BullhornEntityInfo.getTypesRestEntityName(type), params);

String url = restUrlFactory.assembleIdSearchUrlPost(getRestUrl(), params);
if (Candidate.class == type) {
url = url + "&useV2=true";
}
JSONObject body = new JSONObject();
body.put("query", query);

IdListWrapper wrapper = performGetRequest(url, IdListWrapper.class, uriVariables);
IdListWrapper wrapper = performPostRequest(url, body.toString(), IdListWrapper.class, uriVariables);
if (wrapper == null) {
return new IdListWrapper<>();
}
return wrapper;

}

/**
Expand Down Expand Up @@ -310,7 +331,10 @@ public <T extends SearchEntity, L extends ListWrapper<T>> L search(Class<T> type
*/
@Override
public FastFindListWrapper fastFind(String query, FastFindParams params) {
return this.handleFastFindForEntities(query, params);
if(MAX_URL_LENGTH > query.length()){
return this.handleFastFindForEntities(query, params);
}
return this.handleFastFindForEntitiesPost(query, params);
}


Expand Down Expand Up @@ -843,14 +867,14 @@ protected <T extends BullhornEntity> T handleGetEntity(Class<T> type, Integer id
String jsonString = this.performGetRequest(url, String.class, uriVariables);

return restJsonConverter.jsonToEntityUnwrapRoot(jsonString, type);

}

/**
* Makes the "entity" api call for getting multiple entities.
* It actually does a search for candidates and a query for other entities when ids total > 7500 characters
* <p>
* <p>
* HTTP Method: GET
* HTTP Method: GET (POST)
*
* @param type
* @param idList
Expand All @@ -860,22 +884,38 @@ protected <T extends BullhornEntity> T handleGetEntity(Class<T> type, Integer id
* @param <T>
* @return
*/
protected <L extends ListWrapper<T>, T extends BullhornEntity> L handleGetMultipleEntities(Class<T> type, Set<Integer> idList, Set<String> fieldSet, EntityParams params) {
protected < T extends BullhornEntity,L extends ListWrapper<T>> L handleGetMultipleEntities(Class<T> type, Set<Integer> idList, Set<String> fieldSet, EntityParams params) {
String ids = idList.stream().map(id -> String.valueOf(id)).collect(Collectors.joining(","));
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForGetMultiple(BullhornEntityInfo.getTypesRestEntityName(type), ids, fieldSet, params);
String url = restUrlFactory.assembleEntityUrl(params);
try {
String response = this.performGetRequest(url, String.class, uriVariables);
if(MAX_URL_LENGTH > ids.length()) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForGetMultiple(BullhornEntityInfo.getTypesRestEntityName(type), ids, fieldSet, params);
String url = restUrlFactory.assembleEntityUrl(params);
try {
return restJsonConverter.jsonToEntityDoNotUnwrapRoot(response, BullhornEntityInfo.getTypesListWrapperType(type));
} catch(RestMappingException onlyOneEntityWasReturned) {
String response = this.performGetRequest(url, String.class, uriVariables);
try {
return restJsonConverter.jsonToEntityDoNotUnwrapRoot(response, BullhornEntityInfo.getTypesListWrapperType(type));
} catch (RestMappingException onlyOneEntityWasReturned) {
List<T> list = new ArrayList<T>();
list.add(restJsonConverter.jsonToEntityUnwrapRoot(response, type));
return (L) new StandardListWrapper<T>(list);
}
} catch (RestApiException noneReturned) {
List<T> list = new ArrayList<T>();
list.add(restJsonConverter.jsonToEntityUnwrapRoot(response, type));
return (L) new StandardListWrapper<T>(list);
}
} catch(RestApiException noneReturned) {
List<T> list = new ArrayList<T>();
return (L) new StandardListWrapper<T>(list);
}
if(type != Candidate.class) {
String where = "id in (" + ids + ")";
JSONObject body = new JSONObject();
body.put("where", where);
return (L) handleQueryForEntitiesWithPostGeneral(type,
body.toString(), fieldSet, ParamFactory.queryParams()).getData();
}else{
String idsSpaced = idList.stream().map(id -> String.valueOf(id)).collect(Collectors.joining(" "));
String query = "id:" + idsSpaced ;
JSONObject body = new JSONObject();
body.put("query", query);
return (L) handleSearchForEntitiesWithPostGeneral(type,
body.toString(), fieldSet,ParamFactory.searchParams()).getData();
}
}

Expand All @@ -901,10 +941,23 @@ protected <L extends ListWrapper<T>, T extends QueryEntity> L handleQueryForEnti
JSONObject body = new JSONObject();
body.put("where", where);

return (L) this.performPostRequest(url, body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);
return this.performPostRequest(url, body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);

}

protected <L extends ListWrapper<T>, T extends BullhornEntity> L handleQueryForEntitiesWithPostGeneral(Class<T> type, String where, Set<String> fieldSet,
QueryParams params) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForQueryWithPost(BullhornEntityInfo.getTypesRestEntityName(type),
fieldSet, params);

String url = restUrlFactory.assembleQueryUrlWithPost(params);

JSONObject body = new JSONObject();
body.put("where", where);

return this.performPostRequest(url, body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);

}
/**
* Makes the "query" api call
* <p>
Expand All @@ -928,7 +981,6 @@ protected <L extends ListWrapper<T>, T extends QueryEntity> L handleQueryForEnti
return (L) this.performGetRequest(url, BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);
}
return handleQueryForEntitiesWithPost(type,where,fieldSet,params);

}

/**
Expand Down Expand Up @@ -1005,7 +1057,6 @@ protected boolean ceilingNotReached(List<?> allEntities) {
return true;
}
return false;

}

protected boolean moreRecordsExist(ListWrapper<?> onePull) {
Expand All @@ -1016,7 +1067,6 @@ protected boolean moreRecordsExist(ListWrapper<?> onePull) {
if ((start + count >= total) || count == 0) {
return false;
}

return true;
}

Expand Down Expand Up @@ -1045,7 +1095,6 @@ protected <L extends ListWrapper<T>, T extends SearchEntity> L handleSearchForEn
return (L) this.performGetRequest(url, BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);
}
return handleSearchForEntitiesWithPost(type,query,fieldSet,params);

}

/**
Expand All @@ -1072,7 +1121,21 @@ protected <L extends ListWrapper<T>, T extends SearchEntity> L handleSearchForEn
body.put("query", query);

return (L) this.performPostRequest(url,body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);
}

protected <L extends ListWrapper<T>, T extends BullhornEntity> L handleSearchForEntitiesWithPostGeneral(Class<T> type, String query, Set<String> fieldSet,
SearchParams params) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForSearchWithPost(BullhornEntityInfo.getTypesRestEntityName(type),
fieldSet, params);

String url = restUrlFactory.assembleSearchUrlWithPost(params);
if (Candidate.class == type) {
url = url + "&useV2=true";
}
JSONObject body = new JSONObject();
body.put("query", query);

return (L) this.performPostRequest(url,body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables);
}

/**
Expand All @@ -1094,6 +1157,28 @@ protected FastFindListWrapper handleFastFindForEntities(String query, FastFindPa
return restJsonConverter.jsonToEntityDoNotUnwrapRoot(jsonString, FastFindListWrapper.class);
}

/**
* Makes the "fast find" api call
* <p>
* HTTP Method: GET
*
* @param query fast find query string
* @param params optional FastFindParams .
* @return a ListWrapper containing the records plus some additional information
*/
protected FastFindListWrapper handleFastFindForEntitiesPost(String query, FastFindParams params) {
Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForFastFindPost(params);

String url = restUrlFactory.assembleFastFindUrlPost(params);

JSONObject body = new JSONObject();
body.put("query", query);

String jsonString = this.performPostRequest(url, body.toString(), String.class, uriVariables);

return restJsonConverter.jsonToEntityDoNotUnwrapRoot(jsonString, FastFindListWrapper.class);
}

/**
* Makes the "entity" api call for updating entities
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ public Map<String, String> getUriVariablesForGetMultiple(BullhornEntityInfo enti
return uriVariables;
}

public Map<String, String> getUriVariablesForGetMultiplePost(BullhornEntityInfo entityInfo, Set<String> fieldSet, EntityParams params) {

Map<String, String> uriVariables = params.getParameterMap();

this.addCommonUriVariables(fieldSet, entityInfo, uriVariables);

return uriVariables;
}

/**
* Returns the uri variables needed for an "entity" DELETE
*
Expand Down Expand Up @@ -283,6 +292,20 @@ public Map<String, String> getUriVariablesForIdSearch(BullhornEntityInfo entityI
return uriVariables;
}

/**
* Returns the uri variables needed for a id "search" request
*/
public Map<String, String> getUriVariablesForIdSearchPost(BullhornEntityInfo entityInfo,
SearchParams params) {

Map<String, String> uriVariables = params.getParameterMap();

uriVariables.put(BH_REST_TOKEN, bullhornApiRest.getBhRestToken());
uriVariables.put(ENTITY_TYPE, entityInfo.getName());

return uriVariables;
}

/**
* Returns the uri variables needed for a resume file request
*
Expand Down Expand Up @@ -508,21 +531,36 @@ public String convertFieldSetToString(Set<String> fieldSet) {
}

/**
* Returns the uri variables needed for a "fastFind" request
*
* @param query
* @param params
* @return all uriVariables needed for the api call
*/
public Map<String, String> getUriVariablesForFastFind(String query, FastFindParams params) {
* Returns the uri variables needed for a "fastFind" request
*
* @param query
* @param params
* @return all uriVariables needed for the api call
*/
public Map<String, String> getUriVariablesForFastFind(String query, FastFindParams params) {

Map<String, String> uriVariables = params.getParameterMap();
Map<String, String> uriVariables = params.getParameterMap();

uriVariables.put(BH_REST_TOKEN, bullhornApiRest.getBhRestToken());
uriVariables.put(QUERY, query);
uriVariables.put(BH_REST_TOKEN, bullhornApiRest.getBhRestToken());
uriVariables.put(QUERY, query);

return uriVariables;
}
return uriVariables;
}

/**
* Returns the uri variables needed for a "fastFind" request sans query
*
* @param params
* @return all uriVariables needed for the api call
*/
public Map<String, String> getUriVariablesForFastFindPost(FastFindParams params) {

Map<String, String> uriVariables = params.getParameterMap();

uriVariables.put(BH_REST_TOKEN, bullhornApiRest.getBhRestToken());

return uriVariables;
}

public Map<String, String> getUriVariablesForSettings(Set<String> settingSet) {

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/com/bullhornsdk/data/api/helper/RestUrlFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,21 @@ public String assembleSearchUrlWithPost(SearchParams params) {
* SearchParams
* @return the full url to use in the api call with {fieldName} type placeholders for the uriVariables
*/
public static String assembleIdSearchUrl(String restUrl,
SearchParams params) {
public static String assembleIdSearchUrl(String restUrl, SearchParams params) {
return restUrl + "search/{entityType}?query={query}&BhRestToken={bhRestToken}" + params.getUrlString();
}

/**
* Assemble url for id search request.
*
* @param params
* SearchParams
* @return the full url to use in the api call with {fieldName} type placeholders for the uriVariables
*/
public static String assembleIdSearchUrlPost(String restUrl, SearchParams params) {
return restUrl + "search/{entityType}?BhRestToken={bhRestToken}" + params.getUrlString();
}

/**
* Assemble the url for a meta request
*
Expand Down Expand Up @@ -257,6 +267,17 @@ public String assembleFastFindUrl(FastFindParams params) {
return restUrl + "find?query={query}&BhRestToken={bhRestToken}" + params.getUrlString();
}

/**
* Assemble url for fastFind request for POST.
*
* @param params
* SearchParams
* @return the full url to use in the api call with {fieldName} type placeholders for the uriVariables
*/
public String assembleFastFindUrlPost(FastFindParams params) {
return restUrl + "find?BhRestToken={bhRestToken}" + params.getUrlString();
}

public String assembleUrlForSettings() {
return restUrl + "settings/{settings}?BhRestToken={bhRestToken}";
}
Expand Down