Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Introduction

JS7 offers a number of JS7 - Job TypesClasses including JS7 - Shell JobsJS7 - JavaScript Jobs and Java Jobs.

...

A Java Job extends the class com.sos.js7.job.Job like this:

Code Block
languagejava
titleExample for implementation of a HelloWorld job with Java
linenumberstrue
import com.sos.js7.job.Job;
import com.sos.js7.job.JobArguments;
import com.sos.js7.job.OrderProcessStep;

public class HelloWorld extends Job<JobArguments> {

	@Override
	public void processOrder(OrderProcessStep<JobArguments> step) throws Exception {
		
		step.getLogger().info("Hello World!");
		
	}

}

...

Code Block
languagejava
titleExample for implementation of a Job with Java
linenumberstrue
import java.util.List;

import com.sos.js7.job.Job;
import com.sos.js7.job.JobArgument;
import com.sos.js7.job.OrderProcessStep;
import com.sos.js7.job.OrderProcessStepOutcome;

public class JobWithParams extends Job<MyJobArguments> {

	@Override
	public void processOrder(OrderProcessStep<MyJobArguments> step) throws Exception {
		
		// reading all arguments with "getAllArgumentsAsNameValueMap"
		step.getAllArgumentsAsNameValueMap().forEach((name, value) -> {
			step.getLogger().info("argument: " + name + "=" + value.toString());
		});
		
		// reading all arguments with "getAllArguments"
		step.getAllArguments().forEach((name, jobArgument) -> {
			step.getLogger().info("argument: " + name + "=" + jobArgument.getValue().toString());
		});
        
        MyJobArguments myArgs = step.getDeclaredArguments();
		
		// reading job-specific argument: myString
		JobArgument<String> myString = myArgs.getMyString();
		step.getLogger().info(myString.getName() + "=" + myString.getValue());
		
		// reading job-specific argument: myBool
		JobArgument<Boolean> myBool = myArgs.getMyBool();
		step.getLogger().info(myBool.getName() + "=" + myBool.getValue());
		
		// reading job-specific argument: myList
		JobArgument<List<String>> myList = myArgs.getMyList();
		step.getLogger().info(myList.getName() + "=" + myList.getValue().toString());
		
		// return values
		OrderProcessStepOutcome outcome = step.getOutcome();
		outcome.putVariable(myString.getName(), "hello world");
		outcome.putVariable("myInteger", 42);
	}

}

...

  • The getAllArgumentsAsNameValueMap() method provides a map of all argument values.
  • The getAllArguments() method provides a map of argument objects.
  • The OrderProcessStep object is here typed by MyJobArguments that is a class with job-specific declared arguments.
    • A class with job specific declared arguments extends com.sos.js7.job.JobArguments 

      Code Block
      languagejava
      titleExample of a class of the job-specific declared arguments
      import java.util.List;
      
      import com.sos.js7.job.JobArgument;
      import com.sos.js7.job.JobArguments;
      
      public class MyJobArguments extends JobArguments {
      	
      	private JobArgument<String> myString = new JobArgument<String>("myString", false);
          private JobArgument<List<String>> myList = new JobArgument<>("myList", false);
          private JobArgument<Boolean> myBool = new JobArgument<>("test", false, true);
      
          public JobArgument<String> getMyString() {
              return myString;
          }
      
          public JobArgument<List<String>> getMyList() {
              return myList;
          }
      
          public JobArgument<Boolean> getMyBool() {
              return myBool;
          }
      }
  • For further methods to access arguments see JS7 - Job API

...

