Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9f4291510474a05311eafe787a7187577e5cde0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/********************************************************************************
 * Copyright (c) 2015-2018 Contributors to the Eclipse Foundation
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 ********************************************************************************/


package org.eclipse.mdm.api.base.model;

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

import org.eclipse.mdm.api.base.BaseEntityManager;
import org.eclipse.mdm.api.base.adapter.Core;
import org.eclipse.mdm.api.base.query.DataAccessException;

/**
 * Implementation of the test step entity type. A test step is an atomic
 * measurement task as part of a {@link Test}. The boundary conditions do not
 * change within a single test step, therefore every ordered test step has to be
 * fully described. It may have relations to {@link ContextRoot}s, which contain
 * the describing order data. Test steps may have a sort order in the context of
 * their parent {@code Test}, indicating the desired execution order. The name
 * of a test step should be chosen in a speaking way, because it is often used
 * in different contexts, e.g. as a link between the measurement data from the
 * device and the order in the database. Furthermore the name has to be unique
 * under the parent {@code Test}. Children of a test step are
 * {@link Measurement}s.
 *
 * @since 1.0.0
 * @author Viktor Stoehr, Gigatronik Ingolstadt GmbH
 * @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
 */
public class TestStep extends BaseEntity implements ContextDescribable, Datable, Deletable, Describable,
		FilesAttachable, Sortable, StatusAttachable, Tagable {

	// ======================================================================
	// Class variables
	// ======================================================================

	/**
	 * The {@link Test} parent type.
	 */
	public static final Class<Test> PARENT_TYPE_TEST = Test.class;

	/**
	 * The {@link Measurement} child type.
	 */
	public static final Class<Measurement> CHILD_TYPE_MEASUREMENT = Measurement.class;

	/**
	 * The 'Optional' attribute name.
	 */
	public static final String ATTR_OPTIONAL = "Optional";

	// ======================================================================
	// Constructors
	// ======================================================================

	/**
	 * Constructor.
	 *
	 * @param core
	 *            The {@link Core}.
	 */
	TestStep(Core core) {
		super(core);
	}

	// ======================================================================
	// Public methods
	// ======================================================================

	/**
	 * Returns the optional flag of this test step.
	 *
	 * @return Returns the optional flag.
	 */
	public Boolean isOptional() {
		return getValue(ATTR_OPTIONAL).extract();
	}

	/**
	 * Sets new optional flag for this test step.
	 *
	 * @param optional
	 *            The new optional flag.
	 */
	public void setOptional(Boolean optional) {
		getValue(ATTR_OPTIONAL).set(optional);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<ContextType> loadContextTypes(BaseEntityManager manager)
			throws DataAccessException {
		return manager.loadContextTypes(this);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Map<ContextType, ContextRoot> loadContexts(BaseEntityManager manager,
			ContextType... contextTypes) throws DataAccessException {
		
		Map<ContextType, ContextRoot> map = new HashMap<>();
		
		for (ContextType contextType : contextTypes) {
			ContextRoot c = getCore().getMutableStore().get(ContextRoot.class, contextType);
			if (c != null) {
				map.put(contextType, c);
			}
		}
		if (map.isEmpty()) {
			return manager.loadContexts(this, contextTypes);
		} else {
			return map;
		}
	}

}

Back to the top