Skip to content

Commit

Permalink
new version 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
herve91 committed Oct 26, 2018
1 parent 0f7b81e commit dc11856
Show file tree
Hide file tree
Showing 7 changed files with 683 additions and 549 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ When ran, the plugin asks for an INI file that contains all the required options
- Mapping between the ServiceNow relations and the Archi relations
- ...

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.
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.

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).

Expand Down
2 changes: 1 addition & 1 deletion org.archicontribs.servicenow/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.archicontribs.servicenow
Bundle-ManifestVersion: 2
Bundle-Name: Plugin to import from ServiceNow (Oasis)
Bundle-SymbolicName: org.archicontribs.servicenow;singleton:=true
Bundle-Version: 1.3
Bundle-Version: 1.5
Bundle-Vendor: Hervé JOUIN
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,27 @@
* Can now follow reference links in in properties (with a cache mechanism to reduce the calls to ServiceNow)
* Can now use variables ${xxx} in ini properties
* Use CIs operational status to determine if Archi elements should be created/updated or removed
* Allow to specify the import mode: full, create_only, update_only, create_or_update_only and remove_only
* Allow to specify the import mode: full, create_only, update_only, create_or_update_only and remove_only
*
* version 1.4: 26/09/2018
* continue in case we cannot follow a link
*
* version 1.5: 26/10/2018
* add "filter" option
*
* TODO: retrieve the applications and business services
* TODO: use commands to allow rollback
* TODO: validate that relations are permitted before creating them
* TODO: add an option to continue in case of error --> but count the number of errors and show this counter on the summary popup
* TODO: transform progressbar window: show all tables/relationships with one progress bar in front of each table/relationship
* TODO: transform progressbar window: show same look and feel that database plugin
* TOTO: add cancel button
* TODO: add variable ${on_error:xxxxxxx) ou ${on_empty:xxxxx}
*
*/

public class MyImporter implements ISelectedModelImporter {
static String SNowPluginVersion = "1.3";
static String SNowPluginVersion = "1.5";
static String title = "ServiceNow import plugin v" + SNowPluginVersion;

Logger logger;
Expand Down Expand Up @@ -135,6 +147,7 @@ public void doImport(IArchimateModel model) throws IOException {
String generalArchiElementsName = null;
String generalArchiElementsDocumentation = null;
String generalArchiElementsFolder = null;
String generalArchiElementsFilter = null;
String generalArchiElementsImportMode = null;

// general relations properties
Expand Down Expand Up @@ -244,6 +257,7 @@ public void doImport(IArchimateModel model) throws IOException {
generalArchiElementsName = this.iniProperties.getString("archi.elements.*.name", "sys_class_name");
generalArchiElementsDocumentation = this.iniProperties.getString("archi.elements.*.documentation", "short_description");
generalArchiElementsFolder = this.iniProperties.getString("archi.elements.*.folder", "sys_class_name");
generalArchiElementsFilter = this.iniProperties.getString("archi.elements.*.filter", "");
generalArchiElementsImportMode = this.iniProperties.getString("archi.elements.*.import_mode", "full");
if ( !generalArchiElementsImportMode.equals("full") && !generalArchiElementsImportMode.equals("create_or_update_only") && !generalArchiElementsImportMode.equals("create_only") && !generalArchiElementsImportMode.equals("update_only") && !generalArchiElementsImportMode.equals("remove_only") ) {
@SuppressWarnings("unused")
Expand Down Expand Up @@ -382,7 +396,7 @@ public void doImport(IArchimateModel model) throws IOException {
urlBuilder.append(",");
urlBuilder.append(field);
}

String archiElementsImportMode = this.iniProperties.getString("archi.elements."+tableName+".importMode", generalArchiElementsImportMode);
if ( !archiElementsImportMode.equals("full") && !archiElementsImportMode.equals("create_or_update_only") && !archiElementsImportMode.equals("create_only") && !archiElementsImportMode.equals("update_only") && !generalArchiElementsImportMode.equals("remove_only") ) {
@SuppressWarnings("unused")
Expand Down Expand Up @@ -431,11 +445,24 @@ public void doImport(IArchimateModel model) throws IOException {
// operational_status = 1 if create or update only
// operational_status = 2 if remove_only
// and no filter if create, update and remove
StringBuilder sysparmQuery = new StringBuilder();
if ( generalArchiElementsImportMode.equals("create_or_update_only") || generalArchiElementsImportMode.equals("create_only") || generalArchiElementsImportMode.equals("update_only") )
urlBuilder.append("&sysparm_query=operational_status="+this.OPERATIONAL);
sysparmQuery.append("operational_status="+this.OPERATIONAL);
else if ( generalArchiElementsImportMode.equals("remove_only") )
urlBuilder.append("&sysparm_query=operational_status="+this.NON_OPERATIONAL);

sysparmQuery.append("operational_status="+this.NON_OPERATIONAL);

String archiElementsFilter = this.iniProperties.getString("archi.elements."+tableName+".filter", generalArchiElementsFilter);
if ( archiElementsFilter.length() != 0 ) {
if ( sysparmQuery.length() != 0 )
sysparmQuery.append(",");
sysparmQuery.append(archiElementsFilter);
}

if ( sysparmQuery.length() != 0 ) {
urlBuilder.append("&sysparm_query=");
urlBuilder.append(sysparmQuery);
}

this.logger.debug(" Generated URL is " + urlBuilder.toString());

// we invoke the ServiceNow web service
Expand Down Expand Up @@ -1162,17 +1189,25 @@ private String getJsonField(JsonNode node, String fieldName, String defaultValue
else {
// we invoke the ServiceNow web service
this.logger.trace(" Following reference link to URL "+linkURL);
MyConnection connection = new MyConnection(this.proxyHost, this.proxyPort, this.proxyUser, this.proxyPassword);
connection.setLogger(this.logger);
String linkContent = connection.get(subFields[column], linkURL, this.serviceNowUser, this.serviceNowPassword);
JsonFactory jsonFactory = new MappingJsonFactory();
try ( JsonParser jsonParser = jsonFactory.createJsonParser(linkContent) ) {
jsonNode = jsonParser.readValueAsTree().get("result");
this.referenceLinkCache.put(linkURL, jsonNode);
} catch (JsonParseException err) {
this.logger.error("Failed to parse JSON got from ServiceNow.", err);
jsonNode = null;
break;
try {
MyConnection connection = new MyConnection(this.proxyHost, this.proxyPort, this.proxyUser, this.proxyPassword);
connection.setLogger(this.logger);
String linkContent = connection.get(subFields[column], linkURL, this.serviceNowUser, this.serviceNowPassword);
JsonFactory jsonFactory = new MappingJsonFactory();
try ( JsonParser jsonParser = jsonFactory.createJsonParser(linkContent) ) {
jsonNode = jsonParser.readValueAsTree().get("result");
this.referenceLinkCache.put(linkURL, jsonNode);
} catch (JsonParseException err) {
this.logger.error("Failed to parse JSON got from ServiceNow.", err);
jsonNode = null;
//TODO: ++error_count;
break;
}
} catch (MyException | IOException err2) {
this.logger.error("Failed to get URL from ServiceNow.", err2);
jsonNode = null;
//TODO: ++error_count;
break;
}
}
}
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions release_note.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### v1.5: 16/10/2018
* add "filter" option in ini file

### v1.4: 26/09/2018
* continue to process ServiceNow data in case a link cannot be followed

### v1.3: 16/09/2018
* make the progress bar application modal
* rewrite progress bar to be more readable on 4K displays
Expand Down
Loading

0 comments on commit dc11856

Please sign in to comment.