Skip to content

Commit dc11856

Browse files
committed
new version 1.5
1 parent 0f7b81e commit dc11856

File tree

7 files changed

+683
-549
lines changed

7 files changed

+683
-549
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ When ran, the plugin asks for an INI file that contains all the required options
2525
- Mapping between the ServiceNow relations and the Archi relations
2626
- ...
2727

28-
You may download the *sample_servicenow_ini_file.ini* file to your local drive (like "My documents") and update it to your needs. The file is self documented.
28+
You may download the *sample_snow-import_plugin_ini_file.ini* file to your local drive (like "My documents") and update it to your needs. The file is self documented.
2929

3030
The plugin generates the REST request and connects to the ServiceNow web services to download and parse the data. The request is optimised to reduce the quantity of data downloaded (only the fields described in the ini file are downloaded).
3131

org.archicontribs.servicenow/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.archicontribs.servicenow
33
Bundle-ManifestVersion: 2
44
Bundle-Name: Plugin to import from ServiceNow (Oasis)
55
Bundle-SymbolicName: org.archicontribs.servicenow;singleton:=true
6-
Bundle-Version: 1.3
6+
Bundle-Version: 1.5
77
Bundle-Vendor: Hervé JOUIN
88
Bundle-Localization: plugin
99
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

org.archicontribs.servicenow/src/org/archicontribs/servicenow/MyImporter.java

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,27 @@
8686
* Can now follow reference links in in properties (with a cache mechanism to reduce the calls to ServiceNow)
8787
* Can now use variables ${xxx} in ini properties
8888
* Use CIs operational status to determine if Archi elements should be created/updated or removed
89-
* Allow to specify the import mode: full, create_only, update_only, create_or_update_only and remove_only
89+
* Allow to specify the import mode: full, create_only, update_only, create_or_update_only and remove_only
90+
*
91+
* version 1.4: 26/09/2018
92+
* continue in case we cannot follow a link
93+
*
94+
* version 1.5: 26/10/2018
95+
* add "filter" option
9096
*
9197
* TODO: retrieve the applications and business services
9298
* TODO: use commands to allow rollback
9399
* TODO: validate that relations are permitted before creating them
100+
* TODO: add an option to continue in case of error --> but count the number of errors and show this counter on the summary popup
101+
* TODO: transform progressbar window: show all tables/relationships with one progress bar in front of each table/relationship
102+
* TODO: transform progressbar window: show same look and feel that database plugin
103+
* TOTO: add cancel button
104+
* TODO: add variable ${on_error:xxxxxxx) ou ${on_empty:xxxxx}
105+
*
94106
*/
95107

