use of org.ff4j.cache.FF4jCacheProxy in project ff4j by ff4j.
the class HomeController method post.
/**
* {@inheritDoc}
*/
public void post(HttpServletRequest req, HttpServletResponse res, WebContext ctx) throws Exception {
String msg = null;
String msgType = "success";
String operation = req.getParameter(WebConstants.OPERATION);
// Upload XML File
if (ServletFileUpload.isMultipartContent(req)) {
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(req);
for (FileItem item : items) {
if (item.isFormField()) {
if (OPERATION.equalsIgnoreCase(item.getFieldName())) {
LOGGER.info("Processing action : " + item.getString());
}
} else if (FLIPFILE.equalsIgnoreCase(item.getFieldName())) {
String filename = FilenameUtils.getName(item.getName());
if (filename.toLowerCase().endsWith("xml")) {
try {
importFile(getFf4j(), item.getInputStream());
msg = "The file <b>" + filename + "</b> has been successfully imported";
} catch (RuntimeException re) {
msgType = ERROR;
msg = "Cannot Import XML:" + re.getMessage();
break;
}
} else {
msgType = ERROR;
msg = "Invalid FILE, must be CSV, XML or PROPERTIES files";
}
}
}
ctx.setVariable("msgType", msgType);
ctx.setVariable("msgInfo", msg);
get(req, res, ctx);
} else if (WebConstants.OP_CREATE_SCHEMA.equalsIgnoreCase(operation)) {
try {
getFf4j().createSchema();
msg = "Schema has been created in DB (if required).";
ctx.setVariable("msgType", msgType);
ctx.setVariable("msgInfo", msg);
get(req, res, ctx);
} catch (RuntimeException re) {
ctx.setVariable("msgType", ERROR);
ctx.setVariable("msgInfo", "Cannot create Schema:" + re.getMessage());
ctx.setVariable(KEY_TITLE, "Home");
ctx.setVariable("today", Calendar.getInstance());
ctx.setVariable("homebean", new HomeBean());
}
} else if (WebConstants.OP_CLEAR_CACHE.equalsIgnoreCase(operation)) {
FF4jCacheProxy cacheProxy = getFf4j().getCacheProxy();
if (cacheProxy != null) {
cacheProxy.getCacheManager().clearFeatures();
cacheProxy.getCacheManager().clearProperties();
msg = "Cache Cleared!";
} else {
msg = "Cache not present: it cannot be cleared!";
}
ctx.setVariable("msgType", msgType);
ctx.setVariable("msgInfo", msg);
get(req, res, ctx);
}
}
use of org.ff4j.cache.FF4jCacheProxy in project ff4j by ff4j.
the class FeatureStoreServices method clearCachedFeatureStore.
public void clearCachedFeatureStore() {
// Fixing #218 : If audit is enabled, cannot clear cache.
FF4jCacheProxy cacheProxy = ff4j.getCacheProxy();
if (cacheProxy == null) {
throw new FeatureStoreNotCached();
}
cacheProxy.getCacheManager().clearFeatures();
}
use of org.ff4j.cache.FF4jCacheProxy in project ff4j by ff4j.
the class FeatureStoreServicesStepDef method the_feature_store_is_cached.
@Given("^the feature store is cached$")
public void the_feature_store_is_cached() throws Throwable {
FF4jCacheProxy proxy = new FF4jCacheProxy(ff4j.getFeatureStore(), null, new InMemoryCacheManager());
ff4j.setFeatureStore(proxy);
}
use of org.ff4j.cache.FF4jCacheProxy in project ff4j by ff4j.
the class FF4j method cache.
/**
* Enable a cache proxy.
*
* @param cm
* current cache manager
* @return
* current ff4j bean
*/
public FF4j cache(FF4JCacheManager cm) {
FF4jCacheProxy cp = new FF4jCacheProxy(getFeatureStore(), getPropertiesStore(), cm);
setFeatureStore(cp);
setPropertiesStore(cp);
return this;
}
use of org.ff4j.cache.FF4jCacheProxy in project ff4j by ff4j.
the class FeatureStoreResource method clear.
/**
* POST Operation to clean cache.
*/
@POST
@Path("/" + RESOURCE_CACHE)
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Clear Cache", response = Response.class)
@ApiResponses({ @ApiResponse(code = 200, message = "cache is cleard"), @ApiResponse(code = 404, message = "no cache content provided") })
public Response clear() {
FF4jCacheProxy cacheProxy = ff4j.getCacheProxy();
if (cacheProxy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Current Store is not cached").build();
}
cacheProxy.getCacheManager().clearFeatures();
return Response.ok("Cache has been cleared").build();
}
Aggregations