Skip to content

Commit

Permalink
NXP-16433: add nuxeo-automation-scripting module in nuxeo-features re…
Browse files Browse the repository at this point in the history
…pository - temporarily removed from nuxeo-automation-parent pom waiting for java 8 upgrade
  • Loading branch information
Vladimir Pasquier committed Jan 30, 2015
1 parent 9c02447 commit 4c22e55
Show file tree
Hide file tree
Showing 22 changed files with 1,493 additions and 0 deletions.
@@ -0,0 +1,99 @@
## About

This module is a work in progress for allowing to use JavaScript

- as an Automation based DSL to write custom extensions
- to create "Automation chains"

## Motivations

The initial idea comes from the following constations :

- Automation Operations are a good High Level API : people succeed is doing amazing stuffs with it
- Automation Chain control flow is too primitive
- loops are complex
- conditions are complex
- reusing "code segment" forces using several chains and makes maintenability more complex

So, the idea is to use a simple scripting language to manage the control flow and give accees to the Automation API.

## Example :

Here is a example of an Automation Script :

var root = Document.Fetch(null, {
"value": "/"
});

var newDocs = [];
for (var i = 1; i < 10; i++) {

var newDoc = Document.Create(root, {
"type": "File",
"name": "newDoc" + i,
"properties": {
"dc:title": "New Title" + i,
"dc:source": "JavaScript",
"dc:subjects": ["from", "javascript"]
}
});
var lastUUIDDigit = parseInt(newDoc.getId().slice(-1));
if (lastUUIDDigit % 2 == 0) {
newDoc = Document.Update(newDoc, {
"properties": {
"dc:nature": "even"
}
});
} else {
newDoc = Document.Update(newDoc, {
"properties": {
"dc:nature": "odd"
}
});
}
newDocs.push(newDoc);
}

var evenDocs = Document.Query(null, {
"query": "select * from Document where dc:nature='even'"
});

println("Created " + evenDocs.size() + " even Documents");


Here is an exemple of an "Automation Chain" defined via a script


<scriptedOperation id="Scripting.AddFacetInSubTree">
<inputType>Document</inputType>
<outputType>Documents</outputType>
<param name="facet" type="string"/>
<param name="type" type="string"/>

<script><![CDATA[
function run(ctx, input, params) {

var query = "select * from " + params.type + " where ecm:path startswith '";
query = query + input.getPathAsString();
query = query + "'";

//println("query = " + query);
var subDocs = Document.Query(null, {
"query": query
});

//println("Query run with " + subDocs.size() + " result");

var updated = [];
for (var i = 0; i < subDocs.size(); i++) {
var doc = subDocs.get(i);
if (!doc.hasFacet(params.facet)) {
doc.addFacet(params.facet);
updated.push(Document.Save(doc,{}));
}
}
return updated;
}
]]>
</script>
</scriptedOperation>
169 changes: 169 additions & 0 deletions nuxeo-features/nuxeo-automation/nuxeo-automation-scripting/pom.xml
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nuxeo.ecm.automation</groupId>
<artifactId>nuxeo-automation-parent</artifactId>
<version>7.2-SNAPSHOT</version>
</parent>
<artifactId>nuxeo-automation-scripting</artifactId>
<name>nuxeo-automation-scripting</name>
<description>Nuxeo Automation Scripting</description>
<dependencies>
<dependency>
<groupId>org.nuxeo.common</groupId>
<artifactId>nuxeo-common</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.runtime</groupId>
<artifactId>nuxeo-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-core</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.automation</groupId>
<artifactId>nuxeo-automation-core</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.automation</groupId>
<artifactId>nuxeo-automation-features</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-core-api</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-core-query</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-core-schema</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.webengine</groupId>
<artifactId>nuxeo-webengine-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.webengine</groupId>
<artifactId>nuxeo-webengine-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-platform-web-common</artifactId>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-platform-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-platform-login</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-platform-login-default</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-core-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.runtime</groupId>
<artifactId>nuxeo-runtime-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-plugin-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
<onlyWhenRelease>true</onlyWhenRelease>
<excludes>
<exclude>com.googlecode.gmail4j:gmail4j:*</exclude>
</excludes>
</requireReleaseDeps>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>public</id>
<url>http://maven.nuxeo.org/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>public-snapshot</id>
<url>http://maven.nuxeo.org/nexus/content/groups/public-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<scm>
<connection>scm:git:git://github.com/nuxeo/nuxeo/nuxeo-features.git
</connection>
<developerConnection>
scm:git:ssh://git@github.com:nuxeo/nuxeo/nuxeo-features.git
</developerConnection>
<url>https://github.com/nuxeo/nuxeo</url>
</scm>
</project>

0 comments on commit 4c22e55

Please sign in to comment.