The classes com.sos.js7.job.Job, com.sos.js7.job.JobArguments etc. are not available in a public Maven repository, so a local repository must be created in the Maven project.

  • The directories sos and lib must directory sos has to be created
    Image Removed
    Image Added

  • The lib directory will be the local repository.The following JAR files must following .jar files have to be copied from an agent installation a JS7 Agent installation's ./lib/sos into directory to the sos directory of the Maven project (here at the example . The example makes use of release 2.6.1), users should check for a current release.
    • com.sos-berlin.js7.engine.js7-base-2.6.1<version>.jar
    • com.sos-berlin.js7.engine.js7-data-for-java-2.6<version>.1.jar
    • com.sos-berlin.js7.engine.js7-launcher-for-java-<version>.jar
      • Note: Since release 2.6.
      1.jarsos-commons-exception
      • 4, the three jar files mentioned above have been combined into one jar file
      • com.sos-berlin.js7.engine.js7-engine-2.6.
      1.jar
      • 4
    • sos-commons-utilexception-<version>.jar
    • sos-commons-util-<version>2.6.1.jar
    • sos-js7-job-2<version>.6.1.jar
  • The following pom.xml should file can be used as a base in the Maven project for release < 2.6.4.
Code Block
languagexml
titlepom.xml
collapsetrue
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.sos-berlin</groupId>
	

...

<artifactId>js7jobs</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<!-- release version of js7 jars -->

...

		<sos.js7.version>2.

...

5.

...

5</sos.js7.version>

...

		<!-- 3rd party versions -->

...

		<scala.library.version>2.13.11</scala.library.version>

...

		<slf4j.version>1.7.36</slf4j.version>

...

		<io.vavr.version>0.10.4</io.vavr.version>

...


...

		<!-- groupId and artifactIds of js7 jars -->

...

		<sos.js7.groupId>com.sos-berlin</sos.js7.groupId>

...

		<sos.js7.job.artifactId>sos-js7-job</sos.js7.job.artifactId>

...

		<sos.js7.commons.util.artifactId>sos-commons-util</sos.js7.commons.util.artifactId>

...

		<sos.js7.commons.exception.artifactId>sos-commons-exception</sos.js7.commons.exception.artifactId>

...

		

...

<sos.js7.commons.httpclient.artifactId>sos-commons-httpclient</sos.js7.commons.httpclient.artifactId>

		<sos.js7.engine.groupId>com.sos-berlin.js7.engine</sos.js7.engine.groupId>

...

		<sos.js7.launcher.artifactId>js7-launcher-for-java</sos.js7.launcher.artifactId>

...

		<sos.js7.data-for-java.artifactId>js7-data-for-java</sos.js7.data-for-java.artifactId>

...

		<sos.js7.base.artifactId>js7-base</sos.js7.base.artifactId>

...


...

		<!-- directories with js7 jars to install the local project repository -->

...

		<sos.js7.external.srcdir>${project.basedir}/sos</sos.js7.external.srcdir>

...


	</properties>

...


	<repositories>

		<!-- 

...

public repository for 

...

3rd party jars -->
		<repository>
			

...

<id>central</id>
			

...

<name>Central Repository</name>
			

...

<url>https://

...

repo1.

...

maven.org/maven2</url>
		

...

	<snapshots>
		

...

		<enabled>false</enabled>
				<updatePolicy>never</updatePolicy>
			</snapshots>
		</repository>
	</repositories>

...


	<dependencies>

