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