dd560ffa1f9be73b515ac8cb673af626d42a06c4
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
17
18 import com.alibaba.fastjson.JSONObject;
19 import lombok.extern.log4j.Log4j2;
20 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
22 import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAPICall;
23 import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAuthConfig;
24 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
25 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
27 import org.onap.usecaseui.intentanalysis.util.RestfulServices;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30 import retrofit2.Response;
31
32 import java.io.IOException;
33
34 @Log4j2
35 @Component
36 public class CLLAssuranceKnowledgeModule extends KnowledgeModule {
37     private AAIAPICall aaiapiCall;
38     @Autowired
39     AAIAuthConfig aaiAuthConfig;
40
41     public AAIAPICall getAaiApiCall() {
42         if (null == aaiapiCall) {
43             this.aaiapiCall = RestfulServices.create(AAIAPICall.class,
44                     aaiAuthConfig.getUserName(), aaiAuthConfig.getPassword());
45         }
46         return this.aaiapiCall;
47     }
48
49     public void setAAIApiCall(AAIAPICall aaiApiCall) {
50         this.aaiapiCall = aaiApiCall;
51     }
52
53     @Override
54     public IntentGoalBean intentCognition(Intent intent) {
55         return null;
56     }
57
58     @Override
59     public boolean recieveCreateIntent() {
60         return false;
61     }
62
63     @Override
64     public boolean recieveUpdateIntent() {
65         return false;
66     }
67
68     @Override
69     public boolean recieveDeleteIntent() {
70         return false;
71     }
72
73     /**
74      * healthy check
75      */
76     int getSystemStatus(Intent intent) {
77         try {
78             if (CollectionUtils.isEmpty(intent.getIntentExpectations())) {
79                 return -1;
80             }
81             String objectInstance = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
82             if (StringUtils.isEmpty(objectInstance)){
83                 return -1;
84             }
85             Response<JSONObject> response = getAaiApiCall().getInstanceInfo(objectInstance).execute();
86             log.debug(response.toString());
87             if (response.isSuccessful()) {
88                 // TODO: 2022/9/20 judge by the return result
89             }
90             log.error("getIntentInstance Create Statue Error:" + response.toString());
91             return -1;
92         } catch (Exception ex) {
93             log.error("Details:" + ex.getMessage());
94             return 0;
95         }
96     }
97 }