Skip to main content
summaryrefslogtreecommitdiffstats
blob: b2ab8ec78d5cecd0edb6a2c86c009f1bf7f2c59b (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/********************************************************************************
 * 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.time.LocalDateTime;
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 measurement entity type. The measurement entity holds
 * data of a measurement or an analysis. It is the linking point to the
 * following related data:
 *
 * <ul>
 * <li>To ensure any persisted measurement can always be reinterpreted it,
 * always should have relations to {@link ContextRoot}s that contain the
 * description of the test run. All measurement entities under the same parent
 * {@link TestStep} must reference the same {@code
 * 		ContextRoot}.</li>
 * <li>The results of a test run are accessible via the children of type
 * {@link ChannelGroup} and {@link Channel}.</li>
 * </ul>
 *
 * The name of a measurement should be chosen in a speaking way. It has to be
 * unique under the parent {@code TestStep}.
 * <p>
 *
 * @since 1.0.0
 * @author Viktor Stoehr, Gigatronik Ingolstadt GmbH
 * @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
 * @see ParameterSet
 */
public class Measurement extends BaseEntity
		implements ContextDescribable, Datable, Deletable, Describable, FilesAttachable, Tagable, StatusAttachable {

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

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

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

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

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

	/**
	 * The 'MeasurementBegin' attribute name.
	 */
	public static final String ATTR_MEASUREMENT_BEGIN = "MeasurementBegin";

	/**
	 * The 'MeasurementEnd' attribute name.
	 */
	public static final String ATTR_MEASUREMENT_END = "MeasurementEnd";

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

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

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

	/**
	 * Returns the time stamp of the date when this measurement was started.
	 *
	 * @return Measurement execution start time stamp is returned.
	 */
	public LocalDateTime getMeasurementBegin() {
		return getValue(ATTR_MEASUREMENT_BEGIN).extract();
	}

	/**
	 * Sets new time stamp for the date when this measurement was started.
	 *
	 * @param measurementBegin
	 *            The new measurement start time stamp.
	 */
	public void setMeasurementBegin(LocalDateTime measurementBegin) {
		getValue(ATTR_MEASUREMENT_BEGIN).set(measurementBegin);
	}

	/**
	 * Returns the time stamp of the date when this measurement was finished.
	 *
	 * @return Measurement execution end time stamp is returned.
	 */
	public LocalDateTime getMeasurementEnd() {
		return getValue(ATTR_MEASUREMENT_END).extract();
	}

	/**
	 * Sets new time stamp for the date when this measurement was finished.
	 *
	 * @param measurementEnd
	 *            The new measurement execution end time stamp.
	 */
	public void setMeasurementEnd(LocalDateTime measurementEnd) {
		getValue(ATTR_MEASUREMENT_END).set(measurementEnd);
	}
	
	/**
	 * {@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