private VersionedFlowSnapshot getVersionedFlowSnapshot(final BucketEntity bucketEntity, final FlowEntity flowEntity, final Integer version) {
final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowEntity.getId(), version);
if (snapshotEntity == null) {
LOGGER.warn("The specified flow snapshot id [{}] does not exist for version [{}].", flowEntity.getId(), version);
throw new ResourceNotFoundException("The specified versioned flow snapshot does not exist for this flow.");
}
final byte[] serializedSnapshot = flowPersistenceProvider.getFlowContent(bucketEntity.getId(), flowEntity.getId(), version);
if (serializedSnapshot == null || serializedSnapshot.length == 0) {
throw new IllegalStateException("No serialized content found for snapshot with flow identifier "
+ flowEntity.getId() + " and version " + version);
}
final InputStream input = new ByteArrayInputStream(serializedSnapshot);
final VersionedProcessGroup flowContents = processGroupSerializer.deserialize(input);
final Bucket bucket = DataModelMapper.map(bucketEntity);
final VersionedFlow versionedFlow = DataModelMapper.map(bucketEntity, flowEntity);
final VersionedFlowSnapshotMetadata snapshotMetadata = DataModelMapper.map(bucketEntity, snapshotEntity);
final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
snapshot.setFlowContents(flowContents);
snapshot.setSnapshotMetadata(snapshotMetadata);
snapshot.setFlow(versionedFlow);
snapshot.setBucket(bucket);
return snapshot;
}