Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / inventory / create / CreateInventoryService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 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.adapters.inventory.create;
22
23 import java.security.GeneralSecurityException;
24 import javax.annotation.PostConstruct;
25 import org.camunda.bpm.client.ExternalTaskClient;
26 import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
27 import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
28 import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
29 import org.onap.so.utils.CryptoUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Profile;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
36
37 @Component
38 @Profile("!test")
39 public class CreateInventoryService {
40
41     private static final Logger logger = LoggerFactory.getLogger(CreateInventoryService.class);
42
43     @Autowired
44     public Environment env;
45
46     @Autowired
47     private CreateInventoryTask createInventory;
48
49     @PostConstruct
50     public void auditAAIInventory() {
51         String auth = "";
52         try {
53             auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
54         } catch (IllegalStateException | GeneralSecurityException e) {
55             logger.error("Error Decrypting Password", e);
56         }
57         ClientRequestInterceptor interceptor =
58                 new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
59         ExternalTaskClient client = ExternalTaskClient.create()
60                 .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor)
61                 .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
62         client.subscribe("InventoryCreate").lockDuration(60000).handler(createInventory::executeExternalTask).open();
63     }
64
65 }