use of org.ff4j.exception.PropertyAlreadyExistException 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);
}
}
use of org.ff4j.exception.PropertyAlreadyExistException in project ff4j by ff4j.
the class JdbcPropertyStore method createProperty.
/**
* {@inheritDoc}
*/
public <T> void createProperty(Property<T> ap) {
Util.assertNotNull(ap);
Connection sqlConn = null;
PreparedStatement ps = null;
try {
sqlConn = getDataSource().getConnection();
if (existProperty(ap.getName())) {
throw new PropertyAlreadyExistException(ap.getName());
}
ps = sqlConn.prepareStatement(getQueryBuilder().createProperty());
ps.setString(1, ap.getName());
ps.setString(2, ap.getType());
ps.setString(3, ap.asString());
ps.setString(4, ap.getDescription());
if (ap.getFixedValues() != null && !ap.getFixedValues().isEmpty()) {
String fixedValues = ap.getFixedValues().toString();
ps.setString(5, fixedValues.substring(1, fixedValues.length() - 1));
} else {
ps.setString(5, null);
}
ps.executeUpdate();
} catch (SQLException sqlEX) {
throw new PropertyAccessException("Cannot update properties database, SQL ERROR", sqlEX);
} finally {
// Connection is closed alse here within clos statement
closeStatement(ps);
closeConnection(sqlConn);
}
}
use of org.ff4j.exception.PropertyAlreadyExistException 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");
}
ClientResponse cRes = //
getStore().path(value.getName()).type(//
MediaType.APPLICATION_JSON).put(ClientResponse.class, new PropertyApiBean(value));
// 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);
}
}
use of org.ff4j.exception.PropertyAlreadyExistException in project ff4j by ff4j.
the class PropertyStoreNeo4j method createProperty.
/**
* {@inheritDoc}
*/
public <T> void createProperty(Property<T> ap) {
Util.assertNotNull(ap);
Util.assertHasLength(ap.getName());
if (existProperty(ap.getName())) {
throw new PropertyAlreadyExistException(ap.getName());
}
StringBuilder cypherCreate = new StringBuilder();
cypherCreate.append("CREATE (p:" + FF4jNeo4jLabels.FF4J_PROPERTY + " { name :'");
cypherCreate.append(ap.getName());
cypherCreate.append("', type:'");
cypherCreate.append(ap.getType());
cypherCreate.append("', value:'");
cypherCreate.append(ap.getValue());
cypherCreate.append("', fixedValues:[");
if (ap.getFixedValues() != null && !ap.getFixedValues().isEmpty()) {
boolean first = true;
for (Object fix : ap.getFixedValues()) {
if (!first) {
cypherCreate.append(",");
}
cypherCreate.append("'" + fix.toString() + "'");
first = false;
}
}
cypherCreate.append("]");
if (ap.getDescription() != null && ap.getDescription().length() > 0) {
cypherCreate.append(", description:'");
cypherCreate.append(ap.getDescription());
cypherCreate.append("'");
}
cypherCreate.append("});");
Transaction tx = graphDb.beginTx();
graphDb.execute(cypherCreate.toString());
tx.success();
}
use of org.ff4j.exception.PropertyAlreadyExistException in project ff4j by ff4j.
the class PropertyStoreRedis method createProperty.
/**
* {@inheritDoc}
*/
public <T> void createProperty(Property<T> prop) {
Util.assertNotNull(prop);
if (existProperty(prop.getName())) {
throw new PropertyAlreadyExistException(prop.getName());
}
Jedis jedis = null;
try {
jedis = getJedis();
String name = prop.getName();
// Store the feature in the mapping bucket.
jedis.sadd(KEY_PROPERTY_MAP, name);
jedis.set(KEY_PROPERTY + name, prop.toJson());
jedis.persist(KEY_PROPERTY + name);
} finally {
if (jedis != null) {
jedis.close();
}
}
}
Aggregations