/** {@inheritDoc} */ @Override public void clear() { Util.assertHasLength(url); Response cRes = ClientHttpUtils.invokePostMethod( getJerseyClient().target(url) .path(RESOURCE_STORE) .path(STORE_CLEAR),authorizationHeaderValue); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot clear feature store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ @Override public void createSchema() { Util.assertHasLength(url); Response cRes = ClientHttpUtils.invokePostMethod( getJerseyClient().target(url) .path(RESOURCE_STORE) .path(STORE_CREATESCHEMA), authorizationHeaderValue); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot create feature store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ @Override public boolean exist(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils.invokeGetMethod(getStore().path(uid), authorizationHeaderValue); if (Status.OK.getStatusCode() == cRes.getStatus()) { return true; } if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { return false; } throw new FeatureAccessException("Cannot check existence of feature, an HTTP error " + cRes.getStatus() + " occured : " + cRes.getEntity()); }
/** {@inheritDoc} */ @Override public boolean existGroup(String groupName) { Util.assertHasLength(groupName); Response cRes = ClientHttpUtils.invokeGetMethod(getGroups().path(groupName), authorizationHeaderValue); if (Status.OK.getStatusCode() == cRes.getStatus()) { return true; } if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { return false; } throw new FeatureAccessException("Cannot check existence of group , an HTTP error " + cRes.getStatus() + OCCURED); }
/** {@inheritDoc} */ @Override public void addToGroup(String uid, String groupName) { Util.assertHasLength(uid, groupName); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_ADDGROUP).path(groupName), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot add feature to group, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public void delete(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils .invokeDeleteMethod(getStore().path(uid), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot delete feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public void enableGroup(String groupName) { Util.assertHasLength(groupName); Response cRes = ClientHttpUtils.invokePostMethod(getGroups() .path(groupName) .path(OPERATION_ENABLE), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new GroupNotFoundException(groupName); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public void grantRoleOnFeature(String uid, String roleName) { Util.assertHasLength(uid, roleName); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_GRANTROLE).path(roleName), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED); } }
public boolean isTableExist(String tableName) { ResultSet rs = null; try { DatabaseMetaData dbmd = getJdbcTemplate().getDataSource().getConnection().getMetaData(); rs = dbmd.getTables(null, null, tableName, new String[] {"TABLE"}); return rs.next(); } catch (SQLException sqlEX) { throw new FeatureAccessException("Cannot check table existence", sqlEX); } finally { JdbcUtils.closeResultSet(rs); } }
/** {@inheritDoc} */ @Override public Feature read(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils.invokeGetMethod( getStore().path(uid), authorizationHeaderValue); log.info(String.valueOf(getStore().path(uid))); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } else if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Error when reaching API code:[" + cRes.getStatus() + "] MSG:" + cRes.getStatusInfo()); } return parseFeature(cRes.readEntity(String.class)); }
/** {@inheritDoc} */ @Override public void delete(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY); } ClientResponse cRes = getStore().path(uid).delete(ClientResponse.class); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot delete feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public Set<String> readAllGroups() { ClientResponse cRes = getGroups().get(ClientResponse.class); List<GroupDescApiBean> groupApiBeans = cRes.getEntity(new GenericType<List<GroupDescApiBean>>() {}); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot read groups, an HTTP error " + cRes.getStatus() + OCCURED); } Set < String > groupNames = new HashSet<String>(); for (GroupDescApiBean groupApiBean : groupApiBeans) { groupNames.add(groupApiBean.getGroupName()); } return groupNames; }
/** {@inheritDoc} */ @Override public JsonDocument toStore(Feature feature) { if (feature == null) return null; JsonObject jsonObject; try { jsonObject = TRANSCODER.stringToJsonObject(feature.toJson()); jsonObject.put("_class", Feature.class.getCanonicalName()); } catch (Exception e) { throw new FeatureAccessException("Cannot parse the feature", e); } return JsonDocument.create(feature.getUid(), jsonObject); }
/** {@inheritDoc} */ @Override public JsonDocument toStore(Property<?> prop) { if (prop == null) return null; JsonObject jsonObject; try { jsonObject = TRANSCODER.stringToJsonObject(prop.toJson()); jsonObject.put("_class", Property.class.getCanonicalName()); } catch (Exception e) { throw new FeatureAccessException("Cannot parse the feature", e); } return JsonDocument.create(prop.getName(), jsonObject); }
/** {@inheritDoc} */ @Override public boolean exist(String featId) { Util.assertHasLength(featId); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(FEATURES_TABLENAME)) { Get queryByIdQuery = new Get(Bytes.toBytes(featId)); return !table.get(queryByIdQuery).isEmpty(); } } catch (IOException e) { throw new FeatureAccessException("Cannot check feature existence", e); } }
private void executePutCommand(Put putQuery) { try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(FEATURES_TABLENAME)) { table.put(putQuery); } } catch (IOException e) { throw new FeatureAccessException("Cannot execute command", e); } }
/** {@inheritDoc} */ @Override public void createSchema() { Util.assertHasLength(url); WebResource wr = getJerseyClient().resource(url).path(RESOURCE_STORE).path(STORE_CREATESCHEMA); if (null != authorization) { wr.header(HEADER_AUTHORIZATION, authorization); } ClientResponse cRes = wr.post(ClientResponse.class); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot create schema for property store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ public void clear() { Util.assertHasLength(url); WebResource wr = getJerseyClient().resource(url).path(RESOURCE_PROPERTYSTORE).path(STORE_CLEAR); if (null != authorization) { wr.header(HEADER_AUTHORIZATION, authorization); } ClientResponse cRes = wr.post(ClientResponse.class); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot clear property store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ @Override public void clear() { Util.assertHasLength(url); WebResource wr = getJerseyClient().resource(url).path(RESOURCE_STORE).path(STORE_CLEAR); if (null != authorization) { wr.header(HEADER_AUTHORIZATION, authorization); } ClientResponse cRes = wr.post(ClientResponse.class); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot clear feature store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ @Override public void createSchema() { Util.assertHasLength(url); WebResource wr = getJerseyClient().resource(url).path(RESOURCE_STORE).path(STORE_CREATESCHEMA); if (null != authorization) { wr.header(HEADER_AUTHORIZATION, authorization); } ClientResponse cRes = wr.post(ClientResponse.class); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot create schema for feature store - " + cRes.getStatus()); } }