add junit coverage for SvnfmService
[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 java.net.URI;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.stream.Collectors;
28 import javax.annotation.PostConstruct;
29 import javax.persistence.EntityNotFoundException;
30 import javax.ws.rs.core.UriBuilder;
31 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
32 import org.onap.so.db.catalog.beans.CloudSite;
33 import org.onap.so.db.catalog.beans.CloudifyManager;
34 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
35 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
36 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
37 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
38 import org.onap.so.db.catalog.beans.CvnfcCustomization;
39 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
40 import org.onap.so.db.catalog.beans.HomingInstance;
41 import org.onap.so.db.catalog.beans.InstanceGroup;
42 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
43 import org.onap.so.db.catalog.beans.NetworkRecipe;
44 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
45 import org.onap.so.db.catalog.beans.OrchestrationAction;
46 import org.onap.so.db.catalog.beans.OrchestrationStatus;
47 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
48 import org.onap.so.db.catalog.beans.PnfResource;
49 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
50 import org.onap.so.db.catalog.beans.ResourceType;
51 import org.onap.so.db.catalog.beans.Service;
52 import org.onap.so.db.catalog.beans.ServiceRecipe;
53 import org.onap.so.db.catalog.beans.VfModule;
54 import org.onap.so.db.catalog.beans.VfModuleCustomization;
55 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
56 import org.onap.so.db.catalog.beans.VnfRecipe;
57 import org.onap.so.db.catalog.beans.VnfResource;
58 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
59 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
60 import org.onap.so.db.catalog.beans.Workflow;
61 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
62 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
63 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
64 import org.onap.so.logger.LogConstants;
65 import org.onap.so.logging.jaxrs.filter.SpringClientFilter;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
68 import org.springframework.beans.factory.annotation.Autowired;
69 import org.springframework.beans.factory.annotation.Value;
70 import org.springframework.http.HttpHeaders;
71 import org.springframework.http.client.BufferingClientHttpRequestFactory;
72 import org.springframework.http.client.ClientHttpRequestFactory;
73 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
74 import org.springframework.stereotype.Component;
75 import org.springframework.web.client.RestTemplate;
76 import org.springframework.web.util.UriComponentsBuilder;
77 import uk.co.blackpepper.bowman.Client;
78 import uk.co.blackpepper.bowman.ClientFactory;
79 import uk.co.blackpepper.bowman.Configuration;
80
81 @Component("CatalogDbClient")
82 public class CatalogDbClient {
83
84     private static final Logger logger = LoggerFactory.getLogger(CatalogDbClient.class);
85
86     private static final String CLOUD_SITE = "/cloudSite";
87     private static final String CLOUDIFY_MANAGER = "/cloudifyManager";
88     private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro";
89     private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup";
90     private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization";
91     private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION =
92             "/collectionResourceInstanceGroupCustomization";
93     private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization";
94     private static final String ORCHESTRATION_FLOW = "/orchestrationFlow";
95     private static final String ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE =
96             "/orchestrationStatusStateTransitionDirective";
97     private static final String INSTANCE_GROUP = "/instanceGroup";
98     private static final String COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION = "/collectionNetworkResourceCustomization";
99     private static final String BUILDING_BLOCK_DETAIL = "/buildingBlockDetail";
100     private static final String NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION = "/networkCollectionResourceCustomization";
101     private static final String VNF_RESOURCE_CUSTOMIZATION = "/vnfResourceCustomization";
102     private static final String SERVICE = "/service";
103     private static final String EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING = "/externalServiceToInternalService";
104     private static final String VNF_RESOURCE = "/vnfResource";
105     private static final String VNF_RECIPE = "/vnfRecipe";
106     private static final String VFMODULE = "/vfModule";
107     private static final String VFMODULE_CUSTOMIZATION = "/vfModuleCustomization";
108     private static final String VNF_COMPONENTS_RECIPE = "/vnfComponentsRecipe";
109     private static final String SERVICE_RECIPE = "/serviceRecipe";
110     private static final String NETWORK_RECIPE = "/networkRecipe";
111     private static final String PNF_RESOURCE = "/pnfResource";
112     private static final String PNF_RESOURCE_CUSTOMIZATION = "/pnfResourceCustomization";
113     private static final String WORKFLOW = "/workflow";
114
115
116     private static final String SEARCH = "/search";
117     private static final String URI_SEPARATOR = "/";
118
119     private static final String SERVICE_MODEL_UUID = "serviceModelUUID";
120     private static final String SERVICE_NAME = "serviceName";
121     private static final String MODEL_UUID = "modelUUID";
122     private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
123     private static final String ACTION = "action";
124     private static final String MODEL_NAME = "modelName";
125     private static final String MODEL_VERSION = "modelVersion";
126     private static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
127     private static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
128     private static final String NF_ROLE = "nfRole";
129     private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
130     private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
131     private static final String BUILDING_BLOCK_NAME = "buildingBlockName";
132     private static final String RESOURCE_TYPE = "resourceType";
133     private static final String ORCHESTRATION_STATUS = "orchestrationStatus";
134     private static final String TARGET_ACTION = "targetAction";
135     private static final String REQUEST_SCOPE = "requestScope";
136     private static final String IS_ALACARTE = "isALaCarte";
137     private static final String CLOUD_OWNER = "cloudOwner";
138     private static final String FLOW_NAME = "flowName";
139     private static final String ERROR_MESSAGE = "errorMessage";
140     private static final String SERVICE_TYPE = "serviceType";
141     private static final String VNF_TYPE = "vnfType";
142     private static final String ERROR_CODE = "errorCode";
143     private static final String WORK_STEP = "workStep";
144     private static final String CLLI = "clli";
145     private static final String CLOUD_VERSION = "cloudVersion";
146     private static final String HOMING_INSTANCE = "/homingInstance";
147     private static final String ARTIFACT_UUID = "artifactUUID";
148     private static final String SOURCE = "source";
149
150     private static final String TARGET_ENTITY = "SO:CatalogDB";
151     private static final String ASTERISK = "*";
152
153     private String findExternalToInternalServiceByServiceName = "/findByServiceName";
154     private String findServiceByModelName = "/findOneByModelName";
155     private String findServiceRecipeByActionAndServiceModelUUID = "/findByActionAndServiceModelUUID";
156     private String findServiceByModelUUID = "/findOneByModelUUID";
157     private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
158     private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
159     private String findFirstByModelVersionAndModelInvariantUUIDURI = "/findFirstByModelVersionAndModelInvariantUUID";
160     private String findByModelInvariantUUIDURI = "/findByModelInvariantUUIDOrderByModelVersionDesc";
161     private String findFirstByModelNameAndAction = "/findFirstByModelNameAndAction";
162     private String findFirstResourceByModelInvariantUUIDAndModelVersion =
163             "/findFirstResourceByModelInvariantUUIDAndModelVersion";
164     private String findByModelInstanceNameAndVnfResources = "/findByModelInstanceNameAndVnfResources";
165     private String findFirstVnfRecipeByNfRoleAndAction = "/findFirstVnfRecipeByNfRoleAndAction";
166     private String findByModelCustomizationUUIDAndVfModuleModelUUID =
167             "/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc";
168     private String findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction =
169             "/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction";
170     private String findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
171             "/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction";
172     private String findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
173             "/findByModelInvariantUUIDOrderByModelVersionDesc";
174     private String findFirstVfModuleByModelInvariantUUIDAndModelVersion =
175             "/findFirstVfModuleByModelInvariantUUIDAndModelVersion";
176     private String findOneByBuildingBlockName = "/findOneByBuildingBlockName";
177     private String findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
178             "/findOneByResourceTypeAndOrchestrationStatusAndTargetAction";
179     private String findByAction = "/findByAction";
180     private String findVnfcInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
181     private String findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
182             "/findByModelCustomizationUUID";
183     private String findOneByActionAndRequestScopeAndIsAlacarte = "/findOneByActionAndRequestScopeAndIsAlacarte";
184     private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner =
185             "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner";
186     private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
187             "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType";
188
189     private static final String findRainyDayHandler = "/findRainyDayHandler";
190     private String findByClliAndCloudVersion = "/findByClliAndCloudVersion";
191     private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId";
192     private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
193     private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
194     private String findWorkflowByModelUUID = "/findWorkflowByModelUUID";
195     private String findWorkflowBySource = "/findBySource";
196     private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
197
198     private String serviceURI;
199     private String vfModuleURI;
200     private String vnfResourceURI;
201     private String networkCollectionResourceCustomizationURI;
202     private String networkResourceCustomizationURI;
203     private String collectionNetworkResourceCustomizationURI;
204     private String instanceGroupURI;
205     private String cloudifyManagerURI;
206     private String cloudSiteURI;
207     private String homingInstanceURI;
208     private String cvnfcResourceCustomizationURI;
209     private String pnfResourceURI;
210     private String pnfResourceCustomizationURI;
211     private String workflowURI;
212
213     private final Client<Service> serviceClient;
214
215     private final Client<NetworkRecipe> networkRecipeClient;
216
217     private final Client<NetworkResourceCustomization> networkResourceCustomizationClient;
218
219     private final Client<VnfResource> vnfResourceClient;
220
221     private final Client<VnfResourceCustomization> vnfResourceCustomizationClient;
222
223     private final Client<VnfRecipe> vnfRecipeClient;
224
225     private final Client<VfModuleCustomization> vfModuleCustomizationClient;
226
227     private final Client<VfModule> vfModuleClient;
228
229     private final Client<VnfComponentsRecipe> vnfComponentsRecipeClient;
230
231     private final Client<OrchestrationFlow> orchestrationClient;
232
233     private final Client<NorthBoundRequest> northBoundRequestClient;
234
235     private final Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
236
237     private final Client<BuildingBlockDetail> buildingBlockDetailClient;
238
239     private final Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
240
241     private final Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
242
243     private final Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
244
245     private final Client<InstanceGroup> instanceGroupClient;
246
247     private final Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
248
249     private final Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
250
251     private final Client<ServiceRecipe> serviceRecipeClient;
252
253     private final Client<ExternalServiceToInternalService> externalServiceToInternalServiceClient;
254
255     private final Client<CloudSite> cloudSiteClient;
256
257     private final Client<HomingInstance> homingInstanceClient;
258
259     private final Client<CloudifyManager> cloudifyManagerClient;
260
261     private final Client<ControllerSelectionReference> controllerSelectionReferenceClient;
262
263     private final Client<PnfResource> pnfResourceClient;
264
265     private final Client<PnfResourceCustomization> pnfResourceCustomizationClient;
266
267     private final Client<Workflow> workflowClient;
268
269     @Value("${mso.catalog.db.spring.endpoint:#{null}}")
270     private String endpoint;
271
272     @Value("${mso.db.auth:#{null}}")
273     private String msoAdaptersAuth;
274
275     @Autowired
276     RestTemplate restTemplate;
277
278     @PostConstruct
279     public void init() {
280         findExternalToInternalServiceByServiceName = endpoint + EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING + SEARCH
281                 + findExternalToInternalServiceByServiceName;
282         findServiceByModelName = endpoint + SERVICE + SEARCH + findServiceByModelName;
283         findServiceRecipeByActionAndServiceModelUUID =
284                 endpoint + SERVICE_RECIPE + SEARCH + findServiceRecipeByActionAndServiceModelUUID;
285         findServiceByModelUUID = endpoint + SERVICE + SEARCH + findServiceByModelUUID;
286         findFirstByModelNameURI = endpoint + SERVICE + SEARCH + findFirstByModelNameURI;
287         findFirstByModelVersionAndModelInvariantUUIDURI =
288                 endpoint + SERVICE + SEARCH + findFirstByModelVersionAndModelInvariantUUIDURI;
289         findByModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findByModelInvariantUUIDURI;
290         findFirstByServiceModelUUIDAndActionURI =
291                 endpoint + SERVICE_RECIPE + SEARCH + findFirstByServiceModelUUIDAndActionURI;
292         findFirstByModelNameAndAction = endpoint + NETWORK_RECIPE + SEARCH + findFirstByModelNameAndAction;
293         findFirstResourceByModelInvariantUUIDAndModelVersion =
294                 endpoint + VNF_RESOURCE + SEARCH + findFirstResourceByModelInvariantUUIDAndModelVersion;
295         findByModelInstanceNameAndVnfResources =
296                 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findByModelInstanceNameAndVnfResources;
297         findFirstVnfRecipeByNfRoleAndAction = endpoint + VNF_RECIPE + SEARCH + findFirstVnfRecipeByNfRoleAndAction;
298         findByModelCustomizationUUIDAndVfModuleModelUUID =
299                 endpoint + VFMODULE_CUSTOMIZATION + SEARCH + findByModelCustomizationUUIDAndVfModuleModelUUID;
300         findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE
301                 + SEARCH + findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction;
302         findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
303                 endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVnfComponentTypeAndAction;
304         findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
305                 endpoint + VFMODULE + SEARCH + findVfModuleByModelInvariantUUIDOrderByModelVersionDesc;
306         findFirstVfModuleByModelInvariantUUIDAndModelVersion =
307                 endpoint + VFMODULE + SEARCH + findFirstVfModuleByModelInvariantUUIDAndModelVersion;
308         findOneByBuildingBlockName = endpoint + BUILDING_BLOCK_DETAIL + SEARCH + findOneByBuildingBlockName;
309         findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
310                 endpoint + ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE + SEARCH
311                         + findOneByResourceTypeAndOrchestrationStatusAndTargetAction;
312         findByAction = endpoint + ORCHESTRATION_FLOW + SEARCH + findByAction;
313         findVnfcInstanceGroupCustomizationByModelCustomizationUUID = endpoint + VNFC_INSTANCE_GROUP_CUSTOMIZATION
314                 + SEARCH + findVnfcInstanceGroupCustomizationByModelCustomizationUUID;
315         findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
316                 endpoint + COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION + SEARCH
317                         + findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID;
318         findOneByActionAndRequestScopeAndIsAlacarte =
319                 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH + findOneByActionAndRequestScopeAndIsAlacarte;
320         findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner = endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
321                 + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner;
322         findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
323                 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
324                         + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType;
325         findByClliAndCloudVersion = endpoint + CLOUD_SITE + SEARCH + findByClliAndCloudVersion;
326
327         findPnfResourceCustomizationByModelUuid =
328                 endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid;
329
330         findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
331         findWorkflowByModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByModelUUID;
332         findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
333
334         findVnfResourceCustomizationByModelUuid =
335                 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid;
336
337         serviceURI = endpoint + SERVICE + URI_SEPARATOR;
338         vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR;
339         vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR;
340         networkCollectionResourceCustomizationURI =
341                 endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
342         networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
343         collectionNetworkResourceCustomizationURI =
344                 endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
345         instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR;
346         cloudifyManagerURI = endpoint + CLOUDIFY_MANAGER + URI_SEPARATOR;
347         cloudSiteURI = endpoint + CLOUD_SITE + URI_SEPARATOR;
348         homingInstanceURI = endpoint + HOMING_INSTANCE + URI_SEPARATOR;
349         pnfResourceURI = endpoint + PNF_RESOURCE + URI_SEPARATOR;
350         pnfResourceCustomizationURI = endpoint + PNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
351         workflowURI = endpoint + WORKFLOW + URI_SEPARATOR;
352
353     }
354
355     public CatalogDbClient() {
356         ClientHttpRequestFactory factory =
357                 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
358
359         ClientFactory clientFactory =
360                 Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
361                     restTemplate.getInterceptors().add((new SpringClientFilter()));
362
363                     restTemplate.getInterceptors().add((request, body, execution) -> {
364
365                         request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
366                         request.getHeaders().add(LogConstants.TARGET_ENTITY_HEADER, TARGET_ENTITY);
367                         return execution.execute(request, body);
368                     });
369                 }).build().buildClientFactory();
370         serviceClient = clientFactory.create(Service.class);
371         networkRecipeClient = clientFactory.create(NetworkRecipe.class);
372         networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
373         vnfResourceClient = clientFactory.create(VnfResource.class);
374         vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
375         vnfRecipeClient = clientFactory.create(VnfRecipe.class);
376         orchestrationClient = clientFactory.create(OrchestrationFlow.class);
377         vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
378         vfModuleClient = clientFactory.create(VfModule.class);
379         vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
380         northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
381         rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
382         buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
383         orchestrationStatusStateTransitionDirectiveClient =
384                 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
385         vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
386         collectionResourceInstanceGroupCustomizationClient =
387                 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
388         instanceGroupClient = clientFactory.create(InstanceGroup.class);
389         networkCollectionResourceCustomizationClient =
390                 clientFactory.create(NetworkCollectionResourceCustomization.class);
391         collectionNetworkResourceCustomizationClient =
392                 clientFactory.create(CollectionNetworkResourceCustomization.class);
393         cloudSiteClient = clientFactory.create(CloudSite.class);
394         homingInstanceClient = clientFactory.create(HomingInstance.class);
395         cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
396         serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
397         controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
398         externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
399         pnfResourceClient = clientFactory.create(PnfResource.class);
400         pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
401         workflowClient = clientFactory.create(Workflow.class);
402     }
403
404     public CatalogDbClient(String baseUri, String auth) {
405         ClientHttpRequestFactory factory =
406                 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
407
408         ClientFactory clientFactory = Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory)
409                 .setRestTemplateConfigurer(restTemplate -> {
410                     restTemplate.getInterceptors().add((new SpringClientFilter()));
411
412                     restTemplate.getInterceptors().add((request, body, execution) -> {
413
414                         request.getHeaders().add(HttpHeaders.AUTHORIZATION, auth);
415                         request.getHeaders().add(LogConstants.TARGET_ENTITY_HEADER, TARGET_ENTITY);
416                         return execution.execute(request, body);
417                     });
418                 }).build().buildClientFactory();
419         serviceClient = clientFactory.create(Service.class);
420         networkRecipeClient = clientFactory.create(NetworkRecipe.class);
421         networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
422         vnfResourceClient = clientFactory.create(VnfResource.class);
423         vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
424         vnfRecipeClient = clientFactory.create(VnfRecipe.class);
425         orchestrationClient = clientFactory.create(OrchestrationFlow.class);
426         vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
427         vfModuleClient = clientFactory.create(VfModule.class);
428         vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
429         northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
430         rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
431         buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
432         orchestrationStatusStateTransitionDirectiveClient =
433                 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
434         vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
435         collectionResourceInstanceGroupCustomizationClient =
436                 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
437         instanceGroupClient = clientFactory.create(InstanceGroup.class);
438         networkCollectionResourceCustomizationClient =
439                 clientFactory.create(NetworkCollectionResourceCustomization.class);
440         collectionNetworkResourceCustomizationClient =
441                 clientFactory.create(CollectionNetworkResourceCustomization.class);
442         cloudSiteClient = clientFactory.create(CloudSite.class);
443         homingInstanceClient = clientFactory.create(HomingInstance.class);
444         cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
445         serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
446         controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
447         externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
448         pnfResourceClient = clientFactory.create(PnfResource.class);
449         pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
450         workflowClient = clientFactory.create(Workflow.class);
451     }
452
453     public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(
454             String modelCustomizationUUID) {
455         NetworkCollectionResourceCustomization networkCollectionResourceCustomization =
456                 this.getSingleResource(networkCollectionResourceCustomizationClient,
457                         getUri(networkCollectionResourceCustomizationURI + modelCustomizationUUID));
458         if (networkCollectionResourceCustomization != null) {
459             networkCollectionResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
460         }
461         return networkCollectionResourceCustomization;
462     }
463
464     public Service getServiceByID(String modelUUID) {
465         Service service = getSingleResource(serviceClient, getUri(serviceURI + modelUUID));
466         if (service != null) {
467             service.setModelUUID(modelUUID);
468         }
469         return service;
470     }
471
472     public VfModule getVfModuleByModelUUID(String modelUUID) {
473         VfModule vfModule = getSingleResource(vfModuleClient, getUri(vfModuleURI + modelUUID));
474         if (vfModule != null) {
475             vfModule.setModelUUID(modelUUID);
476         }
477         return vfModule;
478     }
479
480     public VnfResource getVnfResourceByModelUUID(String modelUUID) {
481
482         VnfResource vnfResource = this.getSingleResource(vnfResourceClient, getUri(vnfResourceURI + modelUUID));
483         if (vnfResource != null) {
484             vnfResource.setModelUUID(modelUUID);
485         }
486         return vnfResource;
487     }
488
489     // A VNFResource customization UUID is the same object across services, so we can return anyone from the list
490     // In the future the client should query starting at a service model uuid
491     public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
492         List<VnfResourceCustomization> vnfResourceCustomization = this.getMultipleResources(
493                 vnfResourceCustomizationClient, getUri(endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH
494                         + "/findByModelCustomizationUUID" + "?MODEL_CUSTOMIZATION_UUID=" + modelCustomizationUUID));
495         if (vnfResourceCustomization != null && !vnfResourceCustomization.isEmpty()) {
496             return vnfResourceCustomization.get(0);
497         } else {
498             return null;
499         }
500     }
501
502     public List<VnfResourceCustomization> getVnfResourceCustomizationByModelUuid(String modelUuid) {
503         return this.getMultipleResources(vnfResourceCustomizationClient,
504                 getUri(UriBuilder.fromUri(findVnfResourceCustomizationByModelUuid)
505                         .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
506     }
507
508     public PnfResource getPnfResourceByModelUUID(String modelUUID) {
509         PnfResource PnfResource = this.getSingleResource(pnfResourceClient, getUri(pnfResourceURI + modelUUID));
510         if (PnfResource != null) {
511             PnfResource.setModelUUID(modelUUID);
512         }
513         return PnfResource;
514     }
515
516     public PnfResourceCustomization getPnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
517         PnfResourceCustomization pnfResourceCustomization = getSingleResource(pnfResourceCustomizationClient,
518                 getUri(pnfResourceCustomizationURI + modelCustomizationUUID));
519         if (pnfResourceCustomization != null) {
520             pnfResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
521         }
522         return pnfResourceCustomization;
523     }
524
525     public List<PnfResourceCustomization> getPnfResourceCustomizationByModelUuid(String modelUuid) {
526         return this.getMultipleResources(pnfResourceCustomizationClient,
527                 getUri(UriBuilder.fromUri(findPnfResourceCustomizationByModelUuid)
528                         .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
529     }
530
531     public CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomizationByID(
532             String modelCustomizationUUID) {
533         CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
534                 this.getSingleResource(collectionNetworkResourceCustomizationClient,
535                         getUri(UriBuilder.fromUri(collectionNetworkResourceCustomizationURI + modelCustomizationUUID)
536                                 .build().toString()));
537         if (collectionNetworkResourceCustomization != null) {
538             collectionNetworkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
539         }
540         return collectionNetworkResourceCustomization;
541     }
542
543     public InstanceGroup getInstanceGroupByModelUUID(String modelUUID) {
544         InstanceGroup instanceGroup = this.getSingleResource(instanceGroupClient, getUri(instanceGroupURI + modelUUID));
545         if (instanceGroup != null) {
546             instanceGroup.setModelUUID(modelUUID);
547         }
548         return instanceGroup;
549     }
550
551     public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
552         return this.getSingleResource(vfModuleCustomizationClient,
553                 getUri(endpoint + VFMODULE_CUSTOMIZATION + SEARCH
554                         + "/findFirstByModelCustomizationUUIDOrderByCreatedDesc" + "?MODEL_CUSTOMIZATION_UUID="
555                         + modelCustomizationUUID));
556     }
557
558     public NetworkResourceCustomization getNetworkResourceCustomizationByModelCustomizationUUID(
559             String modelCustomizationUUID) {
560         NetworkResourceCustomization networkResourceCustomization = this.getSingleResource(
561                 networkResourceCustomizationClient, getUri(networkResourceCustomizationURI + modelCustomizationUUID));
562         if (networkResourceCustomization != null) {
563             networkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
564         }
565         return networkResourceCustomization;
566     }
567
568
569     public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) {
570         BuildingBlockDetail buildingBlockDetail =
571                 getSingleResource(buildingBlockDetailClient, getUri(UriBuilder.fromUri(findOneByBuildingBlockName)
572                         .queryParam(BUILDING_BLOCK_NAME, buildingBlockName).build().toString()));
573         if (buildingBlockDetail != null) {
574             buildingBlockDetail.setBuildingBlockName(buildingBlockName);
575         }
576         return buildingBlockDetail;
577     }
578
579
580     public OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective(
581             ResourceType resourceType, OrchestrationStatus orchestrationStatus, OrchestrationAction targetAction) {
582         return getSingleResource(orchestrationStatusStateTransitionDirectiveClient,
583                 UriBuilder.fromUri(findOneByResourceTypeAndOrchestrationStatusAndTargetAction)
584                         .queryParam(RESOURCE_TYPE, resourceType.name())
585                         .queryParam(ORCHESTRATION_STATUS, orchestrationStatus.name())
586                         .queryParam(TARGET_ACTION, targetAction.name()).build());
587     }
588
589     public List<OrchestrationFlow> getOrchestrationFlowByAction(String action) {
590         return this.getMultipleResources(orchestrationClient,
591                 UriBuilder.fromUri(findByAction).queryParam(ACTION, action).build());
592     }
593
594     public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupsByVnfResourceCust(String modelCustomizationUUID) {
595         return this.getMultipleResources(vnfcInstanceGroupCustomizationClient,
596                 UriBuilder.fromUri(findVnfcInstanceGroupCustomizationByModelCustomizationUUID)
597                         .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
598     }
599
600     public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomizationByModelCustUUID(
601             String modelCustomizationUUID) {
602         return this.getMultipleResources(collectionResourceInstanceGroupCustomizationClient,
603                 UriBuilder.fromUri(findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID)
604                         .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
605     }
606
607     public VfModuleCustomization getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
608             String modelCustomizationUUID, String vfModuleModelUUID) {
609         return this.getSingleResource(vfModuleCustomizationClient,
610                 getUri(UriBuilder.fromUri(findByModelCustomizationUUIDAndVfModuleModelUUID)
611                         .queryParam("MODEL_CUSTOMIZATION_UUID", modelCustomizationUUID)
612                         .queryParam("MODEL_UUID", vfModuleModelUUID).build().toString()));
613     }
614
615     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(String requestAction,
616             String resourceName, boolean aLaCarte) {
617         return this.getSingleResource(northBoundRequestClient,
618                 UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarte).queryParam(ACTION, requestAction)
619                         .queryParam(REQUEST_SCOPE, resourceName).queryParam(IS_ALACARTE, aLaCarte).build());
620     }
621
622     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(String requestAction,
623             String resourceName, boolean aLaCarte, String cloudOwner) {
624         return this.getSingleResource(northBoundRequestClient,
625                 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
626                         .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
627                         .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
628                         .queryParam(SERVICE_TYPE, ASTERISK).build().toString()));
629     }
630
631     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(
632             String requestAction, String resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
633         return this.getSingleResource(northBoundRequestClient,
634                 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
635                         .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
636                         .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
637                         .queryParam(SERVICE_TYPE, serviceType).build().toString()));
638     }
639
640     public RainyDayHandlerStatus getRainyDayHandlerStatus(String flowName, String serviceType, String vnfType,
641             String errorCode, String workStep, String errorMessage) {
642         logger.debug(
643                 "Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}",
644                 flowName, serviceType, vnfType, errorCode, workStep, errorMessage);
645         return this.getSingleResource(rainyDayHandlerStatusClient,
646                 UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler)
647                         .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType)
648                         .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep)
649                         .queryParam(ERROR_MESSAGE, errorMessage).build().encode().toUri());
650     }
651
652     public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) {
653         return this.getSingleResource(serviceRecipeClient,
654                 getUri(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI)
655                         .queryParam(SERVICE_MODEL_UUID, modelUUID).queryParam(ACTION, action).build().toString()));
656     }
657
658
659
660     public NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action) {
661         return this.getSingleResource(networkRecipeClient, UriBuilder.fromUri(findFirstByModelNameAndAction)
662                 .queryParam(MODEL_NAME, modelName).queryParam(ACTION, action).build());
663     }
664
665     public ControllerSelectionReference getControllerSelectionReferenceByVnfTypeAndActionCategory(String vnfType,
666             String actionCategory) {
667         return this.getSingleResource(controllerSelectionReferenceClient, UriBuilder.fromUri(endpoint
668                 + "/controllerSelectionReference/search/findControllerSelectionReferenceByVnfTypeAndActionCategory")
669                 .queryParam("VNF_TYPE", vnfType).queryParam("ACTION_CATEGORY", actionCategory).build());
670     }
671
672     public Service getFirstByModelNameOrderByModelVersionDesc(String modelName) {
673         return this.getSingleResource(serviceClient,
674                 UriBuilder.fromUri(findFirstByModelNameURI).queryParam(MODEL_NAME, modelName).build());
675     }
676
677     public ExternalServiceToInternalService findExternalToInternalServiceByServiceName(String serviceName) {
678         return this.getSingleResource(externalServiceToInternalServiceClient,
679                 getUri(UriBuilder.fromUri(findExternalToInternalServiceByServiceName)
680                         .queryParam(SERVICE_NAME, serviceName).build().toString()));
681     }
682
683     public ServiceRecipe findServiceRecipeByActionAndServiceModelUUID(String action, String modelUUID) {
684         return this.getSingleResource(serviceRecipeClient,
685                 getUri(UriBuilder.fromUri(findServiceRecipeByActionAndServiceModelUUID).queryParam(ACTION, action)
686                         .queryParam(SERVICE_MODEL_UUID, modelUUID).build().toString()));
687     }
688
689     public Service getServiceByModelName(String modelName) {
690         return this.getSingleResource(serviceClient, getUri(
691                 UriBuilder.fromUri(findServiceByModelName).queryParam(MODEL_NAME, modelName).build().toString()));
692     }
693
694     public Service getServiceByModelUUID(String modelModelUUID) {
695         return this.getSingleResource(serviceClient, getUri(
696                 UriBuilder.fromUri(findServiceByModelUUID).queryParam(MODEL_UUID, modelModelUUID).build().toString()));
697     }
698
699     public VnfResource getFirstVnfResourceByModelInvariantUUIDAndModelVersion(String modelInvariantUUID,
700             String modelVersion) {
701         return this.getSingleResource(vnfResourceClient,
702                 getUri(UriBuilder.fromUri(findFirstResourceByModelInvariantUUIDAndModelVersion)
703                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
704                         .build().toString()));
705     }
706
707
708     public VnfResourceCustomization getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(
709             String modelInstanceName, VnfResource vnfResource) {
710         return this.getSingleResource(vnfResourceCustomizationClient,
711                 getUri(UriBuilder.fromUri(findByModelInstanceNameAndVnfResources)
712                         .queryParam("MODEL_INSTANCE_NAME", modelInstanceName)
713                         .queryParam("VNF_RESOURCE_MODEL_UUID", vnfResource.getModelUUID()).build().toString()));
714     }
715
716     public VnfRecipe getFirstVnfRecipeByNfRoleAndAction(String nfRole, String action) {
717         return this.getSingleResource(vnfRecipeClient, getUri(UriBuilder.fromUri(findFirstVnfRecipeByNfRoleAndAction)
718                 .queryParam(NF_ROLE, nfRole).queryParam(ACTION, action).build().toString()));
719     }
720
721     public VnfComponentsRecipe getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
722             String vfModuleModelUUID, String modelType, String action) {
723         return this.getSingleResource(vnfComponentsRecipeClient,
724                 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction)
725                         .queryParam(VF_MODULE_MODEL_UUID, vfModuleModelUUID).queryParam(VNF_COMPONENT_TYPE, modelType)
726                         .queryParam(ACTION, action).build().toString()));
727     }
728
729     public VnfComponentsRecipe getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(String modelType, String action) {
730         return this.getSingleResource(vnfComponentsRecipeClient,
731                 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVnfComponentTypeAndAction)
732                         .queryParam(VNF_COMPONENT_TYPE, modelType).queryParam(ACTION, action).build().toString()));
733     }
734
735
736     protected URI getUri(String template) {
737         return URI.create(template);
738     }
739
740     public CloudifyManager getCloudifyManager(String id) {
741         return this.getSingleResource(cloudifyManagerClient, getUri(cloudifyManagerURI + id));
742     }
743
744     public CloudSite getCloudSite(String id) {
745         return this.getSingleResource(cloudSiteClient, getUri(cloudSiteURI + id));
746     }
747
748     public CloudSite getCloudSite(String id, String uri) {
749         return this.getSingleResource(cloudSiteClient, getUri(uri + id));
750     }
751
752     public void postCloudSite(CloudSite cloudSite) {
753         this.postSingleResource(cloudSiteClient, cloudSite);
754     }
755
756     public CloudSite getCloudSiteByClliAndAicVersion(String clli, String cloudVersion) {
757         return this.getSingleResource(cloudSiteClient, getUri(UriBuilder.fromUri(findByClliAndCloudVersion)
758                 .queryParam(CLLI, clli).queryParam(CLOUD_VERSION, cloudVersion).build().toString()));
759     }
760
761     public HomingInstance getHomingInstance(String serviceInstanceId) {
762         return this.getSingleResource(homingInstanceClient, getUri(homingInstanceURI + serviceInstanceId));
763     }
764
765     public HomingInstance getHomingInstance(String serviceInstanceId, String uri) {
766         return this.getSingleResource(homingInstanceClient, getUri(uri + serviceInstanceId));
767     }
768
769     public void postHomingInstance(HomingInstance homingInstance) {
770         this.postSingleResource(homingInstanceClient, homingInstance);
771     }
772
773     public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
774         return this.getSingleResource(serviceClient,
775                 getUri(UriBuilder.fromUri(findFirstByModelVersionAndModelInvariantUUIDURI)
776                         .queryParam(MODEL_VERSION, modelVersion).queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID)
777                         .build().toString()));
778     }
779
780     public VfModule getVfModuleByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion) {
781         return this.getSingleResource(vfModuleClient,
782                 getUri(UriBuilder.fromUri(findFirstVfModuleByModelInvariantUUIDAndModelVersion)
783                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
784                         .build().toString()));
785     }
786
787     public List<Service> getServiceByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
788         return this.getMultipleResources(serviceClient, getUri(UriBuilder.fromUri(findByModelInvariantUUIDURI)
789                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
790     }
791
792     public List<VfModule> getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
793         return this.getMultipleResources(vfModuleClient,
794                 getUri(UriBuilder.fromUri(findVfModuleByModelInvariantUUIDOrderByModelVersionDesc)
795                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
796     }
797
798     private <T> T getSingleResource(Client<T> client, URI uri) {
799         return client.get(uri);
800     }
801
802     private <T> List<T> getMultipleResources(Client<T> client, URI uri) {
803         Iterable<T> iterator = client.getAll(uri);
804         List<T> list = new ArrayList<>();
805         Iterator<T> it = iterator.iterator();
806         it.forEachRemaining(list::add);
807         return list;
808     }
809
810     private <T> URI postSingleResource(Client<T> client, T type) {
811         return client.post(type);
812     }
813
814     public List<CvnfcCustomization> getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUUID,
815             String vfModuleCustomizationUUID) {
816         Service service = this.getServiceByID(serviceModelUUID);
817         VnfResourceCustomization vnfResourceCust =
818                 findVnfResourceCustomizationInList(vnfCustomizationUUID, service.getVnfCustomizations());
819         VfModuleCustomization vfModuleCust =
820                 findVfModuleCustomizationInList(vfModuleCustomizationUUID, vnfResourceCust.getVfModuleCustomizations());
821         return vfModuleCust.getCvnfcCustomization().stream().collect(Collectors.toList());
822     }
823
824     public VnfResourceCustomization findVnfResourceCustomizationInList(String vnfCustomizationUUID,
825             List<VnfResourceCustomization> vnfResourceCusts) {
826         if (vnfCustomizationUUID == null) {
827             throw new EntityNotFoundException(
828                     "a NULL UUID was provided in query to search for VnfResourceCustomization");
829         }
830         List<VnfResourceCustomization> filtered =
831                 vnfResourceCusts.stream().filter(v -> v.getModelCustomizationUUID() != null)
832                         .filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
833                         .collect(Collectors.toList());
834         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
835             return filtered.get(0);
836         } else
837             throw new EntityNotFoundException(
838                     "Unable to find VnfResourceCustomization ModelCustomizationUUID:" + vnfCustomizationUUID);
839     }
840
841     protected VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
842             List<VfModuleCustomization> vfModuleList) {
843         if (vfModuleCustomizationUUID == null) {
844             throw new EntityNotFoundException("a NULL UUID was provided in query to search for VfModuleCustomization");
845         }
846         List<VfModuleCustomization> filtered = vfModuleList.stream().filter(v -> v.getModelCustomizationUUID() != null)
847                 .filter(vfModuleCust -> vfModuleCustomizationUUID.equals(vfModuleCust.getModelCustomizationUUID()))
848                 .collect(Collectors.toList());
849         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
850             return filtered.get(0);
851         } else
852             throw new EntityNotFoundException(
853                     "Unable to find VfModuleCustomization ModelCustomizationUUID:" + vfModuleCustomizationUUID);
854     }
855
856     protected CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
857             List<CvnfcCustomization> cvnfcCustomList) {
858         if (cvnfcCustomizationUuid == null) {
859             throw new EntityNotFoundException("a NULL UUID was provided in query to search for CvnfcCustomization");
860         }
861         List<CvnfcCustomization> filtered = cvnfcCustomList.stream().filter(c -> c.getModelCustomizationUUID() != null)
862                 .filter(cvnfc -> cvnfcCustomizationUuid.equals(cvnfc.getModelCustomizationUUID()))
863                 .collect(Collectors.toList());
864         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
865             logger.debug("Found CvnfcCustomization: {}", filtered.get(0));
866             return filtered.get(0);
867         } else
868             throw new EntityNotFoundException(
869                     "Unable to find CvnfcCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
870     }
871
872     public CvnfcConfigurationCustomization getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUuid,
873             String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
874         List<CvnfcCustomization> cvnfcCustomization =
875                 getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid);
876         CvnfcCustomization cvnfc = findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcCustomization);
877         List<CvnfcConfigurationCustomization> fabricConfigs = cvnfc
878                 .getCvnfcConfigurationCustomization().stream().filter(cvnfcCustom -> cvnfcCustom
879                         .getConfigurationResource().getToscaNodeType().contains("FabricConfiguration"))
880                 .collect(Collectors.toList());
881         if (fabricConfigs != null && !fabricConfigs.isEmpty() && fabricConfigs.size() == 1) {
882             logger.debug("Found Fabric Configuration: {}", fabricConfigs.get(0));
883             return fabricConfigs.get(0);
884         } else
885             throw new EntityNotFoundException(
886                     "Unable to find CvnfcConfigurationCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
887     }
888
889     public Workflow findWorkflowByArtifactUUID(String artifactUUID) {
890         return this.getSingleResource(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByArtifactUUID)
891                 .queryParam(ARTIFACT_UUID, artifactUUID).build().toString()));
892     }
893
894     public List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID) {
895         return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByModelUUID)
896                 .queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
897     }
898
899     public List<Workflow> findWorkflowBySource(String source) {
900         return this.getMultipleResources(workflowClient,
901                 getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
902     }
903
904     public String getEndpoint() {
905         return endpoint;
906     }
907
908     public void setEndpoint(String endpoint) {
909         this.endpoint = endpoint;
910     }
911 }