@GET @Path("/" + RESOURCE_FEATURES) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Display information regarding <b>Features</b>", response=FeatureApiBean.class) @ApiResponses(@ApiResponse(code = 200, message= "get all features")) public List < FeatureApiBean> readFeatures() { Feature[] storeContent = getFeatureStore().readAll().values().toArray(new Feature[0]); List < FeatureApiBean > apiBean = new ArrayList<FeatureApiBean>(); for (Feature feature : storeContent) { apiBean.add(new FeatureApiBean(feature)); } return apiBean; }
public Response upsertFeature(@Context HttpHeaders headers, @PathParam("uid") String id, FeatureApiBean fApiBean) { if ("".equals(id) || !id.equals(fApiBean.getUid())) { String errMsg = "Invalid identifier expected " + id; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); feat.setDescription(fApiBean.getDescription()); feat.setEnable(fApiBean.isEnable()); feat.setGroup(fApiBean.getGroup()); feat.setPermissions(new HashSet<String>(fApiBean.getPermissions())); FlippingStrategyApiBean flipApiBean = fApiBean.getFlippingStrategy(); if (flipApiBean != null) { try { Map<String, PropertyApiBean> mapProperties = fApiBean.getCustomProperties(); if (mapProperties != null) { for(PropertyApiBean propertyBean : mapProperties.values()) {
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @RolesAllowed({ROLE_READ}) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Read information about a feature", response=FeatureApiBean.class) @ApiResponses({ @ApiResponse(code = 200, message= "Information about features"), @ApiResponse(code = 404, message= "Feature not found") }) public Response read(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(new FeatureApiBean(ff4j.getFeatureStore().read(id))).build(); }
/** {@inheritDoc} */ @Override public void update(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } if (!exist(fp.getUid())) { throw new FeatureNotFoundException(fp.getUid()); } Response cRes = ClientHttpUtils .createRequest(getStore().path(fp.getUid()), authorizationHeaderValue, null) .put(Entity.entity(new FeatureApiBean(fp), MediaType.APPLICATION_JSON)); if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot update feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public void create(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } if (exist(fp.getUid())) { throw new FeatureAlreadyExistException(fp.getUid()); } /* Now can process upsert through PUT HTTP method Response cRes = getStore().path(fp.getUid())// .request(MediaType.APPLICATION_JSON) // .put(Entity.entity(new FeatureApiBean(fp), MediaType.APPLICATION_JSON));*/ Response cRes = ClientHttpUtils .createRequest(getStore().path(fp.getUid()), authorizationHeaderValue, null) .put(Entity.entity(new FeatureApiBean(fp), MediaType.APPLICATION_JSON)); // Check response code CREATED or raised error if (Status.CREATED.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot create feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ @Override public void create(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } if (exist(fp.getUid())) { throw new FeatureAlreadyExistException(fp.getUid()); } // Now can process upsert through PUT HTTP method ClientResponse cRes = getStore().path(fp.getUid())// .type(MediaType.APPLICATION_JSON) // .put(ClientResponse.class, new FeatureApiBean(fp)); // Check response code CREATED or raised error if (Status.CREATED.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot create feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@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); } }