@Override public String renderSchemaEntry(SchemaEntry schemaEntry, boolean requestForLatest) { return renderTemplate("Schema with ID = " + schemaEntry.getId() + (requestForLatest ? " (latest)" : ""), "schemaEntry", Collections.singletonMap("schemaEntry", schemaEntry)); }
@Override public String renderSchemaEntry(SchemaEntry schemaEntry, boolean requestForLatest) { return renderTemplate("Schema with ID = " + schemaEntry.getId() + (requestForLatest ? " (latest)" : ""), "schemaEntry", Collections.singletonMap("schemaEntry", schemaEntry)); }
@Override public synchronized SchemaEntry add(SchemaEntry entry) { if (null == entry) { return entry; } SchemaEntry prior = schemaToEntry.putIfAbsent(entry.getSchema(), entry); if (null != prior) { entry = prior; } idToSchema.put(entry.getId(), entry); schemasInOrder.push(entry); return entry; }
@Override public synchronized SchemaEntry add(SchemaEntry entry) { if (null == entry) { return entry; } SchemaEntry prior = schemaToEntry.putIfAbsent(entry.getSchema(), entry); if (null != prior) { entry = prior; } idToSchema.put(entry.getId(), entry); schemasInOrder.push(entry); return entry; }
/** * Register a schema with a subject * * @param subject * The subject name to register the schema in * @param schema * The schema to register * @return A 200 response with the corresponding id if successful, a 403 * forbidden response if the schema fails validation, or a 404 not * found response if the subject does not exist */ @PUT @Path("{subject}/register") @Consumes(MediaType.TEXT_PLAIN) public Response addSchema(@PathParam("subject") String subject, String schema) { try { return Response.ok(getSubject(subject).register(schema).getId()).build(); } catch (SchemaValidationException e) { return Response.status(Status.FORBIDDEN).build(); } }
/** * Look up an id by a subject + schema pair. * * @param subject * the name of the subject * @param schema * the schema to search for * @return A 200 response with the id in the body, or a 404 response if the * subject or schema is not found */ @POST @Path("{subject}/schema") @Consumes(MediaType.TEXT_PLAIN) public String idFromSchema(@PathParam("subject") String subject, String schema) { return exists(getSubject(subject).lookupBySchema(schema)).getId(); }
/** * Look up an id by a subject + schema pair. * * @param subject * the name of the subject * @param schema * the schema to search for * @return A 200 response with the id in the body, or a 404 response if the * subject or schema is not found */ @POST @Path("{subject}/schema") @Consumes(MediaType.TEXT_PLAIN) public String idFromSchema(@PathParam("subject") String subject, String schema) { return exists(getSubject(subject).lookupBySchema(schema)).getId(); }
/** * Register a schema with a subject * * @param subject * The subject name to register the schema in * @param schema * The schema to register * @return A 200 response with the corresponding id if successful, * a 403 forbidden response with exception message if the schema fails validation, * or a 404 not found response if the subject does not exist */ @PUT @Path("{subject}/register") @Consumes(MediaType.TEXT_PLAIN) public Response addSchema(@PathParam("subject") String subject, String schema) { try { return Response.ok(getSubject(subject).register(schema).getId()).build(); } catch (SchemaValidationException e) { return Response.status(Status.FORBIDDEN).entity(e.getMessage()).build(); } }
return Response.status(Status.CONFLICT).build(); return Response.ok(created.getId()).build(); } catch (SchemaValidationException e) { return Response.status(Status.FORBIDDEN).build();
@Override public SchemaEntry registerIfLatest(String schema, SchemaEntry latest) throws SchemaValidationException { RepositoryUtil.validateSchemaOrSubject(schema); String idStr = (latest == null) ? "" : latest.getId(); String path = getName() + "/register_if_latest/" + idStr; return handleRegisterRequest(path, schema); }
@Override public SchemaEntry registerIfLatest(String schema, SchemaEntry latest) throws SchemaValidationException { RepositoryUtil.validateSchemaOrSubject(schema); String idStr = (latest == null) ? "" : latest.getId(); String path = getName() + "/register_if_latest/" + idStr; return handleRegisterRequest(path, schema, true); }
@Override public SchemaEntry registerIfLatest(String schema, SchemaEntry latest) throws SchemaValidationException { RepositoryUtil.validateSchemaOrSubject(schema); String idStr = (latest == null) ? "" : latest.getId(); String path = getName() + "/register_if_latest/" + idStr; return handleRegisterRequest(path, schema, true); }
@Override public SchemaEntry registerIfLatest(String schema, SchemaEntry latest) throws SchemaValidationException { RepositoryUtil.validateSchemaOrSubject(schema); String idStr = (latest == null) ? "" : latest.getId(); String path = getName() + "/register_if_latest/" + idStr; return handleRegisterRequest(path, schema); }
@Override public synchronized SchemaEntry register(String schema) throws SchemaValidationException { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); SchemaEntry entry = lookupBySchema(schema); if (entry == null) { entry = createNewSchemaFile(schema); appendLineToFile(idFile, entry.getId()); latest = entry; } return entry; }
@Override public synchronized SchemaEntry register(String schema) throws SchemaValidationException { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); SchemaEntry entry = lookupBySchema(schema); if (entry == null) { entry = createNewSchemaFile(schema); appendLineToFile(idFile, entry.getId()); latest = entry; } return entry; }
SchemaEntry schemaEntry = subject.lookupBySchema(convertSchema.toString(schema)); if (schemaEntry != null) { id = convertId.fromString(schemaEntry.getId());
private void validateSchemaEntry(String expectedSchema, SchemaEntry foo) { Assert.assertNotNull("Failed to create SchemaEntry with schema: " + expectedSchema, foo); Assert.assertEquals("SchemaEntry does not have expected schema value", expectedSchema, foo.getSchema()); Assert.assertNotNull("SchemaEntry does not have a valid id", foo.getId()); Assert.assertFalse("SchemaEntry has an empty id", foo.getId().isEmpty()); }
if (schemaEntry != null) { Map<ID, SCHEMA> idToSchemaCache = getIdToSchemaCache(subjectName); ID id = convertId.fromString(schemaEntry.getId());
if (schemaEntry != null) { Map<ID, SCHEMA> idToSchemaCache = getIdToSchemaCache(subjectName); ID id = convertId.fromString(schemaEntry.getId());
@Test public void testGetters() { String id = "id"; String sc = "sc"; SchemaEntry entry = new SchemaEntry(id, sc); Assert.assertEquals(id, entry.getId()); Assert.assertEquals(sc, entry.getSchema()); }