2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22 import java.util.Optional;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.so.client.exception.ExceptionBuilder;
26 import org.onap.so.db.catalog.client.CatalogDbClient;
27 import org.onap.so.db.catalog.beans.CloudSite;
28 import org.onap.so.logger.MsoLogger;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
33 public class CloudSiteCatalogUtils {
35 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CloudSiteCatalogUtils.class);
37 private ExceptionBuilder exceptionUtil;
40 private CatalogDbClient catalogDbClient;
43 public void getIdentityUrlFromCloudSite(DelegateExecution execution) {
44 String cloudRegionId = (String) execution.getVariable("lcpCloudRegionId");
46 if (cloudRegionId != null) {
47 Optional<CloudSite> cloudSite = getCloudSite(cloudRegionId);
48 if (!cloudSite.isPresent()) {
49 msoLogger.debug("Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB");
50 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB");
53 if (cloudSite.get().getIdentityService() == null) {
54 msoLogger.debug("No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB");
55 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB");
57 String identityUrl = cloudSite.get().getIdentityService().getIdentityUrl();
59 msoLogger.debug("identityUrl from Catalog DB is: " + identityUrl);
60 execution.setVariable("identityUrl", identityUrl);
64 protected Optional<CloudSite> getCloudSite(String id) {
66 return Optional.empty();
68 CloudSite cloudSite = catalogDbClient.getCloudSite(id);
70 if (cloudSite != null) {
71 return Optional.of(cloudSite);
73 return(Optional.of(catalogDbClient.getCloudSiteByClliAndAicVersion(id,"2.5")));