public EventRepositoryApiBean(EventRepository evtRepository, Long start, Long end) { type = evtRepository.getClass().getName(); EventQueryDefinition query = new EventQueryDefinition(); if (start != null) { query.setFrom(start); } if (end != null) { query.setTo(end); } // Create PIE eventsPie = new PieChartApiBean(evtRepository.getFeatureUsagePieChart(query)); // Create BARCHART barChart = new BarChartApiBean(evtRepository.getFeatureUsageBarChart(query)); // Total Count for (PieSectorApiBean sector : eventsPie.getSectors()) { hitCount += sector.getValue(); } }
/** * Constructor for the API. * * @param pie * target pie */ public PieChartApiBean(PieChart pie) { title = pie.getTitle(); for (Serie<Integer> pieSector : pie.getSectors()) { sectors.add(new PieSectorApiBean(pieSector)); } }
/** * Provide core information on ff4J and available sub resources. * @return * status bean */ @GET @ApiOperation( value= "Display <b>ff4j</b> status overview", notes= "Display informations related to <b>Monitoring</b>, <b>Security</b>, <b>Cache</b> and <b>Store</b>") @ApiResponses( @ApiResponse(code = 200, message= "Success, return status of ff4j instance", response=FF4jStatusApiBean.class)) @Produces(MediaType.APPLICATION_JSON) public FF4jStatusApiBean getStatus() { return new FF4jStatusApiBean(ff4j); }
FeatureMonitoringApiBean fmab = new FeatureMonitoringApiBean(uid); int hitcount = 0; for (PieSectorApiBean sec : fmab.getEventsPie().getSectors()) { hitcount+= sec.getValue(); fmab.setHitCount(hitcount); return Response.ok().entity(fmab).build();
/** * Copy constructor. * * @param f * * target feature */ public FeatureApiBean(Feature f) { this.uid = f.getUid(); this.enable = f.isEnable(); this.description = f.getDescription(); this.group = f.getGroup(); this.permissions = new ArrayList<String>(f.getPermissions()); if (f.getFlippingStrategy() != null) { this.flippingStrategy = new FlippingStrategyApiBean(f.getFlippingStrategy()); } if (f.getCustomProperties() != null) { for (Property<?> ap1 : f.getCustomProperties().values()) { customProperties.put(ap1.getName(), new PropertyApiBean(ap1)); } } }
/** {@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); } }
@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; }
version = ff4j.getVersion(); if (null != ff4j.getFeatureStore()) { featuresStore = new FeatureStoreApiBean(ff4j.getFeatureStore()); eventRepository = new EventRepositoryApiBean(ff4j.getEventRepository(), null, null); authorizationsManager = new AuthorizationsManagerApiBean(ff4j.getAuthorizationsManager());
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @ApiOperation( value= "Display information regarding to <b>Features</b>", notes= "other sub resources to be displayed", response=FeatureStoreApiBean.class) @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean")) @Produces(MediaType.APPLICATION_JSON) public FeatureStoreApiBean get() { return new FeatureStoreApiBean(ff4j.getFeatureStore()); }
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @ApiOperation( value= "Display information regarding to <b>Properties</b>", notes= "other sub resources to be displayed", response=FeatureStoreApiBean.class) @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean")) @Produces(MediaType.APPLICATION_JSON) public PropertyStoreApiBean get() { return new PropertyStoreApiBean(ff4j.getPropertiesStore()); }
/** * Constructor from its feature store. * * @param featureStore * cuurent fature store */ public PropertyStoreApiBean(PropertyStore pStore) { type = pStore.getClass().getName(); if (pStore instanceof FF4jCacheProxy) { cache = new CacheApiBean(pStore); } properties = pStore.listPropertyNames(); numberOfProperties = properties.size(); }
/** * Display security resources. * * @return * api bean, representation of authorization manager */ @GET @Path("/" + RESOURCE_SECURITY) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Display <b>Security</b> informations (permissions manager)", notes="Security is implemented through dedicated <b>AuthorizationsManager</b> but it's not mandatory") @ApiResponses({ @ApiResponse(code = 200, message= "Status of current ff4j security bean", response=AuthorizationsManagerApiBean.class), @ApiResponse(code = 404, message= "No security defined, no response") }) public Response getSecurityStatus() { AuthorizationsManager authMgner = ff4j.getAuthorizationsManager(); if (null == authMgner) { return Response.status(Status.NOT_FOUND).entity("No security has been defined").build(); } return Response.ok(new AuthorizationsManagerApiBean(authMgner)).build(); }
/** {@inheritDoc} */ @Override public Set<String> readAllGroups() { ClientResponse cRes = getGroups().get(ClientResponse.class); List<GroupDescApiBean> groupApiBeans = cRes.getEntity(new GenericType<List<GroupDescApiBean>>() {}); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot read groups, an HTTP error " + cRes.getStatus() + OCCURED); } Set < String > groupNames = new HashSet<String>(); for (GroupDescApiBean groupApiBean : groupApiBeans) { groupNames.add(groupApiBean.getGroupName()); } return groupNames; }
/** {@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); } }
/** {@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); } }
@POST @Path("/" + STORE_CLEAR) @ApiOperation(value= "Delete all <b>Features</b> in store") @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean", response=FeatureStoreApiBean.class)) @Produces(MediaType.APPLICATION_JSON) public FeatureStoreApiBean clearFeatures() { getFeatureStore().clear(); return new FeatureStoreApiBean(ff4j.getFeatureStore()); }
@POST @Path("/" + STORE_CLEAR) @ApiOperation(value= "Delete all <b>Properties</b> in store") @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean", response=PropertyStoreApiBean.class)) @Produces(MediaType.APPLICATION_JSON) public PropertyStoreApiBean clearProperties() { getPropertyStore().clear(); return new PropertyStoreApiBean(ff4j.getPropertiesStore()); }
/** * Constructor from its feature store. * * @param featureStore * cuurent fature store */ public FeatureStoreApiBean(FeatureStore featureStore) { type = featureStore.getClass().getName(); if (featureStore instanceof FF4jCacheProxy) { cache = new CacheApiBean(featureStore); } features = new ArrayList<String>(featureStore.readAll().keySet()); groups = new ArrayList<String>(featureStore.readAllGroups()); numberOfFeatures = features.size(); numberOfGroups = groups.size(); }
@POST @Path("/" + STORE_CREATESCHEMA) @ApiOperation(value= "Create underlying DB schema for store") @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean", response=PropertyStoreApiBean.class)) @Produces(MediaType.APPLICATION_JSON) public FeatureStoreApiBean createSchema() { getFeatureStore().createSchema(); return new FeatureStoreApiBean(ff4j.getFeatureStore()); }
@POST @Path("/" + STORE_CREATESCHEMA) @ApiOperation(value= "Create underlying DB schema for store") @ApiResponses(@ApiResponse(code = 200, message= "status of current ff4j bean", response=PropertyStoreApiBean.class)) @Produces(MediaType.APPLICATION_JSON) public PropertyStoreApiBean createSchema() { getPropertyStore().createSchema(); return new PropertyStoreApiBean(ff4j.getPropertiesStore()); }