2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * Modifications Copyright (C) 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 * The UpdateRequest class provides processing related to update transaction.
24 * @author richtabedzki
27 package org.onap.ccsdk.sli.adaptors.aai;
29 import java.io.UnsupportedEncodingException;
30 import java.net.MalformedURLException;
31 import java.net.URISyntaxException;
33 import java.util.ArrayList;
34 import java.util.List;
36 import java.util.Properties;
38 import java.util.stream.Collectors;
40 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
42 import com.fasterxml.jackson.core.JsonProcessingException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
45 public class UpdateRequest extends AAIRequest {
47 private AAIRequest request;
48 private Map<String, String> params;
50 public UpdateRequest(AAIRequest request, Map<String, String> parms) {
51 this.request = request;
56 public URL getRequestUrl(String method, String resourceVersion)
57 throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
58 return request.getRequestUrl(method, resourceVersion);
62 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
63 return request.getRequestQueryUrl(method);
67 public String toJSONString() {
68 updateArrayEntries(params);
69 ObjectMapper mapper = AAIService.getObjectMapper();
73 json = mapper.writeValueAsString(params);
74 } catch (JsonProcessingException e) {
75 LOG.error("Could not convert parameters of " + request.getRequestObject().getClass().getName(), e);
83 * Update array entries.
84 * The method converts indexed data entries to an array of values
86 * @param data Map containing String:String values representing input data
88 private void updateArrayEntries( Map<String, String> data) {
89 Set<String> set = data.keySet()
91 .filter(s -> s.endsWith("_length"))
92 .collect(Collectors.toSet());
94 for(String lenghtKey : set) {
95 String key = lenghtKey.replace("_length", "");
96 // String index = data.get(lenghtKey);
97 List<String> array = new ArrayList<>();
99 Set<String> subset = data.keySet()
101 .filter(s -> s.startsWith(String.format("%s[",key)))
102 .collect(Collectors.toSet());
103 for(String subKey : subset) {
104 String subValue = data.get(subKey);
106 LOG.trace("{} : {} ", subKey, subValue);
108 data.put(key, array.toString());
109 data.remove(lenghtKey);
110 for(String subKey : subset) {
117 public String[] getArgsList() {
118 return request.getArgsList();
122 public Class<? extends AAIDatum> getModelClass() {
123 return request.getModelClass();
127 public void addRequestProperty(String key, String value) {
128 request.requestProperties.put(key, value);
131 public static String processPathData(String requestUrl, Properties requestProperties) {
133 // if(request != null) {
134 // Class<?> clazz = request.getClass();
135 // Method function = null;
137 // function = clazz.getMethod("processPathData", request_url.getClass(), requestProperties.getClass());
138 // request_url = (String) function.invoke(null, request_url, requestProperties);
139 // } catch (Exception e) {
140 // e.printStackTrace();
144 // request.processPathData(request_url, requestProperties);
148 public void processRequestPathValues(Map<String, String> nameValues) {
149 request.processRequestPathValues(nameValues);