Skip to content

Package: StepContextWrapper

StepContextWrapper

nameinstructionbranchcomplexitylinemethod
StepContextWrapper(StepContext)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getBatchStatus()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getException()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getExitStatus()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getKapuaStepName()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getMetrics()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNextStepIndex()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPersistentUserData()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getProperties()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStepExecutionId()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStepIndex()
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getStepName()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStepProperty(String, Class)
M: 107 C: 0
0%
M: 24 C: 0
0%
M: 13 C: 0
0%
M: 32 C: 0
0%
M: 1 C: 0
0%
getTransientUserData()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setExitStatus(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setPersistentUserData(Serializable)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setTransientUserData(Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.job.engine.commons.wrappers;
14:
15: import com.google.common.base.Strings;
16: import org.eclipse.kapua.KapuaIllegalArgumentException;
17: import org.eclipse.kapua.KapuaRuntimeException;
18: import org.eclipse.kapua.commons.util.xml.XmlUtil;
19: import org.eclipse.kapua.locator.KapuaLocator;
20: import org.eclipse.kapua.model.id.KapuaId;
21: import org.eclipse.kapua.model.id.KapuaIdFactory;
22: import org.xml.sax.SAXException;
23:
24: import javax.batch.runtime.BatchStatus;
25: import javax.batch.runtime.Metric;
26: import javax.batch.runtime.context.StepContext;
27: import javax.xml.bind.DatatypeConverter;
28: import javax.xml.bind.JAXBException;
29: import java.io.Serializable;
30: import java.util.Properties;
31:
32: /**
33: * {@link StepContextWrapper} wraps the {@link StepContext} and offers utility methods around it.
34: *
35: * @since 1.0.0
36: */
37: public class StepContextWrapper {
38:
39: private static final KapuaIdFactory KAPUA_ID_FACTORY = KapuaLocator.getInstance().getFactory(KapuaIdFactory.class);
40:
41: private StepContext stepContext;
42:
43: public StepContextWrapper(StepContext stepContext) {
44: this.stepContext = stepContext;
45: }
46:
47: public int getStepIndex() {
48: Properties stepContextProperties = stepContext.getProperties();
49: String stepIndexString = stepContextProperties.getProperty(StepContextPropertyNames.STEP_INDEX);
50:
51:• if (Strings.isNullOrEmpty(stepIndexString)) {
52: throw KapuaRuntimeException.internalError("stepIndexString is not available in the StepContext.properties");
53: }
54:
55: return Integer.parseInt(stepIndexString);
56: }
57:
58: public Integer getNextStepIndex() {
59: Properties jobContextProperties = stepContext.getProperties();
60: String stepNextIndexString = jobContextProperties.getProperty(StepContextPropertyNames.STEP_NEXT_INDEX);
61:• return stepNextIndexString != null ? Integer.parseInt(stepNextIndexString) : null;
62: }
63:
64: public <T, E extends Enum<E>> T getStepProperty(String stepPropertyName, Class<T> type) throws KapuaIllegalArgumentException {
65: Properties jobContextProperties = stepContext.getProperties();
66: String stepPropertyString = jobContextProperties.getProperty(stepPropertyName);
67:
68: T stepProperty;
69:• if (stepPropertyString != null) {
70:• if (type == String.class) {
71: stepProperty = (T) stepPropertyString;
72:• } else if (type == Integer.class) {
73: stepProperty = (T) Integer.valueOf(stepPropertyString);
74:• } else if (type == Long.class) {
75: stepProperty = (T) Long.valueOf(stepPropertyString);
76:• } else if (type == Float.class) {
77: stepProperty = (T) Float.valueOf(stepPropertyString);
78:• } else if (type == Double.class) {
79: stepProperty = (T) Double.valueOf(stepPropertyString);
80:• } else if (type == Boolean.class) {
81: stepProperty = (T) Boolean.valueOf(stepPropertyString);
82:• } else if (type == byte[].class || type == Byte[].class) {
83: stepProperty = (T) DatatypeConverter.parseBase64Binary(stepPropertyString);
84:• } else if (type == KapuaId.class || KapuaId.class.isAssignableFrom(type)) {
85: stepProperty = (T) KAPUA_ID_FACTORY.newKapuaId(stepPropertyString);
86:• } else if (type.isEnum()) {
87: Class<E> enumType = (Class<E>) type;
88:
89: try {
90: stepProperty = (T) Enum.valueOf(enumType, stepPropertyString);
91: } catch (IllegalArgumentException iae) {
92: throw new KapuaIllegalArgumentException(stepPropertyName, stepPropertyString);
93: }
94: } else {
95: try {
96: stepProperty = XmlUtil.unmarshal(stepPropertyString, type);
97: } catch (JAXBException | SAXException e) {
98: throw new KapuaIllegalArgumentException(stepPropertyName, stepPropertyString);
99: }
100: }
101: } else {
102: stepProperty = null;
103: }
104:
105: return stepProperty;
106: }
107:
108: public String getStepName() {
109: return stepContext.getStepName();
110: }
111:
112: public Object getTransientUserData() {
113: return stepContext.getTransientUserData();
114: }
115:
116: public void setTransientUserData(Object data) {
117: stepContext.setTransientUserData(data);
118: }
119:
120: public long getStepExecutionId() {
121: return stepContext.getStepExecutionId();
122: }
123:
124: public Properties getProperties() {
125: return stepContext.getProperties();
126: }
127:
128: public Serializable getPersistentUserData() {
129: return stepContext.getPersistentUserData();
130: }
131:
132: public void setPersistentUserData(Serializable data) {
133: stepContext.setPersistentUserData(data);
134: }
135:
136: public BatchStatus getBatchStatus() {
137: return stepContext.getBatchStatus();
138: }
139:
140: public String getExitStatus() {
141: return stepContext.getExitStatus();
142: }
143:
144: public void setExitStatus(String status) {
145: stepContext.setExitStatus(status);
146: }
147:
148: public Exception getException() {
149: return stepContext.getException();
150: }
151:
152: public Metric[] getMetrics() {
153: return stepContext.getMetrics();
154: }
155:
156: public String getKapuaStepName() {
157: Properties stepContextProperties = stepContext.getProperties();
158: String stepName = stepContextProperties.getProperty(StepContextPropertyNames.STEP_NAME);
159:• if (Strings.isNullOrEmpty(stepName)) {
160: throw KapuaRuntimeException.internalError("stepName is not available in the StepContext.properties");
161: }
162: return stepName;
163: }
164: }