fix catalogdb cvfnc customization
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / rest / CatalogDbAdapterRest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.adapters.catalogdb.rest;
24
25
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import javax.ws.rs.GET;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.QueryParam;
35 import javax.ws.rs.core.GenericEntity;
36 import javax.ws.rs.core.HttpHeaders;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.core.Response;
39
40 import org.apache.http.HttpStatus;
41 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery;
42 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException;
43 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
44 import org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
45 import org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe;
46 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar;
47 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
48 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks;
49 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs;
50 import org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule;
51 import org.onap.so.db.catalog.beans.AllottedResource;
52 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
53 import org.onap.so.db.catalog.beans.NetworkResource;
54 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
55 import org.onap.so.db.catalog.beans.Recipe;
56 import org.onap.so.db.catalog.beans.Service;
57 import org.onap.so.db.catalog.beans.ToscaCsar;
58 import org.onap.so.db.catalog.beans.VfModule;
59 import org.onap.so.db.catalog.beans.VfModuleCustomization;
60 import org.onap.so.db.catalog.beans.VnfResource;
61 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
62 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
63 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
64 import org.onap.so.db.catalog.data.repository.ArRecipeRepository;
65 import org.onap.so.db.catalog.data.repository.NetworkRecipeRepository;
66 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
67 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
68 import org.onap.so.db.catalog.data.repository.ServiceRepository;
69 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
70 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
71 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
72 import org.onap.so.db.catalog.data.repository.VnfRecipeRepository;
73 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
74 import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder;
75 import org.slf4j.Logger;
76 import org.slf4j.LoggerFactory;
77 import org.springframework.beans.factory.annotation.Autowired;
78 import org.springframework.stereotype.Component;
79 import org.springframework.transaction.annotation.Transactional;
80
81
82 @Path("/{version: v[0-9]+}")
83 @Component
84 public class CatalogDbAdapterRest {
85     protected static Logger logger = LoggerFactory.getLogger(CatalogDbAdapterRest.class);
86     private static final boolean IS_ARRAY = true;
87     private static final String NETWORK_SERVICE = "network service";
88
89     @Autowired
90     private VnfCustomizationRepository vnfCustomizationRepo;
91
92     @Autowired
93     private ServiceRepository serviceRepo;
94
95     @Autowired
96     private NetworkResourceCustomizationRepository networkCustomizationRepo;
97
98     @Autowired
99     private NetworkResourceRepository networkResourceRepo;
100
101     @Autowired
102     private AllottedResourceCustomizationRepository allottedCustomizationRepo;
103
104     @Autowired
105     private ToscaCsarRepository toscaCsarRepo;
106
107     @Autowired
108     private VFModuleRepository vfModuleRepo;
109
110     @Autowired
111     private VnfRecipeRepository vnfRecipeRepo;
112
113     @Autowired
114     private NetworkRecipeRepository networkRecipeRepo;
115
116     @Autowired
117     private ArRecipeRepository arRecipeRepo;
118
119     @Autowired
120     private VnfResourceRepository vnfResourceRepo;
121
122     @Autowired
123     private AllottedResourceRepository arResourceRepo;
124
125     private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
126
127     public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
128         return Response
129                 .status(respStatus)
130                 .entity(qryResp.toJsonString(version, isArray))
131                 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
132                 .build();
133     }
134
135     @GET
136     @Path("vnfResources/{vnfModelCustomizationUuid}")
137     @Transactional( readOnly = true)
138     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
139     public Response serviceVnfs (
140             @PathParam("version") String version,
141             @PathParam("vnfModelCustomizationUuid") String vnfUuid
142             ) {
143         return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
144     }
145
146     @GET
147     @Path("serviceVnfs")
148     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
149     @Transactional( readOnly = true)
150     public Response serviceVnfs(
151             @PathParam("version") String version,
152             @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
153             @QueryParam("serviceModelUuid") String smUuid,
154             @QueryParam("serviceModelInvariantUuid") String smiUuid,
155             @QueryParam("serviceModelVersion") String smVer,
156             @QueryParam("serviceModelName") String smName
157             ) {
158         return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
159     }
160
161     public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID, String smiUuid, String smVer, String smName) {
162         QueryServiceVnfs qryResp = null;
163         int respStatus = HttpStatus.SC_OK;              
164         List<VnfResourceCustomization> ret = new ArrayList<>();
165         Service service = null;
166         try {
167             if (vnfUuid != null && !"".equals(vnfUuid)) 
168                 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);                       
169             else if (serviceModelUUID != null && !"".equals(serviceModelUUID))                          
170                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
171             else if (smiUuid != null && !"".equals(smiUuid))                    
172                 if (smVer != null && !"".equals(smVer)) 
173                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer,smiUuid);                                  
174                 else                                    
175                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
176             else if (smName != null && !"".equals(smName)) {
177                 if (smVer != null && !"".equals(smVer))                                         
178                     service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
179                 else 
180                     service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);                  
181             }
182             else {
183                 throw(new Exception(NO_MATCHING_PARAMETERS));
184             }
185
186             if (service == null && ret.isEmpty()) {
187                 respStatus = HttpStatus.SC_NOT_FOUND;
188                 qryResp = new QueryServiceVnfs();
189             }else if( service == null && !ret.isEmpty()){
190                 qryResp = new QueryServiceVnfs(ret);                            
191             } else if (service != null) {
192                 qryResp = new QueryServiceVnfs(service.getVnfCustomizations());                         
193             }
194             logger.debug ("serviceVnfs qryResp= {}", qryResp);
195             return respond(version, respStatus, isArray, qryResp);
196         } catch (Exception e) {
197             logger.error("Exception - queryServiceVnfs", e);
198             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
199             return Response
200                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
201                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
202                     .build();
203         }
204     }
205
206     @GET
207     @Path("networkResources/{networkModelCustomizationUuid}")
208     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
209     @Transactional( readOnly = true)
210     public Response serviceNetworks (
211             @PathParam("version") String version,
212             @PathParam("networkModelCustomizationUuid") String nUuid
213             ) {
214         return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
215     }
216
217     @GET
218     @Path("serviceNetworks")
219     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
220     @Transactional( readOnly = true)
221     public Response serviceNetworks (
222             @PathParam("version") String version,
223             @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
224             @QueryParam("networkType") String networkType,
225             @QueryParam("networkModelName") String networkModelName,
226             @QueryParam("serviceModelUuid") String serviceModelUuid,
227             @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
228             @QueryParam("serviceModelVersion") String serviceModelVersion,
229             @QueryParam("networkModelVersion") String networkModelVersion
230             ) {
231         if (networkModelName != null && !"".equals(networkModelName)) {
232             networkType = networkModelName;
233         }
234         return serviceNetworksImpl (version, IS_ARRAY,  networkModelCustomizationUuid, networkType, serviceModelUuid, serviceModelInvariantUuid, serviceModelVersion);
235     }
236
237     public Response serviceNetworksImpl (String version, boolean isArray, String  networkModelCustomizationUuid, String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
238         QueryServiceNetworks qryResp;
239         int respStatus = HttpStatus.SC_OK;
240         String uuid = "";
241         List<NetworkResourceCustomization> ret = new ArrayList<>();
242         Service service = null;
243
244         try{
245             if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
246                 uuid = networkModelCustomizationUuid;                           
247                 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
248             }else if (networkType != null && !"".equals(networkType)) {
249                 uuid = networkType;                             
250                 NetworkResource networkResources = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
251                 if(networkResources != null)
252                     ret=networkResources.getNetworkResourceCustomization();
253             }
254             else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
255                 uuid = serviceModelInvariantUuid;
256                 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {                                   
257                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
258                 }
259                 else {                                  
260                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
261                 }
262             }else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
263                 uuid = serviceModelUuid;                                
264                 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
265             }
266             else {
267                 throw(new Exception(NO_MATCHING_PARAMETERS));
268             }
269
270             if(service != null)
271                 ret = service.getNetworkCustomizations();
272
273             if (ret == null || ret.isEmpty()) {
274                 logger.debug ("serviceNetworks not found");
275                 respStatus = HttpStatus.SC_NOT_FOUND;
276                 qryResp = new QueryServiceNetworks();
277             } else {                            
278                 qryResp = new QueryServiceNetworks(ret);
279                 logger.debug ("serviceNetworks found qryResp= {}", qryResp);
280             }
281             return respond(version, respStatus, isArray, qryResp);
282         } catch (Exception e) {
283             logger.error ("Exception - queryServiceNetworks", e);
284             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
285             return Response
286                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
287                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
288                     .build();
289         }
290     }
291
292     @GET
293     @Path("serviceResources")
294     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
295     @Transactional(readOnly = true)
296     public Response serviceResources(
297             @PathParam("version") String version,
298             @QueryParam("serviceModelUuid") String modelUUID,
299             @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
300             @QueryParam("serviceModelVersion") String modelVersion) {
301         QueryServiceMacroHolder qryResp;
302         int respStatus = HttpStatus.SC_OK;
303         String uuid = "";
304         ServiceMacroHolder ret = new ServiceMacroHolder();
305
306         try{
307             if (modelUUID != null && !"".equals(modelUUID)) {
308                 uuid = modelUUID;
309                 logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}" , uuid);
310                 Service serv =serviceRepo.findOneByModelUUID(uuid);
311
312                 if (serv != null) {
313                     ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
314                     ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
315                     ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
316                 }
317                 ret.setService(serv);
318             }
319             else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
320                 uuid = modelInvariantUUID;
321                 if (modelVersion != null && !"".equals(modelVersion)) {
322                     logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {}  serviceModelVersion: {}",uuid, modelVersion);
323                     Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
324
325                     ret.setService(serv);
326                 }
327                 else {
328                     logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}" , uuid);
329                     Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
330                     ret.setService(serv);
331                 }
332             }
333             else {
334                 throw(new Exception(NO_MATCHING_PARAMETERS));
335             }
336
337             if (ret.getService() == null) {
338                 logger.debug ("serviceMacroHolder not found");
339                 respStatus = HttpStatus.SC_NOT_FOUND;
340                 qryResp = new QueryServiceMacroHolder();
341             } else {
342                 qryResp = new QueryServiceMacroHolder(ret);
343                 logger.debug ("serviceMacroHolder qryResp= {}", qryResp);
344             }
345             return respond(version, respStatus, IS_ARRAY, qryResp);
346         } catch (Exception e) {
347             logger.error ("Exception - queryServiceMacroHolder", e);
348             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
349             return Response
350                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
351                     .entity(new GenericEntity<CatalogQueryException>(excResp){} )
352                     .build();
353         }
354     }
355
356
357     @GET
358     @Path("allottedResources/{arModelCustomizationUuid}")
359     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
360     @Transactional( readOnly = true)
361     public Response serviceAllottedResources (
362             @PathParam("version") String version,
363             @PathParam("arModelCustomizationUuid") String aUuid
364             ) {
365         return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
366     }
367
368     @GET
369     @Path("serviceAllottedResources")
370     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
371     @Transactional( readOnly = true)
372     public Response serviceAllottedResources(
373             @PathParam("version") String version,
374             @QueryParam("serviceModelUuid") String smUuid,
375             @QueryParam("serviceModelInvariantUuid") String smiUuid,
376             @QueryParam("serviceModelVersion") String smVer,
377             @QueryParam("arModelCustomizationUuid") String aUuid
378             ) {
379         return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
380     }
381
382     public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String serviceModelInvariantUuid, String smVer) {
383         QueryAllottedResourceCustomization qryResp;
384         int respStatus = HttpStatus.SC_OK;
385         String uuid = "";
386         List<AllottedResourceCustomization> ret = new ArrayList<>();
387         Service service = null;
388         try{
389             if (smUuid != null && !"".equals(smUuid)) {
390                 uuid = smUuid;                          
391                 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);                     
392             }
393             else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
394                 uuid = serviceModelInvariantUuid;
395                 if (smVer != null && !"".equals(smVer)) {                                       
396                     service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
397                 }
398                 else {                          
399                     service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
400                 }
401             }
402             else if (aUuid != null && !"".equals(aUuid)) {
403                 uuid = aUuid;                           
404                 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
405             }
406             else {
407                 throw(new Exception(NO_MATCHING_PARAMETERS));
408             }
409
410             if(service != null)
411                 ret=service.getAllottedCustomizations();
412
413             if (ret == null || ret.isEmpty()) {
414                 logger.debug ("AllottedResourceCustomization not found");
415                 respStatus = HttpStatus.SC_NOT_FOUND;
416                 qryResp = new QueryAllottedResourceCustomization();
417             } else {                            
418                 qryResp = new QueryAllottedResourceCustomization(ret);
419                 logger.debug ("AllottedResourceCustomization qryResp= {}", qryResp);
420             }                   
421             return respond(version, respStatus, isArray, qryResp);
422         } catch (Exception e) {
423             logger.error ("Exception - queryAllottedResourceCustomization", e);
424             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
425             return Response
426                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
427                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
428                     .build();
429         }
430     }
431
432     @GET
433     @Path("vfModules")
434     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
435     @Transactional( readOnly = true)
436     public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
437         QueryVfModule qryResp;
438         int respStatus = HttpStatus.SC_OK;
439         List<VfModuleCustomization> ret = null; 
440         try{
441             if(vfModuleModelName != null && !"".equals(vfModuleModelName)){
442                 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
443                 if(vfModule != null)
444                     ret = vfModule.getVfModuleCustomization();                          
445             }else{
446                 throw(new Exception(NO_MATCHING_PARAMETERS));
447             }
448
449             if(ret == null || ret.isEmpty()){
450                 logger.debug ("vfModules not found");
451                 respStatus = HttpStatus.SC_NOT_FOUND;
452                 qryResp = new QueryVfModule();
453             }else{                      
454                 qryResp = new QueryVfModule(ret);                               
455                 if(logger.isDebugEnabled())
456                     logger.debug ("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
457             }                   
458             return Response
459                     .status(respStatus)
460                     .entity(qryResp.JSON2(false, false)) 
461                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
462                     .build();
463         }catch(Exception e){
464             logger.error ("Exception during query VfModules by vfModuleModuleName: ", e);
465             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
466             return Response
467                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
468                     .entity(new GenericEntity<CatalogQueryException>(excResp) {})
469                     .build();
470         }
471     }
472     /**
473      * Get the tosca csar info from catalog
474      * <br>
475      * 
476      * @param smUuid service model uuid
477      * @return the tosca csar information of the serivce.
478      * @since ONAP Beijing Release
479      */
480     @GET
481     @Path("serviceToscaCsar")
482     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
483     public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
484         int respStatus = HttpStatus.SC_OK;
485         String entity = "";
486         try {
487             if (smUuid != null && !"".equals(smUuid)) {
488                 logger.debug("Query Csar by service model uuid: {}",smUuid);
489
490                 Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
491
492                 if (service != null) {
493                     ToscaCsar toscaCsar = service.getCsar();
494                     if (toscaCsar != null) {
495                         QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
496                         entity = serviceCsar.JSON2(false, false);
497                     } else {
498                         respStatus = HttpStatus.SC_NOT_FOUND;
499                     }
500                 } else {
501                     respStatus = HttpStatus.SC_NOT_FOUND;
502                 }
503
504             } else {
505                 throw (new Exception("Incoming parameter is null or blank"));
506             }
507             return Response
508                     .status(respStatus)
509                     .entity(entity)
510                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
511                     .build();
512         } catch (Exception e) {
513             logger.error("Exception during query csar by service model uuid: ", e);
514             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
515                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
516             return Response
517                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
518                     .entity(new GenericEntity<CatalogQueryException>(excResp) {
519                     })
520                     .build();
521         }
522     }
523
524     /**
525      * Get the resource recipe info from catalog
526      * <br>
527      * 
528      * @param rmUuid resource model uuid
529      * @return the recipe information of the resource.
530      * @since ONAP Beijing Release
531      */
532     @GET
533     @Path("resourceRecipe")
534     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
535     public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
536         int respStatus = HttpStatus.SC_OK;
537         String entity = "";
538         try {
539             if (rmUuid != null && !"".equals(rmUuid)) {
540                 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
541                 //check vnf and network and ar, the resource could be any resource.
542                 Recipe recipe = null;
543
544                 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
545                 if (vnf != null) {
546                     recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion());
547
548                     // for network service fetch the default recipe
549                     if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
550                         recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
551                     }
552                 }
553
554
555                 if (null == recipe) {
556                     NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
557
558                     if(nResource != null) {
559                         recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, nResource.getModelVersion());
560
561                         // for network fetch the default recipe
562                         if (recipe == null) {
563                             recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
564                         }
565                     }
566                 }
567
568                 if (null == recipe) {
569                     AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
570                     if (arResource != null) {
571                         recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion());
572                     }
573                 }
574                 if (recipe != null) {
575                     QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
576                     entity = resourceRecipe.JSON2(false, false);
577                 } else {
578                     respStatus = HttpStatus.SC_NOT_FOUND;
579                 }
580             } else {
581                 throw new Exception("Incoming parameter is null or blank");
582             }
583             return Response
584                     .status(respStatus)
585                     .entity(entity)
586                     .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
587                     .build();
588         } catch (Exception e) {
589             logger.error("Exception during query recipe by resource model uuid: ", e);
590             CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
591                     CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
592             return Response
593                     .status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
594                     .entity(new GenericEntity<CatalogQueryException>(excResp) {
595                     })
596                     .build();
597         }
598     }
599 }