Search in sources :

Example 1 with FF4jCacheProxy

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);
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) HomeBean(org.ff4j.web.bean.HomeBean) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory)

Example 2 with FF4jCacheProxy

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();
}
Also used : FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) FeatureStoreNotCached(org.ff4j.services.exceptions.FeatureStoreNotCached)

Example 3 with FF4jCacheProxy

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);
}
Also used : InMemoryCacheManager(org.ff4j.cache.InMemoryCacheManager) FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Given(cucumber.api.java.en.Given)

Example 4 with FF4jCacheProxy

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;
}
Also used : FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy)

Example 5 with FF4jCacheProxy

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();
}
Also used : FF4jCacheProxy(org.ff4j.cache.FF4jCacheProxy) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)21 InMemoryCacheManager (org.ff4j.cache.InMemoryCacheManager)9 Test (org.junit.Test)9 Given (cucumber.api.java.en.Given)5 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)5 PropertyString (org.ff4j.property.PropertyString)3 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashSet (java.util.HashSet)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 FF4JCacheManager (org.ff4j.cache.FF4JCacheManager)2 Feature (org.ff4j.core.Feature)2 FeatureStore (org.ff4j.core.FeatureStore)2 Property (org.ff4j.property.Property)2 FileItem (org.apache.commons.fileupload.FileItem)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1