...

		<dependency>
			<groupId>${sos.js7.engine.groupId}</groupId>
			<artifactId>${sos.js7.launcher.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>${sos.js7.engine.groupId}</groupId>
			<artifactId>${sos.js7.data-for-java.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>${sos.js7.engine.groupId}</groupId>
			<artifactId>${sos.js7.base.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>

...


         <dependency>
            <groupId>${sos.js7.groupId}</groupId>

...

            <artifactId>${sos.js7.job.artifactId}</artifactId>

...

            <version>${sos.js7.version}</version>

...

            <scope>provided</scope>
        </dependency>
		<dependency>
			<groupId>${sos.js7.groupId}</groupId>
			<artifactId>${sos.js7.commons.util.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>${sos.js7.groupId}</groupId>
			<artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>
		
		<!-- Example for a custom dependency -->
		<dependency>
			<groupId>${sos.js7.groupId}</groupId>
			<artifactId>${sos.js7.commons.httpclient.artifactId}</artifactId>
			<version>${sos.js7.version}</version>
			<scope>provided</scope>
		</dependency>

		<!-- 3rd Party -->
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-library</artifactId>
			<version>${scala.library.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>io.vavr</groupId>
			<artifactId>vavr</artifactId>

...

			<version>${io.vavr.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
			<scope>provided</scope>
		</dependency>

	</dependencies>

...


	<profiles>
		<profile>
			<id>create-local-repo</id>
			<build>
				<plugins>
					<plugin>
	

...

					<artifactId>maven-install-plugin</artifactId>
	

...

					<version>3.1.0</version>
						<executions>
							<execution>
								<id>install-${sos.js7.launcher.artifactId}</id>

...

								<goals>
									<goal>install-file</goal>
	

...

							</goals>
	

...

							<phase>initialize</phase>
	

...

							<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.launcher.artifactId}-${sos.js7.version}.jar</file>
	

...

								<groupId>${sos.js7.engine.groupId}</groupId>
									<artifactId>${sos.js7.launcher.artifactId}</artifactId>

...

									<version>${sos.js7.version}</version>

...

									<packaging>jar</packaging>
		

...

							<generatePom>true</generatePom> 
								</configuration>
							</execution>
							<execution>
								<id>install-${sos.js7.data-for-java.artifactId}</id>

...

								<goals>
									<goal>install-file</goal>

...

								</goals>

...

								<phase>initialize</phase>

...

								<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.data-for-java.artifactId}-${sos.js7.version}.jar</file>

...

									<groupId>${sos.js7.engine.groupId}</groupId>
									<artifactId>${sos.js7.data-for-java.artifactId}</artifactId>

...

									<version>${sos.js7.version}</version>
	

...

								<packaging>jar</packaging>
					

...

				<generatePom>true</generatePom> 
								</configuration>
							</execution>
							<execution>
								<id>install-${sos.js7.

...

base.

...

artifactId}</

...

id>
								<goals>
									<goal>install-file</goal>
								</goals>
								<phase>initialize</phase>
								<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.base.artifactId}-${sos.js7.version}.jar</file>
									<groupId>${sos.js7.engine.groupId}</groupId>
									<artifactId>${sos.js7.base.artifactId}</artifactId>
									<version>${sos.js7.version}</version>
									<packaging>jar</packaging>
									<generatePom>true</generatePom> 
								</configuration>
							

...

</

...

execution>

							<execution>
								<id>install-${sos.js7.

...

job.

...

artifactId}</

...

id>

...

								<goals>
									<goal>install-file</goal>
								</goals>
								<phase>initialize</phase>
								<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.job.artifactId}

...

-${sos.js7.version}.jar</file>
									<groupId>${sos.js7.groupId}</groupId>
									<artifactId>${sos.js7.job.artifactId}</artifactId>
									<version>${sos.js7.version}</version>
									<packaging>jar</packaging>
									<generatePom>true</generatePom> 
								</configuration>
							</execution>
							<execution>
								<id>install-${sos.js7.commons.util.artifactId}</id>
								<goals>
									<goal>install-file</goal>
								</goals>
								<phase>initialize</phase>
								<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.commons.util.artifactId}-${sos.js7.version}.jar</file>
	

...

								<groupId>${sos.js7.groupId}</groupId>
									<artifactId>${sos.js7.

...

commons.util.artifactId}</artifactId>

...

									<version>${sos.js7.version}</version>

...

									<packaging>jar</packaging>

...

									<generatePom>true</generatePom> 
								</configuration>
							</execution>

							<execution>
								<id>install-${sos.js7.commons.

...

httpclient.artifactId}</id>

...

								<goals>

...

									<goal>install-file</goal>
	

...

							</goals>
	

...

							<phase>initialize</phase>

...

								<configuration>

...

									<file>${sos.js7.external.srcdir}/${sos.js7.commons.

...

httpclient.artifactId}-${sos.js7.version}.jar</file>
	

...

								<groupId>${sos.js7.groupId}</groupId>
									<artifactId>${sos.js7.commons.

...

httpclient.artifactId}</artifactId>

...

									<version>${sos.js7.version}</version>

...

									<packaging>jar</packaging>								
			

...

						<generatePom>true</generatePom> 
								</configuration>
							</execution>
							<execution>
								<id>install-${sos.js7.

...

commons.exception.

...

artifactId}</

...

id>
								<goals>
									<goal>install-file</goal>
								</goals>
								<phase>initialize</phase>
								<configuration>
									<file>${sos.js7.external.srcdir}/${sos.js7.commons.exception.artifactId}

...

-${sos.js7.version}.jar</file>
									<groupId>${sos.js7.groupId}</groupId>
									<artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
									<version>${sos.js7.version}

...

</

...

version>

...

									<packaging>jar</packaging>
									

...

<localRepositoryPath>${sos.js7.

...

local.

...

repodir}</

...

localRepositoryPath>
									<generatePom>true</generatePom> 
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

...


	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>3.10.1</version>
				

...

This pom.xml contains a profile create-local-repo that must be executed once after copying the jar files. It creates the local repository in the lib directory

	<configuration>
						<source>1.8</source>
						<target>1.8</target>
						<optimize>true</optimize>
						<showDeprecation>true</showDeprecation>
						<showWarnings>true</showWarnings>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>
  • The following pom.xml file can be used as a base in the Maven project for release since 2.6.4.
Code Block
languagexml
titlepom.xml
collapsetrue
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ur</groupId>
    <artifactId>js7</artifactId>
    <version>0.0.1-SNAPSHOT</version>
 
    <properties>
        <!-- release version of js7 jars -->
        <sos.js7.version>2.6.4</sos.js7.version>
        <!-- 3rd party versions -->
        <scala.library.version>2.13.11</scala.library.version>
        <slf4j.version>1.7.36</slf4j.version>
        <io.vavr.version>0.10.4</io.vavr.version>
 
        <!-- groupId and artifactIds of js7 jars -->
        <sos.js7.groupId>com.sos-berlin</sos.js7.groupId>
        <sos.js7.job.artifactId>sos-js7-job</sos.js7.job.artifactId>
        <sos.js7.commons.util.artifactId>sos-commons-util</sos.js7.commons.util.artifactId>
        <sos.js7.commons.exception.artifactId>sos-commons-exception</sos.js7.commons.exception.artifactId>
        <sos.js7.commons.httpclient.artifactId>sos-commons-httpclient</sos.js7.commons.httpclient.artifactId>
 
        <sos.js7.engine.groupId>com.sos-berlin.js7.engine</sos.js7.engine.groupId>
        <sos.js7.js7-engine.artifactId>js7-engine</sos.js7.js7-engine.artifactId>
 
        <!-- directories with js7 jars to install the local project repository -->
        <sos.js7.external.srcdir>${project.basedir}/sos</sos.js7.external.srcdir>
    </properties>
 
    <repositories>
 
        <!-- public repository for 3rd party jars -->
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
 
    <dependencies>
        <dependency>
            <groupId>${sos.js7.engine.groupId}</groupId>
            <artifactId>${sos.js7.js7-engine.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        
 
         <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.job.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.util.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
         
        <!-- Example for a custom dependency -->
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.httpclient.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
 
        <!-- 3rd Party -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.library.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.vavr</groupId>
            <artifactId>vavr</artifactId>
            <version>${io.vavr.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>
 
    </dependencies>
 
    <profiles>
        <profile>
            <id>create-local-repo</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>install-${sos.js7.js7-engine.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.js7-engine.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.engine.groupId}</groupId>
                                    <artifactId>${sos.js7.js7-engine.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                             
                           
 
                            <execution>
                                <id>install-${sos.js7.job.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.job.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.job.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.commons.util.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.util.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.util.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
 
                            <execution>
                                <id>install-${sos.js7.commons.httpclient.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.httpclient.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.httpclient.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>                             
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.commons.exception.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.exception.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <localRepositoryPath>${sos.js7.local.repodir}</localRepositoryPath>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
 
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <optimize>true</optimize>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>



  • groupId, artifactId and version should be adjusted.
  • The pom.xml file contains a profile create-local-repo that must be executed once after copying the jar files. It updates the users local .m2 repository with the jars from the sos folder. The dependencies to the .jar files are in scope provided as these jars are needed at compile time, but are already present in the agent environment.

    Code Block
    languagepowershell
    > mvn initialize -Pcreate-local-repo -U

Activating JUnit Tests and Debugging for JS7 Java Jobs

  • The following .jar files have to be copied additionally from a JS7 Agent installation ./lib/sos directory to the sos directory of the Maven project. The additional .jar files are required in scope test for use with full debugging. The example makes use of release 2.6.1, users should check for a current release.
    • com.sos-berlin.js7.engine.js7-data-<version>.jar
    • sos-js7-job-<version>.jar
    • sos-commons-hibernate-<version>.jar
    • sos-commons-sign-<version>.jar
    • sos-commons-vfs-<version>.jar

Rerun the profile create-local-repo to copy the .jar files to the local Maven .m2 repository. 


Code Block
languagepowershell
> mvn initialize -Pcreate-local-repo -U


The following pom.xml file can be used as a base in the Maven project for JUnit tests and debugging thereof.

Code Block
languagexml
titlePOM with JUNIT test and debugging JS7 Jobs
collapsetrue
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sos-berlin</groupId>
    <artifactId>js7jobs</artifactId>
    <version>0.0.1-SNAPSHOT</version>
 
    <properties>
        <!-- release version of js7 jars -->
        <sos.js7.version>2.6.1</sos.js7.version>
        <!-- 3rd party versions -->
        <scala.library.version>2.13.11</scala.library.version>
        <slf4j.version>1.7.36</slf4j.version>
        <io.vavr.version>0.10.4</io.vavr.version>
        <!-- JS7 3rd party test versions -->
        <javax.json.version>1.0.2</javax.json.version>
        <log4j.version>2.20.0</log4j.version>
        <junit.version>4.8.2</junit.version>
        <sourcecode.version>0.3.0</sourcecode.version>
        <circe.version>0.14.3</circe.version>
        <jackson.databind.version>2.14.2</jackson.databind.version>
        
        <!-- JS7 3rd party SOSApiRestclient versions --> 
        <!--
        <httpclient.version>4.5.13</httpclient.version>
        <httpcore.version>4.4.16</httpcore.version>
        <jakarta.api.version>3.0.0</jakarta.api.version>
        -->

        <!-- groupId and artifactIds of js7 jars -->
        <sos.js7.groupId>com.sos-berlin</sos.js7.groupId>
        <sos.js7.job.artifactId>sos-js7-job</sos.js7.job.artifactId>
        <sos.js7.commons.util.artifactId>sos-commons-util</sos.js7.commons.util.artifactId>
        <sos.js7.commons.exception.artifactId>sos-commons-exception</sos.js7.commons.exception.artifactId>
        <sos.js7.commons.httpclient.artifactId>sos-commons-httpclient</sos.js7.commons.httpclient.artifactId>
 
        <sos.js7.engine.groupId>com.sos-berlin.js7.engine</sos.js7.engine.groupId>
        <sos.js7.launcher.artifactId>js7-launcher-for-java</sos.js7.launcher.artifactId>
        <sos.js7.data-for-java.artifactId>js7-data-for-java</sos.js7.data-for-java.artifactId>
        <sos.js7.base.artifactId>js7-base</sos.js7.base.artifactId>
        <!-- sos jars for tests -->
        <sos.js7.commons.hibernate.artifactId>sos-commons-hibernate</sos.js7.commons.hibernate.artifactId>
        <sos.js7.commons.vfs.artifactId>sos-commons-vfs</sos.js7.commons.vfs.artifactId>
        <sos.js7.commons.sign.artifactId>sos-commons-sign</sos.js7.commons.sign.artifactId>
        <sos.js7.data.artifactId>js7-data</sos.js7.data.artifactId>
          
        <!-- directories with js7 jars to install the local project repository -->
        <sos.js7.external.srcdir>${project.basedir}/sos</sos.js7.external.srcdir>
    </properties>
 
    <repositories>
 
        <!-- public repository for 3rd party jars -->
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
 
    <dependencies>
        <!-- SOS dependencies -->
        <dependency>
            <groupId>${sos.js7.engine.groupId}</groupId>
            <artifactId>${sos.js7.launcher.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.engine.groupId}</groupId>
            <artifactId>${sos.js7.data-for-java.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.engine.groupId}</groupId>
            <artifactId>${sos.js7.base.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.job.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.util.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
         
        <!-- Example for a custom dependency -->
        <!--
          <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.httpclient.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>provided</scope>
        </dependency>
        
        
        -->
 
        <!-- SOS test dependencies -->
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.hibernate.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.vfs.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.groupId}</groupId>
            <artifactId>${sos.js7.commons.sign.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${sos.js7.engine.groupId}</groupId>
            <artifactId>${sos.js7.data.artifactId}</artifactId>
            <version>${sos.js7.version}</version>
            <scope>test</scope>
        </dependency>
                 
        <!-- 3rd Party -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.library.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.vavr</groupId>
            <artifactId>vavr</artifactId>
            <version>${io.vavr.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>
         
        <!-- 3rd party test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.circe</groupId>
            <artifactId>circe-core_2.13</artifactId>
            <version>${circe.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.circe</groupId>
            <artifactId>circe-generic_2.13</artifactId>
            <version>${circe.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.lihaoyi</groupId>
            <artifactId>sourcecode_2.13</artifactId>
            <version>${sourcecode.version}</version>
            <scope>test</scope>
        </dependency>
  		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
            <version>${jackson.databind.version}</version>
            <scope>test</scope>
		</dependency>        
		
        <!-- JS7 3rd party SOSApiRestclient dependencies --> 
        <!--
  		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
            <scope>test</scope>
		</dependency>        
  		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
            <version>${httpcore.version}</version>
            <scope>test</scope>
		</dependency>        
  		<dependency>
			<groupId>jakarta.ws.rs</groupId>
			<artifactId>jakarta.ws.rs-api</artifactId>
            <version>${jakarta.api.version}</version>
            <scope>test</scope>
		</dependency>     
		-->   
    </dependencies>
 
    <profiles>
        <profile>
            <id>create-local-repo</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>install-${sos.js7.launcher.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.launcher.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.engine.groupId}</groupId>
                                    <artifactId>${sos.js7.launcher.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.data-for-java.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.data-for-java.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.engine.groupId}</groupId>
                                    <artifactId>${sos.js7.data-for-java.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.base.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.engine.groupId}.${sos.js7.base.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.engine.groupId}</groupId>
                                    <artifactId>${sos.js7.base.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
 
                            <execution>
                                <id>install-${sos.js7.job.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.job.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.job.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.commons.util.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.util.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.util.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
 
                            <!-- JS7 copy Jar for SOSApiRestclient --> 
                            <!--

                            <execution>
                                <id>install-${sos.js7.commons.httpclient.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.httpclient.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.httpclient.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>                             
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            -->
                            <execution>
                                <id>install-${sos.js7.commons.exception.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.exception.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.exception.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <localRepositoryPath>${sos.js7.local.repodir}</localRepositoryPath>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
 
                            <!-- SOS Jars for testing-->
                            <execution>
                                <id>install-${sos.js7.commons.hibernate.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.hibernate.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.hibernate.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <localRepositoryPath>${sos.js7.local.repodir}</localRepositoryPath>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.commons.sign.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.sign.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.sign.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <localRepositoryPath>${sos.js7.local.repodir}</localRepositoryPath>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-${sos.js7.commons.vfs.artifactId}</id>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <file>${sos.js7.external.srcdir}/${sos.js7.commons.vfs.artifactId}-${sos.js7.version}.jar</file>
                                    <groupId>${sos.js7.groupId}</groupId>
                                    <artifactId>${sos.js7.commons.vfs.artifactId}</artifactId>
                                    <version>${sos.js7.version}</version>
                                    <packaging>jar</packaging>
                                    <localRepositoryPath>${sos.js7.local.repodir}</localRepositoryPath>
									<generatePom>true</generatePom> 
                                </configuration>
                            </execution>
 
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
 
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <optimize>true</optimize>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>


Creating a JUnit Test for a JS7 Java job

Thie is an example for a JUnit test class for the JS7 Java job MyJavaJob. 

Code Block
languagejava
titleJUnit Test for JS7 Java Jobs
collapsetrue
package com.sos_berlin.js7jobs;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sos.js7.job.UnitTestJobHelper;
import com.sos.js7jobs.MyJobArguments;
import com.sos.js7jobs.MyJavaJob;

import js7.data_for_java.order.JOutcome;

public class MyJavaJobTest { 
      private static final Logger LOGGER = LoggerFactory.getLogger(MyJavaJobTest.class);

 	    @Test
	    public void test() throws Exception {
	        Map<String, Object> args = new HashMap<>();
	        args.put("myString", "value 1");
	        args.put("test", true);

	        UnitTestJobHelper<MyJobArguments> h = new UnitTestJobHelper<>(new MyJavaJob());
 	        JOutcome.Completed result = h.processOrder(args);
 	        LOGGER.info(String.format("[RESULT]%s", result));
	    }

}

Logging in JUnit Tests

  • Create the folder src/test/resources
  • Add a log4j.xml configuration file to the folder 


Code Block
languagexml
titleExample for a log4j.xml configuration file
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
	<Appenders>
		<!-- Appender for root logger -->
		<Console name="stdout" target="SYSTEM_OUT">
			<PatternLayout pattern="%d{ISO8601}{Europe/Berlin} %-5p %-16.16t %-44.70c{1.} - %m%n"/>
		</Console>
	</Appenders>

	<Loggers>
		<!-- General Loggers - set the following loggers to 'debug' to debug the JOC Cockpit -->
    <Logger name="js7.base.io.https.Https" level="warn"/>
		<Logger name="com.sos" level="debug"/>
		<Logger name="org.hibernate.SQL" level="error"/>

		<!-- root logger with console appender. All other loggers inherit from this logger. -->
		<Root level="info">
			<AppenderRef ref="stdout"/>
		</Root>
	</Loggers>
</Configuration>

Adding other sos-berlin .jar files to the repository

There are two ways to install files with the maven-install-plugin to the local .m2 maven repository that are not available in public maven repositories. Please use one of these methods. 

  • Using the pom.xml file
    • this is the recommended way, if the build configuration of the JS7 Java Job has to be portable and should be executed on different environments, for example in shared development.
  • Using  command line
    • For example for testing purposes on a local machine.
    • Note
      This should only be used, if a single developer wants to add a dependency quickly in his own local environment. As this is executed locally this is not portable and other developers have to do the same again.

Using the pom.xml file

Add an execution element to the pom.xml file for each .jar file that has to be added. Adjust the values for file, version and artifactId:

Code Block
languagexml
<execution>
	    <id>install-${sos.js7.commons.exception.artifactId}</id>
	    <goals>
	         <goal>install-file</goal>
	    </goals>
	    <phase>initialize</phase>
	    <configuration>
	        <file>[filePath]</file>
	        <groupId>${sos.js7.groupId}</groupId>
			<artifactId>[artefactId]</artifactId>
	        <version>${sos.js7.version}</version>
	        <packaging>jar</packaging>
	        <createChecksum>true</createChecksum>
	   </configuration>
</execution>


Using  the Command Line

Open a command shell and call:

Code Block
languagebash
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

Example:

Code Block
languagebash
titleExample: Based on the custom dependency example
mvn install:install-file -Dfile=/sos/sos-commons-httpclient-2.6.1.jar -DgroupId=com.sos-berlin -DartifactId=sos-commons-httpclient -Dversion=2.6.1 -Dpackaging=jar

...

languagepowershell

...

Further Resources

Features

Articles

Display children header

...