Commit 5e30905e authored by Ole Voldsæter's avatar Ole Voldsæter

fixes #2305

parent 9105a686
......@@ -6,16 +6,10 @@ import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import com.nesstar.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nesstar.api.Bank;
import com.nesstar.api.NesstarObject;
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 com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.ETagData;
......@@ -24,7 +18,7 @@ import com.nesstar.rest.common.ServerHandler;
public class CommonEntityTagFilter extends EntityTagFilter {
private static final Logger LOG = LoggerFactory.getLogger(CommonEntityTagFilter.class);
public CommonEntityTagFilter(ServerHandler serverHandler) {
super(serverHandler);
}
......@@ -32,7 +26,7 @@ public class CommonEntityTagFilter extends EntityTagFilter {
@Override
protected boolean checkForMatchingETag(HttpServletRequest request) {
boolean matches = false;
NesstarObject object = getObject(request);
if (object != null) {
ETag etag = getEtagFromResource(request, object);
......@@ -40,30 +34,30 @@ public class CommonEntityTagFilter extends EntityTagFilter {
}
return matches;
}
private NesstarObject getObject(HttpServletRequest request) {
String[] uriParts = getUriPartsFromRequest(request);
NesstarObject foundObject = null;
switch (uriParts.length) {
case 1:
if ("studies".equals(uriParts[0])) {
foundObject = getStudyList();
}
break;
case 2:
foundObject = getParticularObject(uriParts[0], uriParts[1]);
break;
case 3:
foundObject = getChildObjects(uriParts[0], uriParts[1], uriParts[2]);
break;
default:
break;
}
return foundObject;
}
......@@ -77,7 +71,7 @@ public class CommonEntityTagFilter extends EntityTagFilter {
}
return null;
}
private NesstarObject getParticularObject(String type, String id) {
try {
return getObjectFromBank(type, id);
......@@ -101,7 +95,7 @@ public class CommonEntityTagFilter extends EntityTagFilter {
}
return list;
}
private NesstarObject getObjectFromBank(String objectType, String id) throws IOException {
NesstarObject foundObject = null;
Server server = getServer();
......@@ -111,13 +105,13 @@ public class CommonEntityTagFilter extends EntityTagFilter {
}
return foundObject;
}
private NesstarObject getChildObjectFromParent(NesstarObject parent, String childType) throws NotAuthorizedException, IOException {
NesstarObject child = null;
if ("all-metadata".equalsIgnoreCase(childType)) {
child = parent;
} else if ("variables".equalsIgnoreCase(childType)) {
child = ((Study) parent).getVariables();
child = getVariablesFromParent(parent);
} else if ("variable-groups".equalsIgnoreCase(childType)) {
child = ((Study) parent).getVariableGroups();
} else if ("child-groups".equalsIgnoreCase(childType)) {
......@@ -125,8 +119,17 @@ public class CommonEntityTagFilter extends EntityTagFilter {
}
return child;
}
private NesstarObject getListOfObjectsFromBank(String listType) throws IOException, NotAuthorizedException {
private DdiList<Variable> getVariablesFromParent(NesstarObject parent) throws NotAuthorizedException, IOException {
if (parent instanceof Study) {
return ((Study) parent).getVariables();
} else if (parent instanceof VariableGroup) {
return ((VariableGroup) parent).getVariables();
}
throw new IllegalArgumentException("argument must be of type Study of VariableGroup");
}
private NesstarObject getListOfObjectsFromBank(String listType) throws IOException, NotAuthorizedException {
String type = translateListTypeToObjectType(listType);
if (type == null) {
throw new IOException();
......@@ -142,7 +145,7 @@ public class CommonEntityTagFilter extends EntityTagFilter {
private String translateListTypeToObjectType(String listType) {
String objectType = null;
if ("studies".equalsIgnoreCase(listType)) {
objectType = "study";
} else if ("variables".equalsIgnoreCase(listType)) {
......@@ -156,7 +159,7 @@ public class CommonEntityTagFilter extends EntityTagFilter {
private Bank getBankFromRequest(String type, Server server) {
Class klass = null;
Bank bank = null;
if ("study".equalsIgnoreCase(type)) {
klass = Study.class;
} else if ("variable".equalsIgnoreCase(type)) {
......
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