diff options
69 files changed, 2453 insertions, 598 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java new file mode 100644 index 0000000..db89ed6 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.adapters.aai.apicall; + +import com.alibaba.fastjson.JSONObject; +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Headers; +import retrofit2.http.Path; + +public interface AAIAPICall { + @GET("/aai/v24/network/network-routes") + Call<JSONObject> queryNetworkRoute(); + + @Headers({ + "X-TransactionId: 9999", + "X-FromAppId: MSO", + "Content-Type: application/json", + "Accept: application/json" + }) + @GET("/aai/v24/business/customers/customer/IBNCustomer/service-subscriptions/service-subscription/IBN/service-instances/service-instance/{resource-service-id}") + Call<JSONObject> getInstanceInfo(@Path("resource-service-id") String resourceServiceId); +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAuthConfig.java index d2d66c7..7e85e40 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAuthConfig.java @@ -13,25 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.onap.usecaseui.intentanalysis.adapters.aai.apicall; -package org.onap.usecaseui.intentanalysis.service; +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +@Getter +@Setter +public class AAIAuthConfig { -import java.util.List; -import org.onap.usecaseui.intentanalysis.bean.models.State; + @Value("${rest.aai.username}") + private String userName; - -public interface StateService { - - void createStateList(List<State> stateList, String expectationId); - - void deleteStateListByExpectationId(String expectationId); - - void updateStateListByExpectationId(List<State> stateList, String expectationId); - - List<State> getStateListByExpectationId(String expectationId); - - void createState(State state, String expectationId); - - void deleteStateById(String stateId); + @Value("${rest.aai.password}") + private String password; } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAPICall.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAPICall.java index 897aed2..8240661 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAPICall.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAPICall.java @@ -29,14 +29,14 @@ import retrofit2.http.Path; public interface PolicyAPICall { @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @POST("/policy/api/v1/policytypes") Call<ResponseBody> createPolicyType(@Body RequestBody body); @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @POST("/policy/api/v1/policytypes/{policyType}/versions/{policyTypeVersion}/policies") @@ -44,32 +44,32 @@ public interface PolicyAPICall { @Path("policyTypeVersion") String policyTypeVersion, @Body RequestBody body); @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @POST("/policy/pap/v1/pdps/policies") Call<ResponseBody> deployPolicy(@Body RequestBody body); @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @DELETE("/policy/pap/v1/pdps/policies/{policyName}") Call<ResponseBody> undeployPolicy(@Path("policyName") String policyName); @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @DELETE("/policy/api/v1/policies/{policyName}/versions/{policyVersion}") Call<ResponseBody> removePolicy(@Path("policyName") String policyName, @Path("policyVersion") String policyVersion); @Headers({ - "Authorization: Basic cG9saWN5YWRtaW46emIhWHp0RzM0", "Accept: application/json", + "Accept: application/json", "Content-Type: application/json" }) @GET( - "https://192.168.100.2:30283/policy/api/v1/policytypes/{policyType}/versions/{policyTypeVersion}/policies/{policyName}/versions/{policyVersiion}") + "/policy/api/v1/policytypes/{policyType}/versions/{policyTypeVersion}/policies/{policyName}/versions/{policyVersion}") Call<ResponseBody> getPolicy(@Path("policyType") String policyType, @Path("policyTypeVersion") String policyTypeVersion, @Path("policyName") String policyName, @Path("policyVersion") String policyVersion); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAuthConfig.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAuthConfig.java new file mode 100644 index 0000000..2ef1e26 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/apicall/PolicyAuthConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.adapters.policy.apicall; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +@Getter +@Setter +public class PolicyAuthConfig { + + @Value("${rest.policy.username}") + private String userName; + + @Value("${rest.policy.password}") + private String password; +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/impl/PolicyServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/impl/PolicyServiceImpl.java index 26b7add..d51d338 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/impl/PolicyServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/impl/PolicyServiceImpl.java @@ -26,9 +26,11 @@ import org.apache.commons.io.FileUtils; import org.apache.ibatis.io.Resources; import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService; import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAuthConfig; import org.onap.usecaseui.intentanalysis.util.RestfulServices; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import retrofit2.Response; @@ -39,8 +41,19 @@ public class PolicyServiceImpl implements PolicyService { private PolicyAPICall policyAPICall; - public PolicyServiceImpl() { - this.policyAPICall = RestfulServices.create(PolicyAPICall.class); + @Autowired + PolicyAuthConfig policyAuthConfig; + + public PolicyAPICall getPolicyAPICall() { + if (null == policyAPICall) { + this.policyAPICall = RestfulServices.create(PolicyAPICall.class, policyAuthConfig.getUserName(), + policyAuthConfig.getPassword()); + } + return this.policyAPICall; + } + + public void setPolicyAPICall(PolicyAPICall policyAPICall) { + this.policyAPICall = policyAPICall; } @Override @@ -51,10 +64,10 @@ public class PolicyServiceImpl implements PolicyService { String policyBody = FileUtils.readFileToString(policyFile, StandardCharsets.UTF_8); logger.info(String.format("Create policy, request body: %s", policyBody)); RequestBody policyReq = RequestBody.create(MediaType.parse("application/json"), policyBody.toString()); - Response<ResponseBody> policyResponse = policyAPICall.createPolicy(ModifyCLLPolicyConstants.policyType, + Response<ResponseBody> policyResponse = getPolicyAPICall().createPolicy(ModifyCLLPolicyConstants.policyType, ModifyCLLPolicyConstants.policyTypeVersion, policyReq).execute(); - logger.info( - String.format("Create policy result, code: %d body: %s", policyResponse.code(), policyResponse.body())); + logger.info(String.format("Create policy result, code: %d body: %s", policyResponse.code(), + getResponseBodyStr(policyResponse))); if (!policyResponse.isSuccessful()) { logger.error("Create modify cll policy failed."); return false; @@ -66,9 +79,9 @@ public class PolicyServiceImpl implements PolicyService { logger.info(String.format("Deploy policy, request body: %s", deployPolicyBody)); RequestBody deployPolicyReq = RequestBody.create(MediaType.parse("application/json"), deployPolicyBody.toString()); - Response<ResponseBody> deployPolicyResponse = policyAPICall.deployPolicy(deployPolicyReq).execute(); + Response<ResponseBody> deployPolicyResponse = getPolicyAPICall().deployPolicy(deployPolicyReq).execute(); logger.info(String.format("Deploy policy result, code: %d body: %s", deployPolicyResponse.code(), - deployPolicyResponse.body())); + getResponseBodyStr(deployPolicyResponse))); if (!deployPolicyResponse.isSuccessful()) { logger.error("Deploy modify cll policy failed."); return false; @@ -125,9 +138,9 @@ public class PolicyServiceImpl implements PolicyService { logger.info(String.format("Create policy type, request body: %s", policyTypeBody)); RequestBody policyTypeReq = RequestBody.create(MediaType.parse("application/json"), policyTypeBody.toString()); - Response<ResponseBody> response = policyAPICall.createPolicyType(policyTypeReq).execute(); - logger.info( - String.format("Create policy type result, code: %d body: %s", response.code(), response.body())); + Response<ResponseBody> response = getPolicyAPICall().createPolicyType(policyTypeReq).execute(); + logger.info(String.format("Create policy type result, code: %d body: %s", response.code(), + getResponseBodyStr(response))); if (!response.isSuccessful()) { logger.error("Create intent configuration policy type failed."); return false; @@ -140,10 +153,11 @@ public class PolicyServiceImpl implements PolicyService { .replace("${ORIGINAL_BW}", originalBW); logger.info(String.format("Create policy, request body: %s", policyBody)); RequestBody policyReq = RequestBody.create(MediaType.parse("application/json"), policyBody.toString()); - Response<ResponseBody> policyResponse = policyAPICall.createPolicy(IntentConfigPolicyConstants.policyType, - IntentConfigPolicyConstants.policyTypeVersion, policyReq).execute(); - logger.info( - String.format("Create policy result, code: %d body: %s", policyResponse.code(), policyResponse.body())); + Response<ResponseBody> policyResponse = getPolicyAPICall().createPolicy( + IntentConfigPolicyConstants.policyType, IntentConfigPolicyConstants.policyTypeVersion, policyReq) + .execute(); + logger.info(String.format("Create policy result, code: %d body: %s", policyResponse.code(), + getResponseBodyStr(policyResponse))); if (!policyResponse.isSuccessful()) { logger.error("Create intent configuration policy failed."); return false; @@ -155,9 +169,9 @@ public class PolicyServiceImpl implements PolicyService { logger.info(String.format("Deploy policy, request body: %s", deployPolicyBody)); RequestBody deployPolicyReq = RequestBody.create(MediaType.parse("application/json"), deployPolicyBody.toString()); - Response<ResponseBody> deployPolicyResponse = policyAPICall.deployPolicy(deployPolicyReq).execute(); + Response<ResponseBody> deployPolicyResponse = getPolicyAPICall().deployPolicy(deployPolicyReq).execute(); logger.info(String.format("Deploy policy result, code: %d body: %s", deployPolicyResponse.code(), - deployPolicyResponse.body())); + getResponseBodyStr(deployPolicyResponse))); if (!deployPolicyResponse.isSuccessful()) { logger.error("Deploy intent configuration policy failed."); return false; @@ -179,19 +193,21 @@ public class PolicyServiceImpl implements PolicyService { String policyVersion) { try { //check if the policy exists - Response<ResponseBody> response = policyAPICall.getPolicy(policyType, policyTypeVersion, policyName, + Response<ResponseBody> response = getPolicyAPICall().getPolicy(policyType, policyTypeVersion, policyName, policyVersion).execute(); - logger.info(String.format("The policy query result, code: %d body: %s", response.code(), response.body())); + logger.info(String.format("The policy query result, code: %d body: %s", response.code(), + getResponseBodyStr(response))); // remove the policy if exists. if (response.isSuccessful()) { logger.info("The policy exists, start to undeploy."); - Response<ResponseBody> undeployResponse = policyAPICall.undeployPolicy(policyName).execute(); + Response<ResponseBody> undeployResponse = getPolicyAPICall().undeployPolicy(policyName).execute(); logger.info(String.format("Undeploy policy result. code: %d body: %s", undeployResponse.code(), - undeployResponse.body())); + getResponseBodyStr(undeployResponse))); logger.info("Start to remove the policy."); - Response<ResponseBody> removeResponse = policyAPICall.removePolicy(policyName, policyVersion).execute(); + Response<ResponseBody> removeResponse = getPolicyAPICall().removePolicy(policyName, policyVersion) + .execute(); logger.info(String.format("Remove policy result. code: %d body: %s", removeResponse.code(), - removeResponse.body())); + getResponseBodyStr(removeResponse))); return true; } return true; @@ -202,4 +218,11 @@ public class PolicyServiceImpl implements PolicyService { } } + + private String getResponseBodyStr(Response<ResponseBody> response) throws IOException { + if (response.body() != null) { + return response.body().string(); + } + return null; + } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java index 92ef65c..4129b8e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java @@ -15,4 +15,12 @@ */ package org.onap.usecaseui.intentanalysis.adapters.so; -public interface SOService { } +import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance; + +public interface SOService { + + int createCCVPNInstance(CCVPNInstance instance); + + void deleteIntentInstance(String instanceId); + +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java new file mode 100644 index 0000000..cd07292 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.adapters.so.apicall; + +import com.alibaba.fastjson.JSONObject; +import okhttp3.RequestBody; +import retrofit2.Call; +import retrofit2.http.*; + +public interface SOAPICall { + @Headers({ + "Accept: application/json", + "Content-Type: application/json" + }) + @POST("/so/infra/serviceIntent/v1/create") + Call<JSONObject> createIntentInstance(@Body RequestBody body); + + @Headers({ + "Accept: application/json", + "Content-Type: application/json" + }) + @HTTP(method="DELETE", path="/so/infra/serviceIntent/v1/delete", hasBody = true) + Call<JSONObject> deleteIntentInstance(@Body RequestBody body); + + + +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAuthConfig.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAuthConfig.java new file mode 100644 index 0000000..042be41 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAuthConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.adapters.so.apicall; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +@Getter +@Setter +public class SOAuthConfig { + + @Value("${rest.so.username}") + private String userName; + + @Value("${rest.so.password}") + private String password; +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java new file mode 100644 index 0000000..e4e1f60 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java @@ -0,0 +1,207 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.usecaseui.intentanalysis.adapters.so.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAPICall; +import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAuthConfig; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAuthConfig; +import org.onap.usecaseui.intentanalysis.adapters.so.SOService; +import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAPICall; +import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAuthConfig; +import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance; +import org.onap.usecaseui.intentanalysis.util.RestfulServices; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import retrofit2.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SOServiceImpl implements SOService { + + private static final Logger logger = LoggerFactory.getLogger(SOServiceImpl.class); + + + private SOAPICall soapiCall; + + private AAIAPICall aaiapiCall; + + @Autowired + SOAuthConfig soAuthConfig; + + @Autowired + AAIAuthConfig aaiAuthConfig; + + public SOAPICall getSoApiCall() { + if (null == soapiCall) { + this.soapiCall = RestfulServices.create(SOAPICall.class, soAuthConfig.getUserName(), + soAuthConfig.getPassword()); + } + return this.soapiCall; + } + + public AAIAPICall getAaiApiCall() { + if (null == aaiapiCall) { + this.aaiapiCall = RestfulServices.create(AAIAPICall.class, aaiAuthConfig.getUserName(), + aaiAuthConfig.getPassword()); + } + return this.aaiapiCall; + } + + @Override + public int createCCVPNInstance(CCVPNInstance ccvpnInstance) { + try{ + if (null == ccvpnInstance){ + logger.error("CCVPN instance is null!"); + return 0; + } + String jobId = createIntentInstanceToSO(ccvpnInstance); + if (null == jobId){ + logger.error("CCVPN instance creation error:jobId is null"); + return 0; + } + ccvpnInstance.setJobId(jobId); + ccvpnInstance.setResourceInstanceId("cll-"+ccvpnInstance.getInstanceId()); + + long startTime = System.currentTimeMillis(); + long maxWaitingPeriod = 30 * 1000; // wait for 30s + while (getCreateStatus(ccvpnInstance) != 1){ + if((System.currentTimeMillis() - startTime) > maxWaitingPeriod) { + logger.error("CCVPN instance creation error: failed to send to so within time frame"); + return 0; + } + } + // creation status equals to 1 + return 1; + } catch (Exception e) { + logger.error("Details:" + e.getMessage()); + return 0; + } + } + + @Override + public void deleteIntentInstance(String serviceInstanceId) { + try { + deleteInstanceToSO(serviceInstanceId); + }catch (Exception e) { + logger.error("delete instance to SO error :" + e); + } + } + + public String createIntentInstanceToSO(CCVPNInstance ccvpnInstance) throws IOException { + Map<String, Object> params = paramsSetUp(ccvpnInstance); + params.put("additionalProperties",additionalPropertiesSetUp(ccvpnInstance)); + okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params)); + Response<JSONObject> response = getSoApiCall().createIntentInstance(requestBody).execute(); + if (response.isSuccessful()) { + return response.body().getString("jobId"); + } + return null; + } + + private void deleteInstanceToSO(String serviceInstanceId) throws IOException { + JSONObject params = new JSONObject(); + params.put("serviceInstanceID", serviceInstanceId); + params.put("globalSubscriberId", "IBNCustomer"); + params.put("subscriptionServiceType", "IBN"); + params.put("serviceType", "CLL"); + JSONObject additionalProperties = new JSONObject(); + additionalProperties.put("enableSdnc", "true"); + params.put("additionalProperties", additionalProperties); + okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params)); + getSoApiCall().deleteIntentInstance(requestBody).execute(); + } + + private int getCreateStatus(CCVPNInstance ccvpnInstance) throws IOException { + if (ccvpnInstance == null || ccvpnInstance.getResourceInstanceId() == null) { + return -1; + } + Response<JSONObject> response = getAaiApiCall().getInstanceInfo(ccvpnInstance.getResourceInstanceId()).execute(); + logger.debug(response.toString()); + if (response.isSuccessful()) { + String status = response.body().getString("orchestration-status"); + if ("created".equals(status)) { + return 1; + } + } + logger.error("getIntentInstance Create Statue Error:" + response.toString()); + return -1; + } + + /** + * parameter set up for ccpvpn instance creation + * @param ccvpnInstance + * @return + */ + private Map<String, Object> paramsSetUp(CCVPNInstance ccvpnInstance) { + Map<String, Object> params = new HashMap<>(); + params.put("name", ccvpnInstance.getName()); + params.put("modelInvariantUuid", "6790ab0e-034f-11eb-adc1-0242ac120002"); + params.put("modelUuid", "6790ab0e-034f-11eb-adc1-0242ac120002"); + params.put("globalSubscriberId", "IBNCustomer"); + params.put("subscriptionServiceType", "IBN"); + params.put("serviceType", "CLL"); + return params; + } + + /** + * additional properties set up for ccvpn instance creation + * @param ccvpnInstance + * @return + */ + private Map<String, Object> additionalPropertiesSetUp(CCVPNInstance ccvpnInstance) { + Map<String, Object> additionalProperties = new HashMap<>(); + additionalProperties.put("enableSdnc", "true"); + additionalProperties.put("serviceInstanceID", "cll-" + ccvpnInstance.getInstanceId()); + + // create connection link + Map<String, Object> connectionLink = new HashMap<>(); + connectionLink.put("name", ""); + connectionLink.put("transportEndpointA", ccvpnInstance.getAccessPointOneName()); + connectionLink.put("transportEndpointB", ccvpnInstance.getCloudPointName()); + + // create sla + Map<String, Object> sla = new HashMap<>(); + sla.put("latency", "2"); + sla.put("maxBandwidth", ccvpnInstance.getAccessPointOneBandWidth()); + + // configuration for sla and connection link + if (ccvpnInstance.getProtectStatus() == 1) { + sla.put("protectionType", ccvpnInstance.getProtectionType()); + connectionLink.put("transportEndpointBProtection", ccvpnInstance.getProtectionCloudPointName()); + } + + List<Map<String, Object>> connectionLinks = new ArrayList<>(); + connectionLinks.add(connectionLink); + + Map<String, Object> transportNetwork = new HashMap<>(); + transportNetwork.put("id", ""); + transportNetwork.put("sla", sla); + transportNetwork.put("connectionLinks", connectionLinks); + + List<Map<String, Object>> transportNetworks = new ArrayList<>(); + transportNetworks.add(transportNetwork); + additionalProperties.put("transportNetworks", transportNetworks); + return additionalProperties; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportArea.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportArea.java index 6543580..f71651a 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportArea.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportArea.java @@ -1,19 +1,17 @@ /* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. * - * * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.onap.usecaseui.intentanalysis.bean.enums; diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportInterface.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportInterface.java index d3414bc..19d3d7d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportInterface.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/SupportInterface.java @@ -1,19 +1,17 @@ /* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. * - * * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.onap.usecaseui.intentanalysis.bean.enums; diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java new file mode 100644 index 0000000..468725d --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java @@ -0,0 +1,73 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import lombok.Data; +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name="ccvpn_instance") +@Data + +public class CCVPNInstance implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "id") + private int id; + + @Column(name = "instance_id") + private String instanceId; + + @Column(name = "job_id") + private String jobId; + + @Column(name = "progress") + private int progress; + + @Column(name = "status") + private String status; + + @Column(name = "resource_instance_id") + private String resourceInstanceId; + + @Column(name = "name") + private String name; + + @Column(name = "cloud_point_name") + private String cloudPointName; + + @Column(name = "access_point_one_name") + private String accessPointOneName; + + @Column(name = "access_point_one_band_width") + private int accessPointOneBandWidth; + + @Column(name = "line_num") + private String lineNum; + + @Column(name = "protect_status") + private int protectStatus; + + @Column(name = "delete_state") + private int deleteState; + + @Column(name = "protection_cloud_point_name") + private String protectionCloudPointName; + + @Column(name = "protection_type") + private String protectionType; +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBean.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBean.java index b4ae516..eb48abb 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBean.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBean.java @@ -16,7 +16,6 @@ package org.onap.usecaseui.intentanalysis.bean.models; import lombok.Data; -import lombok.NoArgsConstructor; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; @Data diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java index 9061036..80ff29e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/CLLBusinessIntentManagementFunction.java @@ -26,12 +26,23 @@ import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.Decision import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; import org.springframework.stereotype.Component; +import javax.annotation.Resource; + @Data @Component("CLLBusinessIntentManagementFunction") public class CLLBusinessIntentManagementFunction extends IntentManagementFunction { - private ActuationModule actuationModule = new CLLBusinessActuationModule(); - private DecisionModule decisoinModule = new CLLBusinessDecisionModule(); - private KnowledgeModule knowledgeModule = new CLLBusinessKnowledgeModule(); + @Resource(name= "CLLBusinessActuationModule") + public void setActuationModule(ActuationModule actuationModule) { + this.actuationModule=actuationModule; + } + @Resource(name= "CLLBusinessKnowledgeModule") + public void setKnowledgeModule(KnowledgeModule knowledgeModule) { + this.knowledgeModule=knowledgeModule; + } + @Resource(name= "CLLBusinessDecisionModule") + public void setDecisionModule(DecisionModule decisionModule) { + this.decisionModule=decisionModule; + } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java index 4209c1b..ecd5b50 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java @@ -18,28 +18,27 @@ package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule import org.onap.usecaseui.intentanalysis.bean.models.Intent; import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; -import org.onap.usecaseui.intentanalysis.intentBaseService.IntentHandleService; -import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService; import org.onap.usecaseui.intentanalysis.service.IntentService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; -@Service -public class CLLBusinessActuationModule implements ActuationModule { +@Component +public class CLLBusinessActuationModule extends ActuationModule { @Autowired IntentProcessService processService; @Autowired - IntentHandleService intentHandleService; - @Autowired IntentService intentService; + @Autowired + IntentInterfaceService intentInterfaceService; @Override @@ -57,14 +56,14 @@ public class CLLBusinessActuationModule implements ActuationModule { } @Override - public void saveIntentToDb(List<Map<IntentGoalBean,IntentManagementFunction>> intentMapList) { + public void saveIntentToDb(List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList) { List<IntentGoalBean> subIntentGoalLit = new ArrayList<>(); - for (Map<IntentGoalBean,IntentManagementFunction> map:intentMapList) { + for (Map<IntentGoalBean, IntentManagementFunction> map : intentMapList) { subIntentGoalLit.addAll(map.keySet()); } List<Intent> subIntentList = subIntentGoalLit.stream().map(IntentGoalBean::getIntent) .collect(Collectors.toList()); - for (Intent subIntent:subIntentList) { + for (Intent subIntent : subIntentList) { intentService.createIntent(subIntent); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java index bcda367..6428742 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java @@ -30,14 +30,17 @@ import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService; import org.onap.usecaseui.intentanalysis.util.CommonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Log4j2 -@Service -public class CLLBusinessDecisionModule implements DecisionModule { +@Component +public class CLLBusinessDecisionModule extends DecisionModule { @Autowired private ImfRegInfoService imfRegInfoService; @Autowired @@ -51,17 +54,8 @@ public class CLLBusinessDecisionModule implements DecisionModule { public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) { // db filter imf supportArea; //SupportInterface> supportInterfaces; - IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType(); - String intentName = intentGoalBean.getIntent().getIntentName(); - List<IntentManagementFunctionRegInfo> imfRegInfoList = imfRegInfoService.getImfRegInfoList(); - //todo - List<IntentManagementFunctionRegInfo> imfList = imfRegInfoList.stream(). - filter(x -> x.getSupportArea().contains(intentName) - && x.getSupportInterfaces().contains(intentGoalType)).collect(Collectors.toList()); - if (!Optional.ofNullable(imfList).isPresent()) { - log.info("The intent name is %s not find the corresponding IntentManagementFunction", intentName); - } - return (IntentManagementFunction) applicationContext.getBean(imfList.get(0).getHandleName()); + IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfoList(intentGoalBean); + return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName()); } @Override @@ -146,7 +140,6 @@ public class CLLBusinessDecisionModule implements DecisionModule { for (IntentGoalBean subIntentGoal : sortList) { Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>(); IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal); - //TODO call probe interface if fail intentFulfilmentInfo throw exception map.put(subIntentGoal, imf); intentMapList.add(map); } @@ -157,4 +150,5 @@ public class CLLBusinessDecisionModule implements DecisionModule { } return intentMapList; } + } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessKnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessKnowledgeModule.java index 372b0d5..d2c984d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessKnowledgeModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessKnowledgeModule.java @@ -15,29 +15,27 @@ */ package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule; -import org.apache.commons.collections.CollectionUtils; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; -import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; -import org.onap.usecaseui.intentanalysis.bean.models.Expectation; -import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget; import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentDetectionService; import org.onap.usecaseui.intentanalysis.service.IntentService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; -@Service -public class CLLBusinessKnowledgeModule implements KnowledgeModule { +@Component +public class CLLBusinessKnowledgeModule extends KnowledgeModule { private static Logger LOGGER = LoggerFactory.getLogger(CLLBusinessKnowledgeModule.class); @Autowired IntentService intentService; + @Autowired + IntentDetectionService intentDetectionService; @Override public IntentGoalBean intentCognition(Intent intent) { @@ -46,48 +44,19 @@ public class CLLBusinessKnowledgeModule implements KnowledgeModule { return determineDetectionGoal(intent, intendIdList); } - /** - * find similar intents in DB - * - * @param intent - */ + @Override + public boolean recieveCreateIntent() { + return false; + } - public List<String> intentResolution(Intent intent) { - //db contain original intent - List<Intent> sameNameIntentList = intentService.getIntentByName(intent.getIntentName()); - List<String> intentIdList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(sameNameIntentList)) { - List<Expectation> expectationList = intent.getIntentExpectations(); - for (Intent dbIntent : sameNameIntentList) { - String intentId = dbIntent.getIntentId(); - int count = 0; - for (Expectation expectation : expectationList) {//original expectations - //Determine if there is the same ObjectType - List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream() - .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType())) - .collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(sameObjTypeList)) { - //Determine the targetName of the Expectation which hava same ObjectType - List<String> targetNameList = expectation.getExpectationTargets() - .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList()); - for (Expectation dbExpectation : sameObjTypeList) { - List<String> dbTargetNameList = dbExpectation.getExpectationTargets() - .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList()); - //todo name compare need ai - if (dbTargetNameList.containsAll(targetNameList)) { - count++; - break; - } - } - } - if (count == expectationList.size()) { - intentIdList.add(intentId); - break; - } - } - } - } - return intentIdList; + @Override + public boolean recieveUpdateIntent() { + return false; + } + + @Override + public boolean recieveDeleteIntent() { + return false; } void intentReportResolution() { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java new file mode 100644 index 0000000..3e489ae --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt; + +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; + +public class CLLAssuranceIntentManagementFunction extends IntentManagementFunction { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java new file mode 100644 index 0000000..c061d76 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule; + +public class CLLAssuranceActuationModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceDecisionModule.java new file mode 100644 index 0000000..8a65b55 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceDecisionModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule; + +public class CLLAssuranceDecisionModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceKnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceKnowledgeModule.java new file mode 100644 index 0000000..75bffbd --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceKnowledgeModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule; + +public class CLLAssuranceKnowledgeModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryManagementFunction.java new file mode 100644 index 0000000..76b0cf5 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryManagementFunction.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt; + +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; + +public class CLLDeliveryManagementFunction extends IntentManagementFunction { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java new file mode 100644 index 0000000..65a2ca8 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule; + +public class CLLDeliveryActuationModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryDecisionModule.java new file mode 100644 index 0000000..42dea4f --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryDecisionModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule; + +public class CLLDeliveryDecisionModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryKnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryKnowledgeModule.java new file mode 100644 index 0000000..c2f5278 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryKnowledgeModule.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule; + +public class CLLDeliveryKnowledgeModule { +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java index bb5e085..41d2d2a 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java @@ -19,7 +19,8 @@ package org.onap.usecaseui.intentanalysis.controller; import java.util.List; -import org.onap.usecaseui.intentanalysis.intentBaseService.IntentHandleService; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -38,7 +39,9 @@ public class IntentController { private IntentService intentService; @Autowired - private IntentHandleService intentHandleService; + private IntentProcessService processService; + @Autowired + FormatIntentInputManagementFunction formatIntentInputManagementFunction; @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<List<Intent>> getIntentList() { @@ -70,7 +73,7 @@ public class IntentController { @PostMapping(value="/handleIntent",produces = MediaType.APPLICATION_JSON_VALUE) public void handleIntent(@RequestBody Intent intent) { - intentHandleService.handleOriginalIntent(intent); - + processService.setIntentRole(formatIntentInputManagementFunction, null); + processService.intentProcess(intent); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java new file mode 100644 index 0000000..ebbe9b8 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.formatintentinputMgt; + +import lombok.Data; +import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessActuationModule; +import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessDecisionModule; +import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessKnowledgeModule; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputActuationModule; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputDecisionModule; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputKnowledgeModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Data +@Component("formatIntentInputManagementFunction") +public class FormatIntentInputManagementFunction extends IntentManagementFunction { + + @Resource(name= "formatIntentInputKnowledgeModule") + public void setKnowledgeModule(KnowledgeModule knowledgeModule) { + this.knowledgeModule=knowledgeModule; + } + @Resource(name= "formatIntentInputActuationModule") + public void setKnowledgeModule(ActuationModule actuationModule) { + this.actuationModule=actuationModule; + } + @Resource(name= "formatIntentInputDecisionModule") + public void setKnowledgeModule(DecisionModule decisionModule) { + this.decisionModule=decisionModule; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java new file mode 100644 index 0000000..df8e714 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule; + +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +@Component +public class FormatIntentInputActuationModule extends ActuationModule { + @Override + public void sendToIntentHandler(IntentManagementFunction IntentHandler) { + } + + @Override + public void sendToNonIntentHandler() { + } + + @Override + public void interactWithIntentHandle() { + } + + @Override + public void saveIntentToDb(List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList) { + // + } + + @Override + public boolean distrubuteIntentToHandler(Map<IntentGoalBean, IntentManagementFunction> intentMap) { + return false; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java new file mode 100644 index 0000000..f49326a --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule; + +import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.models.Expectation; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +@Component +public class FormatIntentInputDecisionModule extends DecisionModule { + @Autowired + ApplicationContext applicationContext; + + @Override + public void determineUltimateGoal() { + } + + @Override + public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) { + // if intentName contain cll return + if (StringUtils.equalsIgnoreCase(intentGoalBean.getIntent().getIntentName(), "cll")) { + return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getName()); + } + return null; + } + + @Override + public void intentDefinition() { + } + + @Override + public void decideSuitableAction() { + } + + @Override + public void interactWithTemplateDb() { + } + + @Override + public List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean) { + boolean needDecompostion = needDecompostion(intentGoalBean); + if (needDecompostion) { + intentDecomposition(intentGoalBean); + } + exploreIntentHandlers(intentGoalBean); + return null; + } + + public boolean needDecompostion(IntentGoalBean intentGoalBean) { + //expectationName just contain cll and slicing need decompost + List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations(); + List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName) + .distinct().collect(Collectors.toList()); + if (expectationNameList.size() > 1) { + List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "cll")).collect(Collectors.toList()); + List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "slicing")).collect(Collectors.toList()); + if (cllList.size() > 0 && slicingList.size() > 0) { + return true; + } + } + return false; + } + + public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) { + //todo + return null; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputKnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputKnowledgeModule.java new file mode 100644 index 0000000..22edc86 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputKnowledgeModule.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule; + +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentDetectionService; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class FormatIntentInputKnowledgeModule extends KnowledgeModule { + @Autowired + IntentDetectionService intentDetectionService; + @Autowired + IntentService intentService; + + @Override + public IntentGoalBean intentCognition(Intent intent) { + List<String> intendIdList = intentResolution(intent); + getSystemStatus(); + return determineDetectionGoal(intent, intendIdList); + } + + @Override + public boolean recieveCreateIntent() { + return false; + } + + @Override + public boolean recieveUpdateIntent() { + return false; + } + + @Override + public boolean recieveDeleteIntent() { + return false; + } + + public void getSystemStatus() { + } + + public IntentGoalBean determineDetectionGoal(Intent intent, List<String> intentIdList) { + int size = intentIdList.size(); + if (size == 0) { + return new IntentGoalBean(intent, IntentGoalType.CREATE); + } else { + return new IntentGoalBean(intent, IntentGoalType.UPDATE); + } + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentHandleService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentHandleService.java deleted file mode 100644 index 2d420d7..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentHandleService.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.usecaseui.intentanalysis.intentBaseService; - -import lombok.extern.slf4j.Slf4j; -import org.onap.usecaseui.intentanalysis.bean.models.Intent; -import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo; -import org.onap.usecaseui.intentanalysis.common.ResponseConsts; -import org.onap.usecaseui.intentanalysis.exception.DataBaseException; -import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; -import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -@Slf4j -@Service -public class IntentHandleService { - @Autowired - private IntentProcessService processService; - @Autowired - private ImfRegInfoService imfRegInfoService; - @Autowired - private ApplicationContext applicationContext; - - /** - * Process the original intent and find the corresponding IntentManagementFunction - * - * @param intent - */ - public void handleOriginalIntent(Intent intent) { - IntentManagementFunction intentOwner = getOriginalIMF(intent); - handleIntent(intent, intentOwner); - } - - public void handleIntent(Intent intent, IntentManagementFunction intentOwner) { - processService.setIntentRole(intentOwner, null); - processService.intentProcess(intent); - } - - public IntentManagementFunction selectIntentManagementFunction(Intent intent) { - //select the IntentManagementFunctionRegInfo Based on the IMFRegistry information. - //Only internalFunction support. - //and based on the IntentManagementFunctionRegInfo, get the right IntentManagementFunction bean. - //if no IntentManagementFunction selected, that means this intent is not supported by this system. - return null; - } - - public IntentManagementFunctionRegInfo selectIntentManagementFunctionRegInfo(Intent intent) { - //select the IntentManagementFunctionRegInfo Based on the IMFRegistry information. - //Both internalFunction and externalFunction support. - //This is used to get he IntentManagementFunction for a subIntent decomposition. - return null; - } - - public IntentManagementFunction getOriginalIMF(Intent intent) { - //select IntentManagementFunction based on intent name - String intentName = intent.getIntentName(); - List<IntentManagementFunctionRegInfo> imfRegInfoList = imfRegInfoService.getImfRegInfoList(); - List<IntentManagementFunctionRegInfo> list = imfRegInfoList.stream().filter(x -> x.getSupportArea().contains(intentName)).collect(Collectors.toList()); - if (!Optional.ofNullable(list).isPresent()) { - String msg = String.format("Intent name %s doesn't exist IntentManagementFunction in database.", intent.getIntentName()); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - return (IntentManagementFunction) applicationContext.getBean(list.get(0).getHandleName()); - } -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java index 550051e..387d728 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java @@ -21,11 +21,13 @@ import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.Actuatio import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; @Data @Configuration +@Component public class IntentManagementFunction { - private ActuationModule actuationModule; - private DecisionModule decisionModule; - private KnowledgeModule knowledgeModule; + protected ActuationModule actuationModule; + protected DecisionModule decisionModule; + protected KnowledgeModule knowledgeModule; } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java index 2800c1e..e9ee3f7 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java @@ -15,18 +15,41 @@ */ package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule; +import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService; +import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Map; -public interface ActuationModule { +public abstract class ActuationModule { + @Autowired + IntentInterfaceService intentInterfaceService; + //actuationModel & knownledgeModel interact - void sendToIntentHandler(IntentManagementFunction IntentHandler); - void sendToNonIntentHandler();//直接操作 - void interactWithIntentHandle(); + public abstract void sendToIntentHandler(IntentManagementFunction IntentHandler); + + public abstract void sendToNonIntentHandler();//直接操作 + + public abstract void interactWithIntentHandle(); + //Save intent information to the intent instance database - void saveIntentToDb(List<Map<IntentGoalBean,IntentManagementFunction>> intentMapList); + public abstract void saveIntentToDb(List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList); + public boolean distrubuteIntentToHandler(Map<IntentGoalBean, IntentManagementFunction> intentMap) { + for (Map.Entry<IntentGoalBean, IntentManagementFunction> entry : intentMap.entrySet()) { + IntentGoalType intentGoalType = entry.getKey().getIntentGoalType(); + if (StringUtils.equalsIgnoreCase("create", intentGoalType.name())) { + return intentInterfaceService.createInterface(entry.getKey().getIntent(), entry.getValue()); + } else if (StringUtils.equalsIgnoreCase("update", intentGoalType.name())) { + return intentInterfaceService.updateInterface(entry.getKey().getIntent(), entry.getValue()); + } else if (StringUtils.equalsIgnoreCase("delete", intentGoalType.name())) { + return intentInterfaceService.deleteInterface(entry.getKey().getIntent(), entry.getValue()); + } + } + return false; + } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/DecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/DecisionModule.java index 76601a8..a89656b 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/DecisionModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/DecisionModule.java @@ -22,16 +22,18 @@ import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunct import java.util.List; import java.util.Map; -public interface DecisionModule { - void determineUltimateGoal(); +public abstract class DecisionModule { + public abstract void determineUltimateGoal(); - IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean); + // find intentManageFunction + public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean); - void intentDefinition(); + public abstract void intentDefinition(); - void decideSuitableAction(); + public abstract void decideSuitableAction(); - public void interactWithTemplateDb(); + public abstract void interactWithTemplateDb(); + + public abstract List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean); - public List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java index d5caf1f..02d467a 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java @@ -15,10 +15,95 @@ */ package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule; -import org.onap.usecaseui.intentanalysis.bean.models.Intent; -import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.models.*; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.onap.usecaseui.intentanalysis.service.impl.IntentServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; -public interface KnowledgeModule { +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public abstract class KnowledgeModule { + @Autowired + private IntentService intentService; //Parse, decompose, orchestrate the original intent - IntentGoalBean intentCognition(Intent intent); + public abstract IntentGoalBean intentCognition(Intent intent); + // in distribution, ask permission from imf + public abstract boolean recieveCreateIntent(); + public abstract boolean recieveUpdateIntent(); + public abstract boolean recieveDeleteIntent(); + + public List<String> intentResolution(Intent intent) { + //db contain original intent + List<Intent> sameNameIntentList = intentService.getIntentByName(intent.getIntentName()); + List<String> intentIdList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(sameNameIntentList)) { + //remove context.condition ownerName = formatIntentInputManagementFunction + List<Intent> filterIntentList = filterIntent(sameNameIntentList); + List<Expectation> expectationList = intent.getIntentExpectations(); + for (Intent dbIntent : filterIntentList) { + String intentId = dbIntent.getIntentId(); + int count = 0; + for (Expectation expectation : expectationList) {//original expectations + //Determine if there is the same ObjectType + List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream() + .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(sameObjTypeList)) { + //Determine the targetName of the Expectation which hava same ObjectType + List<String> targetNameList = expectation.getExpectationTargets() + .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList()); + for (Expectation dbExpectation : sameObjTypeList) { + List<String> dbTargetNameList = dbExpectation.getExpectationTargets() + .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList()); + //todo name compare need ai + if (dbTargetNameList.containsAll(targetNameList)) { + count++; + break; + } + } + } + if (count == expectationList.size()) { + intentIdList.add(intentId); + break; + } + } + } + } + return intentIdList; + } + + public List<Intent> filterIntent(List<Intent> list) { + //// condition ownerName = foramtIntentInput + List<Intent> fiterList = new ArrayList<>(); + for (Intent intent : list) { + List<Context> ownerInfo = intent.getIntentContexts().stream().filter(x -> + StringUtils.equalsIgnoreCase(x.getContextName(), "ownerInfo")).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(ownerInfo)) { + for (Context context : ownerInfo) { + List<Condition> contextConditions = context.getContextConditions(); + boolean equals = false; + for (Condition condition : contextConditions) { + String conditionstr = "ownerName = formatIntentInputManagementFunction"; + String concatStr = condition.getConditionName() + condition.getOperator() + condition.getConditionValue(); + if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.trim())) { + fiterList.add(intent); + equals = true; + break; + } + } + if (equals==true) { + break; + } + } + } + } + list.removeAll(fiterList); + return list; + } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDetectionService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDetectionService.java index 699c1b1..60c4f74 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDetectionService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDetectionService.java @@ -27,12 +27,12 @@ public class IntentDetectionService { private IntentManagementFunction intentHandler; private IntentManagementFunction intentOwner; - public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler){ - if (intentOwner!= null){ + public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler) { + if (intentOwner != null) { this.intentOwner = intentOwner; } - if (intentHandler!= null){ - this.intentHandler= intentHandler; + if (intentHandler != null) { + this.intentHandler = intentHandler; } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDistributionService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDistributionService.java index 4622aa1..9e6c921 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDistributionService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDistributionService.java @@ -16,29 +16,40 @@ package org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService; +import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Map; + @Service public class IntentDistributionService { private IntentManagementFunction intentHandler; private IntentManagementFunction intentOwner; - public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler){ - if (intentOwner!= null){ + @Autowired + IntentInterfaceService intentInterfaceService; + + public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler) { + if (intentOwner != null) { this.intentOwner = intentOwner; } - if (intentHandler!= null){ - this.intentHandler= intentHandler; + if (intentHandler != null) { + this.intentHandler = intentHandler; } } - public void distributionProcess() { - ActuationModule intentActuationModule = intentHandler.getActuationModule(); + public boolean distributionProcess(Map<IntentGoalBean, IntentManagementFunction> intentMap) { - intentActuationModule.sendToIntentHandler(intentHandler); + intentOwner.getActuationModule().distrubuteIntentToHandler(intentMap); + return false; } } + diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java index ec4037e..537f582 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java @@ -18,6 +18,7 @@ package org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService import org.onap.usecaseui.intentanalysis.bean.models.Intent; import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.service.IntentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -36,7 +37,8 @@ public class IntentProcessService { IntentDistributionService intentDistributionService; @Autowired IntentOperationService intentOperationService; - +@Autowired + IntentService intentService; private IntentManagementFunction intentOwner; private IntentManagementFunction intentHandler; @@ -66,7 +68,7 @@ public class IntentProcessService { //distribution process intentDistributionService.setIntentRole(intentOwner,intentHandler); - intentDistributionService.distributionProcess(); + intentDistributionService.distributionProcess(map); //operation process intentOperationService.setIntentRole(intentOwner,intentHandler); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/IntentInterfaceService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/IntentInterfaceService.java new file mode 100644 index 0000000..4470d05 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/IntentInterfaceService.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice; + +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; + +public interface IntentInterfaceService { + public boolean createInterface(Intent intent, IntentManagementFunction imf); + + public boolean updateInterface(Intent intent, IntentManagementFunction imf); + + public boolean deleteInterface(Intent intent, IntentManagementFunction imf); +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/impl/IntentInterfaceServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/impl/IntentInterfaceServiceImpl.java new file mode 100644 index 0000000..1c6d853 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentinterfaceservice/impl/IntentInterfaceServiceImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.impl; + +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService; +import org.springframework.stereotype.Service; + +@Service +public class IntentInterfaceServiceImpl implements IntentInterfaceService { + @Override + public boolean createInterface(Intent intent, IntentManagementFunction imf) { + //ask knowledgeModole of handler imf for permision + imf.getKnowledgeModule().recieveCreateIntent(); + return false; + } + + @Override + public boolean updateInterface(Intent intent, IntentManagementFunction imf) { + imf.getKnowledgeModule().recieveUpdateIntent(); + return false; + } + + @Override + public boolean deleteInterface(Intent intent, IntentManagementFunction imf) { + imf.getKnowledgeModule().recieveDeleteIntent(); + return false; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java index cc253ab..1178b6d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java @@ -37,5 +37,5 @@ public interface IntentMapper { int deleteIntent(@Param(value = "intentId") String intentId); - List<Intent> getIntentByName(@Param(value = "name") String name); + List<Intent> getIntentByName(@Param(value = "intentName") String name); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java deleted file mode 100644 index 10538c4..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.usecaseui.intentanalysis.mapper; - - -import java.util.List; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.onap.usecaseui.intentanalysis.bean.models.Expectation; -import org.onap.usecaseui.intentanalysis.bean.models.State; - - -@Mapper - -public interface StateMapper { - - int insertStateList(@Param(value = "stateList") List<State> state, - @Param(value = "expectationId") String expectationId); - - List<State> selectStateByExpectation(@Param(value = "expectationId") String expectationId); - - int deleteStateByExpectationId(@Param(value = "expectationId") String expectationId); - - int updateState(@Param(value = "state") State state); - - int insertState(@Param(value = "state") State state, @Param(value = "expectationId") String expectationId); - - int deleteStateById(@Param(value = "stateId") String stateId); -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ImfRegInfoService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ImfRegInfoService.java index 0d7a6b1..c148975 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ImfRegInfoService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ImfRegInfoService.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.intentanalysis.service; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo; import java.util.List; @@ -23,4 +24,7 @@ public interface ImfRegInfoService { int insertIMFRegInfoRegInfo(IntentManagementFunctionRegInfo regInfo); List<IntentManagementFunctionRegInfo> getImfRegInfoList(); + IntentManagementFunctionRegInfo getImfRegInfoList(IntentGoalBean intentGoalBean); + + } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ImfRegInfoServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ImfRegInfoServiceImpl.java index 9fdc3ba..ba1a4fe 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ImfRegInfoServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ImfRegInfoServiceImpl.java @@ -16,6 +16,8 @@ package org.onap.usecaseui.intentanalysis.service.impl; import lombok.extern.slf4j.Slf4j; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo; import org.onap.usecaseui.intentanalysis.mapper.IMFRegInfoMapper; import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService; @@ -23,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; @Service @Slf4j @@ -39,4 +43,22 @@ public class ImfRegInfoServiceImpl implements ImfRegInfoService { public List<IntentManagementFunctionRegInfo> getImfRegInfoList() { return imfRegInfoMapper.getImfRegInfoList(); } + + @Override + public IntentManagementFunctionRegInfo getImfRegInfoList(IntentGoalBean intentGoalBean) { + String intentName = intentGoalBean.getIntent().getIntentName(); + IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType(); + List<IntentManagementFunctionRegInfo> imfRegInfoList = imfRegInfoMapper.getImfRegInfoList(); + + List<IntentManagementFunctionRegInfo> imfList = imfRegInfoList.stream(). + filter(x -> x.getSupportArea().contains(intentName) + && x.getSupportInterfaces().contains(intentGoalType)).collect(Collectors.toList()); + if (!Optional.ofNullable(imfList).isPresent()) { + log.info("The intent name is %s not find the corresponding IntentManagementFunction", intentName); + } + //TODO call probe interface if fail intentFulfilmentInfo throw exception + + return imfList.get(0); + } + }
\ No newline at end of file diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java index 952b6dd..bb1759c 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java @@ -87,7 +87,9 @@ public class IntentServiceImpl implements IntentService { public Intent getIntent(String intentId) { Intent intent = intentMapper.selectIntent(intentId); if (intent != null) { - intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentExpectations(expectationService.getIntentExpectationList(intentId)); + intent.setIntentContexts(contextService.getContextList(intentId)); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intentId)); } else { log.info(String.format("Intent is null, intentId = %s", intentId)); } @@ -140,6 +142,8 @@ public class IntentServiceImpl implements IntentService { if (!CollectionUtils.isEmpty(intentList)) { for (Intent intent : intentList) { intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentContexts(contextService.getContextList(intent.getIntentId())); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intent.getIntentId())); } } else { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java deleted file mode 100644 index b9c7b95..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.usecaseui.intentanalysis.service.impl; - - -import lombok.extern.slf4j.Slf4j; -import org.onap.usecaseui.intentanalysis.bean.models.State; -import org.onap.usecaseui.intentanalysis.common.ResponseConsts; -import org.onap.usecaseui.intentanalysis.exception.DataBaseException; -import org.onap.usecaseui.intentanalysis.mapper.StateMapper; -import org.onap.usecaseui.intentanalysis.service.StateService; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - - -@Service -@Slf4j -public class StateServiceImpl implements StateService { - - @Autowired - private StateMapper stateMapper; - - @Autowired - private StateService stateService; - - @Override - public void createStateList(List<State> stateList, String expectationId) { - int res = stateMapper.insertStateList(stateList, expectationId); - if (res < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public List<State> getStateListByExpectationId(String expectationId) { - List<State> stateList = stateMapper.selectStateByExpectation(expectationId); - if (stateList == null) { - String msg = String.format("State: Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - return stateList; - } - - @Override - public void deleteStateListByExpectationId(String expectationId) { - if (stateMapper.deleteStateByExpectationId(expectationId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } - - @Override - public void updateStateListByExpectationId(List<State> stateList, String expectationId) { - List<State> stateDBList = stateMapper.selectStateByExpectation(expectationId); - if (stateDBList == null) { - String msg = String.format("Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - List<String> stateDBIdList = new ArrayList<>(); - for (State stateDB : stateDBList) { - stateDBIdList.add(stateDB.getStateId()); - } - for (State state : stateList) { - if (stateDBIdList.contains(state.getStateId())) { - int res = stateMapper.updateState(state); - if (res < 1) { - String msg = "Update state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); - } - stateDBIdList.remove(state.getStateId()); - } else { - stateService.createState(state, expectationId); - } - } - for (String stateDBId : stateDBIdList) { - stateService.deleteStateById(stateDBId); - } - log.info("States are successfully updated."); - } - - @Override - public void createState(State state, String expectationId) { - if (stateMapper.insertState(state, expectationId) < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public void deleteStateById(String stateId) { - if (stateMapper.deleteStateById(stateId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } -}
\ No newline at end of file diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/RestfulServices.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/RestfulServices.java index ff51dc4..eca627a 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/RestfulServices.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/RestfulServices.java @@ -13,11 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.usecaseui.intentanalysis.util; +import javax.annotation.Nullable; +import okhttp3.Authenticator; +import okhttp3.Credentials; import okhttp3.MediaType; import okhttp3.OkHttpClient; +import okhttp3.Request; import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.Route; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import retrofit2.Retrofit; @@ -35,48 +42,47 @@ public class RestfulServices { private static final Logger logger = LoggerFactory.getLogger(RestfulServices.class); private static final String DEFAULT_MSB_IAG_ADDRESS = "msb-iag.onap:443"; + private static final String ENV_MSB_IAG_SERVICE_HOST = "MSB_IAG_SERVICE_HOST"; - private static final String ENV_MSB_IAG_SERVICE_PORT = "MSB_IAG_SERVICE_PORT"; + private static final String ENV_MSB_IAG_SERVICE_PORT = "MSB_IAG_SERVICE_PORT"; public static <T> T create(String baseUrl, Class<T> clazz) { - Retrofit retrofit = new Retrofit.Builder() - .baseUrl(baseUrl) - .addConverterFactory(JacksonConverterFactory.create()) - .build(); + Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl) + .addConverterFactory(JacksonConverterFactory.create()).build(); return retrofit.create(clazz); } - public static <T> T create(Class<T> clazz) { + public static <T> T create(Class<T> clazz, final String userName, final String passWord) { //Set the interface response time - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .connectTimeout(300, TimeUnit.SECONDS) - .readTimeout(300, TimeUnit.SECONDS) - .sslSocketFactory(getSSLSocketFactory(), new CustomTrustManager()) - .hostnameVerifier(getHostnameVerifier()) - .build(); + OkHttpClient okHttpClient = new OkHttpClient.Builder().authenticator(new Authenticator() { + @Nullable + @Override + public Request authenticate(@Nullable Route route, Response response) throws IOException { + String authStr = Credentials.basic(userName, passWord); + return response.request().newBuilder().addHeader("Authorization", authStr).build(); + } + }).connectTimeout(300, TimeUnit.SECONDS).readTimeout(300, TimeUnit.SECONDS) + .sslSocketFactory(getSSLSocketFactory(), new CustomTrustManager()).hostnameVerifier(getHostnameVerifier()) + .build(); String msbUrl = getMSBIAGAddress(); - Retrofit retrofit = new Retrofit.Builder() - .baseUrl("https://" + msbUrl + "/") - .client(okHttpClient) - .addConverterFactory(JacksonConverterFactory.create()) - .build(); + Retrofit retrofit = new Retrofit.Builder().baseUrl("https://" + msbUrl + "/").client(okHttpClient) + .addConverterFactory(JacksonConverterFactory.create()).build(); return retrofit.create(clazz); } - public static String getMSBIAGAddress(){ + public static String getMSBIAGAddress() { String iagAddress = System.getenv(ENV_MSB_IAG_SERVICE_HOST); String iagPort = System.getenv(ENV_MSB_IAG_SERVICE_PORT); - if(iagAddress == null || iagPort == null){ + if (iagAddress == null || iagPort == null) { return DEFAULT_MSB_IAG_ADDRESS; } return iagAddress + ":" + iagPort; } - public static RequestBody extractBody(HttpServletRequest request) throws IOException { BufferedReader br = null; StringBuilder sb = new StringBuilder(""); @@ -104,7 +110,7 @@ public class RestfulServices { try { SSLContext sc = SSLContext.getInstance("TLS"); - sc.init(null, new TrustManager[]{new CustomTrustManager()}, new SecureRandom()); + sc.init(null, new TrustManager[] {new CustomTrustManager()}, new SecureRandom()); ssfFactory = sc.getSocketFactory(); } catch (Exception e) { @@ -114,7 +120,7 @@ public class RestfulServices { } public static HostnameVerifier getHostnameVerifier() { - HostnameVerifier hostnameVerifier= new HostnameVerifier() { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } diff --git a/intentanalysis/src/main/resources/application.yaml b/intentanalysis/src/main/resources/application.yaml index 4dbd108..39b03ae 100644 --- a/intentanalysis/src/main/resources/application.yaml +++ b/intentanalysis/src/main/resources/application.yaml @@ -16,3 +16,14 @@ mybatis: configuration: database-id: PostgreSQL mapper-locations: classpath*:mybatis/sql/*.xml + +rest: + policy: + username: policyadmin + password: zb!XztG34 + so: + username: InfraPortalClient + password: password1$ + aai: + username: AAI + password: AAI diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml index c5d3b3d..57c8952 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml @@ -34,7 +34,7 @@ <select id="getIntentByName" resultType="org.onap.usecaseui.intentanalysis.bean.models.Intent"> select intent_id intentId, intent_name intentName from intent - where intent_name like "%"#{intent.intentName}"%" + where intent_name like #{intentName} </select> </mapper>
\ No newline at end of file diff --git a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml deleted file mode 100644 index d103015..0000000 --- a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.StateMapper"> - - <select id="selectStateByExpectation" resultType="org.onap.usecaseui.intentanalysis.bean.models.State"> - select state_id stateId, state_name stateName, condition, - is_satisfied isSatisfied - from state - where expectation_id = #{expectationId} - </select> - - <insert id="insertStateList" parameterType="java.util.ArrayList"> - <if test="stateList != null"> - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values - <foreach collection="stateList" index="index" item="item" separator=","> - (#{item.stateId}, #{item.stateName}, #{expectationId}, #{item.isSatisfied}, #{item.condition}) - </foreach> - </if> - </insert> - - <delete id="deleteStateByExpectationId"> - delete - from state - where expectation_id = #{expectationId} - </delete> - - <insert id="insertState"> - <if test="state != null"> - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values (#{state.stateId}, #{state.stateName}, #{expectationId}, #{state.isSatisfied}, #{state.condition}) - </if> - </insert> - - <update id="updateState" parameterType="java.util.List"> - update state - <trim prefix="set" suffixOverrides=","> - <if test="stateName != null">state_name = #{stateName},</if> - <if test="isSatisfied != null">is_satisfied = #{isSatisfied},</if> - <if test="condition != null">condition = #{condition},</if> - </trim> - where state_id = #{stateId} - </update> - - <delete id="deleteStateById"> - delete - from state - where state_id = #{stateId} - </delete> - -</mapper>
\ No newline at end of file diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/IntentAnalysisApplicationTests.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplicationTests.java index 529f08d..965ec6d 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/IntentAnalysisApplicationTests.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplicationTests.java @@ -12,7 +12,7 @@ * the License. */ -package org.onap.usecaseui.intentanalysis.test; +package org.onap.usecaseui.intentanalysis; import java.io.IOException; import javax.servlet.FilterChain; diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/policy/PolicyServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/policy/PolicyServiceTest.java new file mode 100644 index 0000000..ea253e7 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/policy/PolicyServiceTest.java @@ -0,0 +1,182 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.onap.usecaseui.intentanalysis.adapters.policy; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +import java.io.IOException; +import mockit.MockUp; +import okhttp3.MediaType; +import okhttp3.ResponseBody; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; +import org.onap.usecaseui.intentanalysis.adapters.policy.impl.PolicyServiceImpl; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.onap.usecaseui.intentanalysis.util.TestCall; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class PolicyServiceTest { + + private static final int CREATE_POLICY_TYPE_FAILED = 0x01; + + private static final int CREATE_POLICY_FAILED = 0x02; + + private static final int DEPLOY_POLICY_FAILED = 0x04; + + private static final int UNDEPLOY_POLICY_FAILED = 0x08; + + private static final int DELETE_POLICY_FAILED = 0x10; + + private static final int QUERY_POLICY_NOT_EXIST = 0x20; + + private static final Logger LOGGER = LoggerFactory.getLogger(PolicyServiceTest.class); + + @Autowired + private PolicyServiceImpl policyService; + + private PolicyAPICall policyAPICall; + + private MockUp mockup; + + @Test + public void testCreateAndDeployCLLPolicySuccess() throws IOException { + mockUpPolicyApiCall(0); + boolean result = policyService.createAndDeployModifyCLLPolicy(); + Assert.assertTrue(result); + } + + + @Test + public void testCreateAndDeployCLLPolicyFailedCreateFailed() throws IOException { + mockUpPolicyApiCall(CREATE_POLICY_FAILED); + boolean result = policyService.createAndDeployModifyCLLPolicy(); + Assert.assertFalse(result); + } + + @Test + public void testCreateAndDeployCLLPolicyFailedDeployFailed() throws IOException { + mockUpPolicyApiCall(DEPLOY_POLICY_FAILED); + boolean result = policyService.createAndDeployModifyCLLPolicy(); + Assert.assertFalse(result); + } + + @Test + public void testUndeployAndRemoveCLLPolicySuccess() throws IOException { + mockUpPolicyApiCall(0); + boolean result = policyService.undeployAndRemoveModifyCLLPolicy(); + Assert.assertTrue(result); + } + + @Test + public void testUndeployAndRemoveCLLPolicySuccessPolicyNotExist() throws IOException { + mockUpPolicyApiCall(QUERY_POLICY_NOT_EXIST); + boolean result = policyService.undeployAndRemoveModifyCLLPolicy(); + Assert.assertTrue(result); + } + + @Test + public void testUpdateIntentConfigPolicySuccess() throws IOException { + mockUpPolicyApiCall(0); + boolean result = policyService.updateIntentConfigPolicy("testCLLID", "1000", true); + Assert.assertTrue(result); + } + + @Test + public void testUpdateIntentConfigPolicySuccessPolicyNotExist(){ + mockUpPolicyApiCall(QUERY_POLICY_NOT_EXIST); + boolean result = policyService.updateIntentConfigPolicy("testCLLID", "1000", true); + Assert.assertTrue(result); + } + + @Test + public void testUpdateIntentConfigPolicyFailedCreatePolicyTypeFailed(){ + mockUpPolicyApiCall(CREATE_POLICY_TYPE_FAILED); + boolean result = policyService.updateIntentConfigPolicy("testCLLID", "1000", true); + Assert.assertFalse(result); + } + + @Test + public void testUpdateIntentConfigPolicyFailedCreatePolicyFailed(){ + mockUpPolicyApiCall(CREATE_POLICY_FAILED); + boolean result = policyService.updateIntentConfigPolicy("testCLLID", "1000", true); + Assert.assertFalse(result); + } + + @Test + public void testUpdateIntentConfigPolicyFailedDeployPolicyFailed(){ + mockUpPolicyApiCall(DEPLOY_POLICY_FAILED); + boolean result = policyService.updateIntentConfigPolicy("testCLLID", "1000", true); + Assert.assertFalse(result); + } + + private void mockUpPolicyApiCall(int failedFlag) { + policyAPICall = mock(PolicyAPICall.class); + policyService.setPolicyAPICall(policyAPICall); + ResponseBody mockedSuccessResponse = ResponseBody.create(MediaType.parse("application/json"), + "Test Success Result"); + if ((CREATE_POLICY_FAILED & failedFlag) > 0) { + when(policyAPICall.createPolicy(anyString(), anyString(), any())).thenReturn( + TestCall.failedCall("Create policy failed")); + } else { + when(policyAPICall.createPolicy(anyString(), anyString(), any())).thenReturn( + TestCall.successfulCall(mockedSuccessResponse)); + } + if ((CREATE_POLICY_TYPE_FAILED & failedFlag) > 0) { + when(policyAPICall.createPolicyType(any())).thenReturn(TestCall.failedCall("Create policy type failed")); + } else { + when(policyAPICall.createPolicyType(any())).thenReturn(TestCall.successfulCall(mockedSuccessResponse)); + } + + if ((DEPLOY_POLICY_FAILED & failedFlag) > 0) { + when(policyAPICall.deployPolicy(any())).thenReturn(TestCall.failedCall("Deploy policy failed")); + } else { + when(policyAPICall.deployPolicy(any())).thenReturn(TestCall.successfulCall(mockedSuccessResponse)); + } + + if ((UNDEPLOY_POLICY_FAILED & failedFlag) > 0) { + when(policyAPICall.undeployPolicy(anyString())).thenReturn(TestCall.failedCall("Undeploy policy failed")); + } else { + when(policyAPICall.undeployPolicy(anyString())).thenReturn(TestCall.successfulCall(mockedSuccessResponse)); + } + + if ((DELETE_POLICY_FAILED & failedFlag) > 0) { + when(policyAPICall.removePolicy(anyString(), anyString())).thenReturn( + TestCall.failedCall("Delete policy failed")); + } else { + when(policyAPICall.removePolicy(anyString(), anyString())).thenReturn( + TestCall.successfulCall(mockedSuccessResponse)); + } + + if ((QUERY_POLICY_NOT_EXIST & failedFlag) > 0) { + when(policyAPICall.getPolicy(anyString(), anyString(), anyString(), anyString())).thenReturn( + TestCall.failedCall("Get policy failed")); + } else { + when(policyAPICall.getPolicy(anyString(), anyString(), anyString(), anyString())).thenReturn( + TestCall.successfulCall(mockedSuccessResponse)); + } + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ConditionTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ConditionTest.java new file mode 100644 index 0000000..49f2cb5 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ConditionTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType; + +import java.util.ArrayList; + +public class ConditionTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testSetConditionTest() throws Exception { + Condition condition = new Condition(); + condition.setConditionId(""); + condition.setConditionName(""); + condition.setOperator(OperatorType.valueOf("OR")); + condition.setConditionValue(""); + condition.setConditionList(new ArrayList<Condition>()); + } + + @Test + public void testGetConditionTest() throws Exception{ + Condition condition = new Condition(); + condition.getConditionId(); + condition.getConditionName(); + condition.getOperator(); + condition.getConditionValue(); + condition.getConditionList(); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ContextTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ContextTest.java new file mode 100644 index 0000000..5ead1c8 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ContextTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class ContextTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + @Test + public void testGetContestTest(){ + Context context = new Context(); + context.getContextId(); + context.getContextName(); + context.getContextConditions(); + } + @Test + public void testSetContestTest(){ + Context context = new Context(); + context.setContextId(""); + context.setContextName(""); + context.setContextConditions(new ArrayList<Condition>()); + } + +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationObjectTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationObjectTest.java new file mode 100644 index 0000000..52d8fbc --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationObjectTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType; + +import java.util.ArrayList; + +public class ExpectationObjectTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetExpectationObjectTest() { + ExpectationObject test = new ExpectationObject(); + test.getObjectType(); + test.getObjectInstance(); + test.getObjectContexts(); + } + + @Test + public void testSetExpectationObjectTest() { + ExpectationObject test = new ExpectationObject(); + test.setObjectType(ObjectType.OBJECT1); + test.setObjectInstance(""); + test.setObjectContexts(new ArrayList<>()); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTargetTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTargetTest.java new file mode 100644 index 0000000..e879b11 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTargetTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; + +import java.util.ArrayList; + +public class ExpectationTargetTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetExpectationTest() { + Expectation test = new Expectation(); + test.getExpectationId(); + test.getExpectationName(); + test.getExpectationType(); + test.getExpectationObject(); + test.getExpectationTargets(); + test.getExpectationContexts(); + test.getExpectationFulfilmentInfo(); + } + + @Test + public void testSetExpectationTest() { + Expectation test = new Expectation(); + test.setExpectationId(""); + test.setExpectationName(""); + test.setExpectationType(ExpectationType.ASSURANCE); + test.setExpectationObject(new ExpectationObject()); + test.setExpectationTargets(new ArrayList<>()); + test.setExpectationContexts(new ArrayList<>()); + test.setExpectationFulfilmentInfo(new FulfilmentInfo()); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTest.java new file mode 100644 index 0000000..a3c2a09 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; + +import java.util.ArrayList; + +public class ExpectationTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetExpectationTest() { + Expectation test = new Expectation(); + test.getExpectationId(); + test.getExpectationContexts(); + test.getExpectationName(); + test.getExpectationType(); + test.getExpectationFulfilmentInfo(); + test.getExpectationObject(); + test.getExpectationTargets(); + } + + @Test + public void testSetExpectationTest() { + Expectation test = new Expectation(); + test.setExpectationId(""); + test.setExpectationContexts(new ArrayList<Context>()); + test.setExpectationName(""); + test.setExpectationTargets(new ArrayList<ExpectationTarget>()); + test.setExpectationType(ExpectationType.ASSURANCE); + test.setExpectationFulfilmentInfo(new FulfilmentInfo()); + test.setExpectationObject(new ExpectationObject()); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/FulfilmentInfoTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/FulfilmentInfoTest.java new file mode 100644 index 0000000..24529fd --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/FulfilmentInfoTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.FulfilmentStatus; +import org.onap.usecaseui.intentanalysis.bean.enums.NotFulfilledState; + +public class FulfilmentInfoTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetFulfilmentInfoTest() { + FulfilmentInfo test = new FulfilmentInfo(); + test.getFulfilmentStatus(); + test.getNotFulfilledState(); + test.getNotFulfilledReason(); + + } + + @Test + public void testSetFulfilmentInfoTest() { + FulfilmentInfo test = new FulfilmentInfo(); + test.setFulfilmentStatus(FulfilmentStatus.FULFILLED); + test.setNotFulfilledState(NotFulfilledState.ACKNOWLEDGED); + test.setNotFulfilledReason(""); + + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBeanTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBeanTest.java new file mode 100644 index 0000000..8a5ac8a --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentGoalBeanTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; + +public class IntentGoalBeanTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetIntentGoalBeanTest() { + IntentGoalBean test = new IntentGoalBean(); + test.getIntent(); + test.getIntentGoalType(); + } + + @Test + public void testSetIntentGoalBeanTest() { + IntentGoalBean test = new IntentGoalBean(); + test.setIntent(new Intent()); + test.setIntentGoalType(IntentGoalType.DELETE); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentManagementFunctionRegInfoTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentManagementFunctionRegInfoTest.java new file mode 100644 index 0000000..2368077 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentManagementFunctionRegInfoTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentFunctionType; +import org.onap.usecaseui.intentanalysis.bean.enums.SupportArea; + +import java.util.ArrayList; + +public class IntentManagementFunctionRegInfoTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetIntentManagementFunctionRegInfoTest() { + IntentManagementFunctionRegInfo test = new IntentManagementFunctionRegInfo(); + test.getId(); + test.getDescription(); + test.getSupportArea(); + test.getSupportModel(); + test.getSupportInterfaces(); + test.getHandleName(); + test.getIntentFunctionType(); + + } + + @Test + public void testSetIntentManagementFunctionRegInfoTest() { + IntentManagementFunctionRegInfo test = new IntentManagementFunctionRegInfo(); + test.setId(""); + test.setDescription(""); + test.setSupportArea(new ArrayList<SupportArea>()); + test.setSupportModel(""); + test.setSupportInterfaces(new ArrayList<>()); + test.setHandleName(""); + test.setIntentFunctionType(IntentFunctionType.INTERNALFUNCTION); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentTest.java new file mode 100644 index 0000000..33609e9 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/IntentTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class IntentTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetIntentTest() { + Intent test = new Intent(); + test.getIntentId(); + test.getIntentName(); + test.getIntentExpectations(); + test.getIntentContexts(); + test.getIntentFulfilmentInfo(); + } + + @Test + public void testSetIntentTest() { + Intent test = new Intent(); + test.setIntentId(""); + test.setIntentName(""); + test.setIntentExpectations(new ArrayList<Expectation>()); + test.setIntentContexts(new ArrayList<Context>()); + test.setIntentFulfilmentInfo(new FulfilmentInfo()); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/StateTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/StateTest.java new file mode 100644 index 0000000..e04ea3a --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/StateTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.bean.models; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class StateTest { + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + } + + @Test + public void testGetStateTest() { + State test = new State(); + test.getStateId(); + test.getStateName(); + test.getCondition(); + test.getIsSatisfied(); + + } + + @Test + public void testSetStateTest() { + State test = new State(); + test.setStateId(""); + test.setStateName(""); + test.setCondition(""); + test.setIsSatisfied(true); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/IntentServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/IntentServiceTest.java new file mode 100644 index 0000000..9e93b87 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/IntentServiceTest.java @@ -0,0 +1,170 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.onap.usecaseui.intentanalysis.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.usecaseui.intentanalysis.bean.enums.*; +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.Condition; +import org.onap.usecaseui.intentanalysis.bean.models.FulfilmentInfo; +import org.onap.usecaseui.intentanalysis.bean.models.Context; +import org.onap.usecaseui.intentanalysis.bean.models.Expectation; +import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget; +import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.onap.usecaseui.intentanalysis.util.SpringContextUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class IntentServiceTest extends AbstractJUnit4SpringContextTests { + + private static final Logger LOGGER = LoggerFactory.getLogger(IntentServiceTest.class); + + private static final String TEST_INTENT_ID_1 = "intentId1"; + + private static final String TEST_INTENT_ID_2 = "intentId2"; + + private static final String TEST_INTENT_NAME = "CLL Business intent"; + + @Autowired + private IntentService intentService; + + @Before + public void setUp() { + SpringContextUtil.setApplicationContext(applicationContext); + } + + @Test + public void testCreateIntentSuccess() throws IOException { + Intent intent = new Intent(); + Expectation expectation1 = new Expectation(); + ExpectationTarget target1 = new ExpectationTarget(); + ExpectationObject object1 = new ExpectationObject(); + Context intentContext = new Context(); + FulfilmentInfo intentFulfilmentInfo = new FulfilmentInfo(); + Condition targetCondition1 = new Condition(); + targetCondition1.setConditionId("conditionId"); + targetCondition1.setConditionName("conditionName"); + targetCondition1.setOperator(OperatorType.valueOf("EQUALTO")); + targetCondition1.setConditionValue("conditionValue"); + List<Condition> targetConditionList = new ArrayList<>(); + targetConditionList.add(targetCondition1); + target1.setTargetId("targetId"); + target1.setTargetName("targetName"); + target1.setTargetConditions(targetConditionList); + List<ExpectationTarget> expectationTargetList = new ArrayList<>(); + expectationTargetList.add(target1); + object1.setObjectType(ObjectType.valueOf("OBJECT1")); + object1.setObjectInstance("objectInstance"); + expectation1.setExpectationId("expectationId"); + expectation1.setExpectationName("expectationName"); + expectation1.setExpectationType(ExpectationType.valueOf("DELIVERY")); + expectation1.setExpectationObject(object1); + expectation1.setExpectationTargets(expectationTargetList); + List<Expectation> expectationList = new ArrayList<>(); + expectationList.add(expectation1); + intentContext.setContextId("intentContextId"); + intentContext.setContextName("intentContextName"); + List<Context> intentContextList = new ArrayList<>(); + intentContextList.add(intentContext); + intentFulfilmentInfo.setFulfilmentStatus(FulfilmentStatus.valueOf("NOT_FULFILLED")); + intentFulfilmentInfo.setNotFulfilledReason("NotFulfilledReason"); + intentFulfilmentInfo.setNotFulfilledState(NotFulfilledState.valueOf("COMPLIANT")); + intent.setIntentId("testIntentId"); + intent.setIntentName("testIntentName"); + intent.setIntentContexts(intentContextList); + intent.setIntentExpectations(expectationList); + intent.setIntentFulfilmentInfo(intentFulfilmentInfo); + + Intent intentTmp = intentService.createIntent(intent); + Assert.assertNotNull(intentTmp); + } + + @Test + public void testGetIntentListSuccess() { + List<Intent> intentList = intentService.getIntentList(); + Assert.assertNotNull(intentList); + } + + @Test + public void testGetIntentSuccess() { + Intent intent = intentService.getIntent(TEST_INTENT_ID_1); + Assert.assertNotNull(intent); + } + + @Test + public void testGetIntentByNameSuccess() { + List<Intent> intentList = intentService.getIntentByName(TEST_INTENT_NAME); + Assert.assertNotNull(intentList); + + } + + @Test + public void testUpdateIntentSuccess() { + Intent intent = intentService.getIntent(TEST_INTENT_ID_1); + intent.setIntentName("new intent name"); + List<Context> contextList = intent.getIntentContexts(); + Context intentContext = contextList.get(0); + intentContext.setContextName("new context name"); + contextList.set(0, intentContext); + intent.setIntentContexts(contextList); + FulfilmentInfo intentFulfilmentInfo = intent.getIntentFulfilmentInfo(); + intentFulfilmentInfo.setNotFulfilledReason("new reason"); + intent.setIntentFulfilmentInfo(intentFulfilmentInfo); + List<Expectation> expectationList = intent.getIntentExpectations(); + Expectation expectation = expectationList.get(0); + expectation.setExpectationName("new expectation name"); + ExpectationObject expectationObject = expectation.getExpectationObject(); + expectationObject.setObjectInstance("new object instance"); + expectation.setExpectationObject(expectationObject); + List<ExpectationTarget> expectationTargetList = expectation.getExpectationTargets(); + ExpectationTarget expectationTarget = expectationTargetList.get(0); + expectationTarget.setTargetName("new target name"); + List<Condition> targetConditionList = expectationTarget.getTargetConditions(); + Condition targetCondition = targetConditionList.get(0); + targetCondition.setConditionName("new conditon name"); + targetConditionList.set(0, targetCondition); + expectationTarget.setTargetConditions(targetConditionList); + expectationTargetList.remove(2); + expectationTargetList.set(0, expectationTarget); + expectation.setExpectationTargets(expectationTargetList); + expectationList.set(0, expectation); + intent.setIntentExpectations(expectationList); + + Intent updatedIntent = intentService.updateIntent(intent); + Assert.assertEquals("new intent name", updatedIntent.getIntentName()); + + } + + @Test + public void testDeleteIntentSuccess() { + intentService.deleteIntent(TEST_INTENT_ID_2); + Intent intent = intentService.getIntent(TEST_INTENT_ID_2); + Assert.assertNull(intent); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java deleted file mode 100644 index 3a692c0..0000000 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.onap.usecaseui.intentanalysis.test.service; - -import java.io.IOException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.usecaseui.intentanalysis.bean.models.Intent; -import org.onap.usecaseui.intentanalysis.service.IntentService; -import org.onap.usecaseui.intentanalysis.test.IntentAnalysisApplicationTests; -import org.onap.usecaseui.intentanalysis.util.SpringContextUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringRunner; - -@SpringBootTest(classes = IntentAnalysisApplicationTests.class) -@RunWith(SpringRunner.class) -public class IntentServiceTest extends AbstractJUnit4SpringContextTests { - - private static final Logger LOGGER = LoggerFactory.getLogger(IntentServiceTest.class); - - @Autowired - private IntentService intentService; - - @Before - public void setUp() { - SpringContextUtil.setApplicationContext(applicationContext); - } - - @Test - public void testCreateIntentSuccess() throws IOException { - Intent intent = new Intent(); - intent.setIntentId("testUUID"); - intent.setIntentName("testIntentName"); - //ToDo - //Intent intentTmp = intentService.createIntent(intent); - Assert.assertNotNull(intent); - } -} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/RestFulServicesTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/RestFulServicesTest.java new file mode 100644 index 0000000..b19e9a1 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/RestFulServicesTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.onap.usecaseui.intentanalysis.util; + +import java.io.IOException; +import javax.servlet.http.HttpServletRequest; + +import okhttp3.RequestBody; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class RestFulServicesTest { + + @Test + public void testCreateSuccess() { + PolicyAPICall call = RestfulServices.create("https://localhost/testurl/", PolicyAPICall.class); + Assert.assertNotNull(call); + } + + @Test + public void testCreateWithAuthSuccess() { + PolicyAPICall call = RestfulServices.create(PolicyAPICall.class, "testUser", "testPwd"); + Assert.assertNotNull(call); + } + + @Test + public void testGetMSBAddressSuccess() { + String msbAddress = RestfulServices.getMSBIAGAddress(); + Assert.assertNotNull(msbAddress); + } + + @Test + public void testExtractBodySuccess() throws IOException { + HttpServletRequest request = new MockHttpServletRequest(); + RequestBody requestBody = RestfulServices.extractBody(request); + Assert.assertNotNull(requestBody); + } +} diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/TestCall.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/TestCall.java new file mode 100644 index 0000000..5454097 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/TestCall.java @@ -0,0 +1,92 @@ +/* + * Copyright 2022 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.onap.usecaseui.intentanalysis.util; + +import java.io.IOException; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class TestCall<T> implements Call<T> { + + private int code; + + private T result; + + private String errorMsg; + + private TestCall(int code, T result, String errorMsg) { + this.code = code; + this.result = result; + this.errorMsg = errorMsg; + } + + @Override + public Response<T> execute() throws IOException { + if (code >= 200 && code < 300) { + return Response.success(code, result); + } + if (code >= 400 && code < 500) { + return Response.error(code, ResponseBody.create(MediaType.parse("application/json"), errorMsg)); + } + throw new IOException("Exception happens"); + } + + public static <T> TestCall<T> successfulCall(T result) { + return new TestCall<>(200, result, null); + } + + public static <T> TestCall<T> failedCall(String errorMsg) { + return new TestCall<>(400, null, errorMsg); + } + + public static <T> TestCall<T> exceptionCall() { + return new TestCall<>(-1, null, null); + } + + @Override + public void enqueue(Callback<T> callback) { + + } + + @Override + public boolean isExecuted() { + return false; + } + + @Override + public void cancel() { + + } + + @Override + public boolean isCanceled() { + return false; + } + + @Override + public Call<T> clone() { + return null; + } + + @Override + public Request request() { + return null; + } + +} diff --git a/intentanalysis/src/test/resources/application.yaml b/intentanalysis/src/test/resources/application.yaml index 8ddc4d8..aa317ef 100644 --- a/intentanalysis/src/test/resources/application.yaml +++ b/intentanalysis/src/test/resources/application.yaml @@ -29,10 +29,12 @@ spring: username: password: driver-class-name: org.h2.Driver - schema: classpath:intentdb-test-init.sql - data: classpath:intentdb-test-data.sql main: allow-bean-definition-overriding: true + sql: + init: + schema-locations: classpath:intentdb-test-init.sql + data-locations: classpath:intentdb-test-data.sql ###mybtis#### mybatis: @@ -42,3 +44,14 @@ security: resource: jwt: key-value: test + +rest: + policy: + username: policyadmin + password: zb!XztG34 + so: + username: InfraPortalClient + password: password1$ + aai: + username: AAI + password: AAI
\ No newline at end of file diff --git a/intentanalysis/src/test/resources/intentdb-test-data.sql b/intentanalysis/src/test/resources/intentdb-test-data.sql index 14cbefc..058e055 100644 --- a/intentanalysis/src/test/resources/intentdb-test-data.sql +++ b/intentanalysis/src/test/resources/intentdb-test-data.sql @@ -16,7 +16,74 @@ */ -- ---------------------------- -MERGE INTO intent (intent_id, intent_name)KEY(intent_id)values ('1234','test-intent'); +-- Records of intent +-- ---------------------------- +MERGE INTO intent (intent_id, intent_name) KEY (intent_id) +values ('intentId1', 'CLL Business intent'); +MERGE INTO intent (intent_id, intent_name) KEY (intent_id) +values ('intentId2', 'CLL Business intent'); + +-- ---------------------------- +-- Records of expectation +-- ---------------------------- +MERGE INTO expectation (expectation_id, expectation_name, expectation_type, intent_id) KEY (expectation_id) +values ('expectationId1', 'CLL Service Expectation', 'DELIVERY', 'intentId1'); +MERGE INTO expectation (expectation_id, expectation_name, expectation_type, intent_id) KEY (expectation_id) +values ('expectationId2', 'CLL Assurance Expectation', 'ASSURANCE', 'intentId1'); +MERGE INTO expectation (expectation_id, expectation_name, expectation_type, intent_id) KEY (expectation_id) +values ('expectationId3', 'CLL Service Expectation', 'DELIVERY', 'intentId2'); + +-- ---------------------------- +-- Records of expectation_object +-- ---------------------------- +MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id) +values ('b1bc45a6-f396-4b65-857d-6d2312bfb352', 'OBJECT1', '', 'expectationId1'); +MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id) +values ('931a8690-fa61-4c2b-a387-9e0fa6152136', 'OBJECT2', '', 'expectationId2'); +MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id) +values ('3f36bf22-3416-4150-8005-cdc406a43310', 'OBJECT2', '', 'expectationId3'); + +-- ---------------------------- +-- Records of expectation_target +-- ---------------------------- +MERGE INTO expectation_target (target_id, target_name, expectation_id) KEY (target_id) +values ('target1-1', 'source', 'expectationId1'); +MERGE INTO expectation_target (target_id, target_name, expectation_id) KEY (target_id) +values ('target1-2', 'destination', 'expectationId1'); +MERGE INTO expectation_target (target_id, target_name, expectation_id) KEY (target_id) +values ('target1-3', 'bandwidth', 'expectationId1'); +MERGE INTO expectation_target (target_id, target_name, expectation_id) KEY (target_id) +values ('target2-1', 'bandwidthAssurance', 'expectationId2'); +MERGE INTO expectation_target (target_id, target_name, expectation_id) KEY (target_id) +values ('target3-1', 'source', 'expectationId3'); +-- ---------------------------- +-- Records of condition +-- ---------------------------- +MERGE INTO condition (condition_id, condition_name, operator_type, condition_value, parent_id) KEY (condition_id) +values ('condition1-1', 'condition of the cll service source', 'EQUALTO', 'Company A', 'target1-1'); +MERGE INTO condition (condition_id, condition_name, operator_type, condition_value, parent_id) KEY (condition_id) +values ('condition1-2', 'condition of the cll service destination', 'EQUALTO', 'Cloud 1', 'target1-2'); +MERGE INTO condition (condition_id, condition_name, operator_type, condition_value, parent_id) KEY (condition_id) +values ('condition1-3', 'condition of the cll service bandwidth', 'EQUALTO', '1000', 'target1-3'); +MERGE INTO condition (condition_id, condition_name, operator_type, condition_value, parent_id) KEY (condition_id) +values ('condition2-1', 'condition of the cll service bandwidth', 'EQUALTO', 'true', 'target2-1'); +MERGE INTO condition (condition_id, condition_name, operator_type, condition_value, parent_id) KEY (condition_id) +values ('condition3-1', 'condition of the cll service source', 'EQUALTO', 'Company A', 'target3-1'); + +-- ---------------------------- +-- Records of context +-- ---------------------------- +MERGE INTO context (context_id, context_name, parent_id) KEY (context_id) +values ('d64f3a5f-b091-40a6-bca0-1bc6b1ce8f43', 'intentContextName', 'intentId1'); +MERGE INTO context (context_id, context_name, parent_id) KEY (context_id) +values ('72f6c546-f234-4be5-a2fe-5740139e20cb', 'intentContextName', 'intentId2'); + +-- ---------------------------- +-- Records of fulfilment_info +-- ---------------------------- +MERGE INTO fulfilment_info (fulfilment_info_id, fulfilment_info_status, not_fulfilled_state, not_fulfilled_reason) KEY (fulfilment_info_id) +values ('intentId1', 'NOT_FULFILLED', 'COMPLIANT', 'NotFulfilledReason'); +MERGE INTO fulfilment_info (fulfilment_info_id, fulfilment_info_status, not_fulfilled_state, not_fulfilled_reason) KEY (fulfilment_info_id) +values ('intentId2', 'NOT_FULFILLED', 'COMPLIANT', 'NotFulfilledReason'); -MERGE INTO expectation (expectation_id, expectation_name, target_moi, intent_id)KEY(expectation_id)values ('2234','test-expectation',null, '1234'); diff --git a/intentanalysis/src/test/resources/intentdb-test-init.sql b/intentanalysis/src/test/resources/intentdb-test-init.sql index b84f8e3..211e1cb 100644 --- a/intentanalysis/src/test/resources/intentdb-test-init.sql +++ b/intentanalysis/src/test/resources/intentdb-test-init.sql @@ -14,29 +14,67 @@ Date: 30/12/2019 14:40:23 */ -DROP TABLE IF EXISTS intent; -DROP TABLE IF EXISTS expectation; -DROP TABLE IF EXISTS state; - -CREATE TABLE if NOT EXISTS intent( - intent_id varchar(255), - intent_name varchar(255), - CONSTRAINT intent_test_task_pkey PRIMARY KEY (intent_id) +//CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +DROP TABLE IF EXISTS intent; +DROP TABLE IF EXISTS expectation; +DROP TABLE IF EXISTS expectation_object; +DROP TABLE IF EXISTS expectation_target; +DROP TABLE IF EXISTS context; +DROP TABLE IF EXISTS fulfilment_info; +DROP TABLE IF EXISTS condition; + +create table if not exists intent +( + intent_id varchar(255) primary key, + intent_name varchar(255) ); -create table if not exists expectation( - expectation_id varchar(255), +create table if not exists expectation +( + expectation_id varchar(255) primary key, expectation_name varchar(255), - target_moi varchar(255), - intent_id varchar(255), - CONSTRAINT expectation_test_task_pkey PRIMARY KEY (expectation_id) + expectation_type varchar(255), + intent_id varchar(255) +); + +create table if not exists expectation_object +( + object_id varchar(255) DEFAULT random_uuid(), + primary key (object_id), + object_type varchar(255), + object_instance varchar(255), + expectation_id varchar(255) +); + +create table if not exists expectation_target +( + target_id varchar(255) primary key, + target_name varchar(255), + expectation_id varchar(255) ); -create table if not exists state( - state_id varchar(255), - state_name varchar(255), - is_satisfied boolean, - condition varchar(255), - expectation_id varchar(255), - CONSTRAINT state_test_task_pkey PRIMARY KEY (state_id) +create table if not exists context +( + context_id varchar(255) primary key, + context_name varchar(255), + parent_id varchar(255) ); + +create table if not exists fulfilment_info +( + fulfilment_info_id varchar(255) primary key, + fulfilment_info_status varchar(255), + not_fulfilled_state varchar(255), + not_fulfilled_reason varchar(255) +); + +create table if not exists condition +( + condition_id varchar(255) primary key, + condition_name varchar(255), + operator_type varchar(255), + condition_value varchar(255), + parent_id varchar(255) +); + |