ae6d51c6a2469e4f7d8bd3146a04d6d65c37c5a5
[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 com.google.common.base.Strings;
24 import java.net.URI;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import javax.annotation.PostConstruct;
30 import javax.persistence.EntityNotFoundException;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.UriBuilder;
33 import org.apache.http.HttpStatus;
34 import org.onap.logging.filter.base.Constants;
35 import org.onap.logging.filter.spring.SpringClientPayloadFilter;
36 import org.onap.so.db.catalog.beans.BBNameSelectionReference;
37 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
38 import org.onap.so.db.catalog.beans.CloudSite;
39 import org.onap.so.db.catalog.beans.CloudifyManager;
40 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
41 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
42 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
43 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
44 import org.onap.so.db.catalog.beans.CvnfcCustomization;
45 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
46 import org.onap.so.db.catalog.beans.HomingInstance;
47 import org.onap.so.db.catalog.beans.InstanceGroup;
48 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
49 import org.onap.so.db.catalog.beans.NetworkRecipe;
50 import org.onap.so.db.catalog.beans.NetworkResource;
51 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
52 import org.onap.so.db.catalog.beans.OrchestrationAction;
53 import org.onap.so.db.catalog.beans.OrchestrationStatus;
54 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
55 import org.onap.so.db.catalog.beans.PnfResource;
56 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
57 import org.onap.so.db.catalog.beans.ProcessingFlags;
58 import org.onap.so.db.catalog.beans.ResourceType;
59 import org.onap.so.db.catalog.beans.Service;
60 import org.onap.so.db.catalog.beans.ServiceRecipe;
61 import org.onap.so.db.catalog.beans.VfModule;
62 import org.onap.so.db.catalog.beans.VfModuleCustomization;
63 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
64 import org.onap.so.db.catalog.beans.VnfRecipe;
65 import org.onap.so.db.catalog.beans.VnfResource;
66 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
67 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
68 import org.onap.so.db.catalog.beans.Workflow;
69 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
70 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
71 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
72 import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
73 import org.onap.so.rest.catalog.beans.Vnf;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
76 import org.springframework.beans.factory.annotation.Autowired;
77 import org.springframework.beans.factory.annotation.Value;
78 import org.springframework.core.ParameterizedTypeReference;
79 import org.springframework.http.HttpEntity;
80 import org.springframework.http.HttpHeaders;
81 import org.springframework.http.HttpMethod;
82 import org.springframework.http.client.BufferingClientHttpRequestFactory;
83 import org.springframework.http.client.ClientHttpRequestFactory;
84 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
85 import org.springframework.stereotype.Component;
86 import org.springframework.web.client.HttpClientErrorException;
87 import org.springframework.web.client.RestTemplate;
88 import org.springframework.web.util.UriComponentsBuilder;
89 import uk.co.blackpepper.bowman.Client;
90 import uk.co.blackpepper.bowman.ClientFactory;
91 import uk.co.blackpepper.bowman.Configuration;
92
93 @Component("CatalogDbClient")
94 public class CatalogDbClient {
95
96     private static final Logger logger = LoggerFactory.getLogger(CatalogDbClient.class);
97
98     private static final String CLOUD_SITE = "/cloudSite";
99     private static final String CLOUDIFY_MANAGER = "/cloudifyManager";
100     private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro";
101     private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup";
102     private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization";
103     private static final String NETWORK_RESOURCE = "/networkResource";
104     private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION =
105             "/collectionResourceInstanceGroupCustomization";
106     private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization";
107     private static final String ORCHESTRATION_FLOW = "/orchestrationFlow";
108     private static final String ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE =
109             "/orchestrationStatusStateTransitionDirective";
110     private static final String INSTANCE_GROUP = "/instanceGroup";
111     private static final String COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION = "/collectionNetworkResourceCustomization";
112     private static final String BUILDING_BLOCK_DETAIL = "/buildingBlockDetail";
113     private static final String NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION = "/networkCollectionResourceCustomization";
114     private static final String VNF_RESOURCE_CUSTOMIZATION = "/vnfResourceCustomization";
115     private static final String SERVICE = "/service";
116     private static final String EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING = "/externalServiceToInternalService";
117     private static final String VNF_RESOURCE = "/vnfResource";
118     private static final String VNF_RECIPE = "/vnfRecipe";
119     private static final String VFMODULE = "/vfModule";
120     private static final String VFMODULE_CUSTOMIZATION = "/vfModuleCustomization";
121     private static final String VNF_COMPONENTS_RECIPE = "/vnfComponentsRecipe";
122     private static final String SERVICE_RECIPE = "/serviceRecipe";
123     private static final String NETWORK_RECIPE = "/networkRecipe";
124     private static final String PNF_RESOURCE = "/pnfResource";
125     private static final String PNF_RESOURCE_CUSTOMIZATION = "/pnfResourceCustomization";
126     private static final String WORKFLOW = "/workflow";
127     private static final String BB_NAME_SELECTION_REFERENCE = "/bbNameSelectionReference";
128     private static final String PROCESSING_FLAGS = "/processingFlags";
129
130
131     private static final String SEARCH = "/search";
132     private static final String URI_SEPARATOR = "/";
133
134     protected static final String SERVICE_MODEL_UUID = "serviceModelUUID";
135     protected static final String SERVICE_NAME = "serviceName";
136     protected static final String MODEL_UUID = "modelUUID";
137     protected static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
138     protected static final String ACTION = "action";
139     protected static final String MODEL_NAME = "modelName";
140     protected static final String MODEL_VERSION = "modelVersion";
141     protected static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
142     protected static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
143     protected static final String PNF_RESOURCE_MODEL_UUID = "pnfResourceModelUUID";
144     protected static final String NF_ROLE = "nfRole";
145     protected static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
146     protected static final String VNF_COMPONENT_TYPE = "vnfComponentType";
147     protected static final String BUILDING_BLOCK_NAME = "buildingBlockName";
148     protected static final String RESOURCE_TYPE = "resourceType";
149     protected static final String ORCHESTRATION_STATUS = "orchestrationStatus";
150     protected static final String TARGET_ACTION = "targetAction";
151     protected static final String REQUEST_SCOPE = "requestScope";
152     protected static final String IS_ALACARTE = "isALaCarte";
153     protected static final String CLOUD_OWNER = "cloudOwner";
154     protected static final String FLOW_NAME = "flowName";
155     protected static final String ERROR_MESSAGE = "errorMessage";
156     protected static final String SERVICE_ROLE = "serviceRole";
157     protected static final String SERVICE_TYPE = "serviceType";
158     protected static final String VNF_TYPE = "vnfType";
159     protected static final String ERROR_CODE = "errorCode";
160     protected static final String WORK_STEP = "workStep";
161     protected static final String CLLI = "clli";
162     protected static final String CLOUD_VERSION = "cloudVersion";
163     protected static final String HOMING_INSTANCE = "/homingInstance";
164     protected static final String ARTIFACT_UUID = "artifactUUID";
165     protected static final String SOURCE = "source";
166     protected static final String RESOURCE_TARGET = "resourceTarget";
167     protected static final String FLAG = "flag";
168     protected static final String OPERATION_NAME = "operationName";
169
170     private static final String TARGET_ENTITY = "SO:CatalogDB";
171     private static final String ASTERISK = "*";
172
173     private String findExternalToInternalServiceByServiceName = "/findByServiceName";
174     private String findServiceByModelName = "/findOneByModelName";
175     private String findServiceRecipeByActionAndServiceModelUUID = "/findByActionAndServiceModelUUID";
176     private String findServiceByModelUUID = "/findOneByModelUUID";
177     private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
178     private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
179     private String findFirstByModelVersionAndModelInvariantUUIDURI = "/findFirstByModelVersionAndModelInvariantUUID";
180     private String findByModelInvariantUUIDURI = "/findByModelInvariantUUIDOrderByModelVersionDesc";
181     private String findFirstByModelNameAndAction = "/findFirstByModelNameAndAction";
182     private String findFirstResourceByModelInvariantUUIDAndModelVersion =
183             "/findFirstResourceByModelInvariantUUIDAndModelVersion";
184     private String findByModelInstanceNameAndVnfResources = "/findByModelInstanceNameAndVnfResources";
185     private String findFirstVnfRecipeByNfRoleAndAction = "/findFirstVnfRecipeByNfRoleAndAction";
186     private String findByModelCustomizationUUIDAndVfModuleModelUUID =
187             "/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc";
188     private String findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction =
189             "/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction";
190     private String findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
191             "/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction";
192     private String findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
193             "/findByModelInvariantUUIDOrderByModelVersionDesc";
194     private String findFirstVfModuleByModelInvariantUUIDAndModelVersion =
195             "/findFirstVfModuleByModelInvariantUUIDAndModelVersion";
196     private String findOneByBuildingBlockName = "/findOneByBuildingBlockName";
197     private String findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
198             "/findOneByResourceTypeAndOrchestrationStatusAndTargetAction";
199     private String findByAction = "/findByAction";
200     private String findVnfcInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
201     private String findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
202             "/findByModelCustomizationUUID";
203     private String findOneByActionAndRequestScopeAndIsAlacarte = "/findOneByActionAndRequestScopeAndIsAlacarte";
204     private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner =
205             "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner";
206     private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
207             "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType";
208
209     private static final String findRainyDayHandler = "/findRainyDayHandler";
210     private String findByClliAndCloudVersion = "/findByClliAndCloudVersion";
211     private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId";
212     private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
213     private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
214     private String findWorkflowByVnfModelUUID = "/findWorkflowByVnfModelUUID";
215     private String findWorkflowByPnfModelUUID = "/findWorkflowByPnfModelUUID";
216     private String findWorkflowBySource = "/findBySource";
217     private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
218     private String findBBNameSelectionReferenceByControllerActorAndScopeAndAction =
219             "/findBBNameSelectionReferenceByControllerActorAndScopeAndAction";
220     private String findWorkflowByResourceTarget = "/findByResourceTarget";
221     private String findProcessingFlagsByFlag = "/findByFlag";
222     private String findWorkflowByOperationName = "/findByOperationName";
223
224     private String serviceURI;
225     private String vfModuleURI;
226     private String vnfResourceURI;
227     private String networkCollectionResourceCustomizationURI;
228     private String networkResourceCustomizationURI;
229     private String networkResourceURI;
230     private String collectionNetworkResourceCustomizationURI;
231     private String instanceGroupURI;
232     private String cloudifyManagerURI;
233     private String cloudSiteURI;
234     private String homingInstanceURI;
235     private String cvnfcResourceCustomizationURI;
236     private String pnfResourceURI;
237     private String pnfResourceCustomizationURI;
238     private String workflowURI;
239
240     private final Client<Service> serviceClient;
241
242     private final Client<NetworkRecipe> networkRecipeClient;
243
244     private final Client<NetworkResourceCustomization> networkResourceCustomizationClient;
245
246     private final Client<VnfResource> vnfResourceClient;
247
248     private final Client<VnfResourceCustomization> vnfResourceCustomizationClient;
249
250     private final Client<VnfRecipe> vnfRecipeClient;
251
252     private final Client<VfModuleCustomization> vfModuleCustomizationClient;
253
254     private final Client<VfModule> vfModuleClient;
255
256     private final Client<VnfComponentsRecipe> vnfComponentsRecipeClient;
257
258     private final Client<OrchestrationFlow> orchestrationClient;
259
260     private final Client<NorthBoundRequest> northBoundRequestClient;
261
262     private final Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
263
264     private final Client<BuildingBlockDetail> buildingBlockDetailClient;
265
266     private final Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
267
268     private final Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
269
270     private final Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
271
272     private final Client<InstanceGroup> instanceGroupClient;
273
274     private final Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
275
276     private final Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
277
278     private final Client<ServiceRecipe> serviceRecipeClient;
279
280     private final Client<NetworkResource> networkResourceClient;
281
282     private final Client<ExternalServiceToInternalService> externalServiceToInternalServiceClient;
283
284     private final Client<CloudSite> cloudSiteClient;
285
286     private final Client<HomingInstance> homingInstanceClient;
287
288     private final Client<CloudifyManager> cloudifyManagerClient;
289
290     private final Client<ControllerSelectionReference> controllerSelectionReferenceClient;
291
292     private final Client<PnfResource> pnfResourceClient;
293
294     private final Client<PnfResourceCustomization> pnfResourceCustomizationClient;
295
296     private final Client<Workflow> workflowClient;
297
298     private final Client<BBNameSelectionReference> bbNameSelectionReferenceClient;
299
300     private final Client<ProcessingFlags> processingFlagsClient;
301
302     @Value("${mso.catalog.db.spring.endpoint:#{null}}")
303     private String endpoint;
304
305     @Value("${mso.db.auth:#{null}}")
306     private String msoAdaptersAuth;
307
308     @Autowired
309     RestTemplate restTemplate;
310
311     @PostConstruct
312     public void init() {
313         findExternalToInternalServiceByServiceName = endpoint + EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING + SEARCH
314                 + findExternalToInternalServiceByServiceName;
315         findServiceByModelName = endpoint + SERVICE + SEARCH + findServiceByModelName;
316         findServiceRecipeByActionAndServiceModelUUID =
317                 endpoint + SERVICE_RECIPE + SEARCH + findServiceRecipeByActionAndServiceModelUUID;
318         findServiceByModelUUID = endpoint + SERVICE + SEARCH + findServiceByModelUUID;
319         findFirstByModelNameURI = endpoint + SERVICE + SEARCH + findFirstByModelNameURI;
320         findFirstByModelVersionAndModelInvariantUUIDURI =
321                 endpoint + SERVICE + SEARCH + findFirstByModelVersionAndModelInvariantUUIDURI;
322         findByModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findByModelInvariantUUIDURI;
323         findFirstByServiceModelUUIDAndActionURI =
324                 endpoint + SERVICE_RECIPE + SEARCH + findFirstByServiceModelUUIDAndActionURI;
325         findFirstByModelNameAndAction = endpoint + NETWORK_RECIPE + SEARCH + findFirstByModelNameAndAction;
326         findFirstResourceByModelInvariantUUIDAndModelVersion =
327                 endpoint + VNF_RESOURCE + SEARCH + findFirstResourceByModelInvariantUUIDAndModelVersion;
328         findByModelInstanceNameAndVnfResources =
329                 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findByModelInstanceNameAndVnfResources;
330         findFirstVnfRecipeByNfRoleAndAction = endpoint + VNF_RECIPE + SEARCH + findFirstVnfRecipeByNfRoleAndAction;
331         findByModelCustomizationUUIDAndVfModuleModelUUID =
332                 endpoint + VFMODULE_CUSTOMIZATION + SEARCH + findByModelCustomizationUUIDAndVfModuleModelUUID;
333         findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE
334                 + SEARCH + findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction;
335         findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
336                 endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVnfComponentTypeAndAction;
337         findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
338                 endpoint + VFMODULE + SEARCH + findVfModuleByModelInvariantUUIDOrderByModelVersionDesc;
339         findFirstVfModuleByModelInvariantUUIDAndModelVersion =
340                 endpoint + VFMODULE + SEARCH + findFirstVfModuleByModelInvariantUUIDAndModelVersion;
341         findOneByBuildingBlockName = endpoint + BUILDING_BLOCK_DETAIL + SEARCH + findOneByBuildingBlockName;
342         findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
343                 endpoint + ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE + SEARCH
344                         + findOneByResourceTypeAndOrchestrationStatusAndTargetAction;
345         findByAction = endpoint + ORCHESTRATION_FLOW + SEARCH + findByAction;
346         findVnfcInstanceGroupCustomizationByModelCustomizationUUID = endpoint + VNFC_INSTANCE_GROUP_CUSTOMIZATION
347                 + SEARCH + findVnfcInstanceGroupCustomizationByModelCustomizationUUID;
348         findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
349                 endpoint + COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION + SEARCH
350                         + findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID;
351         findOneByActionAndRequestScopeAndIsAlacarte =
352                 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH + findOneByActionAndRequestScopeAndIsAlacarte;
353         findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner = endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
354                 + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner;
355         findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
356                 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
357                         + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType;
358         findByClliAndCloudVersion = endpoint + CLOUD_SITE + SEARCH + findByClliAndCloudVersion;
359
360         findPnfResourceCustomizationByModelUuid =
361                 endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid;
362
363         findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
364         findWorkflowByVnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByVnfModelUUID;
365         findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID;
366         findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
367         findWorkflowByResourceTarget = endpoint + WORKFLOW + SEARCH + findWorkflowByResourceTarget;
368
369         findVnfResourceCustomizationByModelUuid =
370                 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid;
371
372         findBBNameSelectionReferenceByControllerActorAndScopeAndAction = endpoint + BB_NAME_SELECTION_REFERENCE + SEARCH
373                 + findBBNameSelectionReferenceByControllerActorAndScopeAndAction;
374
375         findProcessingFlagsByFlag = endpoint + PROCESSING_FLAGS + SEARCH + findProcessingFlagsByFlag;
376         findWorkflowByOperationName = endpoint + WORKFLOW + SEARCH + findWorkflowByOperationName;
377
378         serviceURI = endpoint + SERVICE + URI_SEPARATOR;
379         vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR;
380         vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR;
381         networkCollectionResourceCustomizationURI =
382                 endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
383         networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
384         networkResourceURI = endpoint + NETWORK_RESOURCE + SEARCH;
385         collectionNetworkResourceCustomizationURI =
386                 endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
387         instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR;
388         cloudifyManagerURI = endpoint + CLOUDIFY_MANAGER + URI_SEPARATOR;
389         cloudSiteURI = endpoint + CLOUD_SITE + URI_SEPARATOR;
390         homingInstanceURI = endpoint + HOMING_INSTANCE + URI_SEPARATOR;
391         pnfResourceURI = endpoint + PNF_RESOURCE + URI_SEPARATOR;
392         pnfResourceCustomizationURI = endpoint + PNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
393         workflowURI = endpoint + WORKFLOW + URI_SEPARATOR;
394
395     }
396
397     public CatalogDbClient() {
398         ClientHttpRequestFactory factory =
399                 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
400
401         ClientFactory clientFactory =
402                 Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
403                     restTemplate.getInterceptors().add((new SOSpringClientFilter()));
404                     restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
405
406                     restTemplate.getInterceptors().add((request, body, execution) -> {
407
408                         request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
409                         request.getHeaders().add(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
410                         return execution.execute(request, body);
411                     });
412                 }).build().buildClientFactory();
413         serviceClient = clientFactory.create(Service.class);
414         networkRecipeClient = clientFactory.create(NetworkRecipe.class);
415         networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
416         vnfResourceClient = clientFactory.create(VnfResource.class);
417         vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
418         vnfRecipeClient = clientFactory.create(VnfRecipe.class);
419         orchestrationClient = clientFactory.create(OrchestrationFlow.class);
420         vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
421         vfModuleClient = clientFactory.create(VfModule.class);
422         vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
423         northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
424         rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
425         buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
426         orchestrationStatusStateTransitionDirectiveClient =
427                 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
428         vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
429         collectionResourceInstanceGroupCustomizationClient =
430                 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
431         instanceGroupClient = clientFactory.create(InstanceGroup.class);
432         networkCollectionResourceCustomizationClient =
433                 clientFactory.create(NetworkCollectionResourceCustomization.class);
434         collectionNetworkResourceCustomizationClient =
435                 clientFactory.create(CollectionNetworkResourceCustomization.class);
436         cloudSiteClient = clientFactory.create(CloudSite.class);
437         homingInstanceClient = clientFactory.create(HomingInstance.class);
438         cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
439         serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
440         controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
441         externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
442         pnfResourceClient = clientFactory.create(PnfResource.class);
443         pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
444         workflowClient = clientFactory.create(Workflow.class);
445         bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class);
446         processingFlagsClient = clientFactory.create(ProcessingFlags.class);
447         networkResourceClient = clientFactory.create(NetworkResource.class);
448     }
449
450     public CatalogDbClient(String baseUri, String auth) {
451         ClientHttpRequestFactory factory =
452                 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
453
454         ClientFactory clientFactory = Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory)
455                 .setRestTemplateConfigurer(restTemplate -> {
456                     restTemplate.getInterceptors().add((new SOSpringClientFilter()));
457                     restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
458
459                     restTemplate.getInterceptors().add((request, body, execution) -> {
460
461                         request.getHeaders().add(HttpHeaders.AUTHORIZATION, auth);
462                         request.getHeaders().add(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
463                         return execution.execute(request, body);
464                     });
465                 }).build().buildClientFactory();
466         serviceClient = clientFactory.create(Service.class);
467         networkRecipeClient = clientFactory.create(NetworkRecipe.class);
468         networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
469         vnfResourceClient = clientFactory.create(VnfResource.class);
470         vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
471         vnfRecipeClient = clientFactory.create(VnfRecipe.class);
472         orchestrationClient = clientFactory.create(OrchestrationFlow.class);
473         vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
474         vfModuleClient = clientFactory.create(VfModule.class);
475         vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
476         northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
477         rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
478         buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
479         orchestrationStatusStateTransitionDirectiveClient =
480                 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
481         vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
482         collectionResourceInstanceGroupCustomizationClient =
483                 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
484         instanceGroupClient = clientFactory.create(InstanceGroup.class);
485         networkCollectionResourceCustomizationClient =
486                 clientFactory.create(NetworkCollectionResourceCustomization.class);
487         collectionNetworkResourceCustomizationClient =
488                 clientFactory.create(CollectionNetworkResourceCustomization.class);
489         cloudSiteClient = clientFactory.create(CloudSite.class);
490         homingInstanceClient = clientFactory.create(HomingInstance.class);
491         cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
492         serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
493         controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
494         externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
495         pnfResourceClient = clientFactory.create(PnfResource.class);
496         pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
497         workflowClient = clientFactory.create(Workflow.class);
498         bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class);
499         processingFlagsClient = clientFactory.create(ProcessingFlags.class);
500         networkResourceClient = clientFactory.create(NetworkResource.class);
501     }
502
503     public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(
504             String modelCustomizationUUID) {
505         NetworkCollectionResourceCustomization networkCollectionResourceCustomization =
506                 this.getSingleResource(networkCollectionResourceCustomizationClient,
507                         getUri(networkCollectionResourceCustomizationURI + modelCustomizationUUID));
508         if (networkCollectionResourceCustomization != null) {
509             networkCollectionResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
510         }
511         return networkCollectionResourceCustomization;
512     }
513
514     public Service getServiceByID(String modelUUID) {
515         Service service = getSingleResource(serviceClient, getUri(serviceURI + modelUUID));
516         if (service != null) {
517             service.setModelUUID(modelUUID);
518         }
519         return service;
520     }
521
522     public VfModule getVfModuleByModelUUID(String modelUUID) {
523         VfModule vfModule = getSingleResource(vfModuleClient, getUri(vfModuleURI + modelUUID));
524         if (vfModule != null) {
525             vfModule.setModelUUID(modelUUID);
526         }
527         return vfModule;
528     }
529
530     public VnfResource getVnfResourceByModelUUID(String modelUUID) {
531
532         VnfResource vnfResource = this.getSingleResource(vnfResourceClient, getUri(vnfResourceURI + modelUUID));
533         if (vnfResource != null) {
534             vnfResource.setModelUUID(modelUUID);
535         }
536         return vnfResource;
537     }
538
539     // A VNFResource customization UUID is the same object across services, so we can return anyone from the list
540     // In the future the client should query starting at a service model uuid
541     public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
542         List<VnfResourceCustomization> vnfResourceCustomization = this.getMultipleResources(
543                 vnfResourceCustomizationClient, getUri(endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH
544                         + "/findByModelCustomizationUUID" + "?MODEL_CUSTOMIZATION_UUID=" + modelCustomizationUUID));
545         if (vnfResourceCustomization != null && !vnfResourceCustomization.isEmpty()) {
546             return vnfResourceCustomization.get(0);
547         } else {
548             return null;
549         }
550     }
551
552     public List<VnfResourceCustomization> getVnfResourceCustomizationByModelUuid(String modelUuid) {
553         return this.getMultipleResources(vnfResourceCustomizationClient,
554                 getUri(UriBuilder.fromUri(findVnfResourceCustomizationByModelUuid)
555                         .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
556     }
557
558     public PnfResource getPnfResourceByModelUUID(String modelUUID) {
559         PnfResource PnfResource = this.getSingleResource(pnfResourceClient, getUri(pnfResourceURI + modelUUID));
560         if (PnfResource != null) {
561             PnfResource.setModelUUID(modelUUID);
562         }
563         return PnfResource;
564     }
565
566     public PnfResourceCustomization getPnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
567         PnfResourceCustomization pnfResourceCustomization = getSingleResource(pnfResourceCustomizationClient,
568                 getUri(pnfResourceCustomizationURI + modelCustomizationUUID));
569         if (pnfResourceCustomization != null) {
570             pnfResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
571         }
572         return pnfResourceCustomization;
573     }
574
575     public List<PnfResourceCustomization> getPnfResourceCustomizationByModelUuid(String modelUuid) {
576         return this.getMultipleResources(pnfResourceCustomizationClient,
577                 getUri(UriBuilder.fromUri(findPnfResourceCustomizationByModelUuid)
578                         .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
579     }
580
581     public CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomizationByID(
582             String modelCustomizationUUID) {
583         CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
584                 this.getSingleResource(collectionNetworkResourceCustomizationClient,
585                         getUri(UriBuilder.fromUri(collectionNetworkResourceCustomizationURI + modelCustomizationUUID)
586                                 .build().toString()));
587         if (collectionNetworkResourceCustomization != null) {
588             collectionNetworkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
589         }
590         return collectionNetworkResourceCustomization;
591     }
592
593     public InstanceGroup getInstanceGroupByModelUUID(String modelUUID) {
594         InstanceGroup instanceGroup = this.getSingleResource(instanceGroupClient, getUri(instanceGroupURI + modelUUID));
595         if (instanceGroup != null) {
596             instanceGroup.setModelUUID(modelUUID);
597         }
598         return instanceGroup;
599     }
600
601     public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
602         return this.getSingleResource(vfModuleCustomizationClient,
603                 getUri(endpoint + VFMODULE_CUSTOMIZATION + SEARCH
604                         + "/findFirstByModelCustomizationUUIDOrderByCreatedDesc" + "?MODEL_CUSTOMIZATION_UUID="
605                         + modelCustomizationUUID));
606     }
607
608     public NetworkResourceCustomization getNetworkResourceCustomizationByModelCustomizationUUID(
609             String modelCustomizationUUID) {
610         NetworkResourceCustomization networkResourceCustomization = this.getSingleResource(
611                 networkResourceCustomizationClient, getUri(networkResourceCustomizationURI + modelCustomizationUUID));
612         if (networkResourceCustomization != null) {
613             networkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
614         }
615         return networkResourceCustomization;
616     }
617
618     public NetworkResource getNetworkResourceByModelName(String networkType) {
619         if (Strings.isNullOrEmpty(networkType)) {
620             throw new EntityNotFoundException("networkType passed as Null or Empty String");
621         }
622         try {
623             HttpEntity<?> entity = getHttpEntity();
624             return restTemplate.exchange(
625                     UriBuilder.fromUri(networkResourceURI + "/findFirstByModelNameOrderByModelVersionDesc")
626                             .queryParam("modelName", networkType).build(),
627                     HttpMethod.GET, entity, NetworkResource.class).getBody();
628         } catch (HttpClientErrorException e) {
629             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
630                 throw new EntityNotFoundException("Unable to find NetworkResource By networkType " + networkType);
631             }
632             throw e;
633         }
634     }
635
636
637     public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) {
638         BuildingBlockDetail buildingBlockDetail =
639                 getSingleResource(buildingBlockDetailClient, getUri(UriBuilder.fromUri(findOneByBuildingBlockName)
640                         .queryParam(BUILDING_BLOCK_NAME, buildingBlockName).build().toString()));
641         if (buildingBlockDetail != null) {
642             buildingBlockDetail.setBuildingBlockName(buildingBlockName);
643         }
644         return buildingBlockDetail;
645     }
646
647
648     public OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective(
649             ResourceType resourceType, OrchestrationStatus orchestrationStatus, OrchestrationAction targetAction) {
650         return getSingleResource(orchestrationStatusStateTransitionDirectiveClient,
651                 UriBuilder.fromUri(findOneByResourceTypeAndOrchestrationStatusAndTargetAction)
652                         .queryParam(RESOURCE_TYPE, resourceType.name())
653                         .queryParam(ORCHESTRATION_STATUS, orchestrationStatus.name())
654                         .queryParam(TARGET_ACTION, targetAction.name()).build());
655     }
656
657     public List<OrchestrationFlow> getOrchestrationFlowByAction(String action) {
658         return this.getMultipleResources(orchestrationClient,
659                 UriBuilder.fromUri(findByAction).queryParam(ACTION, action).build());
660     }
661
662     public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupsByVnfResourceCust(String modelCustomizationUUID) {
663         return this.getMultipleResources(vnfcInstanceGroupCustomizationClient,
664                 UriBuilder.fromUri(findVnfcInstanceGroupCustomizationByModelCustomizationUUID)
665                         .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
666     }
667
668     public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomizationByModelCustUUID(
669             String modelCustomizationUUID) {
670         return this.getMultipleResources(collectionResourceInstanceGroupCustomizationClient,
671                 UriBuilder.fromUri(findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID)
672                         .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
673     }
674
675     public VfModuleCustomization getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
676             String modelCustomizationUUID, String vfModuleModelUUID) {
677         return this.getSingleResource(vfModuleCustomizationClient,
678                 getUri(UriBuilder.fromUri(findByModelCustomizationUUIDAndVfModuleModelUUID)
679                         .queryParam("MODEL_CUSTOMIZATION_UUID", modelCustomizationUUID)
680                         .queryParam("MODEL_UUID", vfModuleModelUUID).build().toString()));
681     }
682
683     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(String requestAction,
684             String resourceName, boolean aLaCarte) {
685         return this.getSingleResource(northBoundRequestClient,
686                 UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarte).queryParam(ACTION, requestAction)
687                         .queryParam(REQUEST_SCOPE, resourceName).queryParam(IS_ALACARTE, aLaCarte).build());
688     }
689
690     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(String requestAction,
691             String resourceName, boolean aLaCarte, String cloudOwner) {
692         return this.getSingleResource(northBoundRequestClient,
693                 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
694                         .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
695                         .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
696                         .queryParam(SERVICE_TYPE, ASTERISK).build().toString()));
697     }
698
699     public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(
700             String requestAction, String resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
701         return this.getSingleResource(northBoundRequestClient,
702                 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
703                         .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
704                         .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
705                         .queryParam(SERVICE_TYPE, serviceType).build().toString()));
706     }
707
708     public RainyDayHandlerStatus getRainyDayHandlerStatus(String flowName, String serviceType, String vnfType,
709             String errorCode, String workStep, String errorMessage, String serviceRole) {
710         logger.debug(
711                 "Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}",
712                 flowName, serviceType, vnfType, errorCode, workStep, errorMessage);
713         return this.getSingleResource(rainyDayHandlerStatusClient,
714                 UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler)
715                         .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType)
716                         .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep)
717                         .queryParam(ERROR_MESSAGE, errorMessage).queryParam(SERVICE_ROLE, serviceRole).build().encode()
718                         .toUri());
719     }
720
721     public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) {
722         return this.getSingleResource(serviceRecipeClient,
723                 getUri(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI)
724                         .queryParam(SERVICE_MODEL_UUID, modelUUID).queryParam(ACTION, action).build().toString()));
725     }
726
727
728     public NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action) {
729         return this.getSingleResource(networkRecipeClient, UriBuilder.fromUri(findFirstByModelNameAndAction)
730                 .queryParam(MODEL_NAME, modelName).queryParam(ACTION, action).build());
731     }
732
733     public ControllerSelectionReference getControllerSelectionReferenceByVnfTypeAndActionCategory(String vnfType,
734             String actionCategory) {
735         return this.getSingleResource(controllerSelectionReferenceClient, UriBuilder.fromUri(endpoint
736                 + "/controllerSelectionReference/search/findControllerSelectionReferenceByVnfTypeAndActionCategory")
737                 .queryParam("VNF_TYPE", vnfType).queryParam("ACTION_CATEGORY", actionCategory).build());
738     }
739
740     public Service getFirstByModelNameOrderByModelVersionDesc(String modelName) {
741         return this.getSingleResource(serviceClient,
742                 UriBuilder.fromUri(findFirstByModelNameURI).queryParam(MODEL_NAME, modelName).build());
743     }
744
745     public BBNameSelectionReference getBBNameSelectionReference(String controllerActor, String scope, String action) {
746
747         return this.getSingleResource(bbNameSelectionReferenceClient,
748                 getUri(UriBuilder.fromUri(findBBNameSelectionReferenceByControllerActorAndScopeAndAction)
749                         .queryParam("CONTROLLER_ACTOR", controllerActor).queryParam("SCOPE", scope)
750                         .queryParam("ACTION", action).build().toString()));
751     }
752
753     public ExternalServiceToInternalService findExternalToInternalServiceByServiceName(String serviceName) {
754         return this.getSingleResource(externalServiceToInternalServiceClient,
755                 getUri(UriBuilder.fromUri(findExternalToInternalServiceByServiceName)
756                         .queryParam(SERVICE_NAME, serviceName).build().toString()));
757     }
758
759     public ServiceRecipe findServiceRecipeByActionAndServiceModelUUID(String action, String modelUUID) {
760         return this.getSingleResource(serviceRecipeClient,
761                 getUri(UriBuilder.fromUri(findServiceRecipeByActionAndServiceModelUUID).queryParam(ACTION, action)
762                         .queryParam(SERVICE_MODEL_UUID, modelUUID).build().toString()));
763     }
764
765     public Service getServiceByModelName(String modelName) {
766         return this.getSingleResource(serviceClient, getUri(
767                 UriBuilder.fromUri(findServiceByModelName).queryParam(MODEL_NAME, modelName).build().toString()));
768     }
769
770     public Service getServiceByModelUUID(String modelModelUUID) {
771         return this.getSingleResource(serviceClient, getUri(
772                 UriBuilder.fromUri(findServiceByModelUUID).queryParam(MODEL_UUID, modelModelUUID).build().toString()));
773     }
774
775     public VnfResource getFirstVnfResourceByModelInvariantUUIDAndModelVersion(String modelInvariantUUID,
776             String modelVersion) {
777         return this.getSingleResource(vnfResourceClient,
778                 getUri(UriBuilder.fromUri(findFirstResourceByModelInvariantUUIDAndModelVersion)
779                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
780                         .build().toString()));
781     }
782
783
784     public VnfResourceCustomization getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(
785             String modelInstanceName, VnfResource vnfResource) {
786         return this.getSingleResource(vnfResourceCustomizationClient,
787                 getUri(UriBuilder.fromUri(findByModelInstanceNameAndVnfResources)
788                         .queryParam("MODEL_INSTANCE_NAME", modelInstanceName)
789                         .queryParam("VNF_RESOURCE_MODEL_UUID", vnfResource.getModelUUID()).build().toString()));
790     }
791
792     public VnfRecipe getFirstVnfRecipeByNfRoleAndAction(String nfRole, String action) {
793         return this.getSingleResource(vnfRecipeClient, getUri(UriBuilder.fromUri(findFirstVnfRecipeByNfRoleAndAction)
794                 .queryParam(NF_ROLE, nfRole).queryParam(ACTION, action).build().toString()));
795     }
796
797     public VnfComponentsRecipe getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
798             String vfModuleModelUUID, String modelType, String action) {
799         return this.getSingleResource(vnfComponentsRecipeClient,
800                 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction)
801                         .queryParam(VF_MODULE_MODEL_UUID, vfModuleModelUUID).queryParam(VNF_COMPONENT_TYPE, modelType)
802                         .queryParam(ACTION, action).build().toString()));
803     }
804
805     public VnfComponentsRecipe getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(String modelType, String action) {
806         return this.getSingleResource(vnfComponentsRecipeClient,
807                 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVnfComponentTypeAndAction)
808                         .queryParam(VNF_COMPONENT_TYPE, modelType).queryParam(ACTION, action).build().toString()));
809     }
810
811
812     protected URI getUri(String template) {
813         return URI.create(template);
814     }
815
816     public CloudifyManager getCloudifyManager(String id) {
817         return this.getSingleResource(cloudifyManagerClient, getUri(cloudifyManagerURI + id));
818     }
819
820     public CloudSite getCloudSite(String id) {
821         return this.getSingleResource(cloudSiteClient, getUri(cloudSiteURI + id));
822     }
823
824     public CloudSite getCloudSite(String id, String uri) {
825         return this.getSingleResource(cloudSiteClient, getUri(uri + id));
826     }
827
828     // Bring back old version of methind since the caller - OofInfraUtils.java - is not running in a spring context
829     public void postOofHomingCloudSite(CloudSite cloudSite) {
830         this.postSingleResource(cloudSiteClient, cloudSite);
831     }
832
833     public CloudSite postCloudSite(CloudSite cloudSite) {
834         if (cloudSite == null) {
835             throw new EntityNotFoundException("CloudSite passed as null");
836         }
837         try {
838             HttpHeaders headers = getHttpHeaders();
839             HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers);
840             CloudSite updatedCloudSite = restTemplate
841                     .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite").build().encode().toString(),
842                             HttpMethod.POST, entity, CloudSite.class)
843                     .getBody();
844             return updatedCloudSite;
845         } catch (HttpClientErrorException e) {
846             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
847                 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId());
848             }
849             throw e;
850         }
851     }
852
853     public CloudSite updateCloudSite(CloudSite cloudSite) {
854         if (cloudSite == null) {
855             throw new EntityNotFoundException("CloudSite passed as null");
856         }
857         try {
858             HttpHeaders headers = getHttpHeaders();
859             HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers);
860             CloudSite updatedCloudSite = restTemplate
861                     .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSite.getId()).build()
862                             .encode().toString(), HttpMethod.PUT, entity, CloudSite.class)
863                     .getBody();
864             return updatedCloudSite;
865         } catch (HttpClientErrorException e) {
866             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
867                 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId());
868             }
869             throw e;
870         }
871     }
872
873     public void deleteCloudSite(String cloudSiteId) {
874         if (cloudSiteId == null) {
875             throw new EntityNotFoundException("CloudSiteId passed as null");
876         }
877         try {
878             HttpHeaders headers = getHttpHeaders();
879             HttpEntity<String> entity = new HttpEntity<>(null, headers);
880             restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSiteId).build()
881                     .encode().toString(), HttpMethod.DELETE, entity, CloudSite.class).getBody();
882         } catch (HttpClientErrorException e) {
883             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
884                 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSiteId);
885             }
886             throw e;
887         }
888     }
889
890     public List<CloudSite> getCloudSites() {
891         return this.getMultipleResources(cloudSiteClient,
892                 UriBuilder.fromUri(endpoint + CLOUD_SITE).queryParam("size", "1000").build());
893     }
894
895
896     public CloudSite getCloudSiteByClliAndAicVersion(String clli, String cloudVersion) {
897         return this.getSingleResource(cloudSiteClient, getUri(UriBuilder.fromUri(findByClliAndCloudVersion)
898                 .queryParam(CLLI, clli).queryParam(CLOUD_VERSION, cloudVersion).build().toString()));
899     }
900
901     public HomingInstance getHomingInstance(String serviceInstanceId) {
902         return this.getSingleResource(homingInstanceClient, getUri(homingInstanceURI + serviceInstanceId));
903     }
904
905     public HomingInstance getHomingInstance(String serviceInstanceId, String uri) {
906         return this.getSingleResource(homingInstanceClient, getUri(uri + serviceInstanceId));
907     }
908
909     public void postHomingInstance(HomingInstance homingInstance) {
910         this.postSingleResource(homingInstanceClient, homingInstance);
911     }
912
913     public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
914         return this.getSingleResource(serviceClient,
915                 getUri(UriBuilder.fromUri(findFirstByModelVersionAndModelInvariantUUIDURI)
916                         .queryParam(MODEL_VERSION, modelVersion).queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID)
917                         .build().toString()));
918     }
919
920     public VfModule getVfModuleByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion) {
921         return this.getSingleResource(vfModuleClient,
922                 getUri(UriBuilder.fromUri(findFirstVfModuleByModelInvariantUUIDAndModelVersion)
923                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
924                         .build().toString()));
925     }
926
927     public List<Service> getServiceByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
928         return this.getMultipleResources(serviceClient, getUri(UriBuilder.fromUri(findByModelInvariantUUIDURI)
929                 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
930     }
931
932     public List<VfModule> getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
933         return this.getMultipleResources(vfModuleClient,
934                 getUri(UriBuilder.fromUri(findVfModuleByModelInvariantUUIDOrderByModelVersionDesc)
935                         .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
936     }
937
938     private <T> T getSingleResource(Client<T> client, URI uri) {
939         return client.get(uri);
940     }
941
942     protected <T> List<T> getMultipleResources(Client<T> client, URI uri) {
943         Iterable<T> iterator = client.getAll(uri);
944         List<T> list = new ArrayList<>();
945         Iterator<T> it = iterator.iterator();
946         it.forEachRemaining(list::add);
947         return list;
948     }
949
950     private <T> URI postSingleResource(Client<T> client, T type) {
951         return client.post(type);
952     }
953
954     public List<CvnfcCustomization> getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUUID,
955             String vfModuleCustomizationUUID) {
956         Service service = this.getServiceByID(serviceModelUUID);
957         VnfResourceCustomization vnfResourceCust =
958                 findVnfResourceCustomizationInList(vnfCustomizationUUID, service.getVnfCustomizations());
959         VfModuleCustomization vfModuleCust =
960                 findVfModuleCustomizationInList(vfModuleCustomizationUUID, vnfResourceCust.getVfModuleCustomizations());
961         return vfModuleCust.getCvnfcCustomization();
962     }
963
964     public VnfResourceCustomization findVnfResourceCustomizationInList(String vnfCustomizationUUID,
965             List<VnfResourceCustomization> vnfResourceCusts) {
966         if (vnfCustomizationUUID == null) {
967             throw new EntityNotFoundException(
968                     "a NULL UUID was provided in query to search for VnfResourceCustomization");
969         }
970         List<VnfResourceCustomization> filtered =
971                 vnfResourceCusts.stream().filter(v -> v.getModelCustomizationUUID() != null)
972                         .filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
973                         .collect(Collectors.toList());
974         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
975             return filtered.get(0);
976         } else
977             throw new EntityNotFoundException(
978                     "Unable to find VnfResourceCustomization ModelCustomizationUUID:" + vnfCustomizationUUID);
979     }
980
981     protected VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
982             List<VfModuleCustomization> vfModuleList) {
983         if (vfModuleCustomizationUUID == null) {
984             throw new EntityNotFoundException("a NULL UUID was provided in query to search for VfModuleCustomization");
985         }
986         List<VfModuleCustomization> filtered = vfModuleList.stream().filter(v -> v.getModelCustomizationUUID() != null)
987                 .filter(vfModuleCust -> vfModuleCustomizationUUID.equals(vfModuleCust.getModelCustomizationUUID()))
988                 .collect(Collectors.toList());
989         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
990             return filtered.get(0);
991         } else
992             throw new EntityNotFoundException(
993                     "Unable to find VfModuleCustomization ModelCustomizationUUID:" + vfModuleCustomizationUUID);
994     }
995
996     protected CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
997             List<CvnfcCustomization> cvnfcCustomList) {
998         if (cvnfcCustomizationUuid == null) {
999             throw new EntityNotFoundException("a NULL UUID was provided in query to search for CvnfcCustomization");
1000         }
1001         List<CvnfcCustomization> filtered = cvnfcCustomList.stream().filter(c -> c.getModelCustomizationUUID() != null)
1002                 .filter(cvnfc -> cvnfcCustomizationUuid.equals(cvnfc.getModelCustomizationUUID()))
1003                 .collect(Collectors.toList());
1004         if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
1005             logger.debug("Found CvnfcCustomization: {}", filtered.get(0));
1006             return filtered.get(0);
1007         } else
1008             throw new EntityNotFoundException(
1009                     "Unable to find CvnfcCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
1010     }
1011
1012     public CvnfcConfigurationCustomization getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUuid,
1013             String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
1014         List<CvnfcCustomization> cvnfcCustomization =
1015                 getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid);
1016         CvnfcCustomization cvnfc = findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcCustomization);
1017         List<CvnfcConfigurationCustomization> fabricConfigs = cvnfc.getCvnfcConfigurationCustomization();
1018         fabricConfigs.stream().filter(cvnfcCustom -> cvnfcCustom.getConfigurationResource().getToscaNodeType()
1019                 .contains("FabricConfiguration")).collect(Collectors.toList());
1020         if (fabricConfigs != null && !fabricConfigs.isEmpty() && fabricConfigs.size() == 1) {
1021             logger.debug("Found Fabric Configuration: {}", fabricConfigs.get(0));
1022             return fabricConfigs.get(0);
1023         } else
1024             throw new EntityNotFoundException(
1025                     "Unable to find CvnfcConfigurationCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
1026     }
1027
1028     public org.onap.so.rest.catalog.beans.Service getServiceModelInformation(String serviceModelUUID, String depth) {
1029         if (Strings.isNullOrEmpty(serviceModelUUID)) {
1030             throw new EntityNotFoundException("Service Model UUID passed as Null or Empty String");
1031         }
1032         try {
1033             HttpEntity<?> entity = getHttpEntity();
1034             return restTemplate.exchange(
1035                     UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID)
1036                             .queryParam("depth", depth).build().encode().toString(),
1037                     HttpMethod.GET, entity, org.onap.so.rest.catalog.beans.Service.class).getBody();
1038         } catch (HttpClientErrorException e) {
1039             logger.warn("Entity Not found in DLP", e);
1040             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1041                 throw new EntityNotFoundException("Unable to find Service with ServiceModelUUID:" + serviceModelUUID);
1042             }
1043             throw e;
1044         }
1045     }
1046
1047     public void deleteServiceRecipe(String recipeId) {
1048         this.deleteSingleResource(serviceRecipeClient,
1049                 UriBuilder.fromUri(endpoint + SERVICE_RECIPE + URI_SEPARATOR + recipeId).build());
1050     }
1051
1052     public void postServiceRecipe(ServiceRecipe recipe) {
1053         try {
1054             HttpHeaders headers = getHttpHeaders();
1055             HttpEntity<ServiceRecipe> entity = new HttpEntity<>(recipe, headers);
1056             restTemplate.exchange(
1057                     UriComponentsBuilder.fromUriString(endpoint + "/serviceRecipe").build().encode().toString(),
1058                     HttpMethod.POST, entity, ServiceRecipe.class).getBody();
1059         } catch (HttpClientErrorException e) {
1060             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1061                 throw new EntityNotFoundException("Unable to find ServiceRecipe with  Id: " + recipe.getId());
1062             }
1063             throw e;
1064         }
1065     }
1066
1067     public void postVnfRecipe(VnfRecipe recipe) {
1068         try {
1069             HttpHeaders headers = getHttpHeaders();
1070             HttpEntity<VnfRecipe> entity = new HttpEntity<>(recipe, headers);
1071             restTemplate
1072                     .exchange(UriComponentsBuilder.fromUriString(endpoint + "/vnfRecipe").build().encode().toString(),
1073                             HttpMethod.POST, entity, VnfRecipe.class)
1074                     .getBody();
1075         } catch (HttpClientErrorException e) {
1076             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1077                 throw new EntityNotFoundException("Unable to find VnfRecipe with  Id: " + recipe.getId());
1078             }
1079             throw e;
1080         }
1081     }
1082
1083     public void postNetworkRecipe(NetworkRecipe recipe) {
1084         try {
1085             HttpHeaders headers = getHttpHeaders();
1086             HttpEntity<NetworkRecipe> entity = new HttpEntity<>(recipe, headers);
1087             restTemplate.exchange(
1088                     UriComponentsBuilder.fromUriString(endpoint + "/networkRecipe").build().encode().toString(),
1089                     HttpMethod.POST, entity, NetworkRecipe.class).getBody();
1090         } catch (HttpClientErrorException e) {
1091             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1092                 throw new EntityNotFoundException("Unable to find NetworkRecipe with  Id: " + recipe.getId());
1093             }
1094             throw e;
1095         }
1096     }
1097
1098     public List<ServiceRecipe> getServiceRecipes() {
1099         return this.getMultipleResources(serviceRecipeClient,
1100                 UriBuilder.fromUri(endpoint + SERVICE_RECIPE).queryParam("size", "1000").build());
1101     }
1102
1103     public List<NetworkRecipe> getNetworkRecipes() {
1104         return this.getMultipleResources(networkRecipeClient,
1105                 UriBuilder.fromUri(endpoint + NETWORK_RECIPE).queryParam("size", "1000").build());
1106     }
1107
1108     public List<NetworkResource> getNetworkResources() {
1109         return this.getMultipleResources(networkResourceClient,
1110                 UriBuilder.fromUri(endpoint + "/networkResource").queryParam("size", "1000").build());
1111     }
1112
1113     public List<org.onap.so.rest.catalog.beans.Service> getServices() {
1114         try {
1115             HttpEntity<?> entity = getHttpEntity();
1116             return restTemplate
1117                     .exchange(
1118                             UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services").build()
1119                                     .encode().toString(),
1120                             HttpMethod.GET, entity,
1121                             new ParameterizedTypeReference<List<org.onap.so.rest.catalog.beans.Service>>() {})
1122                     .getBody();
1123         } catch (HttpClientErrorException e) {
1124             logger.error("Error Calling catalog database", e);
1125             throw e;
1126         }
1127     }
1128
1129     public List<VnfResource> getVnfResources() {
1130         return this.getMultipleResources(vnfResourceClient,
1131                 UriBuilder.fromUri(endpoint + "/vnfResource").queryParam("size", "1000").build());
1132     }
1133
1134     public List<VnfRecipe> getVnfRecipes() {
1135         return this.getMultipleResources(vnfRecipeClient,
1136                 UriBuilder.fromUri(endpoint + VNF_RECIPE).queryParam("size", "1000").build());
1137     }
1138
1139     private <T> void deleteSingleResource(Client<T> client, URI uri) {
1140         client.delete(uri);
1141     }
1142
1143     public org.onap.so.rest.catalog.beans.Vnf getVnfModelInformation(String serviceModelUUID,
1144             String vnfCustomizationUUID, String depth) {
1145         if (Strings.isNullOrEmpty(serviceModelUUID)) {
1146             throw new EntityNotFoundException("Service Model UUID passed as Null or Empty String");
1147         }
1148         if (Strings.isNullOrEmpty(vnfCustomizationUUID)) {
1149             throw new EntityNotFoundException("Vnf Customization UUID passed as Null or Empty String");
1150         }
1151         try {
1152             HttpEntity<?> entity = getHttpEntity();
1153             return restTemplate
1154                     .exchange(
1155                             UriComponentsBuilder
1156                                     .fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID
1157                                             + "/vnfs/" + vnfCustomizationUUID)
1158                                     .queryParam("depth", depth).build().encode().toString(),
1159                             HttpMethod.GET, entity, org.onap.so.rest.catalog.beans.Vnf.class)
1160                     .getBody();
1161         } catch (HttpClientErrorException e) {
1162             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1163                 throw new EntityNotFoundException(
1164                         "Unable to find Vnf with Vnf Customization UUID:" + vnfCustomizationUUID);
1165             }
1166             throw e;
1167         }
1168     }
1169
1170     public void updateVnf(String serviceModelUUID, org.onap.so.rest.catalog.beans.Vnf vnf) {
1171         if (vnf == null) {
1172             throw new EntityNotFoundException("Vnf passed as null");
1173         }
1174         try {
1175             HttpHeaders headers = getHttpHeaders();
1176             HttpEntity<org.onap.so.rest.catalog.beans.Vnf> entity = new HttpEntity<>(vnf, headers);
1177
1178             restTemplate.exchange(
1179                     UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID
1180                             + "/vnfs/" + vnf.getModelCustomizationId()).build().encode().toString(),
1181                     HttpMethod.PUT, entity, org.onap.so.rest.catalog.beans.Vnf.class).getBody();
1182         } catch (HttpClientErrorException e) {
1183             if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1184                 throw new EntityNotFoundException(
1185                         "Unable to find Vnf with Vnf Customization UUID:" + vnf.getModelCustomizationId());
1186             }
1187             throw e;
1188         }
1189     }
1190
1191
1192     public Workflow findWorkflowByArtifactUUID(String artifactUUID) {
1193         return this.getSingleResource(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByArtifactUUID)
1194                 .queryParam(ARTIFACT_UUID, artifactUUID).build().toString()));
1195     }
1196
1197     public List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID) {
1198         return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByVnfModelUUID)
1199                 .queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
1200     }
1201
1202     public List<Workflow> findWorkflowByPnfModelUUID(String pnfResourceModelUUID) {
1203         return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByPnfModelUUID)
1204                 .queryParam(PNF_RESOURCE_MODEL_UUID, pnfResourceModelUUID).build().toString()));
1205     }
1206
1207     public List<Workflow> findWorkflowBySource(String source) {
1208         return this.getMultipleResources(workflowClient,
1209                 getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
1210     }
1211
1212     public List<Workflow> findWorkflowByResourceTarget(String resourceTarget) {
1213         return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByResourceTarget)
1214                 .queryParam(RESOURCE_TARGET, resourceTarget).build().toString()));
1215     }
1216
1217     public List<Workflow> findWorkflowByOperationName(String operationName) {
1218         return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByOperationName)
1219                 .queryParam(OPERATION_NAME, operationName).build().toString()));
1220     }
1221
1222     public ProcessingFlags findProcessingFlagsByFlag(String flag) {
1223         return this.getSingleResource(processingFlagsClient,
1224                 getUri(UriBuilder.fromUri(findProcessingFlagsByFlag).queryParam(FLAG, flag).build().toString()));
1225     }
1226
1227     public String getEndpoint() {
1228         return endpoint;
1229     }
1230
1231     public void setEndpoint(String endpoint) {
1232         this.endpoint = endpoint;
1233     }
1234
1235     private HttpHeaders getHttpHeaders() {
1236         HttpHeaders headers = new HttpHeaders();
1237         headers.set(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
1238         headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
1239         headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
1240         headers.set(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
1241         return headers;
1242     }
1243
1244     private HttpEntity<?> getHttpEntity() {
1245         HttpHeaders headers = getHttpHeaders();
1246         return new HttpEntity<>(headers);
1247     }
1248 }