use of org.apache.nifi.registry.db.entity.FlowEntity 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;
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class DatabaseMetadataService method getFlowsByBucket.
@Override
public List<FlowEntity> getFlowsByBucket(final String bucketIdentifier) {
final String sql = "SELECT * FROM flow f, bucket_item item WHERE item.bucket_id = ? AND item.id = f.id";
final List<FlowEntity> flows = jdbcTemplate.query(sql, new Object[] { bucketIdentifier }, new FlowEntityRowMapper());
final Map<String, Long> snapshotCounts = getFlowSnapshotCounts();
for (final FlowEntity flowEntity : flows) {
final Long snapshotCount = snapshotCounts.get(flowEntity.getId());
if (snapshotCount != null) {
flowEntity.setSnapshotCount(snapshotCount);
}
}
return flows;
}
use of org.apache.nifi.registry.db.entity.FlowEntity 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;
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class FlowEntityRowMapper method mapRow.
@Nullable
@Override
public FlowEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
final FlowEntity flowEntity = new FlowEntity();
flowEntity.setId(rs.getString("ID"));
flowEntity.setName(rs.getString("NAME"));
flowEntity.setDescription(rs.getString("DESCRIPTION"));
flowEntity.setCreated(rs.getTimestamp("CREATED"));
flowEntity.setModified(rs.getTimestamp("MODIFIED"));
flowEntity.setBucketId(rs.getString("BUCKET_ID"));
flowEntity.setType(BucketItemEntityType.FLOW);
return flowEntity;
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testGetSnapshotDoesNotExistInPersistenceProvider.
@Test(expected = IllegalStateException.class)
public void testGetSnapshotDoesNotExistInPersistenceProvider() {
final BucketEntity existingBucket = createBucketEntity("b1");
final FlowEntity existingFlow = createFlowEntity(existingBucket.getId());
final FlowSnapshotEntity existingSnapshot = createFlowSnapshotEntity(existingFlow.getId());
existingFlow.setSnapshotCount(10);
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
when(metadataService.getFlowSnapshot(existingFlow.getId(), existingSnapshot.getVersion())).thenReturn(existingSnapshot);
when(flowPersistenceProvider.getFlowContent(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion())).thenReturn(null);
registryService.getFlowSnapshot(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
}
Aggregations