From 1e0bac83b2d1ee5c66a476f85ee2cbc0fd2ec2bb Mon Sep 17 00:00:00 2001 From: zm330 Date: Mon, 2 Mar 2020 00:41:19 +0800 Subject: Add Query ServiceProxyCustomization Issue-ID: SO-2368 Signed-off-by: zm330 Change-Id: I12fc81ea5f0fc3975b5913b56b48ecb4cb3ebff5 --- .../catalogdb/catalogrest/QueryServiceInfo.java | 7 +- .../catalogrest/QueryServiceMacroHolder.java | 8 +- .../QueryServiceProxyCustomization.java | 124 +++++++++++++++++++++ 3 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java (limited to 'adapters/mso-catalog-db-adapter') diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java index b1911654c4..6c1c81c6ef 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java @@ -65,6 +65,9 @@ public class QueryServiceInfo extends CatalogQuery { @Override public String JSON2(boolean isArray, boolean isEmbed) { + if (serviceInfo == null) { + return "\"serviceInfo\": null"; + } StringBuilder sb = new StringBuilder(); sb.append("\"serviceInfo\": "); sb.append("\n"); @@ -73,8 +76,8 @@ public class QueryServiceInfo extends CatalogQuery { put(valueMap, "ID", null == serviceInfo ? null : serviceInfo.getId()); put(valueMap, "SERVICE_INPUT", null == serviceInfo ? null : serviceInfo.getServiceInput()); put(valueMap, "SERVICE_PROPERTIES", null == serviceInfo ? null : serviceInfo.getServiceProperties()); - // String subitem = new QueryServiceArtifact(service.getServiceArtifactList()).JSON2(true, true); - // valueMap.put("_SERVICEARTIFACT_", subitem.replaceAll("(?m)^", "\t\t"));m + String subitem = new QueryServiceArtifact(service.getServiceArtifactList()).JSON2(true, true); + valueMap.put("_SERVICEARTIFACT_", subitem.replaceAll("(?m)^", "\t\t")); sb.append(this.setTemplate(TEMPLATE, valueMap)); sb.append("}"); return sb.toString(); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index 0eb7d0418e..d5aa472c8d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -40,7 +40,7 @@ public class QueryServiceMacroHolder extends CatalogQuery { + "\t\"serviceType\" : ,\n" + "\t\"serviceRole\" : ,\n" + "\t\"environmentContext\" : ,\n" + "\t\"resourceOrder\" : ,\n" + "\t\"workloadContext\" : ,\n" + "<_SERVICEVNFS_>,\n" + "<_SERVICENETWORKS_>,\n" - + "<_SERVICEALLOTTEDRESOURCES_>\n" + "\t}}"; + + "<_SERVICEINFO_>,\n" + "<_SERVICEPROXY_>,\n" + "<_SERVICEALLOTTEDRESOURCES_>\n" + "\t}}"; public QueryServiceMacroHolder() { super(); @@ -94,6 +94,12 @@ public class QueryServiceMacroHolder extends CatalogQuery { subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true); valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); + subitem = new QueryServiceInfo(serviceMacroHolder.getServiceInfo()).JSON2(true, true); + valueMap.put("_SERVICEINFO_", subitem.replaceAll(LINE_BEGINNING, "\t")); + + subitem = new QueryServiceProxyCustomization(service.getServiceProxyCustomizations()).JSON2(true, true); + valueMap.put("_SERVICEPROXY_", subitem.replaceAll(LINE_BEGINNING, "\t")); + buf.append(this.setTemplate(TEMPLATE, valueMap)); return buf.toString(); } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java new file mode 100644 index 0000000000..94cf304120 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (c) 2019, CMCC Technologies Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.catalogdb.catalogrest; + +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@XmlRootElement(name = "serviceProxyCustomizations") +public class QueryServiceProxyCustomization extends CatalogQuery { + + protected static Logger logger = LoggerFactory.getLogger(QueryServiceProxyCustomization.class); + + private List serviceProxyResourceCustomizationList; + + private static final String TEMPLATE = + "\t{\n" + "\t\t\"modelInfo\" : {\n" + "\t\t\t\"modelName\" : ,\n" + + "\t\t\t\"modelUuid\" : ,\n" + + "\t\t\t\"modelInvariantUuid\" : ,\n" + + "\t\t\t\"modelVersion\" : ,\n" + + "\t\t\t\"modelCustomizationUuid\" : ,\n" + + "\t\t\t\"modelInstanceName\" : \n" + "\t},\n" + + "\t\t\"toscaNodeType\" : ,\n" + + "\t\t\"description\" : ,\n" + + "\t\t\"sourceModelUuid\" : \n" + "\t}"; + + public QueryServiceProxyCustomization() { + super(); + this.serviceProxyResourceCustomizationList = new ArrayList<>(); + } + + public QueryServiceProxyCustomization( + List serviceProxyResourceCustomizationList) { + this.serviceProxyResourceCustomizationList = serviceProxyResourceCustomizationList; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (ServiceProxyResourceCustomization o : serviceProxyResourceCustomizationList) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + + first = false; + sb.append(o); + } + return sb.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"serviceProxy\": ["); + Map valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + if (this.serviceProxyResourceCustomizationList != null) { + for (ServiceProxyResourceCustomization o : serviceProxyResourceCustomizationList) { + if (first) + sb.append("\n"); + + first = false; + + boolean arNull = o == null; + + put(valueMap, "MODEL_CUSTOMIZATION_UUID", arNull ? null : o.getModelCustomizationUUID()); + put(valueMap, "MODEL_INSTANCE_NAME", arNull ? null : o.getModelInstanceName()); + put(valueMap, "MODEL_UUID", arNull ? null : o.getModelUUID()); + put(valueMap, "MODEL_INVARIANT_UUID", arNull ? null : o.getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", arNull ? null : o.getModelVersion()); + put(valueMap, "MODEL_NAME", arNull ? null : o.getModelName()); + put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getToscaNodeType()); + put(valueMap, "DESCRIPTION", arNull ? null : o.getDescription()); + put(valueMap, "SOURCE_SERVICE_MODEL_UUID", (String) (arNull ? null + : o.getSourceService() == null ? null : o.getSourceService().getModelUUID())); + + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); + sep = ",\n"; + } + } + if (!first) + sb.append("\n"); + + if (isArray) + sb.append("]"); + + if (!isEmbed && isArray) + sb.append("}"); + + return sb.toString(); + } + +} -- cgit 1.2.3-korg