use of com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping in project registry by hortonworks.
the class SchemaVersionLifecycleManager method getSortedSchemaVersions.
private List<SchemaVersionInfo> getSortedSchemaVersions(Long schemaBranchId) throws SchemaNotFoundException, SchemaBranchNotFoundException {
List<QueryParam> schemaVersionMappingStorableQueryParams = Lists.newArrayList();
schemaVersionMappingStorableQueryParams.add(new QueryParam(SchemaBranchVersionMapping.SCHEMA_BRANCH_ID, schemaBranchId.toString()));
List<OrderByField> orderByFields = new ArrayList<>();
orderByFields.add(OrderByField.of(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, false));
List<SchemaVersionInfo> schemaVersionInfos = new ArrayList<>();
Collection<SchemaBranchVersionMapping> storables = storageManager.find(SchemaBranchVersionMapping.NAMESPACE, schemaVersionMappingStorableQueryParams, orderByFields);
if (storables == null || storables.size() == 0) {
if (schemaBranchCache.get(SchemaBranchCache.Key.of(schemaBranchId)).getName().equals(SchemaBranch.MASTER_BRANCH))
return Collections.emptyList();
else
throw new InvalidSchemaBranchVersionMapping(String.format("No schema versions are attached to the schema branch id : '%s'", schemaBranchId));
}
for (SchemaBranchVersionMapping storable : storables) {
SchemaIdVersion schemaIdVersion = new SchemaIdVersion(storable.getSchemaVersionInfoId());
schemaVersionInfos.add(schemaVersionInfoCache.getSchema(SchemaVersionInfoCache.Key.of(schemaIdVersion)));
}
return schemaVersionInfos;
}
Aggregations