Merge remote-tracking branch 'origin/master' into anehmer/integration
diff --git a/NOTICE.txt b/NOTICE.txt
index 5de48b2..56281c6 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -16,14 +16,15 @@
 For more information regarding authorship of content, please consult the listed
 source code repository logs.
 
-Copyright (c) 2016-2018 Gigatronik Ingolstadt GmbH
-Copyright (c) 2016-2019 Peak Solution GmbH
+Copyright (c) 2016-2019 Gigatronik Ingolstadt GmbH
+Copyright (c) 2016-2020 Peak Solution GmbH
 Copyright (c) 2017-2018 science + computing AG Tuebingen (ATOS SE)
 Copyright (c) 2017-2018 Canoo Engineering AG
 Copyright (c) 2017 Florian Schmitt
-Copyright (c) 2017-2019 Angelika Wittek
-Copyright (c) 2018 Elektronische Fahrwerksysteme GMBH
-Copyright (c) 2018-2019 Karakun AG
+Copyright (c) 2017-2020 Angelika Wittek
+Copyright (c) 2018-2019 Elektronische Fahrwerksysteme GMBH
+Copyright (c) 2018-2020 Karakun AG
+Copyright (c) 2018-2020 Alexander Nehmer
 
 ## Declared Project Licenses
 
@@ -37,7 +38,7 @@
 
 The project maintains the following source code repositories:
 
-org.eclipse.mdm.api.base.git	      - The openMDM(R) API.
+org.eclipse.mdm.api.base.git	    - The openMDM(R) API.
 org.eclipse.mdm.api.default.git	    - Extension of the openMDM(R) API containing default elements.
 org.eclipse.mdm.api.odsadapter.git	- ODS implementation of persistence adapter.
 org.eclipse.mdm.nucleus.git	        - Core building blocks for the openMDM Business Logic and Web Frontend.
@@ -67,9 +68,6 @@
 commons-text-1.6.jar (1.6)
     * License: Apache License, 2.0
 
-commons-math-2.2.jar (2.2)
-    * License: Apache License, 2.0
-
 gson-2.7.jar (2.7)
     * License: Apache License, 2.0
 
@@ -85,7 +83,7 @@
 hk2-locator-2.5.0-b05.jar(2.5.0-b05)
     * License: CDDL
 
-hk2-utils-2.5.0-b05.jar  (2.5.0-b05)
+hk2-utils-2.5.0-b05.jar (2.5.0-b05)
     * License: CDDL
 
 jackson-annotations-2.9.0.jar  (2.9.0)
@@ -151,6 +149,9 @@
 logback-core-1.2.3.jar(1.2.3)
     * License: Eclipse Public License 1.0
 
+mimepull-1.9.6.jar (1.9.4)
+    * License: CDDL
+
 openatfx-0.7.4.jar (0.7.4)
     * License: Apache-2.0
 
@@ -163,18 +164,30 @@
 protobuf-java-util-3.2.0.jar  (3.2.0)
     * License: New BSD license
 
+swagger-annotations-2.0.8.jar (2.0.8)
+    * License: Apache-2.0
+
+swagger-ui-3.23.0.jar (3.23.0)
+    * License: Apache-2.0
+
 slf4j-api-1.7.25.jar  (1.7.25)
     * License: MIT license
     * Licence Path: https://www.slf4j.org/license.html
     * Project URL: https://github.com/qos-ch/slf4j
     * Source URL:  https://github.com/qos-ch/slf4j/releases/tag/v_1.7.25
 
+stax2-api-3.1.4.jar (3.1.4)
+    * License: BSD-2-Clause
+
 validation-api-1.1.0.Final.jar (1.1.0.Final)
   * License: Apache License, 2.0
 
 vavr-0.9.1-sources.jar (0.9.1)
   * License: Apache License, 2.0
 
+vavr-match-0.9.1.jar (0.9.1)
+  * License: Apache License, 2.0
+
 woodstox-core-asl-4.4.1.jar (4.4.1)
   * License: Apache License, 2.0
 
@@ -288,6 +301,18 @@
     * Project: https://valor-software.com/ngx-bootstrap
     * Source:  https://github.com/valor-software/ngx-bootstrap/tree/v3.1.2
 
