diff options
author | zm330 <zhangminyj@chinamobile.com> | 2020-02-28 11:51:17 +0800 |
---|---|---|
committer | zm330 <zhangminyj@chinamobile.com> | 2020-02-28 11:51:47 +0800 |
commit | 6c4ef0760ad023e8a01790eab54a8a427565a19b (patch) | |
tree | 730bcf392a8fd16dce75fc8f989706b535b8763f /adapters/mso-catalog-db-adapter | |
parent | 527090251194bcecf513ff493bed97da7f862927 (diff) |
Add Catalog DB query methods
Issue-ID: SO-2368
Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: I99f3241d4726d3d334b1eeccf30022c939b71b6f
Diffstat (limited to 'adapters/mso-catalog-db-adapter')
2 files changed, 200 insertions, 0 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceArtifact.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceArtifact.java new file mode 100644 index 0000000000..ce39b9713a --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceArtifact.java @@ -0,0 +1,118 @@ +/*- + * ============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.ServiceArtifact; +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 = "serviceArtifacts") +public class QueryServiceArtifact extends CatalogQuery { + + protected static Logger logger = LoggerFactory.getLogger(QueryServiceArtifact.class); + + private List<ServiceArtifact> serviceArtifactList; + + private static final String TEMPLATE = "\t{\n" + "\t\t\"artifactUUID\" : <ARTIFACT_UUID>,\n" + + "\t\t\"name\" : <NAME>,\n" + "\t\t\"version\" : <VERSION>,\n" + + "\t\t\"checksum\" : <CHECKSUM>,\n" + "\t\t\"type\" : <TYPE>,\n" + + "\t\t\"content\" : <CONTENT>,\n" + "\t\t\"description\" : <DESCRIPTION>\n" + "\t}"; + + public QueryServiceArtifact() { + super(); + serviceArtifactList = new ArrayList<>(); + } + + public QueryServiceArtifact(List<ServiceArtifact> alist) { + serviceArtifactList = new ArrayList<>(); + for (ServiceArtifact o : alist) { + if (logger.isDebugEnabled()) + logger.debug(o.toString()); + serviceArtifactList.add(o); + } + } + + public List<ServiceArtifact> getServiceArtifact() { + return this.serviceArtifactList; + } + + public void setServiceArtifact(List<ServiceArtifact> a) { + this.serviceArtifactList = a; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (ServiceArtifact o : serviceArtifactList) { + 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("\"serviceArtifact\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + for (ServiceArtifact o : serviceArtifactList) { + if (first) + sb.append("\n"); + first = false; + + boolean vrNull = o == null; + + put(valueMap, "ARTIFACT_UUID", vrNull ? null : o.getArtifactUUID()); + put(valueMap, "TYPE", vrNull ? null : o.getType()); + put(valueMap, "NAME", vrNull ? null : o.getName()); + put(valueMap, "VERSION", vrNull ? null : o.getVersion()); + put(valueMap, "DESCRIPTION", vrNull ? null : o.getDescription()); + put(valueMap, "CONTENT", vrNull ? null : o.getContent()); + put(valueMap, "CHECKSUM", vrNull ? null : o.getChecksum()); + 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(); + } +} 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 new file mode 100644 index 0000000000..b1911654c4 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java @@ -0,0 +1,82 @@ +/*- + * ============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.Service; +import org.onap.so.db.catalog.beans.ServiceInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.Map; + +@XmlRootElement(name = "serviceInfo") +public class QueryServiceInfo extends CatalogQuery { + + protected static Logger logger = LoggerFactory.getLogger(QueryServiceInfo.class); + + private ServiceInfo serviceInfo; + + private static final String TEMPLATE = + "\n" + "\t{" + "\t\t\"id\" : <ID>,\n" + "\t\t\"serviceInput\" : <SERVICE_INPUT>,\n" + + "\t\"serviceProperties\" : <SERVICE_PROPERTIES>,\n" + "<_SERVICEARTIFACT_>\n"; + + + public QueryServiceInfo() { + super(); + this.serviceInfo = new ServiceInfo(); + } + + public QueryServiceInfo(ServiceInfo serviceInfo) { + this.serviceInfo = serviceInfo; + } + + public ServiceInfo getServiceInfo() { + return this.serviceInfo; + } + + public void setServiceInfo(ServiceInfo serviceInfo) { + this.serviceInfo = serviceInfo; + } + + @Override + public String toString() { + + return serviceInfo.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + sb.append("\"serviceInfo\": "); + sb.append("\n"); + Map<String, String> valueMap = new HashMap<>(); + Service service = serviceInfo.getService(); + 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 + sb.append(this.setTemplate(TEMPLATE, valueMap)); + sb.append("}"); + return sb.toString(); + } +} |