use of com.fasterxml.jackson.annotation.JsonCreator in project dropwizard by dropwizard.
the class Duration method parse.
@JsonCreator
public static Duration parse(String duration) {
final Matcher matcher = DURATION_PATTERN.matcher(duration);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid duration: " + duration);
}
final long count = Long.parseLong(matcher.group(1));
final TimeUnit unit = SUFFIXES.get(matcher.group(2));
if (unit == null) {
throw new IllegalArgumentException("Invalid duration: " + duration + ". Wrong time unit");
}
return new Duration(count, unit);
}
use of com.fasterxml.jackson.annotation.JsonCreator in project graylog2-server by Graylog2.
the class IndexSetConfig method create.
@JsonCreator
public static IndexSetConfig create(@Id @ObjectId @JsonProperty("_id") @Nullable String id, @JsonProperty("title") @NotBlank String title, @JsonProperty("description") @Nullable String description, @JsonProperty("writable") @Nullable Boolean isWritable, @JsonProperty(FIELD_REGULAR) @Nullable Boolean isRegular, @JsonProperty(FIELD_INDEX_PREFIX) @Pattern(regexp = INDEX_PREFIX_REGEX) String indexPrefix, @JsonProperty("index_match_pattern") @Nullable String indexMatchPattern, @JsonProperty("index_wildcard") @Nullable String indexWildcard, @JsonProperty("shards") @Min(1) int shards, @JsonProperty("replicas") @Min(0) int replicas, @JsonProperty("rotation_strategy_class") @Nullable String rotationStrategyClass, @JsonProperty("rotation_strategy") @NotNull RotationStrategyConfig rotationStrategy, @JsonProperty("retention_strategy_class") @Nullable String retentionStrategyClass, @JsonProperty("retention_strategy") @NotNull RetentionStrategyConfig retentionStrategy, @JsonProperty(FIELD_CREATION_DATE) @NotNull ZonedDateTime creationDate, @JsonProperty("index_analyzer") @Nullable String indexAnalyzer, @JsonProperty("index_template_name") @Nullable String indexTemplateName, @JsonProperty(FIELD_INDEX_TEMPLATE_TYPE) @Nullable String indexTemplateType, @JsonProperty("index_optimization_max_num_segments") @Nullable Integer maxNumSegments, @JsonProperty("index_optimization_disabled") @Nullable Boolean indexOptimizationDisabled, @JsonProperty("field_type_refresh_interval") @Nullable Duration fieldTypeRefreshInterval) {
final boolean writableValue = isWritable == null ? true : isWritable;
Duration fieldTypeRefreshIntervalValue = fieldTypeRefreshInterval;
if (fieldTypeRefreshIntervalValue == null) {
// No need to periodically refresh the field types for a non-writable index set
fieldTypeRefreshIntervalValue = writableValue ? DEFAULT_FIELD_TYPE_REFRESH_INTERVAL : Duration.ZERO;
}
return AutoValue_IndexSetConfig.builder().id(id).title(title).description(description).isWritable(writableValue).isRegular(isRegular).indexPrefix(indexPrefix).indexMatchPattern(indexMatchPattern).indexWildcard(indexWildcard).shards(shards).replicas(replicas).rotationStrategyClass(rotationStrategyClass).rotationStrategy(rotationStrategy).retentionStrategyClass(retentionStrategyClass).retentionStrategy(retentionStrategy).creationDate(creationDate).indexAnalyzer(isNullOrEmpty(indexAnalyzer) ? "standard" : indexAnalyzer).indexTemplateName(isNullOrEmpty(indexTemplateName) ? indexPrefix + "-template" : indexTemplateName).indexTemplateType(indexTemplateType).indexOptimizationMaxNumSegments(maxNumSegments == null ? 1 : maxNumSegments).indexOptimizationDisabled(indexOptimizationDisabled == null ? false : indexOptimizationDisabled).fieldTypeRefreshInterval(fieldTypeRefreshIntervalValue).build();
}
use of com.fasterxml.jackson.annotation.JsonCreator in project graylog2-server by Graylog2.
the class MongoIndexRange method create.
@JsonCreator
public static MongoIndexRange create(@JsonProperty("_id") @Id @Nullable ObjectId id, @JsonProperty(FIELD_INDEX_NAME) String indexName, @JsonProperty(FIELD_BEGIN) long beginMillis, @JsonProperty(FIELD_END) long endMillis, @JsonProperty(FIELD_CALCULATED_AT) long calculatedAtMillis, @JsonProperty(FIELD_TOOK_MS) int calculationDuration, @JsonProperty(FIELD_STREAM_IDS) @Nullable List<String> streamIds) {
final DateTime begin = new DateTime(beginMillis, DateTimeZone.UTC);
final DateTime end = new DateTime(endMillis, DateTimeZone.UTC);
final DateTime calculatedAt = new DateTime(calculatedAtMillis, DateTimeZone.UTC);
return create(id, indexName, begin, end, calculatedAt, calculationDuration, streamIds);
}
use of com.fasterxml.jackson.annotation.JsonCreator in project graylog2-server by Graylog2.
the class RegexWhitelistEntry method create.
@JsonCreator
public static RegexWhitelistEntry create(@JsonProperty("id") String id, @JsonProperty("title") String title, @JsonProperty("value") String value) {
// compile the pattern early so that we can catch illegal expressions asap
final Pattern pattern;
try {
pattern = Pattern.compile(value, Pattern.DOTALL);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Cannot create whitelist entry for invalid regular expression '" + value + "': " + e.getMessage(), e);
}
final RegexWhitelistEntry whitelistEntry = new AutoValue_RegexWhitelistEntry(id, Type.REGEX, title, value);
whitelistEntry.pattern = pattern;
return whitelistEntry;
}
use of com.fasterxml.jackson.annotation.JsonCreator in project metacat by Netflix.
the class QualifiedName method fromJson.
/**
* Creates the name from the json.
*
* @param node json node
* @return qualified name
*/
@JsonCreator
public static QualifiedName fromJson(@NonNull final JsonNode node) {
final JsonNode catalogNameNode = node.path("catalogName");
if (catalogNameNode.isMissingNode() || catalogNameNode.isNull() || !catalogNameNode.isTextual()) {
// If catalogName is not present try to load from the qualifiedName node instead
final JsonNode nameNode = node.path("qualifiedName");
if (!nameNode.isNull() && nameNode.isTextual()) {
return fromString(nameNode.asText(), false);
} else {
// if neither are available throw an exception
throw new IllegalStateException("Node '" + node + "' is missing catalogName");
}
}
final String catalogName = catalogNameNode.asText();
final JsonNode databaseNameNode = node.path("databaseName");
String databaseName = null;
if (databaseNameNode != null) {
databaseName = databaseNameNode.asText();
}
final JsonNode tableNameNode = node.path("tableName");
String tableName = null;
if (tableNameNode != null) {
tableName = tableNameNode.asText();
}
final JsonNode partitionNameNode = node.path("partitionName");
String partitionName = null;
if (partitionNameNode != null) {
partitionName = partitionNameNode.asText();
}
final JsonNode viewNameNode = node.path("viewName");
String viewName = null;
if (viewNameNode != null) {
viewName = viewNameNode.asText();
}
return new QualifiedName(catalogName, databaseName, tableName, partitionName, viewName);
}
Aggregations