Introduction
Spotfire allows a user to bookmark certain findings in order to share these findings with others in the organization. It is possible to communicate those findings in an automated way for further processing by the click of one button.
The example script performs following actions:
- bookmark the current findings
- communicates the new bookmark id, by means of a web service, to a third party application. In this specific case, the script sends the bookmark id to BPM. In which then actions can be taken that again a human being again will pick up the issue again and opens the analysis in the bookmarked configuration.
Other scenarios are of course possible using the same principle, for example automated sending of an email to a given distribution list for further actions.
Code sample
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. ##################################################################################### ### This ironpython script allows the user, with one click, to: ### - Bookmark his/her findings ### - Save the Analysis in the Library for further reference ### - Send off the Bookmark ID to a 3rd party application (e.g. BPM), which can then ### further process, and open exactly the same view as the User saved ### This script was built as sample for a BPM integration ##################################################################################### # Import namespaces from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread from Spotfire.Dxp.Application import DocumentSaveSettings from Spotfire.Dxp.Framework.Library import * from Spotfire.Dxp.Application import BookmarkComponentFlags from Spotfire.Dxp.Application.AnalyticItems import BookmarkManager import clr clr.AddReference('System.Data') import System from System import DateTime from System import Uri from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin from System.Net import HttpWebRequest from System.Text import Encoding import datetime #################################################################################### ### First a Bookmark will be created ### and the analysis will be saved in the Spotfire Library for later reference ### by the 3rd. party application (e.g. TIBCO BPM) #################################################################################### # Define Bookmark parameters time = datetime.datetime.now() myBookmarkname = Document.Properties["myComment"] myComment = Document.Properties["myComment"] # added timestamp to make bookmarkname unique myBookmarkname = myBookmarkname + str(time) # Create Bookmark bookmarkManager = Application.GetService(BookmarkManager) myBookmark = bookmarkManager.AddNew(myBookmarkname,BookmarkComponentFlags.All) bookmarkManager.SetPublicVisibility(myBookmark,"true") myBookmarkId = str(myBookmark.Id) Document.Properties["Status1"] = "Bookmark ID: " + myBookmarkId # Declaring the function which will run async def g(app, folder, fileName, metaData, saveSettings): def f(): app.SaveAs(folder, fileName, metaData, saveSettings) return f # Set the folder path and file name folderName = "/BPM" fileName = "Test File v4" # Set up the LibraryMangager and ensure that we can # access the folder path specified libraryManager = Document.GetService(LibraryManager) success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder) # Executing the function on the application thread, and Save the document back to the Library Application.GetService[ApplicationThread]().InvokeAsynchronously(g(Application, libraryFolder, fileName, LibraryItemMetadataSettings(), DocumentSaveSettings())) Document.Properties["Status2"] = "Bookmark saved in Library" #################################################################################### ### Now the BPM web service can be called ### the parameter myBookmarkId has the bookmarkid ### URI to call Spotfire out of BPM should be: http://spotfiredemo/SpotfireWeb/ViewAnalysis.aspx?file=/tui/Test%20File&bookmark=<myBookmarkid>; #################################################################################### uri = "http://localhost:18080/testservice"" payload = "<formalParams payloadMode=\"XML\"><XmlPayload><inputs array=\"false\" name=\"MarkingID\" optional=\"false\" type=\"String\"><simpleSpec><value>" + myBookmarkId + "</value></simpleSpec></inputs></XmlPayload></formalParams>" encpayload = Encoding.ASCII.GetBytes(payload) webRequest = HttpWebRequest.Create(uri) webRequest.Method = "POST" webRequest.ContentType = "application/xml" webRequest.ContentLength = encpayload.Length header =webRequest.Headers header.Add("authorization","Basic dGliY28tYWRtaW46c2VjcmV0") header.Add("cache-control","no-cache") requestStream = webRequest.GetRequestStream() requestStream.Write(encpayload,0,encpayload.Length) requestStream.Close() # as this script is only a sample and for its purpose it was not required to validate the response # this section has not been implemented # response = webRequest.GetResponse() Document.Properties["Status3"] = "Web Service invoked"
License: TIBCO BSD-Style License
Attachment
Download From Resources.
Recommended Comments
There are no comments to display.