+@ngx-translate/core@11.0.1
+    * License: MIT 
+    * Licence Path:   https://github.com/ngx-translate/core/blob/v11.0.1/LICENSE  
+    * Project URL:    http://www.ngx-translate.com/
+    * Source URL:     https://github.com/ngx-translate/core
+
+@ngx-translate/http-loader@4.0.0
+    * License: MIT 
+    * Licence Path:   https://github.com/ngx-translate/http-loader/blob/v4.0.0/LICENSE  
+    * Project URL:    http://www.ngx-translate.com/
+    * Source URL:     https://github.com/ngx-translate/http-loader/tree/v4.0.0
+
 primeicons:1.0.0
     * License: MIT
     * Licence Path: https://github.com/primefaces/primeicons/blob/1.0.0/LICENSE
@@ -300,7 +325,7 @@
     * Project: https://www.primefaces.org/primeng
     * Source:  https://github.com/primefaces/primeng/tree/7.0.1
 
-rxjs@5.1.0
+rxjs@6.3.3
     * License: Apache-2.0
     * Project: https://rxjs-dev.firebaseapp.com/
     * Source:  https://github.com/ReactiveX/rxjs/tree/6.3.3
@@ -310,6 +335,10 @@
     * Project: https://rxjs-dev.firebaseapp.com/
     * Source:  https://github.com/ReactiveX/rxjs/tree/6.3.3/compat
 
+tslib@1.9.0
+    * License: Apache-2.0
+    * Project: https://github.com/Microsoft/tslib
+    * Source:  https://github.com/Microsoft/tslib/tree/1.9.0
 
 zone.js@0.8.26
     * License: MIT
@@ -330,17 +359,12 @@
 * Source: https://www.omg.org/spec/NOT/1.1/PDF
 
 ods530.idl
-Permission of use:
-From Hans-Georg Swolana, Chairman of the Board ASAM e.V.,
- Prof. Dr. Marcus Rieker, Member of the Board ASAM e.V.
 Date: Hoehenkirchen, 06/01/2016
 "The ASAM Board of Directors releases the IDL files for use under the EPL to the Eclipse IWG openMDM.
 This is valid for all versions of ASAM ODS 5.3.x.
 This permission is valid under the conditions of Eclipse will not modify the file."
 
 AvalonEvent.idl, CorbaFileServer.idl
-Permission of use:
-From Dr. Ralph Noerenberg
 Date: 08/15/2016
 "Herewith, we release the generated Client-Source-Code generated from our CORBA IDLs, namely
 * CORBANotification Service (generated from „AvalonEvent.idl”)
diff --git a/build.gradle b/build.gradle
index 69c14af..dd74165 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,7 +14,7 @@
 
 description = 'MDM API - Default Model'
 group = 'org.eclipse.mdm'
-version = '5.1.0M7'
+version = '5.1.0M8'
 
 apply plugin: 'java'
 apply plugin: 'maven'
diff --git a/src/main/java/org/eclipse/mdm/api/dflt/EntityManager.java b/src/main/java/org/eclipse/mdm/api/dflt/EntityManager.java
index 1f42019..2a6b7b0 100644
--- a/src/main/java/org/eclipse/mdm/api/dflt/EntityManager.java
+++ b/src/main/java/org/eclipse/mdm/api/dflt/EntityManager.java
@@ -23,8 +23,12 @@
 import org.eclipse.mdm.api.base.model.ContextType;
 import org.eclipse.mdm.api.base.model.Entity;
 import org.eclipse.mdm.api.base.model.StatusAttachable;
+import org.eclipse.mdm.api.base.model.Test;
+import org.eclipse.mdm.api.base.model.TestStep;
 import org.eclipse.mdm.api.base.query.DataAccessException;
 import org.eclipse.mdm.api.dflt.model.Status;
+import org.eclipse.mdm.api.dflt.model.TemplateTest;
+import org.eclipse.mdm.api.dflt.model.TemplateTestStep;
 import org.eclipse.mdm.api.dflt.model.Versionable;
 
 /**
@@ -144,4 +148,20 @@
 	}
 
 	<T extends StatusAttachable> List<T> loadAll(Class<T> entityClass, Status status, String pattern);
+
+	/**
+	 * Loads the refereced {@link TemplateTest} for a {@link Test}.
+	 * 
+	 * @param test {@link Test} referencing the desired template
+	 * @return {@link Optional} with the loaded {@link TemplateTest}
+	 */
+	Optional<TemplateTest> loadTemplate(Test test);
+
+	/**
+	 * Loads the referenced {@link TemplateTestStep} for a {@link TestStep}
+	 * 
+	 * @param testStep {@link TestStep} referencing the desired template
+	 * @return {@link Optional} with the loaded {@link TemplateTestStep}
+	 */
+	Optional<TemplateTestStep> loadTemplate(TestStep testStep);
 }
