2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. 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
 
  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=========================================================
 
  20 package org.openecomp.mso.adapters.catalogdb.catalogrest;
 
  21 /* should be called QueryVnfResource.java */
 
  23 import org.openecomp.mso.db.catalog.beans.VnfResource;
 
  24 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
 
  25 import org.jboss.resteasy.annotations.providers.NoJackson;
 
  27 import javax.xml.bind.annotation.XmlRootElement;
 
  28 import java.util.ArrayList;
 
  29 import java.util.HashMap;
 
  30 import java.util.List;
 
  33 @XmlRootElement(name = "serviceVnfs")
 
  35 public class QueryServiceVnfs extends CatalogQuery {
 
  36         private List<VnfResourceCustomization> serviceVnfs;
 
  37         private final String template =
 
  39 //        "\t{ \"vnfResource\"                    : {\n"+
 
  40         "\t{ \"modelInfo\"                    : {\n"+
 
  41                         "\t\t\"modelName\"              : <MODEL_NAME>,\n"+
 
  42                         "\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
 
  43                         "\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
 
  44                         "\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
 
  45                         "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
 
  46                         "\t\t\"modelInstanceName\"      : <MODEL_INSTANCE_NAME>\n"+
 
  48                         "\t\"toscaNodeType\"            : <TOSCA_NODE_TYPE>,\n"+
 
  49                         "\t\"nfFunction\"               : <NF_FUNCTION>,\n"+
 
  50                         "\t\"nfType\"                           : <NF_TYPE>,\n"+
 
  51                         "\t\"nfRole\"                           : <NF_ROLE>,\n"+
 
  52                         "\t\"nfNamingCode\"             : <NF_NAMING_CODE>,\n"+
 
  58         public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResourceCustomization>(); }
 
  59         public QueryServiceVnfs(List<VnfResourceCustomization> vlist) { 
 
  60                 LOGGER.debug ("QueryServiceVnfs:");
 
  61                 serviceVnfs = new ArrayList<VnfResourceCustomization>();
 
  62                 for (VnfResourceCustomization o : vlist) {
 
  63                         LOGGER.debug ("-- o is a  serviceVnfs ----");
 
  64                         LOGGER.debug (o.toString());
 
  66                         LOGGER.debug ("-------------------");
 
  70         public List<VnfResourceCustomization> getServiceVnfs(){ return this.serviceVnfs; }
 
  71         public void setServiceVnfs(List<VnfResourceCustomization> v) { this.serviceVnfs = v; }
 
  74         public String toString () {
 
  75                 StringBuffer buf = new StringBuffer();
 
  79                 for (VnfResourceCustomization o : serviceVnfs) {
 
  81                         if (!first) buf.append("\n"); first = false;
 
  84                 return buf.toString();
 
  88         public String JSON2(boolean isArray, boolean isEmbed) {
 
  89                 StringBuffer buf = new StringBuffer();
 
  90                 if (!isEmbed && isArray) buf.append("{ ");
 
  91                 if (isArray) buf.append("\"serviceVnfs\": [");
 
  92                 Map<String, String> valueMap = new HashMap<String, String>();
 
  96                 for (VnfResourceCustomization o : serviceVnfs) {
 
  97                         if (first) buf.append("\n"); first = false;
 
  99                         boolean vrNull = o.getVnfResource() == null ? true : false;
 
 101                     put(valueMap, "MODEL_NAME",               vrNull ? null : o.getVnfResource().getModelName());
 
 102                     put(valueMap, "MODEL_UUID",               vrNull ? null : o.getVnfResource().getModelUuid());
 
 103                     put(valueMap, "MODEL_INVARIANT_ID",       vrNull ? null : o.getVnfResource().getModelInvariantId());
 
 104                     put(valueMap, "MODEL_VERSION",            vrNull ? null : o.getVnfResource().getVersion());
 
 105                     put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
 
 106                     put(valueMap, "MODEL_INSTANCE_NAME",      o.getModelInstanceName());
 
 107                     put(valueMap, "TOSCA_NODE_TYPE",     vrNull ? null : o.getVnfResource().getToscaNodeType());
 
 108                     put(valueMap, "NF_FUNCTION", o.getNfFunction());
 
 109                     put(valueMap, "NF_TYPE", o.getNfType());
 
 110                     put(valueMap, "NF_ROLE", o.getNfRole());
 
 111                     put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
 
 113                     String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); 
 
 114                     valueMap.put("_VFMODULES_",               subitem.replaceAll("(?m)^", "\t\t"));
 
 116             buf.append(sep+ this.setTemplate(template, valueMap));
 
 119                 if (!first) buf.append("\n");
 
 120                 if (isArray) buf.append("]");
 
 121                 if (!isEmbed && isArray) buf.append("}");
 
 122                 return buf.toString();