use of com.hortonworks.registries.schemaregistry.state.details.MergeInfo in project registry by hortonworks.
the class DefaultSchemaRegistry method getAggregatedSchemaBranch.
@Override
public Collection<AggregatedSchemaBranch> getAggregatedSchemaBranch(String schemaName) throws SchemaNotFoundException, SchemaBranchNotFoundException {
Collection<AggregatedSchemaBranch> aggregatedSchemaBranches = new ArrayList<>();
for (SchemaBranch schemaBranch : getSchemaBranches(schemaName)) {
Long rootVersion = schemaBranch.getName().equals(SchemaBranch.MASTER_BRANCH) ? null : schemaVersionLifecycleManager.getRootVersion(schemaBranch).getId();
Collection<SchemaVersionInfo> schemaVersionInfos = getAllVersions(schemaBranch.getName(), schemaName);
schemaVersionInfos.stream().forEach(schemaVersionInfo -> {
SchemaVersionLifecycleContext context = null;
try {
context = schemaVersionLifecycleManager.createSchemaVersionLifeCycleContext(schemaVersionInfo.getId(), SchemaVersionLifecycleStates.INITIATED);
MergeInfo mergeInfo = null;
if (context.getDetails() == null) {
mergeInfo = null;
} else {
try {
InitializedStateDetails details = ObjectMapperUtils.deserialize(context.getDetails(), InitializedStateDetails.class);
mergeInfo = details.getMergeInfo();
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to serialize state details of schema version : '%s'", context.getSchemaVersionId()), e);
}
}
schemaVersionInfo.setMergeInfo(mergeInfo);
} catch (SchemaNotFoundException e) {
// If the schema version has never been in 'INITIATED' state, then SchemaNotFoundException error is thrown which is expected
schemaVersionInfo.setMergeInfo(null);
}
});
aggregatedSchemaBranches.add(new AggregatedSchemaBranch(schemaBranch, rootVersion, schemaVersionInfos));
}
return aggregatedSchemaBranches;
}
Aggregations