2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.adapters.catalogdb.rest;
27 import java.util.ArrayList;
28 import java.util.List;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.PUT;
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 import org.apache.commons.lang3.StringUtils;
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.InstanceGroup;
54 import org.onap.so.db.catalog.beans.NetworkResource;
55 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
56 import org.onap.so.db.catalog.beans.ProcessingFlags;
57 import org.onap.so.db.catalog.beans.Recipe;
58 import org.onap.so.db.catalog.beans.Service;
59 import org.onap.so.db.catalog.beans.ToscaCsar;
60 import org.onap.so.db.catalog.beans.VfModule;
61 import org.onap.so.db.catalog.beans.VfModuleCustomization;
62 import org.onap.so.db.catalog.beans.VnfResource;
63 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
64 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
65 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
66 import org.onap.so.db.catalog.data.repository.ArRecipeRepository;
67 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
68 import org.onap.so.db.catalog.data.repository.NetworkRecipeRepository;
69 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
70 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
71 import org.onap.so.db.catalog.data.repository.ProcessingFlagsRepository;
72 import org.onap.so.db.catalog.data.repository.ServiceRepository;
73 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
74 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
75 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
76 import org.onap.so.db.catalog.data.repository.VnfRecipeRepository;
77 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
78 import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder;
79 import org.slf4j.Logger;
80 import org.slf4j.LoggerFactory;
81 import org.springframework.beans.factory.annotation.Autowired;
82 import org.springframework.stereotype.Component;
83 import org.springframework.transaction.annotation.Transactional;
86 @Path("/{version: v[0-9]+}")
88 public class CatalogDbAdapterRest {
89 protected static Logger logger = LoggerFactory.getLogger(CatalogDbAdapterRest.class);
90 private static final boolean IS_ARRAY = true;
91 private static final String NETWORK_SERVICE = "network service";
92 private static final String RESOURCE_INPUT_FILTER = "resourceInput";
95 private VnfCustomizationRepository vnfCustomizationRepo;
98 private ServiceRepository serviceRepo;
101 private NetworkResourceCustomizationRepository networkCustomizationRepo;
104 private NetworkResourceRepository networkResourceRepo;
107 private AllottedResourceCustomizationRepository allottedCustomizationRepo;
110 private ToscaCsarRepository toscaCsarRepo;
113 private VFModuleRepository vfModuleRepo;
116 private VnfRecipeRepository vnfRecipeRepo;
119 private NetworkRecipeRepository networkRecipeRepo;
122 private ArRecipeRepository arRecipeRepo;
125 private VnfResourceRepository vnfResourceRepo;
128 private AllottedResourceRepository arResourceRepo;
131 private InstanceGroupRepository instanceGroupRepository;
134 private ProcessingFlagsRepository processingFlagsRepo;
136 private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
138 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
139 return Response.status(respStatus).entity(qryResp.toJsonString(version, isArray))
140 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
144 @Path("vnfResources/{vnfModelCustomizationUuid}")
145 @Transactional(readOnly = true)
146 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
147 public Response serviceVnfs(@PathParam("version") String version,
148 @PathParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("filter") String filter) {
149 return serviceVnfsImpl(version, !IS_ARRAY, vnfUuid, null, null, null, null, filter);
154 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
155 @Transactional(readOnly = true)
156 public Response serviceVnfs(@PathParam("version") String version,
157 @QueryParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("serviceModelUuid") String smUuid,
158 @QueryParam("serviceModelInvariantUuid") String smiUuid, @QueryParam("serviceModelVersion") String smVer,
159 @QueryParam("serviceModelName") String smName, @QueryParam("filter") String filter) {
160 return serviceVnfsImpl(version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName, filter);
163 public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID,
164 String smiUuid, String smVer, String smName, String filter) {
165 QueryServiceVnfs qryResp = null;
166 int respStatus = HttpStatus.SC_OK;
167 List<VnfResourceCustomization> ret = new ArrayList<>();
168 Service service = null;
170 if (vnfUuid != null && !"".equals(vnfUuid))
171 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);
172 else if (serviceModelUUID != null && !"".equals(serviceModelUUID))
173 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
174 else if (smiUuid != null && !"".equals(smiUuid))
175 if (smVer != null && !"".equals(smVer))
176 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid);
178 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
179 else if (smName != null && !"".equals(smName)) {
180 if (smVer != null && !"".equals(smVer))
181 service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
183 service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);
185 throw (new Exception(NO_MATCHING_PARAMETERS));
188 if (service == null && ret.isEmpty()) {
189 respStatus = HttpStatus.SC_NOT_FOUND;
190 qryResp = new QueryServiceVnfs();
191 } else if (service == null && !ret.isEmpty()) {
192 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
193 ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
195 qryResp = new QueryServiceVnfs(ret);
196 } else if (service != null) {
197 ret = service.getVnfCustomizations();
198 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
199 ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
201 qryResp = new QueryServiceVnfs(ret);
203 logger.debug("serviceVnfs qryResp= {}", qryResp);
204 return respond(version, respStatus, isArray, qryResp);
205 } catch (Exception e) {
206 logger.error("Exception - queryServiceVnfs", e);
207 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
208 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
209 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
210 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
215 @Path("networkResources/{networkModelCustomizationUuid}")
216 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
217 @Transactional(readOnly = true)
218 public Response serviceNetworks(@PathParam("version") String version,
219 @PathParam("networkModelCustomizationUuid") String nUuid) {
220 return serviceNetworksImpl(version, !IS_ARRAY, nUuid, null, null, null, null);
224 @Path("serviceNetworks")
225 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
226 @Transactional(readOnly = true)
227 public Response serviceNetworks(@PathParam("version") String version,
228 @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
229 @QueryParam("networkType") String networkType, @QueryParam("networkModelName") String networkModelName,
230 @QueryParam("serviceModelUuid") String serviceModelUuid,
231 @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
232 @QueryParam("serviceModelVersion") String serviceModelVersion,
233 @QueryParam("networkModelVersion") String networkModelVersion) {
234 if (networkModelName != null && !"".equals(networkModelName)) {
235 networkType = networkModelName;
237 return serviceNetworksImpl(version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid,
238 serviceModelInvariantUuid, serviceModelVersion);
241 public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid,
242 String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
243 QueryServiceNetworks qryResp;
244 int respStatus = HttpStatus.SC_OK;
246 List<NetworkResourceCustomization> ret = new ArrayList<>();
247 Service service = null;
250 if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
251 uuid = networkModelCustomizationUuid;
252 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
253 } else if (networkType != null && !"".equals(networkType)) {
255 NetworkResource networkResources =
256 networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
257 if (networkResources != null)
258 ret = networkResources.getNetworkResourceCustomization();
259 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
260 uuid = serviceModelInvariantUuid;
261 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
262 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
264 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
266 } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
267 uuid = serviceModelUuid;
268 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
270 throw (new Exception(NO_MATCHING_PARAMETERS));
274 ret = service.getNetworkCustomizations();
276 if (ret == null || ret.isEmpty()) {
277 logger.debug("serviceNetworks not found");
278 respStatus = HttpStatus.SC_NOT_FOUND;
279 qryResp = new QueryServiceNetworks();
281 qryResp = new QueryServiceNetworks(ret);
282 logger.debug("serviceNetworks found qryResp= {}", qryResp);
284 return respond(version, respStatus, isArray, qryResp);
285 } catch (Exception e) {
286 logger.error("Exception - queryServiceNetworks", e);
287 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
288 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
289 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
290 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
295 @Path("serviceResources")
296 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
297 @Transactional(readOnly = true)
298 public Response serviceResources(@PathParam("version") String version,
299 @QueryParam("serviceModelUuid") String modelUUID,
300 @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
301 @QueryParam("serviceModelVersion") String modelVersion, @QueryParam("filter") String filter) {
303 QueryServiceMacroHolder qryResp;
304 int respStatus = HttpStatus.SC_OK;
306 ServiceMacroHolder ret = new ServiceMacroHolder();
309 if (modelUUID != null && !"".equals(modelUUID)) {
311 logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid);
312 Service serv = serviceRepo.findOneByModelUUID(uuid);
315 ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
316 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
317 serv.getVnfCustomizations()
318 .forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
320 ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
321 ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
323 ret.setService(serv);
324 } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
325 uuid = modelInvariantUUID;
326 if (modelVersion != null && !"".equals(modelVersion)) {
328 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}",
330 Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
332 ret.setService(serv);
335 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}",
337 Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
338 ret.setService(serv);
341 throw (new Exception(NO_MATCHING_PARAMETERS));
344 if (ret.getService() == null) {
345 logger.debug("serviceMacroHolder not found");
346 respStatus = HttpStatus.SC_NOT_FOUND;
347 qryResp = new QueryServiceMacroHolder();
349 qryResp = new QueryServiceMacroHolder(ret);
350 logger.debug("serviceMacroHolder qryResp= {}", qryResp);
352 return respond(version, respStatus, IS_ARRAY, qryResp);
353 } catch (Exception e) {
354 logger.error("Exception - queryServiceMacroHolder", e);
355 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
356 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
357 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
358 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
364 @Path("allottedResources/{arModelCustomizationUuid}")
365 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
366 @Transactional(readOnly = true)
367 public Response serviceAllottedResources(@PathParam("version") String version,
368 @PathParam("arModelCustomizationUuid") String aUuid) {
369 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
373 @Path("serviceAllottedResources")
374 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
375 @Transactional(readOnly = true)
376 public Response serviceAllottedResources(@PathParam("version") String version,
377 @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid,
378 @QueryParam("serviceModelVersion") String smVer, @QueryParam("arModelCustomizationUuid") String aUuid) {
379 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
382 public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid,
383 String serviceModelInvariantUuid, String smVer) {
384 QueryAllottedResourceCustomization qryResp;
385 int respStatus = HttpStatus.SC_OK;
387 List<AllottedResourceCustomization> ret = new ArrayList<>();
388 Service service = null;
390 if (smUuid != null && !"".equals(smUuid)) {
392 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);
393 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
394 uuid = serviceModelInvariantUuid;
395 if (smVer != null && !"".equals(smVer)) {
396 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
398 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
400 } else if (aUuid != null && !"".equals(aUuid)) {
402 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
404 throw (new Exception(NO_MATCHING_PARAMETERS));
408 ret = service.getAllottedCustomizations();
410 if (ret == null || ret.isEmpty()) {
411 logger.debug("AllottedResourceCustomization not found");
412 respStatus = HttpStatus.SC_NOT_FOUND;
413 qryResp = new QueryAllottedResourceCustomization();
415 qryResp = new QueryAllottedResourceCustomization(ret);
416 logger.debug("AllottedResourceCustomization qryResp= {}", qryResp);
418 return respond(version, respStatus, isArray, qryResp);
419 } catch (Exception e) {
420 logger.error("Exception - queryAllottedResourceCustomization", e);
421 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
422 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
423 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
424 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
430 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
431 @Transactional(readOnly = true)
432 public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
433 QueryVfModule qryResp;
434 int respStatus = HttpStatus.SC_OK;
435 List<VfModuleCustomization> ret = null;
437 if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
438 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
439 if (vfModule != null)
440 ret = vfModule.getVfModuleCustomization();
442 throw (new Exception(NO_MATCHING_PARAMETERS));
445 if (ret == null || ret.isEmpty()) {
446 logger.debug("vfModules not found");
447 respStatus = HttpStatus.SC_NOT_FOUND;
448 qryResp = new QueryVfModule();
450 qryResp = new QueryVfModule(ret);
451 if (logger.isDebugEnabled())
452 logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
454 return Response.status(respStatus).entity(qryResp.JSON2(false, false))
455 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
456 } catch (Exception e) {
457 logger.error("Exception during query VfModules by vfModuleModuleName: ", e);
458 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
459 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
460 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
461 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
466 * Get the tosca csar info from catalog <br>
468 * @param smUuid service model uuid
469 * @return the tosca csar information of the serivce.
470 * @since ONAP Beijing Release
473 @Path("serviceToscaCsar")
474 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
475 public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
476 int respStatus = HttpStatus.SC_OK;
479 if (smUuid != null && !"".equals(smUuid)) {
480 logger.debug("Query Csar by service model uuid: {}", smUuid);
482 Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
484 if (service != null) {
485 ToscaCsar toscaCsar = service.getCsar();
486 if (toscaCsar != null) {
487 QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
488 entity = serviceCsar.JSON2(false, false);
490 respStatus = HttpStatus.SC_NOT_FOUND;
493 respStatus = HttpStatus.SC_NOT_FOUND;
497 throw (new Exception("Incoming parameter is null or blank"));
499 return Response.status(respStatus).entity(entity)
500 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
501 } catch (Exception e) {
502 logger.error("Exception during query csar by service model uuid: ", e);
503 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
504 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
505 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
506 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
511 * Get the resource recipe info from catalog <br>
513 * @param rmUuid resource model uuid
514 * @return the recipe information of the resource.
515 * @since ONAP Beijing Release
518 @Path("resourceRecipe")
519 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
520 public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid,
521 @QueryParam("action") String action) {
522 int respStatus = HttpStatus.SC_OK;
525 if (rmUuid != null && !"".equals(rmUuid)) {
526 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
527 // check vnf and network and ar, the resource could be any resource.
528 Recipe recipe = null;
530 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
532 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action,
533 vnf.getModelVersion());
535 // for network service fetch the default recipe
536 if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
537 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
542 if (null == recipe) {
543 NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
545 if (nResource != null) {
546 recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(),
547 action, nResource.getModelVersion());
549 // for network fetch the default recipe
550 if (recipe == null) {
551 recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
556 if (null == recipe) {
557 AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
558 if (arResource != null) {
559 recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action,
560 arResource.getModelVersion());
564 if (null == recipe) {
565 InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
566 if (grpResource != null) {
567 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(
568 grpResource.getModelName(), action, grpResource.getModelVersion());
573 if (recipe != null) {
574 QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
575 entity = resourceRecipe.JSON2(false, false);
577 respStatus = HttpStatus.SC_NOT_FOUND;
580 throw new Exception("Incoming parameter is null or blank");
582 return Response.status(respStatus).entity(entity)
583 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
584 } catch (Exception e) {
585 logger.error("Exception during query recipe by resource model uuid: ", e);
586 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
587 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
588 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
589 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
594 @Path("processingFlags/{flag}")
595 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
596 @Transactional(readOnly = true)
597 public Response getProcessingFlags(@PathParam("flag") String flag) {
598 return getProcessingFlagsImpl(flag);
601 public Response getProcessingFlagsImpl(String flag) {
602 ProcessingFlags processingFlags = null;
603 logger.debug("Flag is: " + flag);
604 int respStatus = HttpStatus.SC_OK;
606 processingFlags = processingFlagsRepo.findByFlag(flag);
607 if (processingFlags == null) {
608 logger.debug("ProcessingFlag not found");
609 respStatus = HttpStatus.SC_NOT_FOUND;
613 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
615 return Response.status(respStatus).entity(processingFlags)
616 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
617 } catch (Exception e) {
618 logger.error("Exception - queryProcesssingFlags", e);
619 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
620 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
621 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
622 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
627 @Path("processingFlags/{flag}")
628 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
630 public Response updateProcessingFlagsValue(@PathParam("flag") String flag, ProcessingFlags updatedProcessingFlag) {
631 return updateProcessingFlagsValueImpl(flag, updatedProcessingFlag);
634 public Response updateProcessingFlagsValueImpl(String flag, ProcessingFlags updatedProcessingFlag) {
635 ProcessingFlags processingFlags = null;
636 logger.debug("Flag is: " + flag);
637 int respStatus = HttpStatus.SC_OK;
639 if (updatedProcessingFlag == null) {
640 logger.debug("No valid updatedProcessingFlag is provided");
641 throw new RuntimeException("No valid updatedProcessingFlag is provided");
643 String value = updatedProcessingFlag.getValue();
644 if (value == null || (!value.equalsIgnoreCase("YES") && !value.equalsIgnoreCase("NO"))) {
645 logger.debug("Value " + value + " is invalid, only yes/no are allowed");
646 throw new RuntimeException("Invalid value specified");
648 processingFlags = processingFlagsRepo.findByFlag(flag);
649 if (processingFlags == null) {
650 logger.debug("ProcessingFlag not found");
651 respStatus = HttpStatus.SC_NOT_FOUND;
653 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
654 processingFlags.setValue(value);
655 processingFlagsRepo.saveAndFlush(processingFlags);
656 return Response.status(respStatus).entity(null)
657 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
659 } catch (Exception e) {
660 logger.error("Exception - queryProcesssingFlags", e);
661 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
662 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
663 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
664 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
667 return Response.status(HttpStatus.SC_NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
672 @Path("processingFlags")
673 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
674 @Transactional(readOnly = true)
675 public Response getAllProcessingFlags() {
676 return getAllProcessingFlagsImpl();
679 public Response getAllProcessingFlagsImpl() {
680 List<ProcessingFlags> processingFlags = null;
682 int respStatus = HttpStatus.SC_OK;
684 processingFlags = processingFlagsRepo.findAll();
685 if (processingFlags == null) {
686 logger.debug("ProcessingFlags not found");
687 respStatus = HttpStatus.SC_NOT_FOUND;
690 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
692 return Response.status(respStatus).entity(processingFlags)
693 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
694 } catch (Exception e) {
695 logger.error("Exception - queryProcesssingFlags", e);
696 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
697 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
698 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
699 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();