Search in sources :

Example 6 with FeatureNotFoundException

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

the class FeatureStoreHttp method addToGroup.

/**
 * {@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);
    }
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 7 with FeatureNotFoundException

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

the class FeatureStoreNeo4J method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(String uid) {
    Util.assertHasLength(uid);
    if (!exist(uid)) {
        throw new FeatureNotFoundException(uid);
    }
    // Parameter
    Map<String, Object> paramUID = new HashMap<>();
    paramUID.put("uid", uid);
    Transaction tx = graphDb.beginTx();
    // Delete Flipping Strategy if it exists
    graphDb.execute(QUERY_CYPHER_DELETE_STRATEGY_FEATURE, paramUID);
    // Delete Related Property if exist
    graphDb.execute(QUERY_CYPHER_DELETE_PROPERTIES_FEATURE, paramUID);
    // Check group
    Result result = graphDb.execute(QUERY_CYPHER_GETGROUPNAME, paramUID);
    if (result.hasNext()) {
        String groupName = (String) result.next().get(GROUPNAME);
        Map<String, Object> paramGroupName = new HashMap<>();
        paramGroupName.put(GROUP_NAME, groupName);
        result = graphDb.execute(QUERY_CYPHER_COUNT_FEATURE_OF_GROUP, paramGroupName);
        if (result.hasNext()) {
            long nbFeature = (long) result.next().get(QUERY_CYPHER_ALIAS);
            if (nbFeature == 1) {
                // This is the last feature of this Group => delete the GROUP
                graphDb.execute(QUERY_CYPHER_DELETE_GROUP_FEATURE, paramUID);
            }
        }
    }
    // Delete feature
    graphDb.execute(QUERY_CYPHER_DELETE_FEATURE, paramUID);
    tx.success();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) Result(org.neo4j.graphdb.Result)

Example 8 with FeatureNotFoundException

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

the class FeatureStoreMongoDB method addToGroup.

/**
 * {@inheritDoc}
 */
@Override
public void addToGroup(String uid, String groupName) {
    if (uid == null || uid.isEmpty()) {
        throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
    }
    if (groupName == null || groupName.isEmpty()) {
        throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
    }
    if (!exist(uid)) {
        throw new FeatureNotFoundException(uid);
    }
    DBObject target = BUILDER.getFeatUid(uid);
    DBObject nGroupName = BUILDER.getGroupName(groupName);
    getFeaturesCollection().update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get());
}
Also used : FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 9 with FeatureNotFoundException

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

the class FeatureStoreMongoDB method updateStatus.

/**
 * Update status of feature.
 *
 * @param uid
 *            feature id
 * @param enable
 *            enabler
 */
private void updateStatus(String uid, boolean enable) {
    Util.assertParamHasLength(uid, "uid (feature identifier");
    if (!exist(uid)) {
        throw new FeatureNotFoundException(uid);
    }
    DBObject target = BUILDER.getFeatUid(uid);
    Object enabledd = BUILDER.getEnable(enable);
    getFeaturesCollection().update(target, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get());
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 10 with FeatureNotFoundException

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

the class FeatureStoreSpringJdbc method read.

/**
 * {@inheritDoc}
 */
public Feature read(String uid) {
    Util.assertHasLength(uid);
    try {
        Feature feature = getJdbcTemplate().queryForObject(getQueryBuilder().getFeature(), FMAPPER, uid);
        readProperties(feature);
        readPermissions(feature);
        return feature;
    } catch (EmptyResultDataAccessException ex) {
        throw new FeatureNotFoundException(uid, ex);
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Feature(org.ff4j.core.Feature) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Aggregations

FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)23 Response (javax.ws.rs.core.Response)8 FeatureAccessException (org.ff4j.exception.FeatureAccessException)7 BasicDBObject (com.mongodb.BasicDBObject)3 DBObject (com.mongodb.DBObject)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Path (javax.ws.rs.Path)3 Document (org.bson.Document)3 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)3 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 Jedis (redis.clients.jedis.Jedis)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1