Implementing limit offset

This commit is contained in:
luca.frosini 2023-09-18 18:09:00 +02:00
parent 95b86d8a40
commit d2ca74cc72
6 changed files with 91 additions and 32 deletions

View File

@ -50,6 +50,14 @@ public class ServerRequestInfo extends BaseRequestInfo implements RequestInfo {
case InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER: case InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER:
// TODO check is the user has the role to request such parameter // TODO check is the user has the role to request such parameter
return true; return true;
case InstancePath.LIMIT_QUERY_PARAMETER:
// TODO check is the user has the role to request such parameter
return true;
case InstancePath.OFFSET_QUERY_PARAMETER:
// TODO check is the user has the role to request such parameter
return true;
default: default:
break; break;
@ -62,27 +70,34 @@ public class ServerRequestInfo extends BaseRequestInfo implements RequestInfo {
* Set the parameter if the user is allowed otherwise the default is maintained * Set the parameter if the user is allowed otherwise the default is maintained
* @param queryParameterKey requested query parameter * @param queryParameterKey requested query parameter
* @param bool the value to set * @param bool the value to set
* @return the value of variable corresponding the request parameter independetly if * @return the value of variable corresponding the request parameter
* the value has been set. * independently if the value has been set.
*/ */
public boolean setIfAllowed(String queryParameterKey, boolean bool) { public boolean setIfAllowed(String queryParameterKey, boolean bool) {
boolean toBeSet = bool && isAllowed(queryParameterKey);
switch (queryParameterKey) { switch (queryParameterKey) {
case InstancePath.INCLUDE_META_QUERY_PARAMETER: case InstancePath.INCLUDE_META_QUERY_PARAMETER:
includeMeta = toBeSet; if(isAllowed(queryParameterKey)) {
includeMeta = bool;
}
return includeMeta; return includeMeta;
case InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER: case InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER:
allMeta = toBeSet; if(isAllowed(queryParameterKey)) {
allMeta = bool;
}
return allMeta; return allMeta;
case InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER: case InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER:
includeContexts = toBeSet; if(isAllowed(queryParameterKey)) {
includeContexts = bool;
}
return includeContexts; return includeContexts;
case InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER: case InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER:
hierarchicalMode = toBeSet; if(isAllowed(queryParameterKey)) {
hierarchicalMode = bool;
}
return hierarchicalMode; return hierarchicalMode;
default: default:
@ -92,7 +107,36 @@ public class ServerRequestInfo extends BaseRequestInfo implements RequestInfo {
return false; return false;
} }
public void checkQueryParameter(String queryParameterKey) { /**
* Set the parameter if the user is allowed otherwise the default is maintained
* @param queryParameterKey requested query parameter
* @param integer the int value to set
* @return the value of variable corresponding the request parameter independently if
* the value has been set.
*/
public int setIfAllowed(String queryParameterKey, int integer) {
switch (queryParameterKey) {
case InstancePath.LIMIT_QUERY_PARAMETER:
if(isAllowed(queryParameterKey)) {
limit = integer;
}
return limit;
case InstancePath.OFFSET_QUERY_PARAMETER:
if(isAllowed(queryParameterKey)) {
offset = integer;
}
return offset;
default:
break;
}
return -1;
}
public void checkBooleanQueryParameter(String queryParameterKey) {
try { try {
List<String> queryParameterList = uriInfo.getQueryParameters().get(queryParameterKey); List<String> queryParameterList = uriInfo.getQueryParameters().get(queryParameterKey);
if(queryParameterList!=null && queryParameterList.size()>0) { if(queryParameterList!=null && queryParameterList.size()>0) {
@ -105,27 +149,42 @@ public class ServerRequestInfo extends BaseRequestInfo implements RequestInfo {
} }
} }
public void checkIntegerQueryParameter(String queryParameterKey) {
try {
List<String> queryParameterList = uriInfo.getQueryParameters().get(queryParameterKey);
if(queryParameterList!=null && queryParameterList.size()>0) {
String intString = queryParameterList.get(0);
int integer = Integer.valueOf(intString);
setIfAllowed(queryParameterKey, integer);
}
}catch (Throwable t) {
logger.warn("Unable to properly set the Hierarchical Mode is set", t.getMessage());
}
}
public void setUriInfo(UriInfo uriInfo) { public void setUriInfo(UriInfo uriInfo) {
this.uriInfo = uriInfo; this.uriInfo = uriInfo;
} }
public void checkAllQueryParameters() { public void checkAllQueryParameters() {
checkIncludeQueryParameters(); checkIncludeQueryParameters();
checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER); checkBooleanQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
} }
public void checkIncludeQueryParameters() { public void checkIncludeQueryParameters() {
checkIncludeAllMetaQueryParameters(); checkIncludeAllMetaQueryParameters();
checkQueryParameter(InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER); checkBooleanQueryParameter(InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER);
} }
public void checkIncludeAllMetaQueryParameters() { public void checkIncludeAllMetaQueryParameters() {
checkQueryParameter(InstancePath.INCLUDE_META_QUERY_PARAMETER); checkBooleanQueryParameter(InstancePath.INCLUDE_META_QUERY_PARAMETER);
checkQueryParameter(InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER); checkBooleanQueryParameter(InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER);
} }
public void checkLimitOffset() {
checkIntegerQueryParameter(InstancePath.LIMIT_QUERY_PARAMETER);
checkIntegerQueryParameter(InstancePath.OFFSET_QUERY_PARAMETER);
}
} }

View File

@ -81,7 +81,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
return contextManagement.all(false); return contextManagement.all(false);
@ -104,7 +104,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid)); contextManagement.setUUID(UUID.fromString(uuid));
@ -127,7 +127,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER);
TypeManagement typeManagement = new TypeManagement(); TypeManagement typeManagement = new TypeManagement();
typeManagement.setTypeName(type); typeManagement.setTypeName(type);
@ -152,7 +152,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement(); QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
return queryTemplateManagement.all(false); return queryTemplateManagement.all(false);
@ -172,7 +172,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement(); QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
queryTemplateManagement.setName(queryTemplateName); queryTemplateManagement.setName(queryTemplateName);
@ -239,7 +239,7 @@ public class Access extends BaseRest {
setAccountingMethod(Method.EXIST, InstancesManager.INSTANCE); setAccountingMethod(Method.EXIST, InstancesManager.INSTANCE);
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type); ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
@ -338,7 +338,7 @@ public class Access extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
if(raw) { if(raw) {
// TODO Check if the role allow to request raw data // TODO Check if the role allow to request raw data
serverRequestInfo.checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
}else { }else {
serverRequestInfo.checkAllQueryParameters(); serverRequestInfo.checkAllQueryParameters();
} }

View File

@ -48,7 +48,7 @@ public class ContextManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
return contextManagement.all(false); return contextManagement.all(false);
@ -73,7 +73,7 @@ public class ContextManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid)); contextManagement.setUUID(UUID.fromString(uuid));
@ -98,7 +98,7 @@ public class ContextManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid)); contextManagement.setUUID(UUID.fromString(uuid));

