29/11/2014

[Oracle DB] Create and schedule a job

To create and schedule a basic job on an Oracle DB, you'll need to create:
  • A script performing the desired action
  • A schedule
  • A job
The script can be passed as code directly to the job, a function/procedure, a package function/procedure.

Step 1: Create package with our function

CREATE OR REPLACE PACKAGE myPackage AS   
PROCEDURE myProcedure;  
END;

CREATE OR REPLACE PACKAGE BODY myPackage AS
PROCEDURE myProcedure AS
--variable declaration here
BEGIN
  --something
  NULL;--not actually needed
END myProcedure;
END;

Step 2: Create schedule and job. Refer to the linked documentation for more information regarding the various parameters

 BEGIN  
   
 --create schedule  
 DBMS_SCHEDULER.CREATE_SCHEDULE (           
      repeat_interval => 'FREQ=YOUR_FREQUENCY',     
      start_date => TO_TIMESTAMP('START_DATE', 'FORMAT'),  
      schedule_name => '"mySchedule"');  
       
 --create job on mySchedule  
 DBMS_SCHEDULER.CREATE_JOB (  
       job_name => 'myJob',  
       job_type => 'PLSQL_BLOCK',  
       schedule_name => '"mySchedule"',  
       job_action => 'BEGIN myPackage.myProcedure; END;',  
       number_of_arguments => 0,  
       job_class => 'DEFAULT_JOB_CLASS',  
       enabled => true,  
       auto_drop => true,  
       comments => 'SOME_DESCRIPTION');  
 END;  
   

[TIBCO Spotfire] Run script at startup from a Web Player mashup

If you created a mashup page that includes a Spotfire analysis served via Web Player using JavaScript, you can easily trigger the embedded IronPython scripts to run as soon as the report is opened.

This also works if the report is accessed directly via an URL that uses Configuration Blocks.

  • Create a Document Property as a boolean and set it to false.
  • Tie your script to that Document Property; every time its value changes, the script is triggered
If using the JS mashup page, have a JS script run when the onOpened event is fired and set that property. Make sure that the mashup page runs under the same site as the Web Player on the IIS server, eg: "Add application" under the Spotfire Web Player site.

Mashup page:

 <html>  
   <head>  
     <title>MySamplePage</title>  
     <script type="text/javascript" src="PATH_TO/SpotfireWeb/GetJavaScriptApi.ashx?Version=3.1"></script>  
     <script type="text/javascript" src="PATH_TO/myScript.js"></script>  
   </head>  
   <body>  
           <!-- Whatever -->  
           <div id="webPlayerDiv"/>  
   </body>  
 </html>  


Script:

 var webPlayer;  
 var webPlayerRelativePath = "PATH_TO/SpotfireWeb/";  
 var analysisPath = "PATH_TO/myAnalysis";  
   
 <!-- when the page is accessed, include the Web Player analysis via JS -->  
 window.onload = function()  
 {                 
   openWebPlayer();       
 };  
   
 var openWebPlayer = function()  
 {  
   var webPlayerCustomization = new spotfire.webPlayer.Customization();  
      <!-- enable/disable toolbar buttons -->  
   webPlayerCustomization.showCustomizableHeader = true;  
   webPlayerCustomization.showTopHeader = true;  
   webPlayerCustomization.showClose = true;  
   webPlayerCustomization.showAnalysisInfo = true;  
   webPlayerCustomization.showToolBar = true;  
   webPlayerCustomization.showExportFile = true;  
   webPlayerCustomization.showExportVisualization = true;  
   webPlayerCustomization.showUndoRedo = true;  
   webPlayerCustomization.showDodPanel = true;  
   webPlayerCustomization.showFilterPanel = true;  
   webPlayerCustomization.showPageNavigation = true;  
   webPlayerCustomization.showStatusBar = true;  
   
      webPlayer = new spotfire.webPlayer.Application(webPlayerRelativePath, webPlayerCustomization);  
   
   var onError = function(errorCode, description)  
   {  
     log('<span style="color: red;">[' + errorCode + "]: " + description + "</span>");  
   };  
   
      <!-- when the report is loaded, set our Document Property to true to trigger the script -->  
   var onOpened = function(analysisDocument)  
   {       
           webPlayer.analysisDocument.setDocumentProperty(  
                     "myProperty",  
                     "true");  
   };  
        
   webPlayer.onError(onError);  
   webPlayer.onOpened(onOpened);  
   webPlayer.open(analysisPath, "webPlayerDiv", "");  
 };  

If using the configuration block in the URL instead, add:

 &configurationBlock=PROPERTY_NAME=VALUE;  


So you'll have something like:

 http://myServer:PORT/SpotfireWeb/ViewAnalysis.aspx?file=/PATH_TO/MyAnalysis&configurationBlock=MyDocumentProperty=VALUE;  


[Windows Server] Disable shutdown reason tracker

Every time you halt or reboot your Windows Server machine, you'll have to specify a reason before you can proceed.
This can be disabled by running:

gpedit.msc

then browsing to

Computer Configuration->Administrative Templates->System then searching for the entry: Display Shutdown Event Tracker and setting it to disabled.


[Windows Server] Change password policy

On Windows Server you can change the password policy, eg:

  • User cannot change password
  • Password must be at least X characters long
  • Password expires after X days
  • ...
Either locally for the server:

secpol.msc

Or for the whole domain:

gpedit.msc

Run either one of these tools depending on your needs then browse to Account Policies->Password Policy

[Windows Server] Disable Server Manager auto start at login

You can block Windows Server Manager from starting automatically at login from its configuration.

Open Server Manager, then click on the Manage button and choose "Server Manager properties", you'll have the choice there.

[Windows Server] Enable automatic login

On Windows Server 2008/2012 it's possible to enable automatic login if the server is NOT a domain controller.

Simply run:

netplwiz.exe

Found under WIN_INSTALL_DIR\System32, and uncheck "Users must enter a username [...]". You'll have to insert you username and password and at the next reboot you'll brought directly to your desktop.

If your server is a Domain Controller (DC) too, then you cannot use this tool, but will have to uncheck the same setting from the "Active Directory Users and Computers" snap-in

08/11/2014

[Spotfire] Get data from marking via script

Should you need to get data from a marking while inside an IronPython script in Spotfire, you may try:

 from Spotfire.Dxp.Data import *  
 from System import String,Object  
    
 markingName = 'some_name' #can also be passed as parameter!  
 DataTableSelection = 'some_table' #can also be passed as parameter!  
    
 #get marked rows  
 rowMask = Document.Data.Markings[markingName].GetSelection(DataTableSelection)  
    
 #get cursor on the marking for the values we want  
 cursor = DataValueCursor.CreateFormatted(DataTableSelection.Columns["some_column"])  
    
 #cycle on our cursor and do something with the values  
 for row in DataTableSelection.GetRows(rowMask.AsIndexSet(),cursor):  
         print cursor.CurrentValue  


Remember that all inputs can be passed as parameters to our script!

[Oracle] Run commands in different schema

In Oracle, it is possible to change the current schema/user with the ALTER SESSION statement:

ALTER SESSION SET CURRENT_SCHEMA = new_schema;

All subsequent commands will use that schema as default when nothing is specified. Of course, you'll need permission to execute the ALTER SESSION and all other statements on the new schema.