diff --git a/src/main/java/org/eclipse/mdm/api/dflt/model/EntityFactory.java b/src/main/java/org/eclipse/mdm/api/dflt/model/EntityFactory.java
index 8960acc..97b43c6 100644
--- a/src/main/java/org/eclipse/mdm/api/dflt/model/EntityFactory.java
+++ b/src/main/java/org/eclipse/mdm/api/dflt/model/EntityFactory.java
@@ -819,6 +819,31 @@
 		return valueListValue;
 	}
 
+	/**
+	 * Creates a new {@link Classification} for given {@link Domain},
+	 * {@link ProjectDomain} and {@link Status}.
+	 * 
+	 * @param domain        The {@link Domain} for the {@link Classification}
+	 * @param projectDomain The {@link ProjectDomain} for the {@link Classification}
+	 * @param status        The {@link Status} for the {@link Classification}
+	 * @return The created {@link Classification} is returned.
+	 */
+	public Classification createClassification(Domain domain, ProjectDomain projectDomain, Status status) {
+		String name = String.format("ProjDomainId_%s.DomainId_%s.StatusId_%s", projectDomain.getID(), domain.getID(),
+				status.getID());
+		return createClassification(name, status, projectDomain, domain);
+	}
+
+	/**
+	 * Creates a new {@link Classification} for given {@link Domain},
+	 * {@link ProjectDomain} and {@link Status}.
+	 * 
+	 * @param name          The name for the {@link Classification}
+	 * @param status        The {@link Status} for the {@link Classification}
+	 * @param projectDomain The {@link ProjectDomain} for the {@link Classification}
+	 * @param domain        The {@link Domain} for the {@link Classification}
+	 * @return The created {@link Classification} is returned.
+	 */
 	public Classification createClassification(String name, Status status, ProjectDomain projectDomain, Domain domain) {
 		Classification classification = new Classification(createCore(Classification.class));
 
@@ -832,6 +857,12 @@
 		return classification;
 	}
 
+	/**
+	 * Creates a new {@link ProjectDomain} with given name.
+	 * 
+	 * @param name Name of the {@link ProjectDomain}
+	 * @return The created {@link ProjectDomain} is returned.
+	 */
 	public ProjectDomain createProjectDomain(String name) {
 		ProjectDomain projectDomain = new ProjectDomain(createCore(ProjectDomain.class));
 		// properties
@@ -839,6 +870,12 @@
 		return projectDomain;
 	}
 
