un-cli 0.0.84 → 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.84";
10
+ let version = "0.0.85";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -172,11 +172,15 @@ const inputs = {
172
172
  "topology --validate" : "Validate topology (full extent)",
173
173
  "update subnetworks --subnetwork": "Update the input subnetwork synchronously",
174
174
  "update subnetworks --all": "Update all dirty subnetworks synchronously",
175
+ "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
175
176
  "update subnetworks --deleted": "Update all deleted dirty subnetworks synchronously",
176
177
  "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
178
+
177
179
  "export subnetworks --all [--folder]": "Export all subnetworks with ACK --folder where exported files are saved",
178
180
  "export subnetworks --new [--folder]": "Export all subnetworks with ACK that haven't been exported --folder where exported files are saved",
179
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
+
180
184
  "updateisconnected": "Run update is connected ",
181
185
  "versions": "List all versions available to the current logged in user.",
182
186
  "versions --summary": "Summary of versions.",
@@ -792,8 +796,8 @@ const inputs = {
792
796
  logger.info(`Result from submitting job ${JSON.stringify(subnetworkResult)}`)
793
797
  }
794
798
  },
795
- "^export subnetworks --all --folder .*$|^export subnetworks --all$" : async input => {
796
-
799
+ "^export subnetworks --all --folder .*$|^export subnetworks --all$|^export subnetworks --all --resulttype .*$" : async input => {
800
+
797
801
  let subnetworks
798
802
  let sort = "asc";
799
803
  if (input.indexOf("--desc") > 0) sort = "desc"
@@ -802,6 +806,27 @@ const inputs = {
802
806
  let inputDir = "Exported"
803
807
  if (file != null && file.length > 0)
804
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
+
805
830
  //create directory if doesn't exists
806
831
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
807
832
  let exportedSubnetworks = [];
@@ -823,7 +848,7 @@ const inputs = {
823
848
 
824
849
  const fromDate = new Date();
825
850
 
826
- 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);
827
852
 
828
853
  //code
829
854
  exportedSubnetworks.push("'" + v(f.attributes,"subnetworkName") + "'")
@@ -845,10 +870,10 @@ const inputs = {
845
870
  //although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
846
871
  // if we want to do something with the response then make it json
847
872
  const jsonExport = await subContent.text();
848
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
873
+ fs.writeFileSync(`${inputDir}/${v(f.attributes,"domainNetworkName")}_${v(f.attributes,"tierName")}_${subnetworkName}.json`, jsonExport)
849
874
 
850
875
 
851
- 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`)
852
877
 
853
878
  }
854
879
  }
@@ -856,7 +881,55 @@ const inputs = {
856
881
 
857
882
  },
858
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 = [];
859
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
+ },
860
933
  "^export subnetworks --new --folder .*$|^export subnetworks --new$" : async input => {
861
934
 
862
935
  //create folder
@@ -879,9 +952,11 @@ const inputs = {
879
952
  //fetch the json and write it to disk
880
953
  const subContent = await fetch(subnetworkResult.url);
881
954
  const jsonExport = await subContent.text();
882
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
883
-
884
- 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
+
885
960
  }
886
961
 
887
962
 
@@ -968,19 +1043,19 @@ const inputs = {
968
1043
  logger.error(JSON.stringify(ex))
969
1044
  }
970
1045
  },
971
- "^export subnetworks --deleted$" : async input => {
1046
+ "^export subnetworks --deleted --folder" : async input => {
972
1047
 
973
1048
  //create folder
974
- const file = input.match(/-f .*/gm)
1049
+ const file = input.match(/--folder .*/gm)
975
1050
  let inputDir = "Exported"
976
1051
  if (file != null && file.length > 0)
977
- inputDir = file[0].replace("-f ", "")
1052
+ inputDir = file[0].replace("--folder ", "")
978
1053
  //create directory if doesn't exists
979
1054
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
980
1055
 
981
1056
 
982
1057
  logger.info("Querying all subnetworks that are clean and deleted.");
983
- 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");
984
1059
  logger.info(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
985
1060
  for (let i = 0; i < subnetworks.features.length; i++) {
986
1061
  const f = subnetworks.features[i]
@@ -998,9 +1073,11 @@ const inputs = {
998
1073
  //fetch the json and write it to disk
999
1074
  const subContent = await fetch(subnetworkResult.url);
1000
1075
  const jsonExport = await subContent.text();
1001
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, JSON.stringify(jsonExport))
1002
-
1003
- 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
+
1004
1081
  }
1005
1082
 
1006
1083
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.84",
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)