use of org.ff4j.web.api.resources.domain.PropertyApiBean in project ff4j by ff4j.
the class PropertiesResourceTestIT method testGet.
/**
* TDD.
*/
@Test
public void testGet() {
// Given
// When
WebResource wResFeatures = rscProperties();
ClientResponse httpResponse = wResFeatures.get(ClientResponse.class);
List<PropertyApiBean> fList = httpResponse.getEntity(new GenericType<List<PropertyApiBean>>() {
});
// Then, HTTPResponse
Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), httpResponse.getStatus());
Assert.assertNotNull(fList);
// Then, Entity Object
Assert.assertFalse(fList.isEmpty());
}
use of org.ff4j.web.api.resources.domain.PropertyApiBean 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.web.api.resources.domain.PropertyApiBean in project ff4j by ff4j.
the class PropertyStoreResource method readProperties.
@GET
@Path("/" + RESOURCE_PROPERTIES)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display information regarding <b>Properties</b>", response = PropertyApiBean.class)
@ApiResponses(@ApiResponse(code = 200, message = "get all Properties"))
public List<PropertyApiBean> readProperties() {
List<PropertyApiBean> apiBean = new ArrayList<PropertyApiBean>();
getPropertyStore().readAllProperties();
for (Property<?> prop : getPropertyStore().readAllProperties().values()) {
apiBean.add(new PropertyApiBean(prop));
}
return apiBean;
}
use of org.ff4j.web.api.resources.domain.PropertyApiBean 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.web.api.resources.domain.PropertyApiBean in project ff4j by ff4j.
the class FeatureResource method upsertFeature.
/**
* Create the feature if not exist or update it
*
* @param headers
* current request header
* @param data
* feature serialized as JSON
* @return 204 or 201
*/
@PUT
@RolesAllowed({ ROLE_WRITE })
@ApiOperation(value = "Create of update a feature", response = Response.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = 201, message = "Feature has been created"), @ApiResponse(code = 204, message = "No content, feature is updated") })
public Response upsertFeature(@Context HttpHeaders headers, @PathParam("uid") String id, FeatureApiBean fApiBean) {
// Parameter validations
if ("".equals(id) || !id.equals(fApiBean.getUid())) {
String errMsg = "Invalid identifier expected " + id;
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
}
Feature feat = new Feature(id);
feat.setDescription(fApiBean.getDescription());
feat.setEnable(fApiBean.isEnable());
feat.setGroup(fApiBean.getGroup());
feat.setPermissions(new HashSet<String>(fApiBean.getPermissions()));
// Flipping Strategy
FlippingStrategyApiBean flipApiBean = fApiBean.getFlippingStrategy();
if (flipApiBean != null) {
try {
Map<String, String> initparams = flipApiBean.getInitParams();
feat.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(id, flipApiBean.getType(), initparams));
} catch (Exception e) {
String errMsg = "Cannot read Flipping Strategy, does not seems to have a DEFAULT constructor, " + e.getMessage();
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
}
}
// Properties
Map<String, PropertyApiBean> mapProperties = fApiBean.getCustomProperties();
if (mapProperties != null) {
for (PropertyApiBean propertyBean : mapProperties.values()) {
feat.addProperty(propertyBean.asProperty());
}
}
// Update or create ?
if (!getFeatureStore().exist(feat.getUid())) {
getFeatureStore().create(feat);
String location = String.format("%s", uriInfo.getAbsolutePath().toString());
try {
return Response.created(new URI(location)).build();
} catch (URISyntaxException e) {
return Response.status(Response.Status.CREATED).header(LOCATION, location).entity(id).build();
}
}
// Create
getFeatureStore().update(feat);
return Response.noContent().build();
}
Aggregations