Search in sources :

Example 36 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class PropertyCouchbaseMapper method toStore.

/**
 * {@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);
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) JsonObject(com.couchbase.client.java.document.json.JsonObject) Property(org.ff4j.property.Property) FeatureAccessException(org.ff4j.exception.FeatureAccessException)

Example 37 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method createSchema.

/**
 * {@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());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) WebResource(com.sun.jersey.api.client.WebResource)

Example 38 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method update.

/**
 * {@inheritDoc}
 */
@Override
public void update(Feature fp) {
    Util.assertNotNull(fp);
    if (!exist(fp.getUid())) {
        throw new FeatureNotFoundException(fp.getUid());
    }
    ClientResponse cRes = // 
    getStore().path(fp.getUid()).type(MediaType.APPLICATION_JSON).put(ClientResponse.class, new FeatureApiBean(fp));
    if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot update feature, an HTTP error " + cRes.getStatus() + OCCURED);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 39 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method readAll.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Feature> readAll() {
    ClientResponse cRes = getStore().get(ClientResponse.class);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot read features, an HTTP error " + cRes.getStatus() + OCCURED);
    }
    String resEntity = cRes.getEntity(String.class);
    Feature[] fArray = parseFeatureArray(resEntity);
    Map<String, Feature> features = new HashMap<String, Feature>();
    for (Feature feature : fArray) {
        features.put(feature.getUid(), feature);
    }
    return features;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) FeatureJsonParser.parseFeature(org.ff4j.utils.json.FeatureJsonParser.parseFeature) Feature(org.ff4j.core.Feature)

Example 40 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class PropertyStoreHttp method clear.

/**
 * {@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());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) WebResource(com.sun.jersey.api.client.WebResource)

Aggregations

FeatureAccessException (org.ff4j.exception.FeatureAccessException)50 SQLException (java.sql.SQLException)18 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)16 Response (javax.ws.rs.core.Response)16 JdbcUtils.closeConnection (org.ff4j.utils.JdbcUtils.closeConnection)15 Feature (org.ff4j.core.Feature)11 ResultSet (java.sql.ResultSet)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)9 JdbcUtils.closeResultSet (org.ff4j.utils.JdbcUtils.closeResultSet)8 HashMap (java.util.HashMap)7 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)7 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)5 WebResource (com.sun.jersey.api.client.WebResource)4 HashSet (java.util.HashSet)4 FeatureJsonParser.parseFeature (org.ff4j.utils.json.FeatureJsonParser.parseFeature)4 IOException (java.io.IOException)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Table (org.apache.hadoop.hbase.client.Table)3 HBaseConnection (org.ff4j.hbase.HBaseConnection)3