Commit f001af57 authored by Feng Xue's avatar Feng Xue

Add correlation, regression filter

Add correlation, regression filters to project
The project will response with code 304 with the same request

Fixes ##2075
parent e501c198
package com.nesstar.rest;
import com.nesstar.rest.filters.TabulationEntityTagFilter;
import com.nesstar.rest.filters.CommonEntityTagFilter;
import com.nesstar.rest.filters.CubeEntityTagFilter;
import com.nesstar.rest.filters.LanguageFilter;
import com.nesstar.rest.filters.EntityTagFilter;
import com.nesstar.rest.filters.*;
import com.nesstar.rest.resources.SearchResource;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlets.CrossOriginFilter;
......@@ -71,6 +67,12 @@ public final class NesstarDropService extends Service<NesstarDropConfiguration>
final TabulationEntityTagFilter tabulationETagFilter = new TabulationEntityTagFilter(serverHandler);
environment.addFilter(tabulationETagFilter, "/study/*");
final CorrelationEntityTagFilter correlationEntityTagFilter = new CorrelationEntityTagFilter(serverHandler);
environment.addFilter(correlationEntityTagFilter, "/study/*");
final RegressionEntityTagFilter regressionEntityTagFilter = new RegressionEntityTagFilter(serverHandler);
environment.addFilter(regressionEntityTagFilter, "/study/*");
final CubeEntityTagFilter cubeETagFilter = new CubeEntityTagFilter(serverHandler);
environment.addFilter(cubeETagFilter, "/cube/*");
......
package com.nesstar.rest.filters;
import com.nesstar.api.Study;
import com.nesstar.api.Variable;
import com.nesstar.rest.common.ETagData;
import com.nesstar.rest.common.MissingResourceException;
import com.nesstar.rest.common.ResourceExtractor;
import com.nesstar.rest.common.ServerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public class CorrelationEntityTagFilter extends OperationEntityTagFilter {
private static final Logger LOG = LoggerFactory.getLogger(CorrelationEntityTagFilter.class);
public CorrelationEntityTagFilter(ServerHandler serverHandler) {
super(serverHandler);
}
@Override
protected ETagData generateETagData(final HttpServletRequest request) {
ETagData data = new ETagData();
String url = request.getRequestURL().toString();
data.add(url);
Study study = getStudy(request);
if (study != null) {
data.add(study);
}
List<Variable> correlationVariables = getCorrelationVariables(request);
List<Variable> weightVariables = getWeightVariables(request);
for (Variable variable : correlationVariables) {
data.add(variable);
}
for (Variable weightVariable : weightVariables) {
data.add(weightVariable);
}
data.add(getCaseSubset(request));
data.add(getMissDeletion(request));
return data;
}
private List<Variable> getCorrelationVariables(HttpServletRequest request) {
String[] variableIDs = getVariableIDs(request, "corrVar");
try {
return ResourceExtractor.getVariables(variableIDs, getServer());
} catch (MissingResourceException e) {
LOG.warn("Missing variables");
} catch (IOException e) {
LOG.warn("IOException when getting correlation variables");
}
return new LinkedList<Variable>();
}
private List<Variable> getWeightVariables(HttpServletRequest request) {
String[] weightVariableIDs = getVariableIDs(request, "wgtVar");
try {
return ResourceExtractor.getVariables(weightVariableIDs, getServer());
} catch (MissingResourceException e) {
LOG.warn("Missing weight variables");
} catch (IOException e) {
LOG.warn("IOException when getting weight variables");
}
return null;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// No implementation necessary
}
@Override
public void destroy() {
// No implementation necessary
}
}
......@@ -55,6 +55,23 @@ public abstract class OperationEntityTagFilter extends EntityTagFilter {
return null;
}
protected String[] getVariableIDs(HttpServletRequest request, String queryName) {
String[] vars = request.getParameterValues(queryName);
if (vars == null) {
vars = new String[0];
}
return vars;
}
protected String getCaseSubset(HttpServletRequest request) {
return request.getParameter("caseSubset");
}
protected String getMissDeletion(HttpServletRequest request) {
return request.getParameter("missDeletion");
}
protected abstract ETagData generateETagData(final HttpServletRequest request);
@Override
......
package com.nesstar.rest.filters;
import com.nesstar.api.Study;
import com.nesstar.api.Variable;
import com.nesstar.rest.common.ETagData;
import com.nesstar.rest.common.MissingResourceException;
import com.nesstar.rest.common.ResourceExtractor;
import com.nesstar.rest.common.ServerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public class RegressionEntityTagFilter extends OperationEntityTagFilter{
private static final Logger LOG = LoggerFactory.getLogger(RegressionEntityTagFilter.class);
public RegressionEntityTagFilter(ServerHandler serverHandler) {
super(serverHandler);
}
@Override
protected ETagData generateETagData(final HttpServletRequest request) {
ETagData data = new ETagData();
String url = request.getRequestURL().toString();
data.add(url);
Study study = getStudy(request);
if (study != null) {
data.add(study);
}
List<Variable> correlationVariables = getIndependentVariables(request);
List<Variable> weightVariables = getWeightVariables(request);
for (Variable variable : correlationVariables) {
data.add(variable);
}
for (Variable weightVariable : weightVariables) {
data.add(weightVariable);
}
data.add(getDependentVariable(request));
data.add(getCaseSubset(request));
data.add(getMissDeletion(request));
return data;
}
private List<Variable> getIndependentVariables(HttpServletRequest request) {
String[] variableIDs = getVariableIDs(request, "indVar");
try {
return ResourceExtractor.getVariables(variableIDs, getServer());
} catch (MissingResourceException e) {
LOG.warn("Missing variables");
} catch (IOException e) {
LOG.warn("IOException when getting independent variables");
}
return new LinkedList<Variable>();
}
private Variable getDependentVariable(HttpServletRequest request) {
String id = request.getParameter("depVar");
try {
return ResourceExtractor.getVariable(id, getServer());
} catch (MissingResourceException e) {
LOG.warn("Missing variable {}", id);
} catch (IOException e) {
LOG.warn("IOException when getting dependent variable");
}
return null;
}
private List<Variable> getWeightVariables(HttpServletRequest request) {
String[] weightVariableIDs = getVariableIDs(request, "wgtVar");
try {
return ResourceExtractor.getVariables(weightVariableIDs, getServer());
} catch (MissingResourceException e) {
LOG.warn("Missing weight variables");
} catch (IOException e) {
LOG.warn("IOException when getting weight variables");
}
return null;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// No implementation necessary
}
@Override
public void destroy() {
// No implementation necessary
}
}
......@@ -92,15 +92,6 @@ public class TabulationEntityTagFilter extends OperationEntityTagFilter {
}
}
private String[] getVariableIDs(HttpServletRequest request, String queryName) {
String[] vars = request.getParameterValues(queryName);
if (vars == null) {
vars = new String[0];
}
return vars;
}
private Variable getMeasureVariable(HttpServletRequest request) {
String id = request.getParameter("mrsVar");
try {
......@@ -145,10 +136,6 @@ public class TabulationEntityTagFilter extends OperationEntityTagFilter {
return null;
}
private String getCaseSubset(HttpServletRequest request) {
return request.getParameter("caseSubset");
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// No implementation necessary
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment