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.VnfRecipe;
63 import org.onap.so.db.catalog.beans.VnfResource;
64 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
65 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
66 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
67 import org.onap.so.db.catalog.data.repository.ArRecipeRepository;
68 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
69 import org.onap.so.db.catalog.data.repository.NetworkRecipeRepository;
70 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
71 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
72 import org.onap.so.db.catalog.data.repository.ProcessingFlagsRepository;
73 import org.onap.so.db.catalog.data.repository.ServiceRepository;
74 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
75 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
76 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
77 import org.onap.so.db.catalog.data.repository.VnfRecipeRepository;
78 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
79 import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
82 import org.springframework.beans.factory.annotation.Autowired;
83 import org.springframework.stereotype.Component;
84 import org.springframework.transaction.annotation.Transactional;
87 @Path("/{version: v[0-9]+}")
89 public class CatalogDbAdapterRest {
90 protected static Logger logger = LoggerFactory.getLogger(CatalogDbAdapterRest.class);
91 private static final boolean IS_ARRAY = true;
92 private static final String NETWORK_SERVICE = "network service";
93 private static final String RESOURCE_INPUT_FILTER = "resourceInput";
96 private VnfCustomizationRepository vnfCustomizationRepo;
99 private ServiceRepository serviceRepo;
102 private NetworkResourceCustomizationRepository networkCustomizationRepo;
105 private NetworkResourceRepository networkResourceRepo;
108 private AllottedResourceCustomizationRepository allottedCustomizationRepo;
111 private ToscaCsarRepository toscaCsarRepo;
114 private VFModuleRepository vfModuleRepo;
117 private VnfRecipeRepository vnfRecipeRepo;
120 private NetworkRecipeRepository networkRecipeRepo;
123 private ArRecipeRepository arRecipeRepo;
126 private VnfResourceRepository vnfResourceRepo;
129 private AllottedResourceRepository arResourceRepo;
132 private InstanceGroupRepository instanceGroupRepository;
135 private ProcessingFlagsRepository processingFlagsRepo;
137 private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
139 public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
140 return Response.status(respStatus).entity(qryResp.toJsonString(version, isArray))
141 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
145 @Path("vnfResources/{vnfModelCustomizationUuid}")
146 @Transactional(readOnly = true)
147 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
148 public Response serviceVnfs(@PathParam("version") String version,
149 @PathParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("filter") String filter) {
150 return serviceVnfsImpl(version, !IS_ARRAY, vnfUuid, null, null, null, null, filter);
155 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
156 @Transactional(readOnly = true)
157 public Response serviceVnfs(@PathParam("version") String version,
158 @QueryParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("serviceModelUuid") String smUuid,
159 @QueryParam("serviceModelInvariantUuid") String smiUuid, @QueryParam("serviceModelVersion") String smVer,
160 @QueryParam("serviceModelName") String smName, @QueryParam("filter") String filter) {
161 return serviceVnfsImpl(version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName, filter);
164 public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID,
165 String smiUuid, String smVer, String smName, String filter) {
166 QueryServiceVnfs qryResp = null;
167 int respStatus = HttpStatus.SC_OK;
168 List<VnfResourceCustomization> ret = new ArrayList<>();
169 Service service = null;
171 if (vnfUuid != null && !"".equals(vnfUuid))
172 ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);
173 else if (serviceModelUUID != null && !"".equals(serviceModelUUID))
174 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
175 else if (smiUuid != null && !"".equals(smiUuid))
176 if (smVer != null && !"".equals(smVer))
177 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid);
179 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
180 else if (smName != null && !"".equals(smName)) {
181 if (smVer != null && !"".equals(smVer))
182 service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
184 service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);
186 throw (new Exception(NO_MATCHING_PARAMETERS));
189 if (service == null && ret.isEmpty()) {
190 respStatus = HttpStatus.SC_NOT_FOUND;
191 qryResp = new QueryServiceVnfs();
192 } else if (service == null && !ret.isEmpty()) {
193 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
194 ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
196 qryResp = new QueryServiceVnfs(ret);
197 } else if (service != null) {
198 ret = service.getVnfCustomizations();
199 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
200 ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
202 qryResp = new QueryServiceVnfs(ret);
204 logger.debug("serviceVnfs qryResp= {}", qryResp);
205 return respond(version, respStatus, isArray, qryResp);
206 } catch (Exception e) {
207 logger.error("Exception - queryServiceVnfs", e);
208 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
209 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
210 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
211 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
216 @Path("networkResources/{networkModelCustomizationUuid}")
217 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
218 @Transactional(readOnly = true)
219 public Response serviceNetworks(@PathParam("version") String version,
220 @PathParam("networkModelCustomizationUuid") String nUuid) {
221 return serviceNetworksImpl(version, !IS_ARRAY, nUuid, null, null, null, null);
225 @Path("serviceNetworks")
226 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
227 @Transactional(readOnly = true)
228 public Response serviceNetworks(@PathParam("version") String version,
229 @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid,
230 @QueryParam("networkType") String networkType, @QueryParam("networkModelName") String networkModelName,
231 @QueryParam("serviceModelUuid") String serviceModelUuid,
232 @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid,
233 @QueryParam("serviceModelVersion") String serviceModelVersion,
234 @QueryParam("networkModelVersion") String networkModelVersion) {
235 if (networkModelName != null && !"".equals(networkModelName)) {
236 networkType = networkModelName;
238 return serviceNetworksImpl(version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid,
239 serviceModelInvariantUuid, serviceModelVersion);
242 public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid,
243 String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
244 QueryServiceNetworks qryResp;
245 int respStatus = HttpStatus.SC_OK;
247 List<NetworkResourceCustomization> ret = new ArrayList<>();
248 Service service = null;
251 if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
252 uuid = networkModelCustomizationUuid;
253 ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
254 } else if (networkType != null && !"".equals(networkType)) {
256 NetworkResource networkResources =
257 networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
258 if (networkResources != null)
259 ret = networkResources.getNetworkResourceCustomization();
260 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
261 uuid = serviceModelInvariantUuid;
262 if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
263 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
265 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
267 } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
268 uuid = serviceModelUuid;
269 service = serviceRepo.findOneByModelUUID(serviceModelUuid);
271 throw (new Exception(NO_MATCHING_PARAMETERS));
275 ret = service.getNetworkCustomizations();
277 if (ret == null || ret.isEmpty()) {
278 logger.debug("serviceNetworks not found");
279 respStatus = HttpStatus.SC_NOT_FOUND;
280 qryResp = new QueryServiceNetworks();
282 qryResp = new QueryServiceNetworks(ret);
283 logger.debug("serviceNetworks found qryResp= {}", qryResp);
285 return respond(version, respStatus, isArray, qryResp);
286 } catch (Exception e) {
287 logger.error("Exception - queryServiceNetworks", e);
288 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
289 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
290 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
291 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
296 @Path("serviceResources")
297 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
298 @Transactional(readOnly = true)
299 public Response serviceResources(@PathParam("version") String version,
300 @QueryParam("serviceModelUuid") String modelUUID,
301 @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID,
302 @QueryParam("serviceModelVersion") String modelVersion, @QueryParam("filter") String filter) {
304 QueryServiceMacroHolder qryResp;
305 int respStatus = HttpStatus.SC_OK;
307 ServiceMacroHolder ret = new ServiceMacroHolder();
310 if (modelUUID != null && !"".equals(modelUUID)) {
312 logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid);
313 Service serv = serviceRepo.findOneByModelUUID(uuid);
316 ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
317 if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
318 serv.getVnfCustomizations()
319 .forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
321 ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
322 ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
324 ret.setService(serv);
325 } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
326 uuid = modelInvariantUUID;
327 if (modelVersion != null && !"".equals(modelVersion)) {
329 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}",
331 Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
333 ret.setService(serv);
336 "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}",
338 Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
339 ret.setService(serv);
342 throw (new Exception(NO_MATCHING_PARAMETERS));
345 if (ret.getService() == null) {
346 logger.debug("serviceMacroHolder not found");
347 respStatus = HttpStatus.SC_NOT_FOUND;
348 qryResp = new QueryServiceMacroHolder();
350 qryResp = new QueryServiceMacroHolder(ret);
351 logger.debug("serviceMacroHolder qryResp= {}", qryResp);
353 return respond(version, respStatus, IS_ARRAY, qryResp);
354 } catch (Exception e) {
355 logger.error("Exception - queryServiceMacroHolder", e);
356 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
357 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
358 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
359 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
365 @Path("allottedResources/{arModelCustomizationUuid}")
366 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
367 @Transactional(readOnly = true)
368 public Response serviceAllottedResources(@PathParam("version") String version,
369 @PathParam("arModelCustomizationUuid") String aUuid) {
370 return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
374 @Path("serviceAllottedResources")
375 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
376 @Transactional(readOnly = true)
377 public Response serviceAllottedResources(@PathParam("version") String version,
378 @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid,
379 @QueryParam("serviceModelVersion") String smVer, @QueryParam("arModelCustomizationUuid") String aUuid) {
380 return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
383 public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid,
384 String serviceModelInvariantUuid, String smVer) {
385 QueryAllottedResourceCustomization qryResp;
386 int respStatus = HttpStatus.SC_OK;
388 List<AllottedResourceCustomization> ret = new ArrayList<>();
389 Service service = null;
391 if (smUuid != null && !"".equals(smUuid)) {
393 service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);
394 } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
395 uuid = serviceModelInvariantUuid;
396 if (smVer != null && !"".equals(smVer)) {
397 service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
399 service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
401 } else if (aUuid != null && !"".equals(aUuid)) {
403 ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
405 throw (new Exception(NO_MATCHING_PARAMETERS));
409 ret = service.getAllottedCustomizations();
411 if (ret == null || ret.isEmpty()) {
412 logger.debug("AllottedResourceCustomization not found");
413 respStatus = HttpStatus.SC_NOT_FOUND;
414 qryResp = new QueryAllottedResourceCustomization();
416 qryResp = new QueryAllottedResourceCustomization(ret);
417 logger.debug("AllottedResourceCustomization qryResp= {}", qryResp);
419 return respond(version, respStatus, isArray, qryResp);
420 } catch (Exception e) {
421 logger.error("Exception - queryAllottedResourceCustomization", e);
422 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
423 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
424 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
425 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
431 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
432 @Transactional(readOnly = true)
433 public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
434 QueryVfModule qryResp;
435 int respStatus = HttpStatus.SC_OK;
436 List<VfModuleCustomization> ret = null;
438 if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
439 VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
440 if (vfModule != null)
441 ret = vfModule.getVfModuleCustomization();
443 throw (new Exception(NO_MATCHING_PARAMETERS));
446 if (ret == null || ret.isEmpty()) {
447 logger.debug("vfModules not found");
448 respStatus = HttpStatus.SC_NOT_FOUND;
449 qryResp = new QueryVfModule();
451 qryResp = new QueryVfModule(ret);
452 if (logger.isDebugEnabled())
453 logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
455 return Response.status(respStatus).entity(qryResp.JSON2(false, false))
456 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
457 } catch (Exception e) {
458 logger.error("Exception during query VfModules by vfModuleModuleName: ", e);
459 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
460 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
461 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
462 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
467 * Get the tosca csar info from catalog <br>
469 * @param smUuid service model uuid
470 * @return the tosca csar information of the serivce.
471 * @since ONAP Beijing Release
474 @Path("serviceToscaCsar")
475 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
476 public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
477 int respStatus = HttpStatus.SC_OK;
480 if (smUuid != null && !"".equals(smUuid)) {
481 logger.debug("Query Csar by service model uuid: {}", smUuid);
483 Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
485 if (service != null) {
486 ToscaCsar toscaCsar = service.getCsar();
487 if (toscaCsar != null) {
488 QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
489 entity = serviceCsar.JSON2(false, false);
491 respStatus = HttpStatus.SC_NOT_FOUND;
494 respStatus = HttpStatus.SC_NOT_FOUND;
498 throw (new Exception("Incoming parameter is null or blank"));
500 return Response.status(respStatus).entity(entity)
501 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
502 } catch (Exception e) {
503 logger.error("Exception during query csar by service model uuid: ", e);
504 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
505 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
506 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
507 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
512 * Get the resource recipe info from catalog <br>
514 * @param rmUuid resource model uuid
515 * @return the recipe information of the resource.
516 * @since ONAP Beijing Release
519 @Path("resourceRecipe")
520 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
521 public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid,
522 @QueryParam("action") String action) {
523 int respStatus = HttpStatus.SC_OK;
526 if (rmUuid != null && !"".equals(rmUuid)) {
527 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
528 // check vnf and network and ar, the resource could be any resource.
529 Recipe recipe = null;
531 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
533 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action,
534 vnf.getModelVersion());
536 // for network service fetch the default recipe
537 if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
538 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
543 if (null == recipe) {
544 NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
546 if (nResource != null) {
547 recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(),
548 action, nResource.getModelVersion());
550 // for network fetch the default recipe
551 if (recipe == null) {
552 recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
557 if (null == recipe) {
558 AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
559 if (arResource != null) {
560 recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action,
561 arResource.getModelVersion());
565 if (null == recipe) {
566 InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
567 if (grpResource != null) {
568 recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(
569 grpResource.getModelName(), action, grpResource.getModelVersion());
574 if (recipe != null) {
575 QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
576 entity = resourceRecipe.JSON2(false, false);
578 respStatus = HttpStatus.SC_NOT_FOUND;
581 throw new Exception("Incoming parameter is null or blank");
583 return Response.status(respStatus).entity(entity)
584 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
585 } catch (Exception e) {
586 logger.error("Exception during query recipe by resource model uuid: ", e);
587 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
588 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
589 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
590 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
595 @Path("processingFlags/{flag}")
596 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
597 @Transactional(readOnly = true)
598 public Response getProcessingFlags(@PathParam("flag") String flag) {
599 return getProcessingFlagsImpl(flag);
602 public Response getProcessingFlagsImpl(String flag) {
603 ProcessingFlags processingFlags = null;
604 logger.debug("Flag is: " + flag);
605 int respStatus = HttpStatus.SC_OK;
607 processingFlags = processingFlagsRepo.findByFlag(flag);
608 if (processingFlags == null) {
609 logger.debug("ProcessingFlag not found");
610 respStatus = HttpStatus.SC_NOT_FOUND;
614 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
616 return Response.status(respStatus).entity(processingFlags)
617 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
618 } catch (Exception e) {
619 logger.error("Exception - queryProcesssingFlags", e);
620 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
621 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
622 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
623 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
628 @Path("processingFlags/{flag}")
629 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
631 public Response updateProcessingFlagsValue(@PathParam("flag") String flag, ProcessingFlags updatedProcessingFlag) {
632 return updateProcessingFlagsValueImpl(flag, updatedProcessingFlag);
635 public Response updateProcessingFlagsValueImpl(String flag, ProcessingFlags updatedProcessingFlag) {
636 ProcessingFlags processingFlags = null;
637 logger.debug("Flag is: " + flag);
638 int respStatus = HttpStatus.SC_OK;
640 if (updatedProcessingFlag == null) {
641 logger.debug("No valid updatedProcessingFlag is provided");
642 throw new RuntimeException("No valid updatedProcessingFlag is provided");
644 String value = updatedProcessingFlag.getValue();
645 if (value == null || (!value.equalsIgnoreCase("YES") && !value.equalsIgnoreCase("NO"))) {
646 logger.debug("Value " + value + " is invalid, only yes/no are allowed");
647 throw new RuntimeException("Invalid value specified");
649 processingFlags = processingFlagsRepo.findByFlag(flag);
650 if (processingFlags == null) {
651 logger.debug("ProcessingFlag not found");
652 respStatus = HttpStatus.SC_NOT_FOUND;
654 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
655 processingFlags.setValue(value);
656 processingFlagsRepo.saveAndFlush(processingFlags);
657 return Response.status(respStatus).entity(null)
658 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
660 } catch (Exception e) {
661 logger.error("Exception - queryProcesssingFlags", e);
662 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
663 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
664 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
665 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();
668 return Response.status(HttpStatus.SC_NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
673 @Path("processingFlags")
674 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
675 @Transactional(readOnly = true)
676 public Response getAllProcessingFlags() {
677 return getAllProcessingFlagsImpl();
680 public Response getAllProcessingFlagsImpl() {
681 List<ProcessingFlags> processingFlags = null;
683 int respStatus = HttpStatus.SC_OK;
685 processingFlags = processingFlagsRepo.findAll();
686 if (processingFlags == null) {
687 logger.debug("ProcessingFlags not found");
688 respStatus = HttpStatus.SC_NOT_FOUND;
691 logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
693 return Response.status(respStatus).entity(processingFlags)
694 .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
695 } catch (Exception e) {
696 logger.error("Exception - queryProcesssingFlags", e);
697 CatalogQueryException excResp = new CatalogQueryException(e.getMessage(),
698 CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
699 return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
700 .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build();