- /**
- * Parse parameters from URI request and check their types and values.
- *
- * @param identifier {@link InstanceIdentifierContext}
- * @param uriInfo URI info
- * @return {@link QueryParameters}
- */
- public static QueryParameters parseUriParameters(final InstanceIdentifierContext<?> identifier,
- final UriInfo uriInfo) {
- final QueryParameters.Builder builder = QueryParameters.builder();
- if (uriInfo == null) {
- return builder.build();
- }
-
- // check only allowed parameters
- final MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
- checkParametersTypes(queryParams.keySet(), ALLOWED_PARAMETERS);
-
- // check and set content
- final String contentStr = getSingleParameter(queryParams, ContentParameter.uriName());
- if (contentStr != null) {
- builder.setContent(RestconfDocumentedException.throwIfNull(
- ContentParameter.forUriValue(contentStr), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
- "Invalid content parameter: %s, allowed values are %s", contentStr, POSSIBLE_CONTENT));
- }
-
- // check and set depth
- final String depthStr = getSingleParameter(queryParams, DepthParameter.uriName());
- if (depthStr != null) {
- try {
- builder.setDepth(DepthParameter.forUriValue(depthStr));
- } catch (IllegalArgumentException e) {
- throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
- "Invalid depth parameter: " + depthStr, null,
- "The depth parameter must be an integer between 1 and 65535 or \"unbounded\""));
- }
- }
-
- // check and set fields
- final String fieldsStr = getSingleParameter(queryParams, FieldsParameter.uriName());
- if (fieldsStr != null) {
- // FIXME: parse a FieldsParameter instead
- if (identifier.getMountPoint() != null) {
- builder.setFieldPaths(parseFieldsPaths(identifier, fieldsStr));
- } else {
- builder.setFields(parseFieldsParameter(identifier, fieldsStr));
- }
- }
-
- // check and set withDefaults parameter
- final String withDefaultsStr = getSingleParameter(queryParams, WithDefaultsParameter.uriName());
- if (withDefaultsStr != null) {
- final WithDefaultsParameter val = WithDefaultsParameter.forUriValue(withDefaultsStr);
- if (val == null) {
- throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
- "Invalid with-defaults parameter: " + withDefaultsStr, null,
- "The with-defaults parameter must be a string in " + POSSIBLE_WITH_DEFAULTS));
- }
-
- switch (val) {
- case REPORT_ALL:
- break;
- case REPORT_ALL_TAGGED:
- builder.setTagged(true);
- break;
- default:
- builder.setWithDefault(val);
- }
- }
-
- return builder.build();
- }
-