use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.
the class Value method parseHeaderInformation.
static void parseHeaderInformation(CharSequence text, String type, CSVHeaderInformation info) {
Matcher mapMatcher = MAP_PATTERN.matcher(text);
String errorMessage = format("Failed to parse %s value: '%s'", type, text);
if (!(mapMatcher.find() && mapMatcher.groupCount() == 1)) {
throw new InvalidArgumentException(errorMessage);
}
String mapContents = mapMatcher.group(1);
if (mapContents.isEmpty()) {
throw new InvalidArgumentException(errorMessage);
}
Matcher matcher = KEY_VALUE_PATTERN.matcher(mapContents);
if (!(matcher.find())) {
throw new InvalidArgumentException(errorMessage);
}
do {
String key = matcher.group("k");
if (key != null) {
String value = matcher.group("v");
if (value != null) {
info.assign(key, value);
}
}
} while (matcher.find());
}
use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.
the class DurationValueTest method assertConstructorThrows.
private static void assertConstructorThrows(long months, long days, long seconds, long nanos) {
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> duration(months, days, seconds, nanos));
assertThat(e.getMessage()).contains("Invalid value for duration").contains("months=" + months).contains("days=" + days).contains("seconds=" + seconds).contains("nanos=" + nanos);
}
use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.
the class UserSerialization method deserializeCredentials.
private static Credential deserializeCredentials(String part, int lineNumber) throws FormatException {
String[] split = part.split(CREDENTIAL_SEPARATOR, -1);
String algorithm = split[0];
int iterations;
String hasherVersion;
if (split.length == 4) {
iterations = Integer.parseInt(split[3]);
} else if (split.length == 3) {
iterations = LegacyCredential.ITERATIONS;
} else {
throw new FormatException(format("wrong number of credential fields [line %d]", lineNumber));
}
try {
hasherVersion = SecureHasherConfigurations.getVersionForConfiguration(algorithm, iterations);
} catch (InvalidArgumentException e) {
throw new FormatException(format("unknown digest \"%s\" [line %d]:", part, lineNumber));
}
if (hasherVersion.equals("0")) {
byte[] decodedPassword = HexString.decodeHexString(split[1]);
byte[] decodedSalt = HexString.decodeHexString(split[2]);
return new LegacyCredential(decodedSalt, decodedPassword);
} else {
return SystemGraphCredential.deserialize(part, new SecureHasher(hasherVersion));
}
}
use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.
the class TimeValue method builder.
private static TimeBuilder<TimeValue> builder(Supplier<ZoneId> defaultZone) {
return new TimeBuilder<>(defaultZone) {
@Override
protected boolean supportsTimeZone() {
return true;
}
@Override
public TimeValue buildInternal() {
boolean selectingTime = fields.containsKey(TemporalFields.time);
boolean selectingTimeZone;
OffsetTime result;
if (selectingTime) {
AnyValue time = fields.get(TemporalFields.time);
if (!(time instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct time from: %s", time));
}
TemporalValue t = (TemporalValue) time;
result = t.getTimePart(defaultZone);
selectingTimeZone = t.supportsTimeZone();
} else {
ZoneId timezone = timezone();
if (!(timezone instanceof ZoneOffset)) {
timezone = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
}
result = defaultTime(timezone);
selectingTimeZone = false;
}
result = assignAllFields(result);
if (timezone != null) {
ZoneOffset currentOffset = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
if (selectingTime && selectingTimeZone) {
result = result.withOffsetSameInstant(currentOffset);
} else {
result = result.withOffsetSameLocal(currentOffset);
}
}
return time(result);
}
@Override
protected TimeValue selectTime(AnyValue temporal) {
if (!(temporal instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct time from: %s", temporal));
}
if (temporal instanceof TimeValue && timezone == null) {
return (TimeValue) temporal;
}
TemporalValue v = (TemporalValue) temporal;
OffsetTime time = v.getTimePart(defaultZone);
if (timezone != null) {
ZoneOffset currentOffset = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
time = time.withOffsetSameInstant(currentOffset);
}
return time(time);
}
};
}
use of org.neo4j.exceptions.InvalidArgumentException in project neo4j by neo4j.
the class DateValueTest method shouldEnforceStrictWeekRanges.
@Test
void shouldEnforceStrictWeekRanges() {
LocalDate localDate = weekDate(2017, 52, 7).temporal();
assertEquals(DayOfWeek.SUNDAY, localDate.getDayOfWeek(), "Sunday is the seventh day of the week.");
assertEquals(52, localDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
assertEquals(localDate, date(2017, 12, 31).temporal());
InvalidArgumentException expected = assertThrows(InvalidArgumentException.class, () -> weekDate(2017, 53, 1), "2017 does not have 53 weeks.");
assertEquals("Year 2017 does not contain 53 weeks.", expected.getMessage());
assertEquals(date(2016, 1, 1), weekDate(2015, 53, 5));
}
Aggregations