Appboard/2.4/builder/data processing scripts: Difference between revisions
imported>Andy.hopper |
imported>Andy.hopper |
||
Line 10: | Line 10: | ||
#Select the data source to be affected and click the "Edit" button | #Select the data source to be affected and click the "Edit" button | ||
#Advance through the data source wizard to the "Query" stage for database, IBM Omnibus/Netcool, or ServiceNow adapters, or the "Explore" stage otherwise. | #Advance through the data source wizard to the "Query" stage for database, IBM Omnibus/Netcool, or ServiceNow adapters, or the "Explore" stage otherwise. | ||
#Next, access the "Data Processing Script" area: | |||
#*For database, IBM Omnibus/Netcool, or ServiceNow adapters click the table you want to transform and click the "Edit" button. | #*For database, IBM Omnibus/Netcool, or ServiceNow adapters click the table you want to transform and click the "Edit" button. | ||
#*Otherwise, select the table you want to transform and then click the "Advanced" button. | #*Otherwise, select the table you want to transform and then click the "Advanced" button. |
Revision as of 13:22, 16 October 2013
Data Processing Scripts are a method of processing data returned from Data Sources before it's made available to the rest of the system. This is a very flexible method to transform data in order to meet the specific needs of a solution.
Scripts are written in the Groovy programming language, which is a Java like dynamic language, and attached to Data Source entities.
Applying a Data Processing Script
- Open the AppBoard Builder and click on "Data Sources"
- Select the data source to be affected and click the "Edit" button
- Advance through the data source wizard to the "Query" stage for database, IBM Omnibus/Netcool, or ServiceNow adapters, or the "Explore" stage otherwise.
- Next, access the "Data Processing Script" area:
- For database, IBM Omnibus/Netcool, or ServiceNow adapters click the table you want to transform and click the "Edit" button.
- Otherwise, select the table you want to transform and then click the "Advanced" button.
- Click "Add" in the Data Processing Script section.
- Configure the Data Processing Script
- Input the path name of the script
- Typically Data Processing Script are kept in the following directory: ${appboard_server}/webapps/enportal/WEB-INF/groovy-script/custom
- Set the priority (default 10)
- Priority is only important if you have multiple scripts active
- Set script to run on "Response" or "Refresh"
- Response (called every time the client requests)
- Example when to use: performing a join or status determination by requesting data from another dataset
- Refresh (called only when data is fetched from source)
- Example when to use: substringing a value
- Response (called every time the client requests)
- Input the path name of the script
- Click through the wizard to finish
- View the appropriate data collection (re-query if necessary) to see if data is being updated
Data Processing Script Example
TrimSiteCode.groovy
[java,N]
import com.edgetech.services.ServiceRequestFacade
import com.edgetech.services.ServiceResponseFacade
import com.edgetech.services.GenericRecord
import com.edgetech.services.Association
import com.edgetech.services.impl.ServiceRequestHelper
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
// trim extra whitespace and concatenate two fields into a new one
ServiceResponseFacade serviceResponse = responseFacade;
ServiceRequestFacade serviceRequest = requestFacade;
Collection recordsToClean = serviceResponse.getOrderedGenericRecords();
if ( ( recordsToClean != null ) && !recordsToClean.isEmpty() ) {
for ( GenericRecord recordToClean:recordsToClean ) {
String siteCode = recordToClean.getAttributeValueAsString("SITE_CODE");
if ( siteCode != null ) {
recordToClean.setAttributeValue("SITE_CODE", siteCode.trim());
String stateCode = recordToClean.getAttributeValueAsString("STATE");
if ( stateCode != null ) {
recordToClean.setAttributeValue("SITE_CODE2", siteCode.trim() + stateCode.trim());
}
}
String region = recordToClean.getAttributeValueAsString("REGION");
if ( region != null ) {
recordToClean.setAttributeValue("REGION", region.trim());
}
}
}