Skip to content

Commit

Permalink
fix(arcgis-rest-request): Added Params Preprocessor for GP Mutilvalue…
Browse files Browse the repository at this point in the history
… Inputs (#1027)

* added processed params to ISubmitJobOption

* removed processedParams in ISubmitJobOptions

* modified job test

* added a test for processedParamsFunc

* broke out processJobParams to another file

Co-authored-by: Marcy Silverman <marcysilverman@Marcys-MBP.lan>
Co-authored-by: Marcy Silverman <marcysilverman@esri-o8rw1tsmvv.esri.com>
  • Loading branch information
3 people authored Oct 12, 2022
1 parent 06750e0 commit cf75cd6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/arcgis-rest-request/src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ArcGISJobError } from "./utils/ArcGISJobError.js";
import { JOB_STATUSES } from "./types/job-statuses.js";
import { IAuthenticationManager } from "./utils/IAuthenticationManager.js";
import mitt from "mitt";
import { processJobParams } from "./utils/process-job-params.js";

/**
* Options for creating a new {@linkcode Job}.
Expand Down Expand Up @@ -188,10 +189,11 @@ export class Job {
...requestOptions
};

const processedParams = processJobParams(params);
const baseUrl = cleanUrl(url.replace(/\/submitJob\/?/, ""));
const submitUrl = baseUrl + "/submitJob";
return request(submitUrl, {
params,
params: processedParams,
authentication
}).then(
(response) =>
Expand Down Expand Up @@ -236,6 +238,7 @@ export class Job {
*/
private setIntervalHandler: any;


constructor(options: IJobOptions) {
const { url, id, pollingRate, authentication }: Partial<IJobOptions> = {
...DefaultJobOptions,
Expand Down
13 changes: 13 additions & 0 deletions packages/arcgis-rest-request/src/utils/process-job-params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Processes arrays to JSON strings for Geoprocessing services. See “GPMultiValue” in {@link https://developers.arcgis.com/rest/services-reference/enterprise/gp-data-types.htm}
*/
export function processJobParams(params: any) {
const processedParams = Object.keys(params).reduce((newParams: any, key) => {
const value = params[key]
const type = value.constructor.name;
newParams[key] = type === "Array" ? JSON.stringify(value) : value;
return newParams;
}, {});

return processedParams
}
52 changes: 50 additions & 2 deletions packages/arcgis-rest-request/test/job.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetchMock, { done } from "fetch-mock";
import { Job, JOB_STATUSES, ArcGISRequestError } from "../src/index.js";
import { processJobParams } from "../src/utils/process-job-params.js";
import {
GPJobIdResponse,
GPEndpointCall,
Expand Down Expand Up @@ -473,9 +474,7 @@ describe("Job", () => {
mockHotspot_Raster
);
});

return job.getResult("Hotspot_Raster");

})
.then((result) => {
expect(result).toEqual(mockHotspot_Raster);
Expand Down Expand Up @@ -681,6 +680,55 @@ describe("Job", () => {
Job.submitJob(GPEndpointCall).then((job) => {
expect(job.isMonitoring).toEqual(true);
done();

});
});

it("parses params if there is multi-value input", () => {
processJobParams({
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot/submitJob",
params: {
summarizeType: "['CentralFeature', 'MeanCenter', 'MedianCenter', 'Ellipse']",
weightField: 'NUM_TREES',
ellipseSize: '1 standard deviation',
context: {
extent: {
xmin: -15034729.266472297,
ymin: 5716733.479048933,
xmax: -12070195.56146081,
ymax: 7808050.572930799,
spatialReference: { wkid: 102100, latestWkid: 3857 },
},
},
}
});

expect(processJobParams({
summarizeType: ['CentralFeature', 'MeanCenter', 'MedianCenter', 'Ellipse'],
weightField: 'NUM_TREES',
ellipseSize: '1 standard deviation',
context: {
extent: {
xmin: -15034729.266472297,
ymin: 5716733.479048933,
xmax: -12070195.56146081,
ymax: 7808050.572930799,
spatialReference: { wkid: 102100, latestWkid: 3857 },
},
}
})).toEqual({
summarizeType:'["CentralFeature","MeanCenter","MedianCenter","Ellipse"]',
weightField: 'NUM_TREES',
ellipseSize: '1 standard deviation',
context: {
extent: {
xmin: -15034729.266472297,
ymin: 5716733.479048933,
xmax: -12070195.56146081,
ymax: 7808050.572930799,
spatialReference: { wkid: 102100, latestWkid: 3857 },
},
}
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const GPEndpointCall = {
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot/submitJob",
params: {
Query: `"DATE" > date '1998-01-01 00:00:00' AND "DATE" < date '1998-01-31 00:00:00') AND ("Day" = 'SUN' OR "Day"= 'SAT')
Query: `"DATE" > date '1998-01-01 00:00:00' AND "DATE" < date '1998-01-31 00:00:00') AND ("Day" = 'SUN' OR "Day"= 'SAT'),
`
},
startMonitoring: true,
Expand Down

0 comments on commit cf75cd6

Please sign in to comment.