Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Issue #1
  • Loading branch information
rsoika committed Mar 25, 2020
1 parent c4aa42a commit 411ddf6
Show file tree
Hide file tree
Showing 5 changed files with 344 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ignore all bin directories
# matches "bin" in any subfolder
bin/

# ignore all target directories
target/

# ignore all files ending with ~
*~

# ignore eclipse directories and project files
.settings/
.project
.classpath
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,90 @@
# imixs-spring

The Imixs-Spring project is a place providing integration examples. Imixs-Workflow is based on Jakarta EE but
Imixs-Workflow Spring Examples


Imixs is based on Jakarta EE and the Microprofile standard. Thanks to its powerful interfaces, Imixs-Workflow can easily be integrated with other platforms. In this project we show integration examples for the Spring Framework. If you have any questions about Imixs-Worklfow and Spring feel free to ask your questions [here]().

## Project Dependencies

To get started with the examples, you need to include Spring MVC in your Maven pom.xml only. See the following example:


<properties>
<org.imixs.workflow.version>5.1.9</org.imixs.workflow.version>
<spring.version>5.2.5.RELEASE</spring.version>
</properties>

<dependencies>
<!-- Imixs Workflow core dependencies -->
<dependency>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-engine</artifactId>
<version>${org.imixs.workflow.version}</version>
</dependency>
<!-- JUnit Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

## JAXB Integration


Since Spring 3, one of the feature of “mvc:annotation-driven“, is the support to convert object to/from XML, if JAXB is in the project classpath. The Imixs-Workflow-Core library already supports XML Root classes for the core data objects. So it is very easy to apply these object classes in a Spring rest service.

See the following example code:

@PostMapping("data")
public ResponseEntity<?> getData(@RequestBody XMLDocument requestXML) {
// consume xml request
ItemCollection requestData = XMLDocumentAdapter.putDocument(requestXML);
// consume data....
@SuppressWarnings("unused")
String param1 = requestData.getItemValue("param1", String.class);


// create response data object
ItemCollection resultData = new ItemCollection();
resultData.setItemValue("_subject", "some data...");

// convert resultData into xml
return ResponseEntity.ok().body(XMLDocumentAdapter.getDocument(resultData));

}


The XMLDocument provided by the Imixs-Workflow XML objects can be adapted into the [ItemCollection](https://www.imixs.org/doc/core/itemcollection.html). class providing a large list of methods to build complex data objects within a business process.



112 changes: 112 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Imixs-Spring</name>
<description>Spring integration examples</description>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Dependency Versions -->
<org.imixs.workflow.version>5.1.0</org.imixs.workflow.version>
<spring.version>5.2.5.RELEASE</spring.version>
</properties>
<organization>
<name>Imixs Software Solutions GmbH</name>
<url>http://www.imixs.com</url>
</organization>
<inceptionYear>2020</inceptionYear>
<developers>
<developer>
<id>rsoika</id>
<name>Ralph Soika</name>
<email>ralph.soika@imixs.com</email>
<url>http://blog.imixs.org/</url>
<organization>Imixs Software Solutions GmbH</organization>
<organizationUrl>http://www.imixs.com</organizationUrl>
<roles>
<role>developer</role>
<role>testing</role>
</roles>
<timezone>2</timezone>
</developer>
</developers>

<licenses>
<license>
<name>GNU General Public License</name>
<url>http://www.gnu.org/licenses/gpl-2.0.txt</url>
<distribution>repo</distribution>
<comments>All the results of the imixs workflow project are subject to the GPL licensing model. </comments>
</license>
</licenses>

<build>
<plugins>
<!-- use JDK 1.8 settings for compiling -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

</plugins>
</build>


<dependencies>
<!-- JEE dependencies -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Imixs Workflow core dependencies -->
<dependency>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-engine</artifactId>
<version>${org.imixs.workflow.version}</version>
</dependency>
<!-- JUnit Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>



<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
91 changes: 91 additions & 0 deletions src/main/java/org/imixs/spring/examples/ControllerExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.imixs.spring.examples;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.xml.XMLDocument;
import org.imixs.workflow.xml.XMLDocumentAdapter;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
* This is an example Spring rest service consuming and producing Imixs XMLDocument Data objects.
*
* @author rsoika
*
*/
@Controller
@RequestMapping("/adapter")
public class ControllerExample {


/**
* GET Example
* <p>
* Creates a new document with the item '_name' and returns a XMLDocument data structure.
*
* @param name
* @return
*/
@RequestMapping(value = "{name}", method = RequestMethod.GET)
public @ResponseBody XMLDocument getExampleInXML(@PathVariable String name) {

ItemCollection document = new ItemCollection();
document.setItemValue("_name", name);

XMLDocument xmlItemCollection = XMLDocumentAdapter.getDocument(document);
return xmlItemCollection;

}

/**
* GET Example
* <p>
* Creates a new document with the item '_name' and returns a XMLDocument data structure.
*
* @param name
* @return
*/
@RequestMapping(value = "{name}", method = RequestMethod.GET)
public ResponseEntity<?> getExampleResponseEntity(@PathVariable String name) {

ItemCollection document = new ItemCollection();
document.setItemValue("_name", name);

// convert resultData into xml
return ResponseEntity.ok().body(XMLDocumentAdapter.getDocument(document));

}


/**
* POST Example
* <p>
* request/response XMLDocument data
*
* @param request
* @return
*/
@PostMapping("data")
public ResponseEntity<?> getData(@RequestBody XMLDocument requestXML) {
// consume xml request
ItemCollection requestData = XMLDocumentAdapter.putDocument(requestXML);
// consume data....
@SuppressWarnings("unused")
String param1 = requestData.getItemValue("param1", String.class);


// create response data object
ItemCollection resultData = new ItemCollection();
resultData.setItemValue("_subject", "some data...");

// convert resultData into xml
return ResponseEntity.ok().body(XMLDocumentAdapter.getDocument(resultData));

}
}
39 changes: 39 additions & 0 deletions src/test/java/org/imixs/spring/TestXMLItemCollectionAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.imixs.spring;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.xml.XMLDocument;
import org.imixs.workflow.xml.XMLDocumentAdapter;
import org.junit.Assert;
import org.junit.Test;

/**
* Test class for xmlItemCollection object
*
* @author rsoika
*
*/
public class TestXMLItemCollectionAdapter {

/**
* Simple test converting an ItemCollection into XML
*/
@Test
public void testItemCollection() {
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("_subject", "Hello");
XMLDocument xmlItemCollection = null;
try {
xmlItemCollection = XMLDocumentAdapter.getDocument(itemCollection);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}

ItemCollection result = XMLDocumentAdapter.putDocument(xmlItemCollection);

Assert.assertEquals(itemCollection.getItemValueString("_subject"), "Hello");

Assert.assertEquals(result.getItemValueString("_subject"), "Hello");
}

}

0 comments on commit 411ddf6

Please sign in to comment.