diff --git a/src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java b/src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java index bc6d4eef..73c28f51 100644 --- a/src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java +++ b/src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java @@ -240,24 +240,45 @@ public List searchForList(Class type, String quer * {@inheritDoc} */ @Override - public IdListWrapper searchForIdList(Class type, - String query, - SearchParams params) { - Map uriVariables = restUriVariablesFactory.getUriVariablesForIdSearch( - BullhornEntityInfo.getTypesRestEntityName(type), - query, - params); - - String url = restUrlFactory.assembleIdSearchUrl(getRestUrl(), params); + public IdListWrapper searchForIdList(Class type, String query, SearchParams params) { + if(MAX_URL_LENGTH > query.length()) { + Map 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 IdListWrapper searchForIdListPost(Class type, String query, SearchParams params) { + Map 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; + } /** @@ -310,7 +331,10 @@ public > L search(Class 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); } @@ -843,14 +867,14 @@ protected T handleGetEntity(Class 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 *

*

- * HTTP Method: GET + * HTTP Method: GET (POST) * * @param type * @param idList @@ -860,22 +884,38 @@ protected T handleGetEntity(Class type, Integer id * @param * @return */ - protected , T extends BullhornEntity> L handleGetMultipleEntities(Class type, Set idList, Set fieldSet, EntityParams params) { + protected < T extends BullhornEntity,L extends ListWrapper> L handleGetMultipleEntities(Class type, Set idList, Set fieldSet, EntityParams params) { String ids = idList.stream().map(id -> String.valueOf(id)).collect(Collectors.joining(",")); - Map 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 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 list = new ArrayList(); + list.add(restJsonConverter.jsonToEntityUnwrapRoot(response, type)); + return (L) new StandardListWrapper(list); + } + } catch (RestApiException noneReturned) { List list = new ArrayList(); - list.add(restJsonConverter.jsonToEntityUnwrapRoot(response, type)); return (L) new StandardListWrapper(list); } - } catch(RestApiException noneReturned) { - List list = new ArrayList(); - return (L) new StandardListWrapper(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(); } } @@ -901,10 +941,23 @@ protected , 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 , T extends BullhornEntity> L handleQueryForEntitiesWithPostGeneral(Class type, String where, Set fieldSet, + QueryParams params) { + Map 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 *

@@ -928,7 +981,6 @@ protected , T extends QueryEntity> L handleQueryForEnti return (L) this.performGetRequest(url, BullhornEntityInfo.getTypesListWrapperType(type), uriVariables); } return handleQueryForEntitiesWithPost(type,where,fieldSet,params); - } /** @@ -1005,7 +1057,6 @@ protected boolean ceilingNotReached(List allEntities) { return true; } return false; - } protected boolean moreRecordsExist(ListWrapper onePull) { @@ -1016,7 +1067,6 @@ protected boolean moreRecordsExist(ListWrapper onePull) { if ((start + count >= total) || count == 0) { return false; } - return true; } @@ -1045,7 +1095,6 @@ protected , T extends SearchEntity> L handleSearchForEn return (L) this.performGetRequest(url, BullhornEntityInfo.getTypesListWrapperType(type), uriVariables); } return handleSearchForEntitiesWithPost(type,query,fieldSet,params); - } /** @@ -1072,7 +1121,21 @@ protected , T extends SearchEntity> L handleSearchForEn body.put("query", query); return (L) this.performPostRequest(url,body.toString(), BullhornEntityInfo.getTypesListWrapperType(type), uriVariables); + } + protected , T extends BullhornEntity> L handleSearchForEntitiesWithPostGeneral(Class type, String query, Set fieldSet, + SearchParams params) { + Map 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); } /** @@ -1094,6 +1157,28 @@ protected FastFindListWrapper handleFastFindForEntities(String query, FastFindPa return restJsonConverter.jsonToEntityDoNotUnwrapRoot(jsonString, FastFindListWrapper.class); } + /** + * Makes the "fast find" api call + *

+ * 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 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 *

diff --git a/src/main/java/com/bullhornsdk/data/api/helper/RestUriVariablesFactory.java b/src/main/java/com/bullhornsdk/data/api/helper/RestUriVariablesFactory.java index e4821df1..0afdd81e 100644 --- a/src/main/java/com/bullhornsdk/data/api/helper/RestUriVariablesFactory.java +++ b/src/main/java/com/bullhornsdk/data/api/helper/RestUriVariablesFactory.java @@ -147,6 +147,15 @@ public Map getUriVariablesForGetMultiple(BullhornEntityInfo enti return uriVariables; } + public Map getUriVariablesForGetMultiplePost(BullhornEntityInfo entityInfo, Set fieldSet, EntityParams params) { + + Map uriVariables = params.getParameterMap(); + + this.addCommonUriVariables(fieldSet, entityInfo, uriVariables); + + return uriVariables; + } + /** * Returns the uri variables needed for an "entity" DELETE * @@ -283,6 +292,20 @@ public Map getUriVariablesForIdSearch(BullhornEntityInfo entityI return uriVariables; } + /** + * Returns the uri variables needed for a id "search" request + */ + public Map getUriVariablesForIdSearchPost(BullhornEntityInfo entityInfo, + SearchParams params) { + + Map 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 * @@ -508,21 +531,36 @@ public String convertFieldSetToString(Set fieldSet) { } /** - * Returns the uri variables needed for a "fastFind" request - * - * @param query - * @param params - * @return all uriVariables needed for the api call - */ - public Map 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 getUriVariablesForFastFind(String query, FastFindParams params) { - Map uriVariables = params.getParameterMap(); + Map 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 getUriVariablesForFastFindPost(FastFindParams params) { + + Map uriVariables = params.getParameterMap(); + + uriVariables.put(BH_REST_TOKEN, bullhornApiRest.getBhRestToken()); + + return uriVariables; + } public Map getUriVariablesForSettings(Set settingSet) { diff --git a/src/main/java/com/bullhornsdk/data/api/helper/RestUrlFactory.java b/src/main/java/com/bullhornsdk/data/api/helper/RestUrlFactory.java index 8388368c..43cdce7d 100644 --- a/src/main/java/com/bullhornsdk/data/api/helper/RestUrlFactory.java +++ b/src/main/java/com/bullhornsdk/data/api/helper/RestUrlFactory.java @@ -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 * @@ -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}"; }