un-cli 0.0.83 → 0.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/examples.txt ADDED
@@ -0,0 +1,4 @@
1
+ export subnetworks --all --resulttype [{"type":"features","includeGeometry":true,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":["Source ID","E:Riser"],"diagramTemplateName":"","resultTypeFields":[{"networkSourceId":14,"fieldName":"GLOBALID"},{"networkSourceId":15,"fieldName":"CLUSTERKEY"},{"networkSourceId":9,"fieldName":"LIFECYCLESTATUS"},{"networkSourceId":4,"fieldName":"ASSETGROUP"},{"networkSourceId":12,"fieldName":"ASSETGROUP"}]},{"type":"connectivity","includeGeometry":true,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":[],"diagramTemplateName":"","resultTypeFields":[]},{"type":"associations","includeGeometry":false,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":[],"diagramTemplateName":"","resultTypeFields":[]}]
2
+ update subnewtorks --all
3
+ topology --validate
4
+ trace --subnetwork test
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
7
7
  import logger from "./logger.mjs"
8
8
  import fetch from "node-fetch"
9
9
  //update version
10
- let version = "0.0.83";
10
+ let version = "0.0.85";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -170,12 +170,17 @@ const inputs = {
170
170
  "topology --disable" : "Disable topology",
171
171
  "topology --enable" : "Enable topology",
172
172
  "topology --validate" : "Validate topology (full extent)",
173
+ "update subnetworks --subnetwork": "Update the input subnetwork synchronously",
173
174
  "update subnetworks --all": "Update all dirty subnetworks synchronously",
175
+ "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
174
176
  "update subnetworks --deleted": "Update all deleted dirty subnetworks synchronously",
175
177
  "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
178
+
176
179
  "export subnetworks --all [--folder]": "Export all subnetworks with ACK --folder where exported files are saved",
177
180
  "export subnetworks --new [--folder]": "Export all subnetworks with ACK that haven't been exported --folder where exported files are saved",
178
181
  "export subnetworks --deleted": "Export all subnetworks with ACK that are deleted ",
182
+ "export subnetworks --all [--resulttype]": "Export all subnetworks with ACK --resulttype is a json configuration",
183
+
179
184
  "updateisconnected": "Run update is connected ",
180
185
  "versions": "List all versions available to the current logged in user.",
181
186
  "versions --summary": "Summary of versions.",
@@ -184,6 +189,7 @@ const inputs = {
184
189
  "reconcile --version <version name>": "Reconcile the input version synchronously",
185
190
  "reconcile --withpost --version <version name>": "Reconcile & Post the input version synchronously, oldest common ancestor first",
186
191
  "reconcile --all": "Reconcile all versions available to the current user synchronously, oldest common ancestor first",
192
+ "reconcile --all --withpost": "Reconcile and post all versions available to the current user synchronously, oldest common ancestor first",
187
193
  "reconcile --all --withpost --async": "Reconcile and post all versions available to the current user asynchronously, oldest common ancestor first",
188
194
  "reconcile --all --async": "Reconcile all versions available to the current user asynchronously, oldest common ancestor first",
189
195
  "count": "Lists the number of rows in all feature layers and tables.",
@@ -276,7 +282,7 @@ const inputs = {
276
282
  return;
277
283
  }
278
284
 
279
- const subs = versions.versions.filter( a => a.reconcileDate != null ).sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) ). map( (a) => {
285
+ const subs = versions.versions.filter( a => a.reconcileDate == null ).sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) ). map( (a) => {
280
286
  return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "modified": new Date(a.modifiedDate), "common": a.commonAncestorDate ? new Date( a.commonAncestorDate) : 'N/A' , "reconciled": a.reconcileDate ? new Date(a.reconcileDate) : 'N/A'};
281
287
  })
282
288
 
@@ -324,7 +330,7 @@ const inputs = {
324
330
 
325
331
  summary.totalVersions = versions.versions.length;
326
332
 
327
- summary.unreconciledVersions = versions.versions.filter( a => a.reconcileDate != null ).length
333
+ summary.unreconciledVersions = versions.versions.filter( a => a.reconcileDate == null ).length
328
334
 
329
335
  summary.versionsBehindDefault = versions.versions.filter( a => defaultVersion.modifiedDate > a?.commonAncestorDate ).length
330
336
 
@@ -416,6 +422,24 @@ const inputs = {
416
422
  logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
417
423
  },
418
424
 
425
+
426
+ "^reconcile --all --withpost$": async () => {
427
+
428
+ let versions = await un.versions()
429
+ versions.versions = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) )
430
+
431
+ for (let v = 0; v < versions.versions.length; v++)
432
+ {
433
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
434
+ logger.info (`Reconciling version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
435
+
436
+ const result = await un.reconcile(versions.versions[v].versionGuid, true, false, true, false);
437
+ logger.info(JSON.stringify(result))
438
+ }
439
+ const rowCount = versions.versions.length;
440
+ logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
441
+ },
442
+
419
443
  "^reconcile --all --async$": async () => {
420
444
  //async
421
445
  let versions = await un.versions()
@@ -662,6 +686,40 @@ const inputs = {
662
686
  logger.info (`${numberWithCommas(rowCount)} rows returned.`)
663
687
  },
664
688
 
689
+
690
+
691
+
692
+
693
+ "^update subnetworks --subnetwork" : async (input) => {
694
+
695
+
696
+ const inputParam = input.match(/--subnetwork .*/gm)
697
+ let subnetworkName = null;
698
+ if (inputParam != null && inputParam.length > 0)
699
+ subnetworkName = inputParam[0].replace("--subnetwork ", "")
700
+
701
+
702
+
703
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "1=1 AND subnetworkname = '" + subnetworkName + "'","domainnetworkname,tiername,subnetworkname");
704
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks.`);
705
+ for (let i = 0; i < subnetworks.features.length; i++) {
706
+ const f = subnetworks.features[i]
707
+ logger.info("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
708
+
709
+ const fromDate = new Date();
710
+
711
+ const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
712
+
713
+ //code
714
+
715
+ const toDate = new Date();
716
+ const timeEnable = toDate.getTime() - fromDate.getTime();
717
+ subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
718
+
719
+
720
+ logger.info(`Result ${JSON.stringify(subnetworkResult)}`)
721
+ }
722
+ },
665
723
  "^update subnetworks --deleted$" : async () => {
666
724
  logger.info("Querying all subnetworks that are dirty and deleted.");
667
725
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 and isdeleted=1","domainnetworkname,tiername,subnetworkname");
@@ -738,8 +796,8 @@ const inputs = {
738
796
  logger.info(`Result from submitting job ${JSON.stringify(subnetworkResult)}`)
739
797
  }
740
798
  },
741
- "^export subnetworks --all --folder .*$|^export subnetworks --all$" : async input => {
742
-
799
+ "^export subnetworks --all --folder .*$|^export subnetworks --all$|^export subnetworks --all --resulttype .*$" : async input => {
800
+
743
801
  let subnetworks
744
802
  let sort = "asc";
745
803
  if (input.indexOf("--desc") > 0) sort = "desc"
@@ -748,6 +806,27 @@ const inputs = {
748
806
  let inputDir = "Exported"
749
807
  if (file != null && file.length > 0)
750
808
  inputDir = file[0].replace("--folder ", "")
809
+
810
+ //default resulttype
811
+ let resultType = null;
812
+
813
+ const rt = input.match(/--resulttype .*/gm)
814
+ if (rt != null && v.length > 0)
815
+ resultType = rt[0].replace("--resulttype ", "")
816
+
817
+ logger.info(resultType)
818
+
819
+ try
820
+ {
821
+ resultType = JSON.parse(resultType)
822
+ }
823
+ catch(ex)
824
+ {
825
+ logger.error("Can't parse resulttype" + ex)
826
+ return;
827
+ }
828
+
829
+
751
830
  //create directory if doesn't exists
752
831
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
753
832
  let exportedSubnetworks = [];
@@ -769,7 +848,7 @@ const inputs = {
769
848
 
770
849
  const fromDate = new Date();
771
850
 
772
- const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
851
+ const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false, resultType);
773
852
 
774
853
  //code
775
854
  exportedSubnetworks.push("'" + v(f.attributes,"subnetworkName") + "'")
@@ -791,10 +870,10 @@ const inputs = {
791
870
  //although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
792
871
  // if we want to do something with the response then make it json
793
872
  const jsonExport = await subContent.text();
794
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
873
+ fs.writeFileSync(`${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`, jsonExport)
795
874
 
796
875
 
797
- logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
876
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`)
798
877
 
799
878
  }
800
879
  }
@@ -802,7 +881,55 @@ const inputs = {
802
881
 
803
882
  },
804
883
 
884
+ "^export subnetworks --all --async --folder .*$|^export subnetworks --all --async$|^export subnetworks --all --async --resulttype .*$" : async input => {
885
+
886
+ let subnetworks
887
+ let sort = "asc";
888
+ if (input.indexOf("--desc") > 0) sort = "desc"
889
+ //create folder
890
+ const file = input.match(/--folder .*/gm)
891
+ let inputDir = "Exported"
892
+ if (file != null && file.length > 0)
893
+ inputDir = file[0].replace("--folder ", "")
894
+
895
+
896
+ //default resulttype
897
+ let resultType = null;
898
+
899
+ const rt = input.match(/--resulttype .*/gm)
900
+ if (rt != null && v.length > 0)
901
+ resultType = rt[0].replace("--resulttype ", "")
902
+
903
+ logger.info(resultType)
904
+
905
+ //create directory if doesn't exists
906
+ if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
907
+ let exportedSubnetworks = [];
805
908
 
909
+ do {
910
+
911
+ let exportedSubnetworksWhereClause = ""
912
+
913
+ if (exportedSubnetworks.length > 0 )
914
+ exportedSubnetworksWhereClause = " AND SUBNETWORKNAME NOT IN (" + exportedSubnetworks.join(",") + ")"
915
+
916
+ logger.info("Querying all subnetworks that are clean.");
917
+ subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=0 " + exportedSubnetworksWhereClause,`domainnetworkname ${sort},tiername ${sort},subnetworkname ${sort}`);
918
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
919
+ for (let i = 0; i < subnetworks.features.length; i++) {
920
+ const f = subnetworks.features[i]
921
+ const subnetworkName = v(f.attributes,"subnetworkName")
922
+ logger.info("Exporting subnetworks " + subnetworkName);
923
+
924
+
925
+ const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),true);
926
+ logger.info(`Result from submitting job ${JSON.stringify(subnetworkResult)}`)
927
+
928
+ }
929
+ }
930
+ while (subnetworks?.features?.length > 0)
931
+
932
+ },
806
933
  "^export subnetworks --new --folder .*$|^export subnetworks --new$" : async input => {
807
934
 
808
935
  //create folder
@@ -825,9 +952,11 @@ const inputs = {
825
952
  //fetch the json and write it to disk
826
953
  const subContent = await fetch(subnetworkResult.url);
827
954
  const jsonExport = await subContent.text();
828
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
829
-
830
- logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
955
+ fs.writeFileSync(`${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`, jsonExport)
956
+
957
+
958
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`)
959
+
831
960
  }
832
961
 
833
962
 
@@ -914,19 +1043,19 @@ const inputs = {
914
1043
  logger.error(JSON.stringify(ex))
915
1044
  }
916
1045
  },
917
- "^export subnetworks --deleted$" : async input => {
1046
+ "^export subnetworks --deleted --folder" : async input => {
918
1047
 
919
1048
  //create folder
920
- const file = input.match(/-f .*/gm)
1049
+ const file = input.match(/--folder .*/gm)
921
1050
  let inputDir = "Exported"
922
1051
  if (file != null && file.length > 0)
923
- inputDir = file[0].replace("-f ", "")
1052
+ inputDir = file[0].replace("--folder ", "")
924
1053
  //create directory if doesn't exists
925
1054
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
926
1055
 
927
1056
 
928
1057
  logger.info("Querying all subnetworks that are clean and deleted.");
929
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty = 0 and isdeleted=1");
1058
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdeleted=1", "subnetworkname");
930
1059
  logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
931
1060
  for (let i = 0; i < subnetworks.features.length; i++) {
932
1061
  const f = subnetworks.features[i]
@@ -944,9 +1073,11 @@ const inputs = {
944
1073
  //fetch the json and write it to disk
945
1074
  const subContent = await fetch(subnetworkResult.url);
946
1075
  const jsonExport = await subContent.text();
947
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
948
-
949
- logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
1076
+ fs.writeFileSync(`${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`, jsonExport)
1077
+
1078
+
1079
+ logger.info(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`)
1080
+
950
1081
  }
951
1082
 
952
1083
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "description": "Command line interface for working with ArcGIS Utility Network Extension",
5
5
  "main": "index.mjs",
6
6
  "bin": {
@@ -1180,7 +1180,7 @@ export class UtilityNetwork {
1180
1180
  }
1181
1181
 
1182
1182
 
1183
- exportSubnetworks(domainNetworkName, tierName, subnetworkName, async=false) {
1183
+ exportSubnetworks(domainNetworkName, tierName, subnetworkName, async=false,resultTypes=null) {
1184
1184
 
1185
1185
  let thisObj = this;
1186
1186
  let tier = this.getTier(domainNetworkName, tierName);
@@ -1190,37 +1190,9 @@ export class UtilityNetwork {
1190
1190
  let ar = thisObj.featureServiceUrl.split("/");
1191
1191
  ar[ar.length-1]="UtilityNetworkServer";
1192
1192
  let exportsubnetworkUrl = ar.join("/") + "/exportSubnetwork"
1193
- const resultTypes = [
1194
- {
1195
- "type": "features",
1196
- "includeGeometry": true,
1197
- "includePropagatedValues": false,
1198
- "includeDomainDescriptions": true,
1199
- "networkAttributeNames": [
1200
- "Is subnetwork controller"
1201
- ],
1202
- "diagramTemplateName": "",
1203
- "resultTypeFields": []
1204
- },
1205
- {
1206
- "type": "connectivity",
1207
- "includeGeometry": true,
1208
- "includePropagatedValues": false,
1209
- "includeDomainDescriptions": true,
1210
- "networkAttributeNames": [],
1211
- "diagramTemplateName": "",
1212
- "resultTypeFields": []
1213
- },
1214
- {
1215
- "type": "associations",
1216
- "includeGeometry": false,
1217
- "includePropagatedValues": false,
1218
- "includeDomainDescriptions": true,
1219
- "networkAttributeNames": [],
1220
- "diagramTemplateName": "",
1221
- "resultTypeFields": []
1222
- }
1223
- ]
1193
+ if (!resultTypes)
1194
+ resultTypes = [{"type":"features","includeGeometry":true,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":["Is subnetwork controller"],"diagramTemplateName":"","resultTypeFields":[]},{"type":"connectivity","includeGeometry":true,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":[],"diagramTemplateName":"","resultTypeFields":[]},{"type":"associations","includeGeometry":false,"includePropagatedValues":false,"includeDomainDescriptions":true,"networkAttributeNames":[],"diagramTemplateName":"","resultTypeFields":[]}]
1195
+
1224
1196
  //traceConfiguration: JSON.stringify(subnetworkDef),
1225
1197
  let exportsubnetworkJson = {
1226
1198
  f: "json",
@@ -1231,7 +1203,7 @@ export class UtilityNetwork {
1231
1203
  exportAcknowledgement: true,
1232
1204
  allSubnetworksInTier: false,
1233
1205
  continueOnFailure: false,
1234
- traceConfiguration: subnetworkDef,
1206
+ traceConfiguration: JSON.stringify(subnetworkDef),
1235
1207
  async: async,
1236
1208
  gdbVersion:this.gdbVersion,
1237
1209
  resultTypes: JSON.stringify(resultTypes)