+	/**
+	 * Creates a new {@link Domain} with given name.
+	 * 
+	 * @param name Name of the {@link Domain}
+	 * @return The created {@link Domain} is returned.
+	 */
 	public Domain createDomain(String name) {
 		Domain domain = new Domain(createCore(Domain.class));
 
@@ -884,6 +921,96 @@
 	}
 
 	/**
+	 * Creates a new {@link Test} for given {@link Pool} using given name,
+	 * {@link TemplateTest} and {@link Classification}.
+	 * 
+	 * @param name           Name of the created {@code Test}.
+	 * @param pool           The parent {@code Pool}.
+	 * @param templateTest   The template the returned {@code Test} will be derived
+	 *                       from.
+	 * @param classification The {@link Classification} for the created
+	 *                       {@link Test}.
+	 * @param withTestSteps  If true, {@link TestStep}s are automatically created
+	 *                       based on configured {@link TemplateTestStepUsage}.
+	 * @return The created {@code Test} is returned.
+	 */
+	public Test createTest(String name, Pool pool, TemplateTest templateTest, Classification classification,
+			boolean withTestSteps) {
+		// TODO
+		Test test = createTest(name, pool);
+
+		// relations
+		if (templateTest != null) {
+			getCore(test).getMutableStore().set(templateTest);
+		}
+		getCore(test).getMutableStore().set(classification);
+
+		if (withTestSteps && templateTest != null) {
+			// create default active and mandatory test steps according to the
+			// template
+			templateTest.getTemplateTestStepUsages().stream().filter(TemplateTestStepUsage.IS_IMPLICIT_CREATE)
+					.map(TemplateTestStepUsage::getTemplateTestStep).forEach(templateTestStep -> {
+						createTestStep(test, templateTestStep, classification);
+					});
+		}
+
+		return test;
+	}
+
+	/**
+	 * Creates a new {@link TestStep} for given {@link Test} using given
+	 * {@link TemplateTestStep} and {@link Classification}.
+	 * 
+	 * @param test             The parent {@code Test}.
+	 * @param templateTestStep The template the returned {@code TestStep} will be
+	 *                         derived from.
+	 * @param classification   The {@link Classification} for the created
+	 *                         {@link TestStep}.
+	 * @return The created {@code TestStep} is returned.
+	 */
+	public TestStep createTestStep(Test test, TemplateTestStep templateTestStep, Classification classification) {
+		TestStep testStep = createTestStep(test, templateTestStep);
+		getCore(testStep).getMutableStore().set(classification);
+		return testStep;
+	}
+
+	/**
+	 * Creates a new {@link TestStep} for given {@link Test} using given
+	 * {@link TemplateTestStep} and {@link Classification}.
+	 * 
+	 * @param name           Name of the created {@code TestStep}.
+	 * @param test           The parent {@code Test}.
+	 * @param classification The {@link Classification} for the created
+	 *                       {@link TestStep}.
+	 * @return The created {@code TestStep} is returned.
+	 */
+	public TestStep createTestStep(String name, Test test, Classification classification) {
+		TestStep testStep = createTestStep(name, test);
+		getCore(testStep).getMutableStore().set(classification);
+		return testStep;
+	}
+
+	/**
+	 * Creates a new {@link TestStep} for given {@link Test} using given name,
+	 * {@link TemplateTestStep} and {@link Classification}.
+	 * 
+	 * @param name             Name of the created {@code TestStep}.
+	 * @param test             The parent {@code Test}.
+	 * @param templateTestStep The template the returned {@code TestStep} will be
+	 *                         derived from.
+	 * @param classification   The {@link Classification} for the created
+	 *                         {@link TestStep}.
+	 * @return The created {@code TestStep} is returned.
+	 */
+	public TestStep createTestStep(String name, Test test, TemplateTestStep templateTestStep,
+			Classification classification) {
+		TestStep testStep = createTestStep(test, templateTestStep);
+		getCore(testStep).getMutableStore().set(classification);
+		testStep.setName(name);
+		return testStep;
+	}
+
+	/**
 	 * Creates a new {@link Test} for given {@link Pool}.
 	 *
 	 * @param name   Name of the created {@code Test}.
@@ -899,10 +1026,6 @@
 		getCore(test).getPermanentStore().set(pool);
 		getCore(pool).getChildrenStore().add(test);
 
-		if (status != null) {
-			status.assign(test);
-		}
-
 		return test;
 	}
 
diff --git a/src/main/java/org/eclipse/mdm/api/dflt/model/Status.java b/src/main/java/org/eclipse/mdm/api/dflt/model/Status.java
index 387c482..041a156 100644
--- a/src/main/java/org/eclipse/mdm/api/dflt/model/Status.java
+++ b/src/main/java/org/eclipse/mdm/api/dflt/model/Status.java
@@ -23,6 +23,7 @@
 import org.eclipse.mdm.api.base.model.StatusAttachable;
 import org.eclipse.mdm.api.base.model.Test;
 import org.eclipse.mdm.api.base.model.TestStep;
+import org.eclipse.mdm.api.base.query.DataAccessException;
 
 /**
  * Implementation of the status entity type. A status may be attached to
@@ -68,7 +69,12 @@
 	 * @param statusAttachable This status will be assigned to it.
 	 */
 	public <T extends StatusAttachable> void assign(T statusAttachable) {
-		getCore(statusAttachable).getMutableStore().set(this);
+		Classification classification = getCore(statusAttachable).getMutableStore().get(Classification.class);
+		if (classification == null) {
+			throw new DataAccessException("Mandatory element classification not found!");
+		}
+
+		getCore(classification).getMutableStore().set(this);
 	}
 
 	/**