1 package de.dlr.shepard.data.timeseries.utilities;
2
3 import de.dlr.shepard.common.exceptions.InvalidBodyException;
4 import de.dlr.shepard.data.timeseries.model.Timeseries;
5
6 public class TimeseriesValidator {
7
8 private static String forbiddenCharsRegEx = ".*[ .,/].*";
9 private static String errorStringFormat =
10 "%s is not allowed to be empty or contain one of those characters: 'Space, Comma, Point, Slash'";
11
12 public static void assertTimeseriesPropertiesAreValid(Timeseries timeseries) {
13 validateString(timeseries.getDevice(), "device");
14 validateString(timeseries.getField(), "field");
15 validateString(timeseries.getLocation(), "location");
16 validateString(timeseries.getMeasurement(), "measurement");
17 validateString(timeseries.getSymbolicName(), "symbolicName");
18 }
19
20 private static void validateString(String input, String fieldName) {
21 if (input == null || input.isEmpty() || input.matches(forbiddenCharsRegEx)) throw new InvalidBodyException(
22 errorStringFormat,
23 fieldName
24 );
25 }
26 }