@Override public synchronized SchemaEntry register(String schema) throws SchemaValidationException { String id = String.valueOf(nextId); SchemaEntry toRegister = new SchemaEntry(id, schema); SchemaEntry valueInCache = schemas.add(toRegister); if (toRegister == valueInCache) { // schema is new nextId++; this.latest = toRegister; } return valueInCache; }
@Override public synchronized SchemaEntry register(String schema) throws SchemaValidationException { String id = String.valueOf(nextId); SchemaEntry toRegister = new SchemaEntry(id, schema); SchemaEntry valueInCache = schemas.add(toRegister); if (toRegister == valueInCache) { // schema is new nextId++; this.latest = toRegister; } return valueInCache; }
@Override public synchronized Iterable<SchemaEntry> allEntries() { isValid(); List<SchemaEntry> entries = new ArrayList<SchemaEntry>(); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schema = readSchemaForId(idStr); entries.add(new SchemaEntry(idStr, schema)); } Collections.reverse(entries); return entries; }
@Override public synchronized Iterable<SchemaEntry> allEntries() { isValid(); List<SchemaEntry> entries = new ArrayList<SchemaEntry>(); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schema = readSchemaForId(idStr); entries.add(new SchemaEntry(idStr, schema)); } Collections.reverse(entries); return entries; }
@Override public synchronized SchemaEntry lookupById(String id) { isValid(); String schema = readSchemaForIdOrNull(id); if (schema != null) { return new SchemaEntry(id, schema); } return null; }
@Override public synchronized SchemaEntry lookupById(String id) { isValid(); String schema = readSchemaForIdOrNull(id); if (schema != null) { return new SchemaEntry(id, schema); } return null; }
@Override public synchronized SchemaEntry lookupBySchema(String schema) { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schemaInFile = readSchemaForIdOrNull(idStr); if (schema.equals(schemaInFile)) { return new SchemaEntry(idStr, schema); } } return null; }
@Override public SchemaEntry latest() { String path = getName() + "/latest"; String entryStr; try { entryStr = webResource.path(path).get(String.class); return new SchemaEntry(entryStr); } catch (UniformInterfaceException e) { return null; } }
@Override public SchemaEntry latest() { String path = getName() + "/latest"; String entryStr; try { entryStr = webResource.path(path).get(String.class); return new SchemaEntry(entryStr); } catch (UniformInterfaceException e) { return null; } }
@Override public SchemaEntry latest() { String path = getName() + "/latest"; SchemaEntry schemaEntry = null; try { String entryStr = webResource.path(path).get(String.class); schemaEntry = new SchemaEntry(entryStr); } catch (RuntimeException e) { handleException(e, format("Failed to locate latest schema in subject %s", getName()), true); } return schemaEntry; }
@Override public SchemaEntry latest() { String path = getName() + "/latest"; SchemaEntry schemaEntry = null; try { String entryStr = webResource.path(path).get(String.class); schemaEntry = new SchemaEntry(entryStr); } catch (RuntimeException e) { handleException(e, format("Failed to locate latest schema in subject %s", getName()), true); } return schemaEntry; }
@Test(expected=IllegalArgumentException.class) public void testInvalid() { new SchemaEntry("invalidString"); }
@Override public SchemaEntry lookupById(String schemaId) { RepositoryUtil.validateSchemaOrSubject(schemaId); String path = getName() + "/id/" + schemaId; SchemaEntry schemaEntry = null; try { String schema = webResource.path(path).get(String.class); schemaEntry = new SchemaEntry(schemaId, schema); } catch (RuntimeException e) { handleException(e, format("Failed to locate schema with ID %s in subject %s", schemaId, getName()), true); } return schemaEntry; }
@Override public SchemaEntry lookupById(String schemaId) { RepositoryUtil.validateSchemaOrSubject(schemaId); String path = getName() + "/id/" + schemaId; try { String schema = webResource.path(path).get(String.class); return new SchemaEntry(schemaId, schema); } catch (UniformInterfaceException e) { return null; } }
@Test public void testToString() { SchemaEntry entry = new SchemaEntry("id", "schema"); SchemaEntry toAndFrom = new SchemaEntry(entry.toString()); Assert.assertEquals(entry, toAndFrom); }
@Override public SchemaEntry lookupById(String schemaId) { RepositoryUtil.validateSchemaOrSubject(schemaId); String path = getName() + "/id/" + schemaId; try { String schema = webResource.path(path).get(String.class); return new SchemaEntry(schemaId, schema); } catch (UniformInterfaceException e) { return null; } }
@Override public SchemaEntry lookupBySchema(String schema) { RepositoryUtil.validateSchemaOrSubject(schema); String path = getName() + "/schema"; SchemaEntry schemaEntry = null; try { String schemaId = webResource.path(path).type(MediaType.TEXT_PLAIN_TYPE).post(String.class, schema); schemaEntry = new SchemaEntry(schemaId, schema); } catch (RuntimeException e) { handleException(e, format("Failed to locate schema %s in subject %s", schema, getName()), true); } return schemaEntry; }
@Override public SchemaEntry lookupBySchema(String schema) { RepositoryUtil.validateSchemaOrSubject(schema); String path = getName() + "/schema"; try { String schemaId = webResource.path(path).type(MediaType.TEXT_PLAIN_TYPE).post(String.class, schema); return new SchemaEntry(schemaId, schema); } catch (UniformInterfaceException e) { return null; } }
@Override public SchemaEntry lookupBySchema(String schema) { RepositoryUtil.validateSchemaOrSubject(schema); String path = getName() + "/schema"; try { String schemaId = webResource.path(path).type(MediaType.TEXT_PLAIN_TYPE).post(String.class, schema); return new SchemaEntry(schemaId, schema); } catch (UniformInterfaceException e) { return null; } }
@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()); }