2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
7 # Licensed under the Apache License, Version 2.0 (the "License")
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.beans.nsmf;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.gson.JsonObject;
26 import org.onap.so.beans.nsmf.oof.TemplateInfo;
27 import java.io.IOException;
28 import java.lang.reflect.Field;
29 import java.lang.reflect.Method;
30 import java.util.HashMap;
31 import java.io.Serializable;
40 public class SliceTaskParamsAdapter implements Serializable {
42 private static final long serialVersionUID = -7785578865170503301L;
44 private String serviceId;
46 private String serviceName;
50 private String nstName;
52 private Map<String, Object> serviceProfile = new HashMap<>();
54 private String suggestNsiId;
56 private String suggestNsiName;
58 private TemplateInfo NSTInfo = new TemplateInfo();
60 private SliceTaskInfo<SliceProfileAdapter> tnBHSliceTaskInfo = new SliceTaskInfo<>();
62 private SliceTaskInfo<SliceProfileAdapter> tnMHSliceTaskInfo = new SliceTaskInfo<>();
64 private SliceTaskInfo<SliceProfileAdapter> tnFHSliceTaskInfo = new SliceTaskInfo<>();
66 private SliceTaskInfo<SliceProfileAdapter> cnSliceTaskInfo = new SliceTaskInfo<>();
68 private SliceTaskInfo<SliceProfileAdapter> anSliceTaskInfo = new SliceTaskInfo<>();
70 private SliceTaskInfo<SliceProfileAdapter> anNFSliceTaskInfo = new SliceTaskInfo<>();
73 * change T t to {@link Map}
79 private <T> Map<String, Object> bean2Map(T t) {
80 Map<String, Object> resMap = new HashMap<>();
86 Field[] fields = t.getClass().getDeclaredFields();
87 for (Field field : fields) {
88 String name = field.getName();
90 if (name == null || "".equals(name) || "serialVersionUID".equalsIgnoreCase(name)) {
93 JsonProperty annotation = field.getAnnotation(JsonProperty.class);
94 if (annotation != null && !annotation.value().equals(JsonProperty.USE_DEFAULT_NAME)) {
95 key = annotation.value();
98 Method method = t.getClass().getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
99 Object value = method.invoke(t);
100 resMap.put(key, value);
103 } catch (Exception e) {
110 * replace of slice profile
112 * @param paramMap params map
113 * @param header starts of key
116 private Map<String, Object> replaceHeader(Map<String, String> paramMap, String header) {
117 Map<String, Object> sliceProfileMap = new HashMap<>();
118 for (Map.Entry<String, String> entry : paramMap.entrySet()) {
119 if (entry.getKey().startsWith(header)) {
120 sliceProfileMap.put(entry.getKey().replaceFirst("^" + header, ""), entry.getValue());
123 return sliceProfileMap;