private SchemaBranch getSchemaBranch(Long id) throws SchemaBranchNotFoundException { List<QueryParam> schemaBranchQueryParam = new ArrayList<>(); schemaBranchQueryParam.add(new QueryParam(SchemaBranchStorable.ID, id.toString())); Collection<SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, schemaBranchQueryParam); if(schemaBranchStorables == null || schemaBranchStorables.isEmpty()) throw new SchemaBranchNotFoundException(String.format("Schema branch with id : '%s' not found", id.toString())); // size of the collection will always be less than 2, as ID is a primary key, so no need handle the case where size > 1 return schemaBranchStorables.iterator().next().toSchemaBranch(); }
private SchemaBranch getSchemaBranch(SchemaBranchKey schemaBranchKey) throws SchemaBranchNotFoundException { List<QueryParam> queryParams = new ArrayList<>(); queryParams.add(new QueryParam(SchemaBranchStorable.NAME, schemaBranchKey.getSchemaBranchName())); queryParams.add(new QueryParam(SchemaBranchStorable.SCHEMA_METADATA_NAME, schemaBranchKey.getSchemaMetadataName())); Collection <SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, queryParams); if (schemaBranchStorables == null || schemaBranchStorables.isEmpty()) throw new SchemaBranchNotFoundException(String.format("Schema branch with key : %s not found", schemaBranchKey)); else if (schemaBranchStorables.size() > 1) throw new SchemaBranchNotFoundException(String.format("Failed to unique determine a schema branch with key : %s", schemaBranchKey)); return schemaBranchStorables.iterator().next().toSchemaBranch(); }
@Override public void deleteSchemaBranch(Long schemaBranchId) throws SchemaBranchNotFoundException, InvalidSchemaBranchDeletionException { WebTarget target = currentSchemaRegistryTargets().schemasTarget.path("branch/"+schemaBranchId); Response response = Subject.doAs(subject, new PrivilegedAction<Response>() { @Override public Response run() { return target.request().delete(); } }); int status = response.getStatus(); if (status == Response.Status.NOT_FOUND.getStatusCode()) { throw new SchemaBranchNotFoundException(response.readEntity(String.class)); } else if (status == Response.Status.BAD_REQUEST.getStatusCode()) { throw new InvalidSchemaBranchDeletionException(response.readEntity(String.class)); } else if (status != Response.Status.OK.getStatusCode()) { throw new RuntimeException(response.readEntity(String.class)); } }