2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2019, CMCC Technologies Co., Ltd.
6 * ================================================================================
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=========================================================
21 package org.onap.so.adapters.catalogdb.catalogrest;
23 import org.onap.so.db.catalog.beans.ServiceArtifact;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 @XmlRootElement(name = "serviceArtifacts")
33 public class QueryServiceArtifact extends CatalogQuery {
35 protected static Logger logger = LoggerFactory.getLogger(QueryServiceArtifact.class);
37 private List<ServiceArtifact> serviceArtifactList;
39 private static final String TEMPLATE = "\t{\n" + "\t\t\"artifactUUID\" : <ARTIFACT_UUID>,\n"
40 + "\t\t\"name\" : <NAME>,\n" + "\t\t\"version\" : <VERSION>,\n"
41 + "\t\t\"checksum\" : <CHECKSUM>,\n" + "\t\t\"type\" : <TYPE>,\n"
42 + "\t\t\"content\" : <CONTENT>,\n" + "\t\t\"description\" : <DESCRIPTION>\n" + "\t}";
44 public QueryServiceArtifact() {
46 serviceArtifactList = new ArrayList<>();
49 public QueryServiceArtifact(List<ServiceArtifact> alist) {
50 serviceArtifactList = new ArrayList<>();
51 for (ServiceArtifact o : alist) {
52 if (logger.isDebugEnabled())
53 logger.debug(o.toString());
54 serviceArtifactList.add(o);
58 public List<ServiceArtifact> getServiceArtifact() {
59 return this.serviceArtifactList;
62 public void setServiceArtifact(List<ServiceArtifact> a) {
63 this.serviceArtifactList = a;
67 public String toString() {
68 StringBuilder sb = new StringBuilder();
72 for (ServiceArtifact o : serviceArtifactList) {
73 sb.append(i).append("\t");
83 public String JSON2(boolean isArray, boolean isEmbed) {
84 StringBuilder sb = new StringBuilder();
85 if (!isEmbed && isArray)
88 sb.append("\"serviceArtifact\": [");
89 Map<String, String> valueMap = new HashMap<>();
93 for (ServiceArtifact o : serviceArtifactList) {
98 boolean vrNull = o == null;
100 put(valueMap, "ARTIFACT_UUID", vrNull ? null : o.getArtifactUUID());
101 put(valueMap, "TYPE", vrNull ? null : o.getType());
102 put(valueMap, "NAME", vrNull ? null : o.getName());
103 put(valueMap, "VERSION", vrNull ? null : o.getVersion());
104 put(valueMap, "DESCRIPTION", vrNull ? null : o.getDescription());
105 put(valueMap, "CONTENT", vrNull ? null : o.getContent());
106 put(valueMap, "CHECKSUM", vrNull ? null : o.getChecksum());
107 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
114 if (!isEmbed && isArray)
116 return sb.toString();