@Override public void setTableAttributes(String apiKey, String table, Map<String, String> attributes, Audit audit) { checkNotNull(table, "table"); checkNotNull(attributes, "attributes"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table, "attributes") .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(attributes); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, String> attributes, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(attributes, "attributes"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(attributes); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void put(String apiKey, String table, String blobId, InputSupplier<? extends InputStream> in, Map<String, String> attributes, @Nullable Duration ttl) throws IOException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); checkNotNull(in, "in"); checkNotNull(attributes, "attributes"); try { // Encode the ttl as a URL query parameter Integer ttlSeconds = Ttls.toSeconds(ttl, 0, null); URI uri = _blobStore.clone() .segment(table, blobId) .queryParam("ttl", (ttlSeconds != null) ? new Object[]{ttlSeconds} : new Object[0]) .build(); // Encode the rest of the attributes as request headers EmoResource request = _client.resource(uri); for (Map.Entry<String, String> entry : attributes.entrySet()) { request.header(X_BVA_PREFIX + entry.getKey(), entry.getValue()); } // Upload the object request.type(MediaType.APPLICATION_OCTET_STREAM_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(in.getInput()); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void setTableAttributes(String apiKey, String table, Map<String, String> attributes, Audit audit) { checkNotNull(table, "table"); checkNotNull(attributes, "attributes"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table, "attributes") .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(attributes); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, String> attributes, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(attributes, "attributes"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(attributes); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void put(String apiKey, String table, String blobId, InputSupplier<? extends InputStream> in, Map<String, String> attributes, @Nullable Duration ttl) throws IOException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); checkNotNull(in, "in"); checkNotNull(attributes, "attributes"); try { // Encode the ttl as a URL query parameter Integer ttlSeconds = Ttls.toSeconds(ttl, 0, null); URI uri = _blobStore.clone() .segment(table, blobId) .queryParam("ttl", (ttlSeconds != null) ? new Object[]{ttlSeconds} : new Object[0]) .build(); // Encode the rest of the attributes as request headers EmoResource request = _client.resource(uri); for (Map.Entry<String, String> entry : attributes.entrySet()) { request.header(X_BVA_PREFIX + entry.getKey(), entry.getValue()); } // Upload the object request.type(MediaType.APPLICATION_OCTET_STREAM_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(in.getInput()); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void subscribe(@Credential String apiKey, String subscription, Condition tableFilter, Duration subscriptionTtl, Duration eventTtl, boolean includeDefaultJoinFilter) { checkNotNull(subscription, "subscription"); checkNotNull(tableFilter, "tableFilter"); try { URI uri = _databus.clone() .segment(subscription) .queryParam("ttl", Ttls.toSeconds(subscriptionTtl, 0, (int) Duration.ofDays(30).getSeconds())) .queryParam("eventTtl", Ttls.toSeconds(eventTtl, 0, (int) Duration.ofDays(30).getSeconds())) .queryParam("includeDefaultJoinFilter", Boolean.toString(includeDefaultJoinFilter)) .build(); _client.resource(uri) .type(JSON_CONDITION_MEDIA_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(tableFilter.toString()); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void updateApiKey(String apiKey, UpdateEmoApiKeyRequest request) throws EmoApiKeyNotFoundException { checkNotNull(request, "request"); String id = checkNotNull(request.getId(), "id"); checkArgument(!request.isOwnerPresent() || !Strings.isNullOrEmpty(request.getOwner()), "Non-empty owner is required"); try { URI uri = _uac.clone() .segment("api-key") .segment(id) .build(); _client.resource(uri) .type(APPLICATION_X_UPDATE_API_KEY_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(JsonHelper.asJson(request)); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void setTableTemplate(String apiKey, String table, Map<String, ?> template, Audit audit) { checkNotNull(table, "table"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table, "template") .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void createFacade(String apiKey, String table, FacadeOptions options, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_facade", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void setTableTemplate(String apiKey, String table, Map<String, ?> template, Audit audit) { checkNotNull(table, "table"); checkNotNull(template, "template"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table, "template") .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(template); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void createFacade(String apiKey, String table, FacadeOptions options, Audit audit) throws TableExistsException { checkNotNull(table, "table"); checkNotNull(options, "options"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_facade", table) .queryParam("options", RisonHelper.asORison(options)) .queryParam("audit", RisonHelper.asORison(audit)) .build(); for (int attempt = 0; ; attempt++) { try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(); return; } catch (EmoClientException e) { // The SoR returns a 301 response when we need to make this request against a different data center. // Follow the redirect a few times but don't loop forever. if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) { uri = e.getResponse().getLocation(); continue; } throw convertException(e); } } }
@Override public void updateRole(String apiKey, UpdateEmoRoleRequest request) throws EmoRoleNotFoundException { checkNotNull(request, "request"); EmoRoleKey roleKey = checkNotNull(request.getRoleKey(), "roleKey"); try { URI uri = _uac.clone() .segment("role") .segment(roleKey.getGroup()) .segment(roleKey.getId()) .build(); _client.resource(uri) .type(APPLICATION_X_UPDATE_ROLE_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .put(JsonHelper.asJson(request)); } catch (EmoClientException e) { throw convertException(e); } }