Anda di halaman 1dari 26

10

Service Scripts

Copyright 2009, Oracle. All rights reserved.

Check Point
You know how to:

Define a BO's data structure (i.e., its schema)


Create plug-ins for a BO
Create a child BO that inherits rules defined on a parent BO
Define a BO's lifecycle
Define rules for the different stages of a BO's lifecycle
Control who can access and update a BO

In this section, you'll learn how to create service scripts to


encapsulate common logic

10 - 2

Copyright 2009, Oracle. All rights reserved.

10
What Is A Service Script?

Copyright 2009, Oracle. All rights reserved.

Problem Statement
What if there exists common logic that needs to be
invoked by many BO's
For example:
Many BO's may share common validation logic
Many BO's may share common post processing logic

You've learned several techniques to encapsulate this


logic:
You can create an algorithm and plug it in on the various BO's
This works great for "stand-alone" logic (e.g., create a To Do entry), but
it doesn't work so well if the logic is a small section of a logical
transaction

You can create an algorithm and place it into a common parent BO


But what if the BO's don't share a common parent?
10 - 4

Copyright 2009, Oracle. All rights reserved.

Introducing Service Scripts


Service scripts provide another approach
Service scripts are nothing more than common routines
that have been developed using the scripting language
(rather than Java or Cobol)
In this section, you'll learn about service scripts

10 - 5

Copyright 2009, Oracle. All rights reserved.

Service Scripts Are Invoked From Scripts


The main reason to set up a service script is to encapsulate
commonly used logic that's needed by your plug-in scripts (and by
other service scripts)
The other reason to set these up is something you'll learn later in this
class (it's when you need to invoke a service script from the UI)
Script
(Plug-in &
Service)

Step

10 - 6

And yes, Edit data steps can also


invoke service scripts

Step Type

Conditional branch
Edit data
Go to a step
Invoke business object
Invoke business service
Invoke service script
Label
Move data
Terminate

Copyright 2009, Oracle. All rights reserved.

10

Plug-in Scripts versus Service Scripts

Copyright 2009, Oracle. All rights reserved.

Service Scripts Are Very Similar To Plug-in Scripts


Earlier, you created a plug-in script using the Script
transaction
You'll find that you use the same transaction to create
service scripts
This section explains the similarities and differences
between these two types of scripts
Script

Plug-In

10 - 8

Foreshadowing: there is a 3rd type of


script that will be discussed later in this
course (Business Process Assistant
scripts)

Service

Copyright 2009, Oracle. All rights reserved.

Service Scripts Have A Schema, Plug-In Scripts Don't


Earlier, you learned how a BO has a schema in which its data
structure is defined
Service scripts also have a schema; a service script's schema defines
its API (i.e., its input and output fields)
Note - you cant declare a schema for a plug-in script because the
base-package defines its input and output (in its hard parms)
Script

Algorithm
Entity
A plug-in scripts input and
output is defined by its
plug-in spot and that's why
no schema is allowed for
these types of scripts

10 - 9

You must define a service


scripts input and output
elements by setting up a schema

Plug-In

Service

<input type="group">
<driversLicenseNo />
</input>
<output type="group">
<customerId />
</output>

Copyright 2009, Oracle. All rights reserved.

Validating The Input Elements For Service Scripts


Note - you can use the various schema attributes that you
learned about if you want the system to perform basic
validation of the service script's elements (e.g., you can
use these to validate the input elements)
Script

Plug-In

Service
GetPersonAndPremInfo Service Script Schema
<personId required="true" fkRef="PER" />
<premiseId required="true" fkRef="PREM" />
<effectiveDate required="true" dataType="date" />
<reasonCode required="true" dataType="lookup" lookup="REAS_FLG" />
...

10 - 10

Copyright 2009, Oracle. All rights reserved.

Same Step Types


Plug-in and service scripts support the same step types
There are no differences in their features or functions
Script
(Plug-in &
Service)

Step

Step Type

Notice how you can invoke business


objects and other service scripts

10 - 11

Conditional branch
Edit data
Go to a step
Invoke business object
Invoke business service
Invoke service script
Label
Move data
Terminate

Copyright 2009, Oracle. All rights reserved.

Same Data Areas And Xpath Manipulation


