Skip to content

Package: JobStepServiceImpl

JobStepServiceImpl

nameinstructionbranchcomplexitylinemethod
JobStepServiceImpl()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
count(KapuaQuery)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
create(JobStepCreator)
M: 255 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 44 C: 0
0%
M: 1 C: 0
0%
delete(KapuaId, KapuaId)
M: 58 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
find(KapuaId, KapuaId)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
fromString(String, Class)
M: 63 C: 0
0%
M: 20 C: 0
0%
M: 11 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
getJobStepPropertyMaxLength()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$count$4(KapuaQuery, EntityManager)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$create$0(JobStepCreator, EntityManager)
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%
lambda$delete$5(KapuaId, KapuaId, EntityManager)
M: 67 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
lambda$find$2(KapuaId, KapuaId, EntityManager)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$query$3(KapuaQuery, EntityManager)
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%
lambda$update$1(JobStep, EntityManager)
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%
lambda$validateJobStepPropertyValue$6(JobStepProperty)
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%
query(KapuaQuery)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
update(JobStep)
M: 174 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 29 C: 0
0%
M: 1 C: 0
0%
validateJobStepProperties(JobStep)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
validateJobStepProperties(JobStepCreator)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
validateJobStepProperties(List, JobStepDefinition)
M: 80 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
validateJobStepPropertyValue(JobStepProperty, JobStepProperty)
M: 121 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 22 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.service.job.step.internal;
14:
15: import com.google.common.base.Strings;
16: import org.eclipse.kapua.KapuaDuplicateNameException;
17: import org.eclipse.kapua.KapuaEntityNotFoundException;
18: import org.eclipse.kapua.KapuaEntityUniquenessException;
19: import org.eclipse.kapua.KapuaException;
20: import org.eclipse.kapua.KapuaIllegalArgumentException;
21: import org.eclipse.kapua.commons.model.id.KapuaEid;
22: import org.eclipse.kapua.commons.service.internal.AbstractKapuaService;
23: import org.eclipse.kapua.commons.util.ArgumentValidator;
24: import org.eclipse.kapua.commons.util.xml.XmlUtil;
25: import org.eclipse.kapua.locator.KapuaLocator;
26: import org.eclipse.kapua.locator.KapuaProvider;
27: import org.eclipse.kapua.model.domain.Actions;
28: import org.eclipse.kapua.model.id.KapuaId;
29: import org.eclipse.kapua.model.query.KapuaQuery;
30: import org.eclipse.kapua.model.query.SortOrder;
31: import org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator;
32: import org.eclipse.kapua.service.authorization.AuthorizationService;
33: import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
34: import org.eclipse.kapua.service.job.JobDomains;
35: import org.eclipse.kapua.service.job.exception.CannotModifyJobStepsException;
36: import org.eclipse.kapua.service.job.execution.JobExecutionAttributes;
37: import org.eclipse.kapua.service.job.execution.JobExecutionFactory;
38: import org.eclipse.kapua.service.job.execution.JobExecutionQuery;
39: import org.eclipse.kapua.service.job.execution.JobExecutionService;
40: import org.eclipse.kapua.service.job.internal.JobEntityManagerFactory;
41: import org.eclipse.kapua.service.job.internal.settings.JobServiceSettingKeys;
42: import org.eclipse.kapua.service.job.internal.settings.JobServiceSettings;
43: import org.eclipse.kapua.service.job.step.JobStep;
44: import org.eclipse.kapua.service.job.step.JobStepAttributes;
45: import org.eclipse.kapua.service.job.step.JobStepCreator;
46: import org.eclipse.kapua.service.job.step.JobStepIndex;
47: import org.eclipse.kapua.service.job.step.JobStepListResult;
48: import org.eclipse.kapua.service.job.step.JobStepQuery;
49: import org.eclipse.kapua.service.job.step.JobStepService;
50: import org.eclipse.kapua.service.job.step.definition.JobStepDefinition;
51: import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService;
52: import org.eclipse.kapua.service.job.step.definition.JobStepProperty;
53:
54: import javax.xml.bind.DatatypeConverter;
55: import java.util.AbstractMap;
56: import java.util.ArrayList;
57: import java.util.List;
58: import java.util.Map;
59: import java.util.regex.Pattern;
60:
61: /**
62: * {@link JobStepService} implementation
63: *
64: * @since 1.0.0
65: */
66: @KapuaProvider
67: public class JobStepServiceImpl extends AbstractKapuaService implements JobStepService {
68:
69: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
70:
71: private static final AuthorizationService AUTHORIZATION_SERVICE = LOCATOR.getService(AuthorizationService.class);
72: private static final PermissionFactory PERMISSION_FACTORY = LOCATOR.getFactory(PermissionFactory.class);
73:
74: private static final JobExecutionService JOB_EXECUTION_SERVICE = LOCATOR.getService(JobExecutionService.class);
75: private static final JobExecutionFactory JOB_EXECUTION_FACTORY = LOCATOR.getFactory(JobExecutionFactory.class);
76:
77: private static final JobStepDefinitionService JOB_STEP_DEFINITION_SERVICE = LOCATOR.getService(JobStepDefinitionService.class);
78:
79:
80: private final JobServiceSettings jobServiceSettings = JobServiceSettings.getInstance();
81:
82: /**
83: * The maximum length that a {@link JobStepProperty#getPropertyValue()} is allowed to have
84: *
85: * @since 2.0.0
86: */
87: private final int jobStepPropertyValueLengthMax = jobServiceSettings.getInt(JobServiceSettingKeys.JOB_STEP_PROPERTY_VALUE_LENGTH_MAX);
88:
89: public JobStepServiceImpl() {
90: super(JobEntityManagerFactory.getInstance(), null);
91: }
92:
93: @Override
94: public JobStep create(JobStepCreator jobStepCreator) throws KapuaException {
95: //
96: // Argument validation
97: ArgumentValidator.notNull(jobStepCreator, "jobStepCreator");
98: ArgumentValidator.notNull(jobStepCreator.getScopeId(), "jobStepCreator.scopeId");
99: ArgumentValidator.validateEntityName(jobStepCreator.getName(), "jobStepCreator.name");
100: ArgumentValidator.notNull(jobStepCreator.getJobStepDefinitionId(), "jobStepCreator.stepDefinitionId");
101:
102:• for (JobStepProperty jobStepProperty : jobStepCreator.getStepProperties()) {
103:• if (jobStepProperty.getPropertyValue() != null) {
104:• Integer stepPropertyMaxLength = jobStepProperty.getMaxLength() != null ? jobStepProperty.getMaxLength() : jobStepPropertyValueLengthMax;
105: ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepProperty.getMinLength(), stepPropertyMaxLength, "jobStepCreator.stepProperties[]." + jobStepProperty.getName());
106: }
107: }
108:
109:• if (jobStepCreator.getDescription() != null) {
110: ArgumentValidator.numRange(jobStepCreator.getDescription().length(), 0, 8192, "jobStepCreator.description");
111: }
112:
113: //
114: // Check access
115: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.write, jobStepCreator.getScopeId()));
116:
117: //
118: // Check job step definition
119: validateJobStepProperties(jobStepCreator);
120:
121: //
122: // Check duplicate name
123: JobStepQuery query = new JobStepQueryImpl(jobStepCreator.getScopeId());
124: query.setPredicate(
125: query.andPredicate(
126: query.attributePredicate(JobStepAttributes.JOB_ID, jobStepCreator.getJobId()),
127: query.attributePredicate(JobStepAttributes.NAME, jobStepCreator.getName())
128: )
129: );
130:
131:• if (count(query) > 0) {
132: throw new KapuaDuplicateNameException(jobStepCreator.getName());
133: }
134:
135: //
136: // Check Job Executions
137: JobExecutionQuery jobExecutionQuery = JOB_EXECUTION_FACTORY.newQuery(jobStepCreator.getScopeId());
138: jobExecutionQuery.setPredicate(
139: jobExecutionQuery.attributePredicate(JobExecutionAttributes.JOB_ID, jobStepCreator.getJobId())
140: );
141:
142:• if (JOB_EXECUTION_SERVICE.count(jobExecutionQuery) > 0) {
143: throw new CannotModifyJobStepsException(jobStepCreator.getJobId());
144: }
145:
146: //
147: // Check step index
148:• if (jobStepCreator.getStepIndex() == null) {
149: query.setPredicate(query.attributePredicate(JobStepAttributes.JOB_ID, jobStepCreator.getJobId()));
150: query.setSortCriteria(query.fieldSortCriteria(JobStepAttributes.STEP_INDEX, SortOrder.DESCENDING));
151: query.setLimit(1);
152:
153: JobStepListResult jobStepListResult = query(query);
154: JobStep lastJobStep = jobStepListResult.getFirstItem();
155:
156:• jobStepCreator.setStepIndex(lastJobStep != null ? lastJobStep.getStepIndex() + 1 : JobStepIndex.FIRST);
157: } else {
158: query.setPredicate(
159: query.andPredicate(
160: query.attributePredicate(JobStepAttributes.JOB_ID, jobStepCreator.getJobId()),
161: query.attributePredicate(JobStepAttributes.STEP_INDEX, jobStepCreator.getStepIndex())
162: )
163: );
164:
165:• if (count(query) > 0) {
166: List<Map.Entry<String, Object>> uniquesFieldValues = new ArrayList<>();
167:
168: uniquesFieldValues.add(new AbstractMap.SimpleEntry<>(JobStepAttributes.SCOPE_ID, jobStepCreator.getScopeId()));
169: uniquesFieldValues.add(new AbstractMap.SimpleEntry<>(JobStepAttributes.JOB_ID, jobStepCreator.getJobId()));
170: uniquesFieldValues.add(new AbstractMap.SimpleEntry<>(JobStepAttributes.STEP_INDEX, jobStepCreator.getStepIndex()));
171:
172: throw new KapuaEntityUniquenessException(JobStep.TYPE, uniquesFieldValues);
173: }
174: }
175:
176: //
177: // Do create
178: return entityManagerSession.doTransactedAction(em -> JobStepDAO.create(em, jobStepCreator));
179: }
180:
181: @Override
182: public JobStep update(JobStep jobStep) throws KapuaException {
183: //
184: // Argument validation
185: ArgumentValidator.notNull(jobStep, "jobStep");
186: ArgumentValidator.notNull(jobStep.getScopeId(), "jobStep.scopeId");
187: ArgumentValidator.validateEntityName(jobStep.getName(), "jobStep.name");
188: ArgumentValidator.notNull(jobStep.getJobStepDefinitionId(), "jobStep.stepDefinitionId");
189:
190:• for (JobStepProperty jobStepProperty : jobStep.getStepProperties()) {
191:• if (jobStepProperty.getPropertyValue() != null) {
192:• Integer stepPropertyMaxLength = jobStepProperty.getMaxLength() != null ? jobStepProperty.getMaxLength() : jobStepPropertyValueLengthMax;
193: ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepProperty.getMinLength(), stepPropertyMaxLength, "jobStep.stepProperties[]." + jobStepProperty.getName());
194: }
195: }
196:
197:• if (jobStep.getDescription() != null) {
198: ArgumentValidator.numRange(jobStep.getDescription().length(), 0, 8192, "jobStep.description");
199: }
200:
201: //
202: // Check access
203: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.write, jobStep.getScopeId()));
204:
205: //
206: // Check existence
207:• if (find(jobStep.getScopeId(), jobStep.getId()) == null) {
208: throw new KapuaEntityNotFoundException(jobStep.getType(), jobStep.getId());
209: }
210:
211: //
212: // Check job step definition
213: validateJobStepProperties(jobStep);
214:
215: //
216: // Check duplicate name
217: JobStepQuery query = new JobStepQueryImpl(jobStep.getScopeId());
218: query.setPredicate(
219: query.andPredicate(
220: query.attributePredicate(JobStepAttributes.JOB_ID, jobStep.getJobId()),
221: query.attributePredicate(JobStepAttributes.NAME, jobStep.getName()),
222: query.attributePredicate(JobStepAttributes.ENTITY_ID, jobStep.getId(), Operator.NOT_EQUAL)
223: )
224: );
225:
226:• if (count(query) > 0) {
227: throw new KapuaDuplicateNameException(jobStep.getName());
228: }
229:
230: //
231: // Check Job Executions
232: JobExecutionQuery jobExecutionQuery = JOB_EXECUTION_FACTORY.newQuery(jobStep.getScopeId());
233: jobExecutionQuery.setPredicate(
234: jobExecutionQuery.attributePredicate(JobExecutionAttributes.JOB_ID, jobStep.getJobId())
235: );
236:
237:• if (JOB_EXECUTION_SERVICE.count(jobExecutionQuery) > 0) {
238: throw new CannotModifyJobStepsException(jobStep.getJobId());
239: }
240:
241: // Do Update
242: return entityManagerSession.doTransactedAction(em -> JobStepDAO.update(em, jobStep));
243: }
244:
245: @Override
246: public JobStep find(KapuaId scopeId, KapuaId jobStepId) throws KapuaException {
247: //
248: // Argument Validation
249: ArgumentValidator.notNull(scopeId, "scopeId");
250: ArgumentValidator.notNull(jobStepId, "jobStepId");
251:
252: //
253: // Check Access
254: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.write, scopeId));
255:
256: //
257: // Do find
258: return entityManagerSession.doAction(em -> JobStepDAO.find(em, scopeId, jobStepId));
259: }
260:
261: @Override
262: public JobStepListResult query(KapuaQuery query) throws KapuaException {
263: //
264: // Argument Validation
265: ArgumentValidator.notNull(query, "query");
266:
267: //
268: // Check Access
269: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.read, query.getScopeId()));
270:
271: //
272: // Do query
273: return entityManagerSession.doAction(em -> JobStepDAO.query(em, query));
274: }
275:
276: @Override
277: public long count(KapuaQuery query) throws KapuaException {
278: //
279: // Argument Validation
280: ArgumentValidator.notNull(query, "query");
281:
282: //
283: // Check Access
284: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.read, query.getScopeId()));
285:
286: //
287: // Do query
288: return entityManagerSession.doAction(em -> JobStepDAO.count(em, query));
289: }
290:
291: @Override
292: public void delete(KapuaId scopeId, KapuaId jobStepId) throws KapuaException {
293: //
294: // Argument Validation
295: ArgumentValidator.notNull(scopeId, "scopeId");
296: ArgumentValidator.notNull(jobStepId, "jobStepId");
297:
298: //
299: // Check Access
300: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.delete, scopeId));
301:
302: //
303: // Check existence
304: JobStep jobStep = find(scopeId, jobStepId);
305:• if (jobStep == null) {
306: throw new KapuaEntityNotFoundException(JobStep.TYPE, jobStepId);
307: }
308:
309: //
310: // Check Job Executions
311: JobExecutionQuery jobExecutionQuery = JOB_EXECUTION_FACTORY.newQuery(scopeId);
312: jobExecutionQuery.setPredicate(
313: jobExecutionQuery.attributePredicate(JobExecutionAttributes.JOB_ID, jobStep.getJobId())
314: );
315:
316:• if (JOB_EXECUTION_SERVICE.count(jobExecutionQuery) > 0) {
317: throw new CannotModifyJobStepsException(jobStep.getJobId());
318: }
319:
320: //
321: // Do delete
322: entityManagerSession.doTransactedAction(em -> {
323: JobStep deletedJobStep = JobStepDAO.find(em, scopeId, jobStepId);
324:
325: JobStepDAO.delete(em, scopeId, jobStepId);
326:
327: //
328: // Shift following steps of one position in the step index
329: JobStepQuery query = new JobStepQueryImpl(scopeId);
330:
331: query.setPredicate(
332: query.andPredicate(
333: query.attributePredicate(JobStepAttributes.JOB_ID, deletedJobStep.getJobId()),
334: query.attributePredicate(JobStepAttributes.STEP_INDEX, deletedJobStep.getStepIndex(), Operator.GREATER_THAN)
335: )
336: );
337:
338: JobStepListResult followingJobStep = JobStepDAO.query(em, query);
339:
340:• for (JobStep js : followingJobStep.getItems()) {
341: js.setStepIndex(js.getStepIndex() - 1);
342:
343: JobStepDAO.update(em, js);
344: }
345: return deletedJobStep;
346: });
347: }
348:
349: @Override
350: public int getJobStepPropertyMaxLength() throws KapuaException {
351: //
352: // Check access
353: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(JobDomains.JOB_DOMAIN, Actions.read, KapuaId.ANY));
354:
355: //
356: // Return the value
357: return jobStepPropertyValueLengthMax;
358: }
359:
360: //
361: // Private methods
362: private void validateJobStepProperties(JobStepCreator jobStepCreator) throws KapuaException {
363: JobStepDefinition jobStepDefinition = JOB_STEP_DEFINITION_SERVICE.find(KapuaId.ANY, jobStepCreator.getJobStepDefinitionId());
364: ArgumentValidator.notNull(jobStepDefinition, "jobStepCreator.jobStepDefinitionId");
365:
366: try {
367: validateJobStepProperties(jobStepCreator.getStepProperties(), jobStepDefinition);
368: } catch (KapuaIllegalArgumentException kiae) {
369: throw new KapuaIllegalArgumentException("jobStepCreator." + kiae.getArgumentName(), kiae.getArgumentValue());
370: }
371: }
372:
373: private void validateJobStepProperties(JobStep jobStep) throws KapuaException {
374: JobStepDefinition jobStepDefinition = JOB_STEP_DEFINITION_SERVICE.find(KapuaId.ANY, jobStep.getJobStepDefinitionId());
375: ArgumentValidator.notNull(jobStepDefinition, "jobStep.jobStepDefinitionId");
376:
377: try {
378: validateJobStepProperties(jobStep.getStepProperties(), jobStepDefinition);
379: } catch (KapuaIllegalArgumentException kiae) {
380: throw new KapuaIllegalArgumentException("jobStep." + kiae.getArgumentName(), kiae.getArgumentValue());
381: }
382: }
383:
384: private void validateJobStepProperties(List<JobStepProperty> jobStepProperties, JobStepDefinition jobStepDefinition) throws KapuaIllegalArgumentException {
385:
386:• for (JobStepProperty jobStepProperty : jobStepProperties) {
387:• for (JobStepProperty jobStepDefinitionProperty : jobStepDefinition.getStepProperties()) {
388:• if (jobStepProperty.getName().equals(jobStepDefinitionProperty.getName())) {
389:
390:• if (jobStepDefinitionProperty.getRequired()) {
391: ArgumentValidator.notNull(jobStepProperty.getPropertyValue(), "stepProperties[]." + jobStepProperty.getName());
392: }
393:
394: ArgumentValidator.areEqual(jobStepProperty.getPropertyType(), jobStepDefinitionProperty.getPropertyType(), "stepProperties[]." + jobStepProperty.getName());
395: ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepDefinitionProperty.getMinLength(), jobStepDefinitionProperty.getMaxLength(), "stepProperties[]." + jobStepProperty.getName());
396:
397: validateJobStepPropertyValue(jobStepProperty, jobStepDefinitionProperty);
398: }
399: }
400: }
401: }
402:
403: private <C extends Comparable<C>, E extends Enum<E>> void validateJobStepPropertyValue(JobStepProperty jobStepProperty, JobStepProperty jobStepDefinitionProperty) throws KapuaIllegalArgumentException {
404: try {
405: Class<?> jobStepDefinitionPropertyClass = Class.forName(jobStepDefinitionProperty.getPropertyType());
406:
407:• if (Comparable.class.isAssignableFrom(jobStepDefinitionPropertyClass)) {
408: Class<C> jobStepDefinitionPropertyClassComparable = (Class<C>) jobStepDefinitionPropertyClass;
409:
410: C propertyValue = fromString(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClassComparable);
411: C propertyMinValue = fromString(jobStepDefinitionProperty.getMinValue(), jobStepDefinitionPropertyClassComparable);
412: C propertyMaxValue = fromString(jobStepDefinitionProperty.getMaxValue(), jobStepDefinitionPropertyClassComparable);
413:
414: ArgumentValidator.valueRange(propertyValue, propertyMinValue, propertyMaxValue, "stepProperties[]." + jobStepProperty.getName());
415:
416:• if (String.class.equals(jobStepDefinitionPropertyClass) && !Strings.isNullOrEmpty(jobStepDefinitionProperty.getValidationRegex())) {
417: ArgumentValidator.match((String) propertyValue, () -> Pattern.compile(jobStepDefinitionProperty.getValidationRegex()), "stepProperties[]." + jobStepProperty.getName());
418: }
419:• } else if (KapuaId.class.isAssignableFrom(jobStepDefinitionPropertyClass) ||
420: (jobStepDefinitionPropertyClass == byte[].class || jobStepDefinitionPropertyClass == Byte[].class)) {
421: fromString(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClass);
422:• } else if (jobStepDefinitionPropertyClass.isEnum()) {
423: Class<E> jobStepDefinitionPropertyClassEnum = (Class<E>) jobStepDefinitionPropertyClass;
424: Enum.valueOf(jobStepDefinitionPropertyClassEnum, jobStepProperty.getPropertyValue());
425: } else {
426: XmlUtil.unmarshal(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClass);
427: }
428:
429: } catch (KapuaIllegalArgumentException kiae) {
430: throw kiae;
431: } catch (Exception e) {
432: throw new KapuaIllegalArgumentException("stepProperties[]." + jobStepProperty.getName(), jobStepProperty.getPropertyValue());
433: }
434: }
435:
436: public <T, E extends Enum<E>> T fromString(String jobStepPropertyString, Class<T> type) throws Exception {
437: T stepProperty = null;
438:• if (jobStepPropertyString != null) {
439:• if (type == String.class) {
440: stepProperty = (T) jobStepPropertyString;
441:• } else if (type == Integer.class) {
442: stepProperty = (T) Integer.valueOf(jobStepPropertyString);
443:• } else if (type == Long.class) {
444: stepProperty = (T) Long.valueOf(jobStepPropertyString);
445:• } else if (type == Float.class) {
446: stepProperty = (T) Float.valueOf(jobStepPropertyString);
447:• } else if (type == Double.class) {
448: stepProperty = (T) Double.valueOf(jobStepPropertyString);
449:• } else if (type == Boolean.class) {
450: stepProperty = (T) Boolean.valueOf(jobStepPropertyString);
451:• } else if (type == byte[].class || type == Byte[].class) {
452: stepProperty = (T) DatatypeConverter.parseBase64Binary(jobStepPropertyString);
453:• } else if (type == KapuaId.class) {
454: stepProperty = (T) KapuaEid.parseCompactId(jobStepPropertyString);
455: }
456: }
457:
458: return stepProperty;
459: }
460: }