2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.nbi.commons;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map.Entry;
25 import org.springframework.util.LinkedMultiValueMap;
26 import org.springframework.util.MultiValueMap;
31 public class QueryParserUtils {
33 private QueryParserUtils() {
38 * @param queryParameters
41 public static Set<String> getFields(MultiValueMap<String, String> queryParameters) {
43 Set<String> fieldSet = new HashSet<>();
44 if (queryParameters != null) {
45 // search for "all" parameter
46 if (queryParameters.containsKey(ReservedKeys.ALL_FIELDS)) {
47 queryParameters.remove(ReservedKeys.ALL_FIELDS);
48 fieldSet.add(ReservedKeys.ALL_FIELDS);
50 // search for "fields" parameters
51 List<String> queryParameterField =
52 queryParameters.remove(ReservedKeys.QUERY_KEY_FIELD_ESCAPE + ReservedKeys.QUERY_KEY_FIELD);
53 if (queryParameterField == null) {
54 queryParameterField = queryParameters.remove(ReservedKeys.QUERY_KEY_FIELD);
56 if (queryParameterField != null && !queryParameterField.isEmpty()) {
57 String queryParameterValue = queryParameterField.get(0);
58 if (queryParameterValue != null) {
59 String[] tokenArray = queryParameterValue.split(",");
60 fieldSet.addAll(Arrays.asList(tokenArray));
67 public static MultiValueMap<String, String> popCriteria(MultiValueMap<String, String> queryParameters) {
69 Set<Entry<String, List<String>>> entrySet = queryParameters.entrySet();
71 MultiValueMap<String, String> criterias = new LinkedMultiValueMap<>();
73 entrySet.stream().forEach(entry -> {
74 final List<String> tempValues = new ArrayList<>();
75 entry.getValue().stream().forEach(value -> tempValues.addAll(Arrays.asList(value.split(","))));
76 criterias.put(entry.getKey(), tempValues);