Search in sources :

Example 1 with BucketItemEntity

use of org.apache.nifi.registry.db.entity.BucketItemEntity in project nifi-registry by apache.

the class DatabaseMetadataService method getItemsWithCounts.

private List<BucketItemEntity> getItemsWithCounts(final Iterable<BucketItemEntity> items) {
    final Map<String, Long> snapshotCounts = getFlowSnapshotCounts();
    final List<BucketItemEntity> itemWithCounts = new ArrayList<>();
    for (final BucketItemEntity item : items) {
        if (item.getType() == BucketItemEntityType.FLOW) {
            final Long snapshotCount = snapshotCounts.get(item.getId());
            if (snapshotCount != null) {
                final FlowEntity flowEntity = (FlowEntity) item;
                flowEntity.setSnapshotCount(snapshotCount);
            }
        }
        itemWithCounts.add(item);
    }
    return itemWithCounts;
}
Also used : BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) ArrayList(java.util.ArrayList) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 2 with BucketItemEntity

use of org.apache.nifi.registry.db.entity.BucketItemEntity in project nifi-registry by apache.

the class DatabaseMetadataService method getBucketItems.

@Override
public List<BucketItemEntity> getBucketItems(final Set<String> bucketIds) {
    if (bucketIds == null || bucketIds.isEmpty()) {
        return Collections.emptyList();
    }
    final StringBuilder sqlBuilder = new StringBuilder("SELECT " + "item.id as ID, " + "item.name as NAME, " + "item.description as DESCRIPTION, " + "item.created as CREATED, " + "item.modified as MODIFIED, " + "item.item_type as ITEM_TYPE, " + "b.id as BUCKET_ID, " + "b.name as BUCKET_NAME " + "FROM " + "bucket_item item, bucket b " + "WHERE " + "item.bucket_id = b.id " + "AND " + "item.bucket_id IN (");
    for (int i = 0; i < bucketIds.size(); i++) {
        if (i > 0) {
            sqlBuilder.append(", ");
        }
        sqlBuilder.append("?");
    }
    sqlBuilder.append(")");
    final List<BucketItemEntity> items = jdbcTemplate.query(sqlBuilder.toString(), bucketIds.toArray(), new BucketItemEntityRowMapper());
    return getItemsWithCounts(items);
}
Also used : BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) BucketItemEntityRowMapper(org.apache.nifi.registry.db.mapper.BucketItemEntityRowMapper)

Example 3 with BucketItemEntity

use of org.apache.nifi.registry.db.entity.BucketItemEntity in project nifi-registry by apache.

the class BucketItemEntityRowMapper method mapRow.

@Nullable
@Override
public BucketItemEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    final BucketItemEntityType type = BucketItemEntityType.valueOf(rs.getString("ITEM_TYPE"));
    // Create the appropriate type of sub-class, eventually populate specific data for each type
    final BucketItemEntity item;
    switch(type) {
        case FLOW:
            item = new FlowEntity();
            break;
        default:
            // should never happen
            item = new BucketItemEntity();
            break;
    }
    // populate fields common to all bucket items
    item.setId(rs.getString("ID"));
    item.setName(rs.getString("NAME"));
    item.setDescription(rs.getString("DESCRIPTION"));
    item.setCreated(rs.getTimestamp("CREATED"));
    item.setModified(rs.getTimestamp("MODIFIED"));
    item.setBucketId(rs.getString("BUCKET_ID"));
    item.setBucketName(rs.getString("BUCKET_NAME"));
    item.setType(type);
    return item;
}
Also used : BucketItemEntityType(org.apache.nifi.registry.db.entity.BucketItemEntityType) BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Nullable(org.springframework.lang.Nullable)

Example 4 with BucketItemEntity

use of org.apache.nifi.registry.db.entity.BucketItemEntity in project nifi-registry by apache.

the class TestDatabaseMetadataService method testGetItemsWithCountsFilteredByBuckets.

@Test
public void testGetItemsWithCountsFilteredByBuckets() {
    final List<BucketItemEntity> items = metadataService.getBucketItems(Collections.singleton("1"));
    assertNotNull(items);
    // only 2 items in bucket 1
    assertEquals(2, items.size());
    final BucketItemEntity item1 = items.stream().filter(i -> i.getId().equals("1")).findFirst().orElse(null);
    assertNotNull(item1);
    assertEquals(BucketItemEntityType.FLOW, item1.getType());
    final FlowEntity flowEntity = (FlowEntity) item1;
    assertEquals(3, flowEntity.getSnapshotCount());
    items.stream().forEach(i -> assertNotNull(i.getBucketName()));
}
Also used : BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 5 with BucketItemEntity

use of org.apache.nifi.registry.db.entity.BucketItemEntity in project nifi-registry by apache.

the class TestDatabaseMetadataService method testGetItemsWithCounts.

@Test
public void testGetItemsWithCounts() {
    final List<BucketItemEntity> items = metadataService.getBucketItems(new HashSet<>(Arrays.asList("1", "2")));
    assertNotNull(items);
    // 3 items across all buckets
    assertEquals(3, items.size());
    final BucketItemEntity item1 = items.stream().filter(i -> i.getId().equals("1")).findFirst().orElse(null);
    assertNotNull(item1);
    assertEquals(BucketItemEntityType.FLOW, item1.getType());
    final FlowEntity flowEntity = (FlowEntity) item1;
    assertEquals(3, flowEntity.getSnapshotCount());
    items.stream().forEach(i -> assertNotNull(i.getBucketName()));
}
Also used : BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Aggregations

BucketItemEntity (org.apache.nifi.registry.db.entity.BucketItemEntity)7 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)4 Test (org.junit.Test)3 BucketItemEntityRowMapper (org.apache.nifi.registry.db.mapper.BucketItemEntityRowMapper)2 ArrayList (java.util.ArrayList)1 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)1 BucketItemEntityType (org.apache.nifi.registry.db.entity.BucketItemEntityType)1 Nullable (org.springframework.lang.Nullable)1