diff options
author | hetengjiao <hetengjiao@chinamobile.com> | 2020-09-28 17:55:32 +0800 |
---|---|---|
committer | hetengjiao <hetengjiao@chinamobile.com> | 2020-09-28 17:55:40 +0800 |
commit | 5bed5a76aac23bbabd34312dd2f5b7623c24c586 (patch) | |
tree | 30e82636367a8fa32ea388657380032058cfdad4 /common/src/main/java | |
parent | af1efe8d52d325929e4e9231576a9a5f97e143ae (diff) |
add method adapt SliceTaskParamsAdapter to SliceTaskParams
Issue-ID: SO-2963
Signed-off-by: hetengjiao <hetengjiao@chinamobile.com>
Change-Id: Ie8038437ccaa54ee7477d09fd09f2818db2a65a0
Diffstat (limited to 'common/src/main/java')
3 files changed, 209 insertions, 238 deletions
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java index 83675da5f0..e5eb3e0d21 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java @@ -23,10 +23,12 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import lombok.ToString; import java.util.List; @JsonInclude(JsonInclude.Include.NON_NULL) @Data +@ToString public class AnSliceProfile { @JsonProperty(value = "sliceProfileId", required = true) diff --git a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParams.java b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParams.java index f0857fc458..4aa567112f 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParams.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParams.java @@ -22,11 +22,19 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.Map; +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString public class SliceTaskParams implements Serializable { private static final long serialVersionUID = -4389946152970978423L; @@ -45,17 +53,17 @@ public class SliceTaskParams implements Serializable { private String cnScriptName; - private Map<String, Object> serviceProfile; + private Map<String, Object> serviceProfile = new HashMap<>(); private String suggestNsiId; private String suggestNsiName; - private Map<String, Object> sliceProfileTn; + private Map<String, Object> sliceProfileTn = new HashMap<>(); - private Map<String, Object> sliceProfileCn; + private Map<String, Object> sliceProfileCn = new HashMap<>(); - private Map<String, Object> sliceProfileAn; + private Map<String, Object> sliceProfileAn = new HashMap<>(); private String tnSuggestNssiId; @@ -87,237 +95,6 @@ public class SliceTaskParams implements Serializable { private String anStatusDescription; - public SliceTaskParams() { - this.serviceProfile = new HashMap<>(); - this.sliceProfileAn = new HashMap<>(); - this.sliceProfileCn = new HashMap<>(); - this.sliceProfileTn = new HashMap<>(); - } - - public String getNstId() { - return nstId; - } - - public void setNstId(String nstId) { - this.nstId = nstId; - } - - public String getNstName() { - return nstName; - } - - public void setNstName(String nstName) { - this.nstName = nstName; - } - - public String getTnScriptName() { - return tnScriptName; - } - - public void setTnScriptName(String tnScriptName) { - this.tnScriptName = tnScriptName; - } - - public String getAnScriptName() { - return anScriptName; - } - - public void setAnScriptName(String anScriptName) { - this.anScriptName = anScriptName; - } - - public String getCnScriptName() { - return cnScriptName; - } - - public void setCnScriptName(String cnScriptName) { - this.cnScriptName = cnScriptName; - } - - public String getServiceId() { - return serviceId; - } - - public void setServiceId(String serviceId) { - this.serviceId = serviceId; - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public Map<String, Object> getServiceProfile() { - return serviceProfile; - } - - public void setServiceProfile(Map<String, Object> serviceProfile) { - this.serviceProfile = serviceProfile; - } - - public String getSuggestNsiId() { - return suggestNsiId; - } - - public void setSuggestNsiId(String suggestNsiId) { - this.suggestNsiId = suggestNsiId; - } - - public String getSuggestNsiName() { - return suggestNsiName; - } - - public void setSuggestNsiName(String suggestNsiName) { - this.suggestNsiName = suggestNsiName; - } - - public Map<String, Object> getSliceProfileTn() { - return sliceProfileTn; - } - - public void setSliceProfileTn(Map<String, Object> sliceProfileTn) { - this.sliceProfileTn = sliceProfileTn; - } - - public Map<String, Object> getSliceProfileCn() { - return sliceProfileCn; - } - - public void setSliceProfileCn(Map<String, Object> sliceProfileCn) { - this.sliceProfileCn = sliceProfileCn; - } - - public Map<String, Object> getSliceProfileAn() { - return sliceProfileAn; - } - - public void setSliceProfileAn(Map<String, Object> sliceProfileAn) { - this.sliceProfileAn = sliceProfileAn; - } - - public String getTnSuggestNssiId() { - return tnSuggestNssiId; - } - - public void setTnSuggestNssiId(String tnSuggestNssiId) { - this.tnSuggestNssiId = tnSuggestNssiId; - } - - public String getTnSuggestNssiName() { - return tnSuggestNssiName; - } - - public void setTnSuggestNssiName(String tnSuggestNssiName) { - this.tnSuggestNssiName = tnSuggestNssiName; - } - - public String getTnProgress() { - return tnProgress; - } - - public void setTnProgress(String tnProgress) { - this.tnProgress = tnProgress; - } - - public String getTnStatus() { - return tnStatus; - } - - public void setTnStatus(String tnStatus) { - this.tnStatus = tnStatus; - } - - public String getTnStatusDescription() { - return tnStatusDescription; - } - - public void setTnStatusDescription(String tnStatusDescription) { - this.tnStatusDescription = tnStatusDescription; - } - - public String getCnSuggestNssiId() { - return cnSuggestNssiId; - } - - public void setCnSuggestNssiId(String cnSuggestNssiId) { - this.cnSuggestNssiId = cnSuggestNssiId; - } - - public String getCnSuggestNssiName() { - return cnSuggestNssiName; - } - - public void setCnSuggestNssiName(String cnSuggestNssiName) { - this.cnSuggestNssiName = cnSuggestNssiName; - } - - public String getCnProgress() { - return cnProgress; - } - - public void setCnProgress(String cnProgress) { - this.cnProgress = cnProgress; - } - - public String getCnStatus() { - return cnStatus; - } - - public void setCnStatus(String cnStatus) { - this.cnStatus = cnStatus; - } - - public String getCnStatusDescription() { - return cnStatusDescription; - } - - public void setCnStatusDescription(String cnStatusDescription) { - this.cnStatusDescription = cnStatusDescription; - } - - public String getAnSuggestNssiId() { - return anSuggestNssiId; - } - - public void setAnSuggestNssiId(String anSuggestNssiId) { - this.anSuggestNssiId = anSuggestNssiId; - } - - public String getAnSuggestNssiName() { - return anSuggestNssiName; - } - - public void setAnSuggestNssiName(String anSuggestNssiName) { - this.anSuggestNssiName = anSuggestNssiName; - } - - public String getAnProgress() { - return anProgress; - } - - public void setAnProgress(String anProgress) { - this.anProgress = anProgress; - } - - public String getAnStatus() { - return anStatus; - } - - public void setAnStatus(String anStatus) { - this.anStatus = anStatus; - } - - public String getAnStatusDescription() { - return anStatusDescription; - } - - public void setAnStatusDescription(String anStatusDescription) { - this.anStatusDescription = anStatusDescription; - } - public String convertToJson() { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("ServiceId", serviceId); diff --git a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java index 6ad752f047..dd73fdb76b 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java @@ -19,8 +19,14 @@ */ package org.onap.so.beans.nsmf; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonObject; import lombok.*; import org.onap.so.beans.nsmf.oof.TemplateInfo; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; import java.util.Map; @@ -58,9 +64,195 @@ public class SliceTaskParamsAdapter { private SliceTaskInfo<AnSliceProfile> anSliceTaskInfo; + @SuppressWarnings("unchecked") + public void convertFromJson(String jsonString) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + Map<String, String> paramMap = (Map<String, String>) mapper.readValue(jsonString, Map.class); + + this.setServiceName(paramMap.get("ServiceName")); + this.setServiceId(paramMap.get("ServiceId")); + this.setNstId(paramMap.get("NSTId")); + this.setNstName(paramMap.get("NSTName")); + this.setSuggestNsiId(paramMap.get("suggestNSIId")); + this.setSuggestNsiName(paramMap.get("suggestNSIName")); + + this.setServiceProfile(replaceHeader(paramMap, "ServiceProfile.")); + + TnSliceProfile tnBHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.BH.")), TnSliceProfile.class); + this.tnBHSliceTaskInfo.setSliceProfile(tnBHSliceProfile); + + TnSliceProfile tnMHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.MH.")), TnSliceProfile.class); + this.tnMHSliceTaskInfo.setSliceProfile(tnMHSliceProfile); + + TnSliceProfile tnFHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.FH.")), TnSliceProfile.class); + this.tnFHSliceTaskInfo.setSliceProfile(tnFHSliceProfile); + + CnSliceProfile cnSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.CN.")), CnSliceProfile.class); + this.cnSliceTaskInfo.setSliceProfile(cnSliceProfile); + + AnSliceProfile anSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.AN.")), AnSliceProfile.class); + this.anSliceTaskInfo.setSliceProfile(anSliceProfile); + + this.tnBHSliceTaskInfo.setSuggestNssiId(paramMap.get("TN.BH.SuggestNSSIId")); + this.tnBHSliceTaskInfo.setSuggestNssiName(paramMap.get("TN.BH.SuggestNSSIName")); + this.tnBHSliceTaskInfo.setProgress(paramMap.get("TN.BH.progress")); + this.tnBHSliceTaskInfo.setStatus(paramMap.get("TN.BH.status")); + this.tnBHSliceTaskInfo.setStatusDescription(paramMap.get("TN.BH.statusDescription")); + this.tnBHSliceTaskInfo.setScriptName(paramMap.get("TN.BH.ScriptName")); + + this.tnMHSliceTaskInfo.setSuggestNssiId(paramMap.get("TN.MH.SuggestNSSIId")); + this.tnMHSliceTaskInfo.setSuggestNssiName(paramMap.get("TN.MH.SuggestNSSIName")); + this.tnMHSliceTaskInfo.setProgress(paramMap.get("TN.MH.progress")); + this.tnMHSliceTaskInfo.setStatus(paramMap.get("TN.MH.status")); + this.tnMHSliceTaskInfo.setStatusDescription(paramMap.get("TN.MH.statusDescription")); + this.tnMHSliceTaskInfo.setScriptName(paramMap.get("TN.MH.ScriptName")); + + this.tnFHSliceTaskInfo.setSuggestNssiId(paramMap.get("TN.FH.SuggestNSSIId")); + this.tnFHSliceTaskInfo.setSuggestNssiName(paramMap.get("TN.FH.SuggestNSSIName")); + this.tnFHSliceTaskInfo.setProgress(paramMap.get("TN.FH.progress")); + this.tnFHSliceTaskInfo.setStatus(paramMap.get("TN.FH.status")); + this.tnFHSliceTaskInfo.setStatusDescription(paramMap.get("TN.FH.statusDescription")); + this.tnFHSliceTaskInfo.setScriptName(paramMap.get("TN.FH.ScriptName")); + + this.cnSliceTaskInfo.setSuggestNssiId(paramMap.get("CN.SuggestNSSIId")); + this.cnSliceTaskInfo.setSuggestNssiName(paramMap.get("CN.SuggestNSSIName")); + this.cnSliceTaskInfo.setProgress(paramMap.get("CN.progress")); + this.cnSliceTaskInfo.setStatus(paramMap.get("CN.status")); + this.cnSliceTaskInfo.setStatusDescription(paramMap.get("CN.statusDescription")); + this.cnSliceTaskInfo.setScriptName(paramMap.get("CN.ScriptName")); + + this.anSliceTaskInfo.setSuggestNssiId(paramMap.get("AN.SuggestNSSIId")); + this.anSliceTaskInfo.setSuggestNssiName(paramMap.get("AN.SuggestNSSIName")); + this.anSliceTaskInfo.setProgress(paramMap.get("AN.progress")); + this.anSliceTaskInfo.setStatus(paramMap.get("AN.status")); + this.anSliceTaskInfo.setStatusDescription(paramMap.get("AN.statusDescription")); + this.anSliceTaskInfo.setScriptName(paramMap.get("AN.ScriptName")); + } + public String convertToJson() { - SliceTaskParams sliceTaskParams = new SliceTaskParams(); - sliceTaskParams.setServiceId(serviceId); - return sliceTaskParams.convertToJson(); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("ServiceId", serviceId); + jsonObject.addProperty("ServiceName", serviceName); + jsonObject.addProperty("NSTId", nstId); + jsonObject.addProperty("NSTName", nstName); + jsonObject.addProperty("suggestNSIId", suggestNsiId); + jsonObject.addProperty("suggestNSIName", suggestNsiName); + + for (Map.Entry<String, Object> entry : serviceProfile.entrySet()) { + jsonObject.addProperty("ServiceProfile." + entry.getKey(), entry.getValue().toString()); + } + + Map<String, Object> sliceProfileAn = bean2Map(anSliceTaskInfo.getSliceProfile()); + + for (Map.Entry<String, Object> entry : sliceProfileAn.entrySet()) { + jsonObject.addProperty("SliceProfile.AN." + entry.getKey(), entry.getValue().toString()); + } + + Map<String, Object> sliceProfileCn = bean2Map(cnSliceTaskInfo.getSliceProfile()); + for (Map.Entry<String, Object> entry : sliceProfileCn.entrySet()) { + jsonObject.addProperty("SliceProfile.CN." + entry.getKey(), entry.getValue().toString()); + } + + Map<String, Object> sliceProfileTnBH = bean2Map(tnBHSliceTaskInfo.getSliceProfile()); + for (Map.Entry<String, Object> entry : sliceProfileTnBH.entrySet()) { + jsonObject.addProperty("SliceProfile.TN.BH." + entry.getKey(), entry.getValue().toString()); + } + + Map<String, Object> sliceProfileTnMH = bean2Map(tnMHSliceTaskInfo.getSliceProfile()); + for (Map.Entry<String, Object> entry : sliceProfileTnMH.entrySet()) { + jsonObject.addProperty("SliceProfile.TN.MH." + entry.getKey(), entry.getValue().toString()); + } + + Map<String, Object> sliceProfileTnFH = bean2Map(tnFHSliceTaskInfo.getSliceProfile()); + for (Map.Entry<String, Object> entry : sliceProfileTnFH.entrySet()) { + jsonObject.addProperty("SliceProfile.TN.FH." + entry.getKey(), entry.getValue().toString()); + } + + jsonObject.addProperty("TN.BH.SuggestNSSIId", tnBHSliceTaskInfo.getSuggestNssiId()); + jsonObject.addProperty("TN.BH.SuggestNSSIName", tnBHSliceTaskInfo.getSuggestNssiName()); + jsonObject.addProperty("TN.BH.progress", tnBHSliceTaskInfo.getProgress()); + jsonObject.addProperty("TN.BH.status", tnBHSliceTaskInfo.getStatus()); + jsonObject.addProperty("TN.BH.statusDescription", tnBHSliceTaskInfo.getStatusDescription()); + jsonObject.addProperty("TN.BH.ScriptName", tnBHSliceTaskInfo.getScriptName()); + + + jsonObject.addProperty("TN.MH.SuggestNSSIId", tnMHSliceTaskInfo.getSuggestNssiId()); + jsonObject.addProperty("TN.MH.SuggestNSSIName", tnMHSliceTaskInfo.getSuggestNssiName()); + jsonObject.addProperty("TN.MH.progress", tnMHSliceTaskInfo.getProgress()); + jsonObject.addProperty("TN.MH.status", tnMHSliceTaskInfo.getStatus()); + jsonObject.addProperty("TN.MH.statusDescription", tnMHSliceTaskInfo.getStatusDescription()); + jsonObject.addProperty("TN.MH.ScriptName", tnMHSliceTaskInfo.getScriptName()); + + + jsonObject.addProperty("TN.FH.SuggestNSSIId", tnFHSliceTaskInfo.getSuggestNssiId()); + jsonObject.addProperty("TN.FH.SuggestNSSIName", tnFHSliceTaskInfo.getSuggestNssiName()); + jsonObject.addProperty("TN.FH.progress", tnFHSliceTaskInfo.getProgress()); + jsonObject.addProperty("TN.FH.status", tnFHSliceTaskInfo.getStatus()); + jsonObject.addProperty("TN.FH.statusDescription", tnFHSliceTaskInfo.getStatusDescription()); + jsonObject.addProperty("TN.FH.ScriptName", tnFHSliceTaskInfo.getScriptName()); + + + jsonObject.addProperty("CN.SuggestNSSIId", cnSliceTaskInfo.getSuggestNssiId()); + jsonObject.addProperty("CN.SuggestNSSIName", cnSliceTaskInfo.getSuggestNssiName()); + jsonObject.addProperty("CN.progress", cnSliceTaskInfo.getProgress()); + jsonObject.addProperty("CN.status", cnSliceTaskInfo.getStatus()); + jsonObject.addProperty("CN.statusDescription", cnSliceTaskInfo.getStatusDescription()); + jsonObject.addProperty("CN.ScriptName", cnSliceTaskInfo.getScriptName()); + + + jsonObject.addProperty("AN.SuggestNSSIId", anSliceTaskInfo.getSuggestNssiId()); + jsonObject.addProperty("AN.SuggestNSSIName", anSliceTaskInfo.getSuggestNssiName()); + jsonObject.addProperty("AN.progress", anSliceTaskInfo.getProgress()); + jsonObject.addProperty("AN.status", anSliceTaskInfo.getStatus()); + jsonObject.addProperty("AN.statusDescription", anSliceTaskInfo.getStatusDescription()); + jsonObject.addProperty("AN.ScriptName", anSliceTaskInfo.getScriptName()); + + return jsonObject.toString(); + } + + /** + * change T t to {@link Map} + * + * @param t input + * @param <T> Object + * @return {@link Map} + */ + private <T> Map<String, Object> bean2Map(T t) { + Map<String, Object> resMap = new HashMap<>(); + try { + Field[] fields = t.getClass().getDeclaredFields(); + for (Field field : fields) { + String name = field.getName(); + Method method = t.getClass().getMethod("get" + name); + Object value = method.invoke(t); + resMap.put(name, value); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return resMap; + } + + /** + * replace of slice profile + * + * @param paramMap params map + * @param header starts of key + * @return Map + */ + private Map<String, Object> replaceHeader(Map<String, String> paramMap, String header) { + Map<String, Object> sliceProfileMap = new HashMap<>(); + for (Map.Entry<String, String> entry : paramMap.entrySet()) { + if (entry.getKey().startsWith(header)) { + sliceProfileMap.put(entry.getKey().replaceFirst("^" + header, ""), entry.getValue()); + } + } + return sliceProfileMap; } } |