Skip to content

Commit

Permalink
feat: add downloadMetadata check
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Mar 25, 2024
1 parent 44ce41f commit 7243e5a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache
48 changes: 48 additions & 0 deletions src/scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ky": "^1.2.2",
"pg": "^8.11.3",
"progress": "^2.0.3",
"ts-import": "^5.0.0-beta.0",
"uuid": "^9.0.1"
}
}
43 changes: 42 additions & 1 deletion src/scripts/validate-sgid-index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { GoogleAuth, auth } from 'google-auth-library';
import { GoogleSpreadsheet } from 'google-spreadsheet';
import ky from 'ky';
import ProgressBar from 'progress';
import * as tsImport from 'ts-import';
import { v4 as uuid } from 'uuid';
import { validateOpenDataUrl, validateOpenSgidTableName, validateUrl } from './utilities.mjs';

const downloadMetadata = await tsImport.load('../data/downloadMetadata.ts');

const spreadsheetId = '11ASS7LnxgpnD0jN4utzklREgMf1pcvYjcXcIcESHweQ';

const scopes = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'];
Expand Down Expand Up @@ -137,6 +140,36 @@ async function duplicates(row) {
}
}

async function downloadMetadataCheck(row) {
const name = row.get('hubName');
const metadata = downloadMetadata.dataPages[name];

if (!metadata || metadata.featureServiceId === null) {
return;
}

const checks = [
// sgid index field, metadata field
['itemId', 'itemId'],
['hubName', 'name'],
['serverServiceName', 'featureServiceId'],
['openSgidTableName', 'openSgid'],
['serverLayerId', 'layerId'],
];

for (const [sgidIndexField, metadataField] of checks) {
const sgidIndexValue = row.get(sgidIndexField);
const metadataValue = metadata[metadataField];

if (sgidIndexValue !== metadataValue) {
recordError(
`downloadMetadata(${name}): "${metadataField}" does not match SGID Index column "${sgidIndexField}"`,
row,
);
}
}
}

const duplicateLookups = {
openSgidTableName: {},
itemId: {},
Expand All @@ -162,7 +195,15 @@ function buildDuplicateLookups(rows) {
}
}

const checks = [openSGIDTableName, productPage, idGuid, itemId, duplicates];
const checks = [
// these functions must return a promise
openSGIDTableName,
productPage,
idGuid,
itemId,
duplicates,
downloadMetadataCheck,
];

const rows = await worksheet.getRows();
buildDuplicateLookups(rows);
Expand Down

0 comments on commit 7243e5a

Please sign in to comment.