<commit_before>package com.github.dgautier.icn.plugin;

import com.filenet.api.core.ObjectStore;
import com.github.dgautier.icn.ICNLogger;
import com.github.dgautier.icn.PluginUtils;
import com.github.dgautier.icn.RequestParameters;
import com.github.dgautier.icn.model.json.JsonUtils;
import com.ibm.ecm.extension.PluginResponseFilter;
import com.ibm.ecm.extension.PluginServiceCallbacks;
import com.ibm.json.java.JSONObject;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by DGA on 22/01/2015.
 */
public abstract class AbstractPluginResponseFilter extends PluginResponseFilter {

    private ICNLogger logger;
    private String service;
    private PluginServiceCallbacks callbacks;
    private HttpServletRequest request;
    private JSONObject json;

    protected ObjectStore getObjectStore() {
        return PluginUtils.getObjectStore(getService(),getLogger(),getCallbacks(), getRequest());
    }

    /**
     * FIXME find a way to avoid having to implement this in PluginService, ResponseFilter, RequestFilter etc..
     * @param key
     * @return
     * @throws Exception
     */
    protected String getConfiguration(String key) throws Exception {
        getLogger().debug("AbstractPluginResponseFilter","getConfiguration","Configuration= " + getCallbacks().loadConfiguration());

        return JsonUtils.getConfiguration(getCallbacks().loadConfiguration(), key);
    }


    @Override
    public void filter(String service, PluginServiceCallbacks callbacks,
                       HttpServletRequest request, JSONObject jsonObject) throws Exception {

        this.service = service;
        this.callbacks = callbacks;
        this.request = request;
        this.json = jsonObject;
        this.logger = new ICNLogger(callbacks.getLogger(), request);

        PluginUtils.print(getLogger(), getRequest());
        getLogger().debug(this,"filter","filteringService="+service);
        getLogger().debug(this,"filter","jsonObject="+getJson().toString());
        filter();
    }
    
    public abstract void filter() throws Exception;

    protected ICNLogger getLogger() {
        return logger;
    }

    protected JSONObject getJson() {<commit_msg>Added getDesktop utilityMethod to retrieve Desktop Id<commit_after>package com.github.dgautier.icn.plugin;

import com.filenet.api.core.ObjectStore;
import com.github.dgautier.icn.ICNLogger;
import com.github.dgautier.icn.PluginUtils;
import com.github.dgautier.icn.RequestParameters;
import com.github.dgautier.icn.model.json.JsonUtils;
import com.ibm.ecm.extension.PluginResponseFilter;
import com.ibm.ecm.extension.PluginServiceCallbacks;
import com.ibm.json.java.JSONObject;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by DGA on 22/01/2015.
 */
public abstract class AbstractPluginResponseFilter extends PluginResponseFilter {

    private ICNLogger logger;
    private String service;
    private PluginServiceCallbacks callbacks;
    private HttpServletRequest request;
    private JSONObject json;

    protected ObjectStore getObjectStore() {
        return PluginUtils.getObjectStore(getService(),getLogger(),getCallbacks(), getRequest());
    }

    /**
     * FIXME find a way to avoid having to implement this in PluginService, ResponseFilter, RequestFilter etc..
     * @param key
     * @return
     * @throws Exception
     */
    protected String getConfiguration(String key) throws Exception {
        getLogger().debug("AbstractPluginResponseFilter","getConfiguration","Configuration= " + getCallbacks().loadConfiguration());

        return JsonUtils.getConfiguration(getCallbacks().loadConfiguration(), key);
    }


    @Override
    public void filter(String service, PluginServiceCallbacks callbacks,
                       HttpServletRequest request, JSONObject jsonObject) throws Exception {

        this.service = service;
        this.callbacks = callbacks;
        this.request = request;
        this.json = jsonObject;
        this.logger = new ICNLogger(callbacks.getLogger(), request);

        PluginUtils.print(getLogger(), getRequest());
        getLogger().debug(this,"filter","filteringService="+service);
        getLogger().debug(this,"filter","jsonObject="+getJson().toString());
        filter();
    }

    // TODO create common class to handle this method
    protected String getDesktop(){
        return getRequest().getParameter("desktop");
    }
    
    public abstract void filter() throws Exception;

    protected ICNLogger getLogger() {
        return logger;
    }

    protected JSONObject getJson() {
{'fraction_non_alphanumeric': 0.10129357597018197, 'fraction_numerical': 0.0035080026310019734, 'mean_word_length': 3.752083333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673028', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1174, 'n_words': 273}