Commit e1494095 authored by Yong Liu's avatar Yong Liu

This commit fixes #2627, Correlation/regression gives error messages.

parent 9ebf4c86
package com.nesstar.rest.common;
import com.nesstar.api.Bank;
import com.nesstar.api.NotAuthorizedException;
import com.nesstar.api.Server;
import com.nesstar.api.Study;
import com.nesstar.api.Variable;
import com.nesstar.api.VariableGroup;
import com.nesstar.api.cube.Cube;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.xpath.XPathExpressionException;
public final class ResourceExtractor {
private ResourceExtractor() {
......@@ -38,6 +42,22 @@ public final class ResourceExtractor {
}
}
public static void checkVariableMustBeNumeric(Variable var) throws NotAuthorizedException, IOException, MissingResourceException {
try {
if (!"numeric".equalsIgnoreCase(var.getElement("./varFormat/@type").toString())) {
throw new MissingResourceException("Variable " + var.getId() + " is not numeric.");
}
} catch (XPathExpressionException e) {
throw new MissingResourceException("Variable " + var.getId() + " is not numeric.");
}
}
public static void checkVariablesMustBeNumeric(Collection<Variable> vars) throws NotAuthorizedException, IOException, MissingResourceException {
for (Variable var : vars) {
checkVariableMustBeNumeric(var);
}
}
private static Variable getVariable(Bank<Variable> variableBank, String variableId) throws MissingResourceException {
Variable variable = variableBank.get(variableId);
if (variable == null) {
......@@ -77,5 +97,5 @@ public final class ResourceExtractor {
throw new MissingResourceException(getErrorMessage("cude", cubeId));
}
return cube;
}
}
}
......@@ -59,6 +59,7 @@ public final class CorrelationResource extends AbstractResource {
classVariables.setServer(serverHandler.getServer());
classVariables.setStudy(ResourceExtractor.getStudy(studyId, classVariables.getServer()));
classVariables.setCorrelationVariables(ResourceExtractor.getVariables(correlationVariables, classVariables.getServer()));
ResourceExtractor.checkVariablesMustBeNumeric(classVariables.getCorrelationVariables());
classVariables.setWeightVariables(ResourceExtractor.getVariables(weightVariables, classVariables.getServer()));
classVariables.setCaseSubsetExpression(caseSubset);
if (missingDeletion != null) {
......
......@@ -66,7 +66,9 @@ public final class RegressionResource extends AbstractResource {
Server server = classVariables.getServer();
classVariables.setStudy(ResourceExtractor.getStudy(studyId, server));
classVariables.setDependentVariable(ResourceExtractor.getVariable(dependentVariable, server));
ResourceExtractor.checkVariableMustBeNumeric(classVariables.getDependentVariable());
classVariables.setIndependentVariables(ResourceExtractor.getVariables(independentVariables, server));
ResourceExtractor.checkVariablesMustBeNumeric(classVariables.getIndependentVariables());
classVariables.setWeightVariables(ResourceExtractor.getVariables(weightVariables, server));
classVariables.setCaseSubsetExpression(caseSubset);
if (missingDeletion != null) {
......
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