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

fixes #2305

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