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.http.HttpStatus;
40 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery;
41 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException;
42 import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
43 import org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
44 import org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe;
45 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar;
46 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
47 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks;
48 import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs;
49 import org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule;
50 import org.onap.so.db.catalog.beans.AllottedResource;
51 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
52 import org.onap.so.db.catalog.beans.InstanceGroup;
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.ProcessingFlags;
56 import org.onap.so.db.catalog.beans.Recipe;
57 import org.onap.so.db.catalog.beans.Service;
58 import org.onap.so.db.catalog.beans.ToscaCsar;
59 import org.onap.so.db.catalog.beans.VfModule;
60 import org.onap.so.db.catalog.beans.VfModuleCustomization;
61 import org.onap.so.db.catalog.beans.VnfRecipe;
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";
94 private VnfCustomizationRepository vnfCustomizationRepo;
97 private ServiceRepository serviceRepo;
100 private NetworkResourceCustomizationRepository networkCustomizationRepo;
103 private NetworkResourceRepository networkResourceRepo;
106 private AllottedResourceCustomizationRepository allottedCustomizationRepo;
109 private ToscaCsarRepository toscaCsarRepo;
112 private VFModuleRepository vfModuleRepo;
115 private VnfRecipeRepository vnfRecipeRepo;
118 private NetworkRecipeRepository networkRecipeRepo;
121 private ArRecipeRepository arRecipeRepo;
124 private VnfResourceRepository vnfResourceRepo;
127 private AllottedResourceRepository arResourceRepo;
130 private InstanceGroupRepository instanceGroupRepository;
133 private ProcessingFlagsRepository processingFlagsRepo;
135 private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
137 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
138 return Response.status(respStatus).entity(qryResp.toJsonString(version, isArray))
139 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
143 @Path("vnfResources/{vnfModelCustomizationUuid}")
144 @Transactional(readOnly = true)
145 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
146 public Response serviceVnfs(@PathParam("version") String version,
147 @PathParam("vnfModelCustomizationUuid") String vnfUuid) {
148 return serviceVnfsImpl(version, !IS_ARRAY, vnfUuid, null, null, null, null);
153 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
154 @Transactional(readOnly = true)
155 public Response serviceVnfs(@PathParam("version") String version,
156 @QueryParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("serviceModelUuid") String smUuid,
157 @QueryParam("serviceModelInvariantUuid") String smiUuid, @QueryParam("serviceModelVersion") String smVer,
158 @QueryParam("serviceModelName") String smName) {
159 return serviceVnfsImpl(version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
162 public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID,
163 String smiUuid, String smVer, String smName) {
164 QueryServiceVnfs qryResp = null;
165 int respStatus = HttpStatus.SC_OK;
166 List<VnfResourceCustomization> ret = new ArrayList<>();
167 Service service = null;
169 if (vnfUuid != null && !"".equals(vnfUuid))
170 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);
171 else if (serviceModelUUID != null && !"".equals(serviceModelUUID))
172 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
173 else if (smiUuid != null && !"".equals(smiUuid))
174 if (smVer != null && !"".equals(smVer))
175 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid);
177 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
178 else if (smName != null && !"".equals(smName)) {
179 if (smVer != null && !"".equals(smVer))
180 service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
182 service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);
184 throw (new Exception(NO_MATCHING_PARAMETERS));
187 if (service == null && ret.isEmpty()) {
188 respStatus = HttpStatus.SC_NOT_FOUND;
189 qryResp = new QueryServiceVnfs();
190 } else if (service == null && !ret.isEmpty()) {
191 qryResp = new QueryServiceVnfs(ret);
192 } else if (service != null) {
193 qryResp = new QueryServiceVnfs(service.getVnfCustomizations());
195 logger.debug("serviceVnfs qryResp= {}", qryResp);
196 return respond(version, respStatus, isArray, qryResp);
197 } catch (Exception e) {
198 logger.error("Exception - queryServiceVnfs", e);
199 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
200 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
201 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
202 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
207 @Path("networkResources/{networkModelCustomizationUuid}")
208 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
209 @Transactional(readOnly = true)
210 public Response serviceNetworks(@PathParam("version") String version,
211 @PathParam("networkModelCustomizationUuid") String nUuid) {
212 return serviceNetworksImpl(version, !IS_ARRAY, nUuid, null, null, null, null);
216 @Path("serviceNetworks")
217 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
218 @Transactional(readOnly = true)
219 public Response serviceNetworks(@PathParam("version") String version,
220 @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
221 @QueryParam("networkType") String networkType, @QueryParam("networkModelName") String networkModelName,
222 @QueryParam("serviceModelUuid") String serviceModelUuid,
223 @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
224 @QueryParam("serviceModelVersion") String serviceModelVersion,
225 @QueryParam("networkModelVersion") String networkModelVersion) {
226 if (networkModelName != null && !"".equals(networkModelName)) {
227 networkType = networkModelName;
229 return serviceNetworksImpl(version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid,
230 serviceModelInvariantUuid, serviceModelVersion);
233 public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid,
234 String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
235 QueryServiceNetworks qryResp;
236 int respStatus = HttpStatus.SC_OK;
238 List<NetworkResourceCustomization> ret = new ArrayList<>();
239 Service service = null;
242 if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
243 uuid = networkModelCustomizationUuid;
244 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
245 } else if (networkType != null && !"".equals(networkType)) {
247 NetworkResource networkResources =
248 networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
249 if (networkResources != null)
250 ret = networkResources.getNetworkResourceCustomization();
251 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
252 uuid = serviceModelInvariantUuid;
253 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
254 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
256 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
258 } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
259 uuid = serviceModelUuid;
260 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
262 throw (new Exception(NO_MATCHING_PARAMETERS));
266 ret = service.getNetworkCustomizations();
268 if (ret == null || ret.isEmpty()) {
269 logger.debug("serviceNetworks not found");
270 respStatus = HttpStatus.SC_NOT_FOUND;
271 qryResp = new QueryServiceNetworks();
273 qryResp = new QueryServiceNetworks(ret);
274 logger.debug("serviceNetworks found qryResp= {}", qryResp);
276 return respond(version, respStatus, isArray, qryResp);
277 } catch (Exception e) {
278 logger.error("Exception - queryServiceNetworks", e);
279 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
280 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
281 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
282 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
287 @Path("serviceResources")
288 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
289 @Transactional(readOnly = true)
290 public Response serviceResources(@PathParam("version") String version,
291 @QueryParam("serviceModelUuid") String modelUUID,
292 @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
293 @QueryParam("serviceModelVersion") String modelVersion) {
295 QueryServiceMacroHolder qryResp;
296 int respStatus = HttpStatus.SC_OK;
298 ServiceMacroHolder ret = new ServiceMacroHolder();
301 if (modelUUID != null && !"".equals(modelUUID)) {
303 logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid);
304 Service serv = serviceRepo.findOneByModelUUID(uuid);
307 ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
308 ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
309 ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
311 ret.setService(serv);
312 } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
313 uuid = modelInvariantUUID;
314 if (modelVersion != null && !"".equals(modelVersion)) {
316 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}",
318 Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
320 ret.setService(serv);
323 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}",
325 Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
326 ret.setService(serv);
329 throw (new Exception(NO_MATCHING_PARAMETERS));
332 if (ret.getService() == null) {
333 logger.debug("serviceMacroHolder not found");
334 respStatus = HttpStatus.SC_NOT_FOUND;
335 qryResp = new QueryServiceMacroHolder();
337 qryResp = new QueryServiceMacroHolder(ret);
338 logger.debug("serviceMacroHolder qryResp= {}", qryResp);
340 return respond(version, respStatus, IS_ARRAY, qryResp);
341 } catch (Exception e) {
342 logger.error("Exception - queryServiceMacroHolder", e);
343 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
344 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
345 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
346 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
352 @Path("allottedResources/{arModelCustomizationUuid}")
353 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
354 @Transactional(readOnly = true)
355 public Response serviceAllottedResources(@PathParam("version") String version,
356 @PathParam("arModelCustomizationUuid") String aUuid) {
357 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
361 @Path("serviceAllottedResources")
362 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
363 @Transactional(readOnly = true)
364 public Response serviceAllottedResources(@PathParam("version") String version,
365 @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid,
366 @QueryParam("serviceModelVersion") String smVer, @QueryParam("arModelCustomizationUuid") String aUuid) {
367 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
370 public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid,
371 String serviceModelInvariantUuid, String smVer) {
372 QueryAllottedResourceCustomization qryResp;
373 int respStatus = HttpStatus.SC_OK;
375 List<AllottedResourceCustomization> ret = new ArrayList<>();
376 Service service = null;
378 if (smUuid != null && !"".equals(smUuid)) {
380 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);
381 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
382 uuid = serviceModelInvariantUuid;
383 if (smVer != null && !"".equals(smVer)) {
384 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
386 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
388 } else if (aUuid != null && !"".equals(aUuid)) {
390 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
392 throw (new Exception(NO_MATCHING_PARAMETERS));
396 ret = service.getAllottedCustomizations();
398 if (ret == null || ret.isEmpty()) {
399 logger.debug("AllottedResourceCustomization not found");
400 respStatus = HttpStatus.SC_NOT_FOUND;
401 qryResp = new QueryAllottedResourceCustomization();
403 qryResp = new QueryAllottedResourceCustomization(ret);
404 logger.debug("AllottedResourceCustomization qryResp= {}", qryResp);
406 return respond(version, respStatus, isArray, qryResp);
407 } catch (Exception e) {
408 logger.error("Exception - queryAllottedResourceCustomization", e);
409 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
410 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
411 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
412 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
418 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
419 @Transactional(readOnly = true)
420 public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
421 QueryVfModule qryResp;
422 int respStatus = HttpStatus.SC_OK;
423 List<VfModuleCustomization> ret = null;
425 if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
426 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
427 if (vfModule != null)
428 ret = vfModule.getVfModuleCustomization();
430 throw (new Exception(NO_MATCHING_PARAMETERS));
433 if (ret == null || ret.isEmpty()) {
434 logger.debug("vfModules not found");
435 respStatus = HttpStatus.SC_NOT_FOUND;
436 qryResp = new QueryVfModule();
438 qryResp = new QueryVfModule(ret);
439 if (logger.isDebugEnabled())
440 logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
442 return Response.status(respStatus).entity(qryResp.JSON2(false, false))
443 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
444 } catch (Exception e) {
445 logger.error("Exception during query VfModules by vfModuleModuleName: ", e);
446 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
447 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
448 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
449 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
454 * Get the tosca csar info from catalog <br>
456 * @param smUuid service model uuid
457 * @return the tosca csar information of the serivce.
458 * @since ONAP Beijing Release
461 @Path("serviceToscaCsar")
462 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
463 public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
464 int respStatus = HttpStatus.SC_OK;
467 if (smUuid != null && !"".equals(smUuid)) {
468 logger.debug("Query Csar by service model uuid: {}", smUuid);
470 Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
472 if (service != null) {
473 ToscaCsar toscaCsar = service.getCsar();
474 if (toscaCsar != null) {
475 QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
476 entity = serviceCsar.JSON2(false, false);
478 respStatus = HttpStatus.SC_NOT_FOUND;
481 respStatus = HttpStatus.SC_NOT_FOUND;
485 throw (new Exception("Incoming parameter is null or blank"));
487 return Response.status(respStatus).entity(entity)
488 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
489 } catch (Exception e) {
490 logger.error("Exception during query csar by service model uuid: ", e);
491 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
492 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
493 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
494 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
499 * Get the resource recipe info from catalog <br>
501 * @param rmUuid resource model uuid
502 * @return the recipe information of the resource.
503 * @since ONAP Beijing Release
506 @Path("resourceRecipe")
507 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
508 public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid,
509 @QueryParam("action") String action) {
510 int respStatus = HttpStatus.SC_OK;
513 if (rmUuid != null && !"".equals(rmUuid)) {
514 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
515 // check vnf and network and ar, the resource could be any resource.
516 Recipe recipe = null;
518 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
520 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action,
521 vnf.getModelVersion());
523 // for network service fetch the default recipe
524 if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
525 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
530 if (null == recipe) {
531 NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
533 if (nResource != null) {
534 recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(),
535 action, nResource.getModelVersion());
537 // for network fetch the default recipe
538 if (recipe == null) {
539 recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
544 if (null == recipe) {
545 AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
546 if (arResource != null) {
547 recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action,
548 arResource.getModelVersion());
552 if (null == recipe) {
553 InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
554 if (grpResource != null) {
555 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(
556 grpResource.getModelName(), action, grpResource.getModelVersion());
561 if (recipe != null) {
562 QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
563 entity = resourceRecipe.JSON2(false, false);
565 respStatus = HttpStatus.SC_NOT_FOUND;
568 throw new Exception("Incoming parameter is null or blank");
570 return Response.status(respStatus).entity(entity)
571 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
572 } catch (Exception e) {
573 logger.error("Exception during query recipe by resource model uuid: ", e);
574 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
575 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
576 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
577 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
582 @Path("processingFlags/{flag}")
583 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
584 @Transactional(readOnly = true)
585 public Response getProcessingFlags(@PathParam("flag") String flag) {
586 return getProcessingFlagsImpl(flag);
589 public Response getProcessingFlagsImpl(String flag) {
590 ProcessingFlags processingFlags = null;
591 logger.debug("Flag is: " + flag);
592 int respStatus = HttpStatus.SC_OK;
594 processingFlags = processingFlagsRepo.findByFlag(flag);
595 if (processingFlags == null) {
596 logger.debug("ProcessingFlag not found");
597 respStatus = HttpStatus.SC_NOT_FOUND;
601 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
603 return Response.status(respStatus).entity(processingFlags)
604 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
605 } catch (Exception e) {
606 logger.error("Exception - queryProcesssingFlags", e);
607 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
608 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
609 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
610 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
615 @Path("processingFlags/{flag}")
616 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
618 public Response updateProcessingFlagsValue(@PathParam("flag") String flag, ProcessingFlags updatedProcessingFlag) {
619 return updateProcessingFlagsValueImpl(flag, updatedProcessingFlag);
622 public Response updateProcessingFlagsValueImpl(String flag, ProcessingFlags updatedProcessingFlag) {
623 ProcessingFlags processingFlags = null;
624 logger.debug("Flag is: " + flag);
625 int respStatus = HttpStatus.SC_OK;
627 if (updatedProcessingFlag == null) {
628 logger.debug("No valid updatedProcessingFlag is provided");
629 throw new RuntimeException("No valid updatedProcessingFlag is provided");
631 String value = updatedProcessingFlag.getValue();
632 if (value == null || (!value.equalsIgnoreCase("YES") && !value.equalsIgnoreCase("NO"))) {
633 logger.debug("Value " + value + " is invalid, only yes/no are allowed");
634 throw new RuntimeException("Invalid value specified");
636 processingFlags = processingFlagsRepo.findByFlag(flag);
637 if (processingFlags == null) {
638 logger.debug("ProcessingFlag not found");
639 respStatus = HttpStatus.SC_NOT_FOUND;
641 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
642 processingFlags.setValue(value);
643 processingFlagsRepo.saveAndFlush(processingFlags);
644 return Response.status(respStatus).entity(null)
645 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
647 } catch (Exception e) {
648 logger.error("Exception - queryProcesssingFlags", e);
649 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
650 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
651 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
652 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
655 return Response.status(HttpStatus.SC_NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)