Search in sources :

Example 1 with InvalidSchemaBranchVersionMapping

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;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) OrderByField(com.hortonworks.registries.storage.OrderByField) InvalidSchemaBranchVersionMapping(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping) ArrayList(java.util.ArrayList) InvalidSchemaBranchVersionMapping(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)1 InvalidSchemaBranchVersionMapping (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping)1 OrderByField (com.hortonworks.registries.storage.OrderByField)1 ArrayList (java.util.ArrayList)1