96108
public class MyImporter implements ISelectedModelImporter {
97-
static String SNowPluginVersion = "1.3";
109+
static String SNowPluginVersion = "1.5";
98110
static String title = "ServiceNow import plugin v" + SNowPluginVersion;
99111

100112
Logger logger;
@@ -135,6 +147,7 @@ public void doImport(IArchimateModel model) throws IOException {
135147
String generalArchiElementsName = null;
136148
String generalArchiElementsDocumentation = null;
137149
String generalArchiElementsFolder = null;
150+
String generalArchiElementsFilter = null;
138151
String generalArchiElementsImportMode = null;
139152

140153
// general relations properties
@@ -244,6 +257,7 @@ public void doImport(IArchimateModel model) throws IOException {
244257
generalArchiElementsName = this.iniProperties.getString("archi.elements.*.name", "sys_class_name");
245258
generalArchiElementsDocumentation = this.iniProperties.getString("archi.elements.*.documentation", "short_description");
246259
generalArchiElementsFolder = this.iniProperties.getString("archi.elements.*.folder", "sys_class_name");
260+
generalArchiElementsFilter = this.iniProperties.getString("archi.elements.*.filter", "");
247261
generalArchiElementsImportMode = this.iniProperties.getString("archi.elements.*.import_mode", "full");
248262
if ( !generalArchiElementsImportMode.equals("full") && !generalArchiElementsImportMode.equals("create_or_update_only") && !generalArchiElementsImportMode.equals("create_only") && !generalArchiElementsImportMode.equals("update_only") && !generalArchiElementsImportMode.equals("remove_only") ) {
249263
@SuppressWarnings("unused")
@@ -382,7 +396,7 @@ public void doImport(IArchimateModel model) throws IOException {
382396
urlBuilder.append(",");
383397
urlBuilder.append(field);
384398
}
385-
399+
386400
String archiElementsImportMode = this.iniProperties.getString("archi.elements."+tableName+".importMode", generalArchiElementsImportMode);
387401
if ( !archiElementsImportMode.equals("full") && !archiElementsImportMode.equals("create_or_update_only") && !archiElementsImportMode.equals("create_only") && !archiElementsImportMode.equals("update_only") && !generalArchiElementsImportMode.equals("remove_only") ) {
388402
@SuppressWarnings("unused")
@@ -431,11 +445,24 @@ public void doImport(IArchimateModel model) throws IOException {
431445
// operational_status = 1 if create or update only
432446
// operational_status = 2 if remove_only
433447
// and no filter if create, update and remove
448+
StringBuilder sysparmQuery = new StringBuilder();
434449
if ( generalArchiElementsImportMode.equals("create_or_update_only") || generalArchiElementsImportMode.equals("create_only") || generalArchiElementsImportMode.equals("update_only") )
435-
urlBuilder.append("&sysparm_query=operational_status="+this.OPERATIONAL);
450+
sysparmQuery.append("operational_status="+this.OPERATIONAL);
436451
else if ( generalArchiElementsImportMode.equals("remove_only") )
437-
urlBuilder.append("&sysparm_query=operational_status="+this.NON_OPERATIONAL);
438-
452+
sysparmQuery.append("operational_status="+this.NON_OPERATIONAL);
453+
454+
String archiElementsFilter = this.iniProperties.getString("archi.elements."+tableName+".filter", generalArchiElementsFilter);
455+
if ( archiElementsFilter.length() != 0 ) {
456+
if ( sysparmQuery.length() != 0 )
457+
sysparmQuery.append(",");
458+
sysparmQuery.append(archiElementsFilter);
459+
}
460+
461+
if ( sysparmQuery.length() != 0 ) {
462+
urlBuilder.append("&sysparm_query=");
463+
urlBuilder.append(sysparmQuery);
464+
}
465+
439466
this.logger.debug(" Generated URL is " + urlBuilder.toString());
440467

441468
// we invoke the ServiceNow web service
@@ -1162,17 +1189,25 @@ private String getJsonField(JsonNode node, String fieldName, String defaultValue
11621189
else {
11631190
// we invoke the ServiceNow web service
11641191
this.logger.trace(" Following reference link to URL "+linkURL);
1165-
MyConnection connection = new MyConnection(this.proxyHost, this.proxyPort, this.proxyUser, this.proxyPassword);
1166-
connection.setLogger(this.logger);
1167-
String linkContent = connection.get(subFields[column], linkURL, this.serviceNowUser, this.serviceNowPassword);
1168-
JsonFactory jsonFactory = new MappingJsonFactory();
1169-
try ( JsonParser jsonParser = jsonFactory.createJsonParser(linkContent) ) {
1170-
jsonNode = jsonParser.readValueAsTree().get("result");
1171-
this.referenceLinkCache.put(linkURL, jsonNode);
1172-
} catch (JsonParseException err) {
1173-
this.logger.error("Failed to parse JSON got from ServiceNow.", err);
1174-
jsonNode = null;
1175-
break;
1192+
try {
1193+
MyConnection connection = new MyConnection(this.proxyHost, this.proxyPort, this.proxyUser, this.proxyPassword);
1194+
connection.setLogger(this.logger);
1195+
String linkContent = connection.get(subFields[column], linkURL, this.serviceNowUser, this.serviceNowPassword);
1196+
JsonFactory jsonFactory = new MappingJsonFactory();
1197+
try ( JsonParser jsonParser = jsonFactory.createJsonParser(linkContent) ) {
1198+
jsonNode = jsonParser.readValueAsTree().get("result");
1199+
this.referenceLinkCache.put(linkURL, jsonNode);
1200+
} catch (JsonParseException err) {
1201+
this.logger.error("Failed to parse JSON got from ServiceNow.", err);
1202+
jsonNode = null;
1203+
//TODO: ++error_count;
1204+
break;
1205+
}
1206+
} catch (MyException | IOException err2) {
1207+
this.logger.error("Failed to get URL from ServiceNow.", err2);
1208+
jsonNode = null;
1209+
//TODO: ++error_count;
1210+
break;
11761211
}
11771212
}
11781213
}

release_note.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### v1.5: 16/10/2018
2+
* add "filter" option in ini file
3+
4+
### v1.4: 26/09/2018
5+
* continue to process ServiceNow data in case a link cannot be followed
6+
17
### v1.3: 16/09/2018
28
* make the progress bar application modal
39
* rewrite progress bar to be more readable on 4K displays

0 commit comments

Comments
 (0)