Both plug-in and service scripts have data areas
The superset of all data areas plus the script's schema / hard parms is
held in a single XML document that you manipulate using xpath
Script
(Plug-in &
Service)

Each entry references an


object that has a schema

Data Area

Notice how neither plug-in


nor service scripts can
reference a plug-in script
(this is because only the
base-package modules
can invoke plug-in scripts)

10 - 12

BO
Standalone

As you know, service scripts,


BOs and stand-alone data
areas have their API / data
structure defined in a
schema

Service
Script
Business
Service

Copyright 2009, Oracle. All rights reserved.

Later in this course, youll


learn about business
services (these are common
routines written in Java or
Cobol)

10
Access Rights

Copyright 2009, Oracle. All rights reserved.

Service Scripts Can Be Secured, Plug-In Scripts Can't


Earlier, you learned how a BO's application service governs who can
access and update it
Service scripts can optionally reference an application service
If a service script has an application service, the user must have access
right to this app services in order to execute the service script

Script

Plug-In

10 - 14

Application
Service

Service

This is optional

Copyright 2009, Oracle. All rights reserved.

This type of
service has a
single valid action
- Execute

When Are Access Rights Checked?


Just like for BO interaction, access rights are checked for
the initial service script invoked in a service call

Web
Server

Application
Server

If a service call invokes a service script which, in turn, invokes a


BO and two other service scripts, access rights are only checked
for the initial service script invocation, with one exception

10 - 15

Copyright 2009, Oracle. All rights reserved.

DB

Checking Access Rights Of 2nd Level Calls


If the schema's root node has an appSecurity="true" attribute, access
rights are checked for all "2nd level" BO's and service script interactions
performed by the script
Note,
If a "2nd level" BO invokes another BO, access rights will not be checked for
the "3rd level" BO
If a "2nd level" service script has this attribute set as shown, access rights will
be checked for the "3rd level" BO's and service scripts

Script

Plug-In

10 - 16

Service

GetCustomerForDriversLicense Service Script Schema


<schema appSecurity="true" >
<input type="group">
<driversLicenseNo />
</input>
<output type="group">
<customerId />
</output>
</schema>

Copyright 2009, Oracle. All rights reserved.

10
Transaction Globals

Copyright 2009, Oracle. All rights reserved.

There's Another Way To Pass Data To A Service Script


We discussed how a service script has a schema in which
its input and output elements are declared
Passing data to a script in its input is the "normal" way to
supply input
In this section, we'll describe another technique global
variables

10 - 18

Copyright 2009, Oracle. All rights reserved.

Globals Are Ephemeral


Global variables are only available within plug-in and
service scripts
The global variable will be available for the duration of the
service script and all that it invokes

10 - 19

Copyright 2009, Oracle. All rights reserved.

Initiating A Global
To create a global variable, you just have to move
something to an element prefixed with $$
For example, the following Edit Data statement would
create a global and populate it with a value of true
move 'true' to $$skipValidation;

10 - 20

Copyright 2009, Oracle. All rights reserved.

Using A Global
Once a global is populated, it can be interrogated in any
plug-in or service script that's invoked
if ($$skipValidation = 'yes')
terminate;
end-if;

10 - 21

Copyright 2009, Oracle. All rights reserved.

And Then It Disappears


After the service / plug-in script that initiated it completes,
the global evaporates (so you don't have to worry about
turning it off on subsequent updates)

10 - 22

Copyright 2009, Oracle. All rights reserved.

Defaulting Schema Values From Globals


A global variable can be used as a default value for a
schema element
Obviously, the script that invokes the object with the
schema needs to initialize the global variable
<schemaElement default="$$globalVariable"/>

10 - 23

Copyright 2009, Oracle. All rights reserved.

Team Walk Through (90 minutes)


Create a service script that has validation logic
Break up into teams and follow the instructions in the workbook

Before you start adding any meta-data, please prepare a


brief checklist of everything that you plan to add / change
and have your instructor verify it before adding your data

10 - 24

Copyright 2009, Oracle. All rights reserved.

Review Questions

10 - 25

Copyright 2009, Oracle. All rights reserved.

10 - 26

Copyright 2009, Oracle. All rights reserved.

Anda mungkin juga menyukai