Search in sources :

Example 11 with JsonCreator

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);
}
Also used : Matcher(java.util.regex.Matcher) TimeUnit(java.util.concurrent.TimeUnit) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 12 with JsonCreator

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();
}
Also used : Duration(org.joda.time.Duration) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 13 with JsonCreator

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);
}
Also used : DateTime(org.joda.time.DateTime) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 14 with JsonCreator

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;
}
Also used : Pattern(java.util.regex.Pattern) PatternSyntaxException(java.util.regex.PatternSyntaxException) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 15 with JsonCreator

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);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Aggregations

JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)15 Matcher (java.util.regex.Matcher)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Block (com.facebook.presto.common.block.Block)1 Type (com.facebook.presto.common.type.Type)1 Block (com.facebook.presto.spi.block.Block)1 Type (com.facebook.presto.spi.type.Type)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonSetter (com.fasterxml.jackson.annotation.JsonSetter)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPOJOBuilder (com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1 DataInput (java.io.DataInput)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1