Search in sources :

Example 11 with FeatureAccessException

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

the class JdbcFeatureStore method clear.

/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    Connection sqlConn = null;
    PreparedStatement ps = null;
    try {
        sqlConn = dataSource.getConnection();
        ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllCustomProperties());
        ps.executeUpdate();
        closeStatement(ps);
        ps = null;
        ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllRoles());
        ps.executeUpdate();
        closeStatement(ps);
        ps = null;
        ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllFeatures());
        ps.executeUpdate();
        closeStatement(ps);
        ps = null;
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
    } finally {
        closeStatement(ps);
        closeConnection(sqlConn);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) PreparedStatement(java.sql.PreparedStatement)

Example 12 with FeatureAccessException

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

the class JdbcFeatureStore method createCustomProperties.

/**
 * Ease creation of properties in Database.
 *
 * @param uid
 *      target unique identifier
 * @param props
 *      target properties.
 */
public void createCustomProperties(String uid, Collection<Property<?>> props) {
    Util.assertNotNull(uid);
    if (props == null)
        return;
    Connection sqlConn = null;
    PreparedStatement ps = null;
    Boolean previousAutoCommit = null;
    try {
        sqlConn = dataSource.getConnection();
        // Begin TX
        previousAutoCommit = sqlConn.getAutoCommit();
        sqlConn.setAutoCommit(false);
        // Queries
        for (Property<?> pp : props) {
            ps = createCustomProperty(sqlConn, uid, pp);
            closeStatement(ps);
            ps = null;
        }
        // End TX
        sqlConn.commit();
    } catch (SQLException sqlEX) {
        rollback(sqlConn);
        throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
    } finally {
        closeStatement(ps);
        closeConnection(sqlConn, previousAutoCommit);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) PreparedStatement(java.sql.PreparedStatement)

Example 13 with FeatureAccessException

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

the class PropertyStoreHttp method createProperty.

/**
 * {@inheritDoc}
 */
public <T> void createProperty(Property<T> value) {
    Util.assertNotNull(value);
    Util.assertHasLength(value.getName());
    if (existProperty(value.getName())) {
        throw new PropertyAlreadyExistException("Property already exist");
    }
    /* Now can process upsert through PUT HTTP method
        Response cRes = getStore().path(value.getName())//
                .request(MediaType.APPLICATION_JSON)
                .put(Entity.entity(new PropertyApiBean(value), MediaType.APPLICATION_JSON));*/
    Response cRes = ClientHttpUtils.createRequest(getStore().path(value.getName()), authorization, null).put(Entity.entity(new PropertyApiBean(value), MediaType.APPLICATION_JSON));
    // Check response code CREATED or raised error
    if (Status.CREATED.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot create properties, an HTTP error " + cRes.getStatus() + OCCURED);
    }
}
Also used : Response(javax.ws.rs.core.Response) PropertyApiBean(org.ff4j.web.api.resources.domain.PropertyApiBean) FeatureAccessException(org.ff4j.exception.FeatureAccessException) PropertyAlreadyExistException(org.ff4j.exception.PropertyAlreadyExistException)

Example 14 with FeatureAccessException

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

the class FeatureStoreHttp method readGroup.

/**
 * {@inheritDoc}
 */
public Map<String, Feature> readGroup(String groupName) {
    Util.assertHasLength(groupName);
    Response cRes = ClientHttpUtils.invokeGetMethod(getGroups().path(groupName), authorizationHeaderValue);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new GroupNotFoundException(groupName);
    }
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED);
    }
    String resEntity = cRes.readEntity(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 : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureJsonParser.parseFeature(org.ff4j.utils.json.FeatureJsonParser.parseFeature) Feature(org.ff4j.core.Feature)

Example 15 with FeatureAccessException

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

the class FeatureStoreHttp method disableGroup.

/**
 * {@inheritDoc}
 */
@Override
public void disableGroup(String groupName) {
    Util.assertHasLength(groupName);
    Response cRes = ClientHttpUtils.invokePostMethod(getGroups().path(groupName).path(OPERATION_DISABLE), 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);
    }
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException)

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