View File

@ -80,7 +80,7 @@ public class InstancesManager extends BaseRest {
setAccountingMethod(Method.EXIST, InstancesManager.INSTANCE); setAccountingMethod(Method.EXIST, InstancesManager.INSTANCE);
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ElementManagement erManagement = ElementManagementUtility.getERManagement(type); ElementManagement erManagement = ElementManagementUtility.getERManagement(type);

View File

@ -46,7 +46,7 @@ public class QueryTemplateManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement(); QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
return queryTemplateManagement.all(false); return queryTemplateManagement.all(false);
@ -93,7 +93,7 @@ public class QueryTemplateManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement(); QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
queryTemplateManagement.setName(queryTemplateName); queryTemplateManagement.setName(queryTemplateName);
@ -115,7 +115,7 @@ public class QueryTemplateManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement(); QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
queryTemplateManagement.setName(queryTemplateName); queryTemplateManagement.setName(queryTemplateName);

View File

@ -54,7 +54,7 @@ public class TypeManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER);
TypeManagement schemaManagement = new TypeManagement(); TypeManagement schemaManagement = new TypeManagement();
schemaManagement.setTypeName(typeName); schemaManagement.setTypeName(typeName);
@ -80,7 +80,7 @@ public class TypeManager extends BaseRest {
ServerRequestInfo serverRequestInfo = initRequestInfo(); ServerRequestInfo serverRequestInfo = initRequestInfo();
serverRequestInfo.setAllMeta(true); serverRequestInfo.setAllMeta(true);
serverRequestInfo.checkQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER); serverRequestInfo.checkBooleanQueryParameter(TypePath.INCLUDE_META_QUERY_PARAMETER);
TypeManagement schemaManagement = new TypeManagement(); TypeManagement schemaManagement = new TypeManagement();
schemaManagement.setTypeName(type); schemaManagement.setTypeName(type);