Skip to content
Snippets Groups Projects
Commit 47fe6ad2 authored by Marco Del Tufo's avatar Marco Del Tufo
Browse files

Update as-services.md

parent 77a5ca7f
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -3,52 +3,37 @@ Custom Application Server Services ...@@ -3,52 +3,37 @@ Custom Application Server Services
## Introduction ## Introduction
On Data Store Server (DSS) aggregation/ingestion services based on On Data Store Server (DSS) aggregation/ingestion services based on Jython scripts can be used to extend openBIS by custom services. These services have full access on data store and Application Server (AS).
Jython scripts can be used to extend openBIS by custom services. These
services have full access on data store and Application Server (AS).
Often only access on AS is needed. Going over DSS is a detour. For such Often only access on AS is needed. Going over DSS is a detour. For such cases it is better to write an AS core plugin of type `services`.
cases it is better to write an AS core plugin of type `services`.
## How to write a custom AS service core plugin ## How to write a custom AS service core plugin
Here is the recipe to create an AS core plugin of type `services`: Here is the recipe to create an AS core plugin of type `services`:
1. The 1. The folder `<core plugin folder>/<module>/<version>/as/services/<core plugin name>` has to be created.
folder `<core plugin folder>/<module>/<version>/as/services/<core plugin name>`
has to be created.
2. In this folder two files have to be created: `plugin.properties` 2. In this folder two files have to be created: `plugin.properties` and `script.py`. The properties file should contain:
and `script.py`. The properties file should contain:
**plugin.properties** **plugin.properties**
class = ch.ethz.sis.openbis.generic.server.asapi.v3.helper.service.JythonBasedCustomASServiceExecutor ```
script-path = script.py class = ch.ethz.sis.openbis.generic.server.asapi.v3.helper.service.JythonBasedCustomASServiceExecutor
script-path = script.py
```
3. The script file should have the function `process` with two 3. The script file should have the function `process` with two arguments. The first argument is the context. It contains the methods `getSessionToken()` and `getApplicationService()` which returns an instance of `ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi`. The second argument is a map of key-value pairs. The key is a string and the values is an arbitrary object. Anything returned by the script will be returned to the caller of the service. Here is an example of a script which creates a space:
arguments. The first argument is the context. It contains the **script.py**
methods `getSessionToken()` and `getApplicationService()` which ```py
returns an instance from ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create import SpaceCreation
of `ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi`. The
second argument is a map of key-value pairs. The key is a string and
the values is an arbitrary object.
Anything returned by the script will be returned to the caller of def process(context, parameters):
the service. Here is an example of a script which creates a space: space_creation = SpaceCreation()
space_creation.code = parameters.get('space_code');
**script.py** result = context.applicationService.createSpaces(context.sessionToken, [space_creation]);
return "Space created: %s" % result
from ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create import SpaceCreation ```
Note, that all changes on the AS database will be done in one transaction.
def process(context, parameters):
space_creation = SpaceCreation()
space_creation.code = parameters.get('space_code');
result = context.applicationService.createSpaces(context.sessionToken, [space_creation]);
return "Space created: %s" % result
Note, that all changes on the AS database will be done in one
transaction.
## How to use a custom AS service ## How to use a custom AS service
...@@ -81,14 +66,9 @@ the method `withParameter()`. ...@@ -81,14 +66,9 @@ the method `withParameter()`.
Here is a code example: Here is a code example:
CustomASServiceExecutionOptions options = new CustomASServiceExecutionOptions().withParameter("space_code", "my-space"); ```py
Object result = service.executeCustomASService(sessionToken, new CustomASServiceCode("space-creator"), options); CustomASServiceExecutionOptions options = new CustomASServiceExecutionOptions().withParameter("space_code", "my-space");
System.out.println(result); Object result = service.executeCustomASService(sessionToken, new CustomASServiceCode("space-creator"), options);
System.out.println(result);
```
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment