e29d88cb8968c5bc0973cf80a234d411b5e8d18f
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / client / CatalogDbClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.db.catalog.client;
22
23 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
24 import org.onap.so.db.catalog.beans.CloudSite;
25 import org.onap.so.db.catalog.beans.CloudifyManager;
26 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
27 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
28 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
29 import org.onap.so.db.catalog.beans.CvnfcCustomization;
30 import org.onap.so.db.catalog.beans.InstanceGroup;
31 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
32 import org.onap.so.db.catalog.beans.NetworkRecipe;
33 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
34 import org.onap.so.db.catalog.beans.OrchestrationAction;
35 import org.onap.so.db.catalog.beans.OrchestrationStatus;
36 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
37 import org.onap.so.db.catalog.beans.ResourceType;
38 import org.onap.so.db.catalog.beans.Service;
39 import org.onap.so.db.catalog.beans.ServiceRecipe;
40 import org.onap.so.db.catalog.beans.VfModule;
41 import org.onap.so.db.catalog.beans.VfModuleCustomization;
42 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
43 import org.onap.so.db.catalog.beans.VnfRecipe;
44 import org.onap.so.db.catalog.beans.VnfResource;
45 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
46 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
47 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
48 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
49 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
50 import org.onap.so.logging.jaxrs.filter.SpringClientFilter;
51 import org.springframework.beans.factory.annotation.Value;
52 import org.springframework.http.HttpHeaders;
53 import org.springframework.http.client.BufferingClientHttpRequestFactory;
54 import org.springframework.http.client.ClientHttpRequestFactory;
55 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
56 import org.springframework.stereotype.Component;
57 import uk.co.blackpepper.bowman.Client;
58 import uk.co.blackpepper.bowman.ClientFactory;
59 import uk.co.blackpepper.bowman.Configuration;
60
61 import javax.annotation.PostConstruct;
62 import javax.ws.rs.core.UriBuilder;
63 import java.net.URI;
64 import java.util.ArrayList;
65 import java.util.Iterator;
66 import java.util.List;
67
68 @Component("CatalogDbClient")
69 public class CatalogDbClient {
70
71         private static final String CLOUD_SITE = "/cloudSite";
72         private static final String CLOUDIFY_MANAGER = "/cloudifyManager";
73         private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro";
74         private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup";
75         private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization";
76         private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION = "/collectionResourceInstanceGroupCustomization";
77         private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization";
78         private static final String ORCHESTRATION_FLOW = "/orchestrationFlow";
79         private static final String ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE = "/orchestrationStatusStateTransitionDirective";
80         private static final String INSTANCE_GROUP = "/instanceGroup";
81         private static final String COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION = "/collectionNetworkResourceCustomization";
82         private static final String BUILDING_BLOCK_DETAIL = "/buildingBlockDetail";
83         private static final String NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION = "/networkCollectionResourceCustomization";
84         private static final String VNF_RESOURCE_CUSTOMIZATION = "/vnfResourceCustomization";
85         private static final String SERVICE = "/service";
86         private static final String VNF_RESOURCE = "/vnfResource";
87         private static final String VNF_RECIPE = "/vnfRecipe";
88         private static final String VFMODULE = "/vfModule";
89         private static final String VFMODULE_CUSTOMIZATION = "/vfModuleCustomization";
90         private static final String VNF_COMPONENTS_RECIPE = "/vnfComponentsRecipe";
91         private static final String SERVICE_RECIPE = "/serviceRecipe";
92         private static final String NETWORK_RECIPE = "/networkRecipe";
93
94         private static final String SEARCH = "/search";
95         private static final String URI_SEPARATOR = "/";
96
97         private static final String SERVICE_MODEL_UUID = "serviceModelUUID";
98         private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
99         private static final String ACTION = "action";
100         private static final String MODEL_NAME = "modelName";
101         private static final String MODEL_VERSION = "modelVersion";
102         private static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
103         private static final String MODEL_INSTANCE_NAME = "modelInstanceName";
104         private static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
105         private static final String NF_ROLE = "nfRole";
106         private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
107         private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
108         private static final String BUILDING_BLOCK_NAME = "buildingBlockName";
109         private static final String RESOURCE_TYPE = "resourceType";
110         private static final String ORCHESTRATION_STATUS = "orchestrationStatus";
111         private static final String TARGET_ACTION = "targetAction";
112         private static final String REQUEST_SCOPE = "requestScope";
113         private static final String IS_ALACARTE = "isALaCarte";
114         private static final String FLOW_NAME = "flowName";
115         private static final String SERVICE_TYPE = "serviceType";
116         private static final String VNF_TYPE = "vnfType";
117         private static final String ERROR_CODE = "errorCode";
118         private static final String WORK_STEP = "workStep";
119         private static final String CLLI = "clli";
120         private static final String CLOUD_VERSION = "cloudVersion";
121
122         private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
123         private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
124         private String findFirstByModelVersionAndModelInvariantUUIDURI = "/findFirstByModelVersionAndModelInvariantUUID";
125         private String findByModelInvariantUUIDURI = "/findByModelInvariantUUIDOrderByModelVersionDesc";
126         private String findFirstByModelNameAndAction = "/findFirstByModelNameAndAction";
127         private String findFirstResourceByModelInvariantUUIDAndModelVersion = "/findFirstResourceByModelInvariantUUIDAndModelVersion";
128         private String findByModelInstanceNameAndVnfResources = "/findByModelInstanceNameAndVnfResources";
129         private String findFirstVnfRecipeByNfRoleAndAction = "/findFirstVnfRecipeByNfRoleAndAction";
130         private String findByModelCustomizationUUIDAndVfModuleModelUUID = "/findByModelCustomizationUUIDAndVfModuleModelUUID";
131         private String findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = "/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction";
132         private String findFirstVnfComponentsRecipeByVnfComponentTypeAndAction = "/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction";
133         private String findVfModuleByModelInvariantUUIDOrderByModelVersionDesc = "/findByModelInvariantUUIDOrderByModelVersionDesc";
134         private String findFirstVfModuleByModelInvariantUUIDAndModelVersion = "/findFirstVfModuleByModelInvariantUUIDAndModelVersion";
135         private String findOneByBuildingBlockName = "/findOneByBuildingBlockName";
136         private String findOneByResourceTypeAndOrchestrationStatusAndTargetAction = "/findOneByResourceTypeAndOrchestrationStatusAndTargetAction";
137         private String findByAction = "/findByAction";
138         private String findVnfcInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
139         private String findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
140         private String findOneByActionAndRequestScopeAndIsAlacarte = "/findOneByActionAndRequestScopeAndIsAlacarte";
141         private String findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep = "/findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep";
142         private String findByClliAndCloudVersion = "/findByClliAndCloudVersion";
143
144         private String serviceURI;
145         private String vfModuleURI;
146         private String vnfResourceURI;
147         private String vfModuleCustomizationURI;
148         private String networkCollectionResourceCustomizationURI;
149         private String networkResourceCustomizationURI;
150         private String vnfResourceCustomizationURI;
151         private String collectionNetworkResourceCustomizationURI;
152         private String instanceGroupURI;
153         private String cloudifyManagerURI;
154         private String cloudSiteURI;
155
156         private final Client<Service> serviceClient;
157
158         private final Client<NetworkRecipe> networkRecipeClient;
159
160         private final Client<NetworkResourceCustomization> networkResourceCustomizationClient;
161
162         private final Client<VnfResource> vnfResourceClient;
163
164         private final Client<VnfResourceCustomization> vnfResourceCustomizationClient;
165
166         private final Client<VnfRecipe> vnfRecipeClient;
167
168         private final Client<VfModuleCustomization> vfModuleCustomizationClient;
169
170         private final Client<VfModule> vfModuleClient;
171
172         private final Client<VnfComponentsRecipe> vnfComponentsRecipeClient;
173
174         private final Client<OrchestrationFlow> orchestrationClient;
175
176         private final Client<NorthBoundRequest> northBoundRequestClient;
177
178         private final Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
179
180         private final Client<BuildingBlockDetail> buildingBlockDetailClient;
181
182         private final Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
183
184         private final Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
185
186         private final Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
187
188         private final Client<InstanceGroup> instanceGroupClient;
189
190         private final Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
191
192         private final Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
193
194         private final Client<ServiceRecipe> serviceRecipeClient;
195
196         private final Client<CloudSite> cloudSiteClient;
197
198         private final Client<CloudifyManager> cloudifyManagerClient;
199         
200         private Client<CvnfcCustomization> cvnfcCustomizationClient;
201
202         private final Client<ControllerSelectionReference> controllerSelectionReferenceClient;
203
204         @Value("${mso.catalog.db.spring.endpoint}")
205         private String endpoint;
206
207         @Value("${mso.db.auth}")
208         private String msoAdaptersAuth;
209
210
211         @PostConstruct
212         public void init(){
213                 findFirstByModelNameURI = endpoint + SERVICE + SEARCH + findFirstByModelNameURI;
214                 findFirstByModelVersionAndModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findFirstByModelVersionAndModelInvariantUUIDURI;
215                 findByModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findByModelInvariantUUIDURI;
216                 findFirstByServiceModelUUIDAndActionURI = endpoint + SERVICE_RECIPE + SEARCH + findFirstByServiceModelUUIDAndActionURI;
217                 findFirstByModelNameAndAction = endpoint + NETWORK_RECIPE + SEARCH + findFirstByModelNameAndAction;
218                 findFirstResourceByModelInvariantUUIDAndModelVersion =  endpoint + VNF_RESOURCE + SEARCH + findFirstResourceByModelInvariantUUIDAndModelVersion;
219                 findByModelInstanceNameAndVnfResources =  endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findByModelInstanceNameAndVnfResources;
220                 findFirstVnfRecipeByNfRoleAndAction = endpoint + VNF_RECIPE + SEARCH + findFirstVnfRecipeByNfRoleAndAction;
221                 findByModelCustomizationUUIDAndVfModuleModelUUID = endpoint + VFMODULE_CUSTOMIZATION + SEARCH + findByModelCustomizationUUIDAndVfModuleModelUUID;
222                 findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction;
223                 findFirstVnfComponentsRecipeByVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVnfComponentTypeAndAction;
224                 findVfModuleByModelInvariantUUIDOrderByModelVersionDesc = endpoint + VFMODULE + SEARCH +findVfModuleByModelInvariantUUIDOrderByModelVersionDesc;
225                 findFirstVfModuleByModelInvariantUUIDAndModelVersion = endpoint + VFMODULE + SEARCH + findFirstVfModuleByModelInvariantUUIDAndModelVersion;
226                 findOneByBuildingBlockName = endpoint + BUILDING_BLOCK_DETAIL + SEARCH + findOneByBuildingBlockName;
227                 findOneByResourceTypeAndOrchestrationStatusAndTargetAction = endpoint + ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE + SEARCH + findOneByResourceTypeAndOrchestrationStatusAndTargetAction;
228                 findByAction = endpoint + ORCHESTRATION_FLOW + SEARCH + findByAction;
229                 findVnfcInstanceGroupCustomizationByModelCustomizationUUID = endpoint + VNFC_INSTANCE_GROUP_CUSTOMIZATION + SEARCH + findVnfcInstanceGroupCustomizationByModelCustomizationUUID;
230                 findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID = endpoint + COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION + SEARCH + findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID;
231                 findOneByActionAndRequestScopeAndIsAlacarte = endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH + findOneByActionAndRequestScopeAndIsAlacarte;
232                 findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep = endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep;
233                 findByClliAndCloudVersion = endpoint + CLOUD_SITE + SEARCH + findByClliAndCloudVersion;
234
235                 serviceURI = endpoint + SERVICE + URI_SEPARATOR;
236                 vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR;
237                 vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR;
238                 vfModuleCustomizationURI = endpoint + VFMODULE_CUSTOMIZATION + URI_SEPARATOR;
239                 networkCollectionResourceCustomizationURI = endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
240                 networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
241                 vnfResourceCustomizationURI = endpoint + VNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
242                 collectionNetworkResourceCustomizationURI = endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
243                 instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR;
244                 cloudifyManagerURI = endpoint + CLOUDIFY_MANAGER + URI_SEPARATOR;
245                 cloudSiteURI = endpoint + CLOUD_SITE + URI_SEPARATOR;
246
247         }
248
249         public CatalogDbClient() {
250                 ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
251
252                 ClientFactory clientFactory = Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
253                         restTemplate.getInterceptors().add((new SpringClientFilter()));
254
255                         restTemplate.getInterceptors().add((request, body, execution) -> {
256
257                                 request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
258                                 return execution.execute(request, body);
259                         });
260                 }).build().buildClientFactory();
261                 serviceClient = clientFactory.create(Service.class);
262                 networkRecipeClient = clientFactory.create(NetworkRecipe.class);
263                 networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
264                 vnfResourceClient = clientFactory.create(VnfResource.class);
265                 vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
266                 vnfRecipeClient = clientFactory.create(VnfRecipe.class);
267                 orchestrationClient = clientFactory.create(OrchestrationFlow.class);
268                 vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
269                 vfModuleClient = clientFactory.create(VfModule.class);
270                 vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
271                 northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
272                 rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
273                 buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
274                 orchestrationStatusStateTransitionDirectiveClient = clientFactory
275                                 .create(OrchestrationStatusStateTransitionDirective.class);
276                 vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
277                 collectionResourceInstanceGroupCustomizationClient = clientFactory
278                                 .create(CollectionResourceInstanceGroupCustomization.class);
279                 instanceGroupClient = clientFactory.create(InstanceGroup.class);
280                 networkCollectionResourceCustomizationClient = clientFactory.create(NetworkCollectionResourceCustomization.class);
281                 collectionNetworkResourceCustomizationClient = clientFactory.create(CollectionNetworkResourceCustomization.class);
282                 cloudSiteClient = clientFactory.create(CloudSite.class);
283                 cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
284                 serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
285                 cvnfcCustomizationClient = clientFactory.create(CvnfcCustomization.class);
286                 controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
287         }
288
289         public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(String modelCustomizationUUID) {
290                 NetworkCollectionResourceCustomization networkCollectionResourceCustomization =
291                                 this.getSingleResource(networkCollectionResourceCustomizationClient, getUri(networkCollectionResourceCustomizationURI + modelCustomizationUUID));
292                 if (networkCollectionResourceCustomization != null) {
293                         networkCollectionResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
294                 }
295                 return networkCollectionResourceCustomization;
296         }
297
298         public Service getServiceByID(String modelUUID) {
299                 Service service = getSingleResource(serviceClient,getUri(serviceURI + modelUUID));
300                 if (service != null) {
301                         service.setModelUUID(modelUUID);
302                 }
303                 return service;
304         }
305
306         public VfModule getVfModuleByModelUUID(String modelUUID) {
307                 VfModule vfModule = getSingleResource(vfModuleClient,getUri(vfModuleURI + modelUUID));
308                 if (vfModule != null) {
309                         vfModule.setModelUUID(modelUUID);
310                 }
311                 return vfModule;
312         }
313
314         public VnfResource getVnfResourceByModelUUID(String modelUUID){
315
316                 VnfResource vnfResource = this.getSingleResource(vnfResourceClient, getUri(vnfResourceURI + modelUUID));
317                 if (vnfResource != null) {
318                         vnfResource.setModelUUID(modelUUID);
319                 }
320                 return vnfResource;
321         }
322
323         public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID){
324                 VnfResourceCustomization vnfResourceCustomization = getSingleResource(vnfResourceCustomizationClient, getUri(vnfResourceCustomizationURI + modelCustomizationUUID));
325                 if (vnfResourceCustomization != null) {
326                         vnfResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
327                 }
328                 return vnfResourceCustomization;
329         }
330
331         public CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomizationByID(String modelCustomizationUUID) {
332                 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
333                                 this.getSingleResource(collectionNetworkResourceCustomizationClient,getUri(UriBuilder
334                                                 .fromUri(collectionNetworkResourceCustomizationURI + modelCustomizationUUID).build().toString()));
335                 if (collectionNetworkResourceCustomization != null) {
336                         collectionNetworkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
337                 }
338                 return collectionNetworkResourceCustomization;
339         }
340
341         public InstanceGroup getInstanceGroupByModelUUID(String modelUUID) {
342                 InstanceGroup instanceGroup = this.getSingleResource(instanceGroupClient, getUri(instanceGroupURI + modelUUID));
343                 if (instanceGroup != null) {
344                         instanceGroup.setModelUUID(modelUUID);
345                 }
346                 return instanceGroup;
347         }
348
349         public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
350                 VfModuleCustomization vfModuleCust = this.getSingleResource(vfModuleCustomizationClient, getUri(vfModuleCustomizationURI + modelCustomizationUUID));
351                 if (vfModuleCust != null) {
352                         vfModuleCust.setModelCustomizationUUID(modelCustomizationUUID);
353                 }
354                 return vfModuleCust;
355         }
356
357         public NetworkResourceCustomization getNetworkResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID){
358                 NetworkResourceCustomization networkResourceCustomization =
359                                 this.getSingleResource(networkResourceCustomizationClient, getUri(networkResourceCustomizationURI + modelCustomizationUUID));
360                 if (networkResourceCustomization != null) {
361                         networkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
362                 }
363                 return networkResourceCustomization;
364         }
365
366         public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) {
367                 BuildingBlockDetail buildingBlockDetail = getSingleResource(buildingBlockDetailClient, getUri(UriBuilder
368                                 .fromUri(findOneByBuildingBlockName).queryParam(BUILDING_BLOCK_NAME, buildingBlockName).build().toString()));
369                 if (buildingBlockDetail != null) {
370                         buildingBlockDetail.setBuildingBlockName(buildingBlockName);
371                 }
372                 return buildingBlockDetail;
373         }
374
375
376         public OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective(
377                         ResourceType resourceType, OrchestrationStatus orchestrationStatus, OrchestrationAction targetAction) {
378                 return getSingleResource(orchestrationStatusStateTransitionDirectiveClient, UriBuilder
379                                 .fromUri(findOneByResourceTypeAndOrchestrationStatusAndTargetAction)
380                                 .queryParam(RESOURCE_TYPE, resourceType.name())
381                                 .queryParam(ORCHESTRATION_STATUS, orchestrationStatus.name())
382                                 .queryParam(TARGET_ACTION, targetAction.name()).build());
383         }
384
385         public List<OrchestrationFlow> getOrchestrationFlowByAction(String action) {
386                 return this.getMultipleResources(orchestrationClient, UriBuilder
387                                 .fromUri(findByAction).queryParam(ACTION, action).build());
388         }
389
390         public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupsByVnfResourceCust(String modelCustomizationUUID) {
391                 return this.getMultipleResources(vnfcInstanceGroupCustomizationClient, UriBuilder
392                                 .fromUri(findVnfcInstanceGroupCustomizationByModelCustomizationUUID)
393                                 .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
394         }
395
396         public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomizationByModelCustUUID(
397                         String modelCustomizationUUID) {
398                 return this.getMultipleResources(collectionResourceInstanceGroupCustomizationClient, UriBuilder
399                                 .fromUri(findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID)
400                                 .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
401         }
402
403         public VfModuleCustomization getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(String modelCustomizationUUID, String vfModuleModelUUID) {
404                 return this.getSingleResource(vfModuleCustomizationClient, getUri(UriBuilder
405                                 .fromUri(findByModelCustomizationUUIDAndVfModuleModelUUID)
406                                 .queryParam(MODEL_CUSTOMIZATION_UUID,modelCustomizationUUID)
407                                 .queryParam(VF_MODULE_MODEL_UUID,vfModuleModelUUID).build().toString()));
408         }
409
410         public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(String requestAction,
411                         String resourceName, boolean aLaCarte) {
412                 return this.getSingleResource(northBoundRequestClient, UriBuilder
413                                 .fromUri(findOneByActionAndRequestScopeAndIsAlacarte)
414                                 .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
415                                 .queryParam(IS_ALACARTE, aLaCarte).build());
416         }
417
418         public RainyDayHandlerStatus getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(
419                         String flowName, String serviceType, String vnfType, String errorCode, String workStep) {
420                 return this.getSingleResource(rainyDayHandlerStatusClient, UriBuilder
421                                 .fromUri(findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep)
422                                 .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType)
423                                 .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep)
424                                 .build());
425         }
426
427         public  ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action){
428                 return this.getSingleResource(serviceRecipeClient, getUri(UriBuilder
429                                 .fromUri(findFirstByServiceModelUUIDAndActionURI)
430                                 .queryParam(SERVICE_MODEL_UUID,modelUUID)
431                                 .queryParam(ACTION,action).build().toString()));
432         }
433
434         public  NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action){
435                 return this.getSingleResource(networkRecipeClient, UriBuilder
436                                 .fromUri(findFirstByModelNameAndAction)
437                                 .queryParam(MODEL_NAME,modelName)
438                                 .queryParam(ACTION,action).build());
439         }
440         
441         public ControllerSelectionReference getControllerSelectionReferenceByVnfTypeAndActionCategory(String vnfType, String actionCategory) {
442                 return this.getSingleResource(controllerSelectionReferenceClient, UriBuilder
443                                 .fromUri(endpoint + "/controllerSelectionReference/search/findControllerSelectionReferenceByVnfTypeAndActionCategory")
444                                                 .queryParam("VNF_TYPE", vnfType).queryParam("ACTION_CATEGORY", actionCategory).build());
445         }
446
447         public Service getFirstByModelNameOrderByModelVersionDesc(String modelName){
448                 return this.getSingleResource(serviceClient,UriBuilder
449                                 .fromUri(findFirstByModelNameURI)
450                                 .queryParam(MODEL_NAME,modelName).build());
451         }
452
453
454         public VnfResource getFirstVnfResourceByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion){
455                 return this.getSingleResource(vnfResourceClient, getUri(UriBuilder
456                                 .fromUri(findFirstResourceByModelInvariantUUIDAndModelVersion)
457                                 .queryParam(MODEL_INVARIANT_UUID,modelInvariantUUID)
458                                 .queryParam(MODEL_VERSION,modelVersion).build().toString()));
459         }
460
461
462         public VnfResourceCustomization getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(String modelInstanceName, VnfResource vnfResource){
463                 return this.getSingleResource(vnfResourceCustomizationClient, getUri(UriBuilder
464                                 .fromUri(findByModelInstanceNameAndVnfResources)
465                                 .queryParam(MODEL_INSTANCE_NAME,modelInstanceName)
466                                 .queryParam(VNF_RESOURCE_MODEL_UUID,vnfResource.getModelUUID()).build().toString()));
467         }
468
469         public VnfRecipe getFirstVnfRecipeByNfRoleAndAction(String nfRole, String action){
470                 return this.getSingleResource(vnfRecipeClient,getUri(UriBuilder
471                                 .fromUri(findFirstVnfRecipeByNfRoleAndAction)
472                                 .queryParam(NF_ROLE,nfRole)
473                                 .queryParam(ACTION,action).build().toString()));
474         }
475
476         public VnfComponentsRecipe getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(String vfModuleModelUUID, String vnfComponentType, String action){
477                 return this.getSingleResource(vnfComponentsRecipeClient,getUri(UriBuilder
478                                 .fromUri(findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction)
479                                 .queryParam(VF_MODULE_MODEL_UUID,vfModuleModelUUID)
480                                 .queryParam(VNF_COMPONENT_TYPE,vnfComponentType)
481                                 .queryParam(ACTION,action).build().toString()));
482         }
483
484         public VnfComponentsRecipe getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(String vnfComponentType, String action) {
485                 return this.getSingleResource(vnfComponentsRecipeClient,getUri(UriBuilder
486                                 .fromUri(findFirstVnfComponentsRecipeByVnfComponentTypeAndAction)
487                                 .queryParam(VNF_COMPONENT_TYPE,vnfComponentType)
488                                 .queryParam(ACTION,action).build().toString()));
489         }
490         protected URI getUri(String template){
491                 return URI.create(template);
492         }
493
494         public CloudifyManager getCloudifyManager(String id) {
495                 return this.getSingleResource(cloudifyManagerClient,getUri(cloudifyManagerURI + id));
496         }
497
498         public CloudSite getCloudSite(String id){
499                 return this.getSingleResource(cloudSiteClient, getUri(cloudSiteURI + id));
500         }
501
502         public CloudSite getCloudSiteByClliAndAicVersion (String clli, String cloudVersion){
503                 return this.getSingleResource(cloudSiteClient, getUri(UriBuilder
504                                 .fromUri(findByClliAndCloudVersion)
505                                 .queryParam(CLLI,clli).queryParam(CLOUD_VERSION,cloudVersion).build().toString()));
506         }
507
508         public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
509                 return this.getSingleResource(serviceClient, getUri(UriBuilder
510                                 .fromUri(findFirstByModelVersionAndModelInvariantUUIDURI)
511                                 .queryParam(MODEL_VERSION, modelVersion)
512                                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
513         }
514
515         public VfModule getVfModuleByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion){
516                 return this.getSingleResource(vfModuleClient,getUri(UriBuilder
517                                 .fromUri(findFirstVfModuleByModelInvariantUUIDAndModelVersion)
518                                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID)
519                                 .queryParam(MODEL_VERSION, modelVersion).build().toString()));
520         }
521
522         public List<Service> getServiceByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
523                 return this.getMultipleResources(serviceClient, getUri(UriBuilder
524                                 .fromUri(findByModelInvariantUUIDURI)
525                                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
526         }
527
528         public List<VfModule> getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
529                 return this.getMultipleResources(vfModuleClient, getUri(UriBuilder
530                                 .fromUri(findVfModuleByModelInvariantUUIDOrderByModelVersionDesc)
531                                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
532         }
533
534         private <T> T getSingleResource(Client<T> client, URI uri) {
535                 return client.get(uri);
536         }
537
538         private <T> List<T> getMultipleResources(Client<T> client, URI uri) {
539                 Iterable<T> iterator = client.getAll(uri);
540                 List<T> list = new ArrayList<>();
541                 Iterator<T> it = iterator.iterator();
542                 it.forEachRemaining(list::add);
543                 return list;
544         }
545         
546         public List<CvnfcCustomization> getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID(String vnfCustomizationUUID, String vfModuleCustomizationUUID){
547                 return this.getMultipleVnfcCustomizations(
548                                 UriBuilder.fromUri(endpoint + "/vnfcCustomization/search/findByVnfCustomizationUUIDAndVfModuleCustomizationUUID")
549                                                 .queryParam("VNF_CUSTOMIZATION_UUID", vnfCustomizationUUID)
550                                                 .queryParam("VFMODULE_CUSTOMIZATION_UUID", vfModuleCustomizationUUID).build());
551         }
552         
553         private List<CvnfcCustomization> getMultipleVnfcCustomizations(URI uri) {
554                 Iterable<CvnfcCustomization> vnfcIterator = cvnfcCustomizationClient.getAll(uri);
555                 List<CvnfcCustomization> vnfcList = new ArrayList<>();
556                 Iterator<CvnfcCustomization> it = vnfcIterator.iterator();
557                 it.forEachRemaining(vnfcList::add);
558                 return vnfcList;
559         }
560
561 }