c7ae137759bbca816689d79b2ea6e53e931a0bb1
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / catalogrest / QueryServiceCsar.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.so.adapters.catalogdb.catalogrest;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.onap.so.db.catalog.beans.ToscaCsar;
26
27 /**
28  * serivce csar query support 
29  * <br>
30  * <p>
31  * </p>
32  * 
33  * @author
34  * @version     ONAP Beijing Release  2018-02-28
35  */
36 public class QueryServiceCsar extends CatalogQuery{
37     
38     private static final String TEMPLATE =
39             "\t{\n"+
40             "\t\t\"artifactUUID\"         : <ARTIFACT_UUID>,\n"+
41             "\t\t\"name\"                 : <NAME>,\n"+
42             "\t\t\"version\"              : <VERSION>,\n"+
43             "\t\t\"artifactChecksum\"     : <ARTIFACT_CHECK_SUM>,\n"+
44             "\t\t\"url\"                  : <URL>,\n"+
45             "\t\t\"description\"          : <DESCRIPTION>\n"+
46             "\t}";
47     
48     private ToscaCsar toscaCsar;
49     
50     public QueryServiceCsar(ToscaCsar toscaCsar){
51         this.toscaCsar = toscaCsar;
52     }
53     
54     @Override
55     public String toString() {
56         return toscaCsar.toString();
57     }
58
59     @Override
60     public String JSON2(boolean isArray, boolean isEmbed) {
61         Map<String, String> valueMap = new HashMap<>();
62         put(valueMap, "ARTIFACT_UUID", null == toscaCsar ? null : toscaCsar.getArtifactUUID());
63         put(valueMap, "NAME", null == toscaCsar ? null : toscaCsar.getName());
64         put(valueMap, "VERSION", null == toscaCsar ? null : toscaCsar.getVersion());
65         put(valueMap, "ARTIFACT_CHECK_SUM", null == toscaCsar ? null : toscaCsar.getArtifactChecksum());
66         put(valueMap, "URL", null == toscaCsar ? null : toscaCsar.getUrl());
67         put(valueMap, "DESCRIPTION", null == toscaCsar ? null : toscaCsar.getDescription());
68         return this.setTemplate(TEMPLATE, valueMap);
69     }
70
71 }