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