Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1454 from openlattice/feature/APPS-3291-count-ent…
Browse files Browse the repository at this point in the history
…ities-in-sets

Feature/apps 3291 count entities in sets
  • Loading branch information
UnsungHero97 authored Dec 7, 2021
2 parents b3b00ab + 5a8fb13 commit f762b64
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/api/SearchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import {
} from '../constants/SerializationConstants';
import {
ADVANCED_PATH,
COUNT_PATH,
DATA_SETS_PATH,
IDS_PATH,
NEIGHBORS_PATH,
SEARCH_ENTITY_TYPES_PATH,
} from '../constants/UrlConstants';
import { isDefined, isEmptyArray, isNonEmptyObject } from '../utils/LangUtils';
import { isValidUUID, isValidUUIDArray } from '../utils/ValidationUtils';
Expand All @@ -44,6 +46,48 @@ import type { UUID } from '../types';

const LOG = new Logger('SearchApi');

/**
* `POST /search/entity_types/{entityTypeId}/count`
*
* Searches EntitySet data according to the given constraints.
*
* @static
* @memberof lattice.SearchApi
* @param {UUID} entityTypeId
* @param {UUID[]} entitySetIds
* @returns {Promise<number>} - a Promise that resolves with the number of entities within the provided entity sets.
* Entity sets must belong to the same provided entity type
*
* @example
* SearchApi.countEntitiesInSets(
* "ec6865e6-e60e-424b-a071-6a9c1603d735",
* ["3bf2a30d-fda0-4389-a1e6-8546b230efad", "11442cb3-99dc-4842-8736-6c76e6fcc7c4"]
* );
*/
function countEntitiesInSets(entityTypeId :UUID, entitySetIds :UUID[]) :Promise<number> {
let errorMsg = '';

if (!isValidUUID(entityTypeId)) {
errorMsg = 'invalid parameter: "entityTypeId" must be a valid UUID';
LOG.error(errorMsg, entitySetIds);
return Promise.reject(errorMsg);
}

if (!isValidUUIDArray(entitySetIds)) {
errorMsg = 'invalid parameter: "entitySetIds" must be a non-empty array of valid UUIDs';
LOG.error(errorMsg, entitySetIds);
return Promise.reject(errorMsg);
}

return getApiAxiosInstance(SEARCH_API)
.post(`/${SEARCH_ENTITY_TYPES_PATH}/${entityTypeId}/${COUNT_PATH}`, entitySetIds)
.then((axiosResponse) => axiosResponse.data)
.catch((error :Error) => {
LOG.error(error);
return Promise.reject(error);
});
}

/**
* `POST /search/datasets`
*
Expand Down Expand Up @@ -250,6 +294,7 @@ function searchEntitySetData(searchConstraints :Object) :Promise<Object> {
}

export {
countEntitiesInSets,
searchDataSetMetadata,
searchEntityNeighborsWithFilter,
searchEntitySetData,
Expand Down
20 changes: 20 additions & 0 deletions src/api/SearchApi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as AxiosUtils from '../utils/axios';
import { SEARCH_API } from '../constants/ApiNames';
import {
ADVANCED_PATH,
COUNT_PATH,
DATA_SETS_PATH,
IDS_PATH,
NEIGHBORS_PATH,
SEARCH_ENTITY_TYPES_PATH,
} from '../constants/UrlConstants';
import { runTestSuite } from '../utils/testing/APITestSuite';
import { getMockAxiosInstance } from '../utils/testing/MockUtils';
Expand Down Expand Up @@ -36,6 +38,24 @@ describe(SEARCH_API, () => {
SearchApi,
SEARCH_API,
{
countEntitiesInSets: {
'': {
params: {
optional: [false, false],
valid: [MOCK_EKID_1, [MOCK_ESID_1, MOCK_ESID_2]],
},
},
'(entityTypeId, [entitySetIds])': {
method: 'post',
params: {
axios: [`/${SEARCH_ENTITY_TYPES_PATH}/${MOCK_EKID_1}/${COUNT_PATH}`, [
MOCK_ESID_1,
MOCK_ESID_2
]],
valid: [MOCK_EKID_1, [MOCK_ESID_1, MOCK_ESID_2]],
},
},
},
searchDataSetMetadata: {
'': {
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/index_default_export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EXPECTED_OBJ_EXPORTS = OrderedMap({
PermissionsApi : { size: 5 },
PersistentSearchApi: { size: 4 },
PrincipalsApi : { size: 10 },
SearchApi : { size: 3 },
SearchApi : { size: 4 },
Constants : { size: 8 },
Models : { size: 18 },
Types : { size: 12 },
Expand Down
2 changes: 1 addition & 1 deletion src/index_named_export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EXPECTED_OBJ_EXPORTS = OrderedMap({
PermissionsApi : { size: 5 },
PersistentSearchApi: { size: 4 },
PrincipalsApi : { size: 10 },
SearchApi : { size: 3 },
SearchApi : { size: 4 },
Constants : { size: 8 },
Models : { size: 18 },
Types : { size: 12 },
Expand Down

0 comments on commit f762b64

Please sign in to comment.