Search in sources :

Example 1 with BucketItemType

use of org.apache.nifi.registry.bucket.BucketItemType in project nifi-registry by apache.

the class BucketItemDeserializer method deserialize.

@Override
public BucketItem[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final JsonNode arrayNode = jsonParser.getCodec().readTree(jsonParser);
    final List<BucketItem> bucketItems = new ArrayList<>();
    final Iterator<JsonNode> nodeIter = arrayNode.elements();
    while (nodeIter.hasNext()) {
        final JsonNode node = nodeIter.next();
        final String type = node.get("type").asText();
        if (StringUtils.isBlank(type)) {
            throw new IllegalStateException("BucketItem type cannot be null or blank");
        }
        final BucketItemType bucketItemType;
        try {
            bucketItemType = BucketItemType.valueOf(type);
        } catch (Exception e) {
            throw new IllegalStateException("Unknown type for BucketItem: " + type, e);
        }
        switch(bucketItemType) {
            case Flow:
                final VersionedFlow versionedFlow = jsonParser.getCodec().treeToValue(node, VersionedFlow.class);
                bucketItems.add(versionedFlow);
                break;
            default:
                throw new IllegalStateException("Unknown type for BucketItem");
        }
    }
    return bucketItems.toArray(new BucketItem[bucketItems.size()]);
}
Also used : ArrayList(java.util.ArrayList) BucketItemType(org.apache.nifi.registry.bucket.BucketItemType) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) BucketItem(org.apache.nifi.registry.bucket.BucketItem) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BucketItem (org.apache.nifi.registry.bucket.BucketItem)1 BucketItemType (org.apache.nifi.registry.bucket.BucketItemType)1 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)1