ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
expectationObject.setObjectInstance((String) params.get("name"));
+ intent.getIntentExpectations().get(0).getExpectationObject().setObjectInstance((String) params.get("name"));
expectationObjectService.updateExpectationObject(expectationObject, expectationId);
} else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) {
String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
-import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
-
@Log4j2
@RestController
@RequestMapping("/intentReport")
@GetMapping(value = "/{intentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ServiceResult getIntentById(
@PathVariable("intentId") String intentId) {
- IntentReport report = intentReportService.getIntentReportByIntentId(intentId);
- return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "get report success"),
- report);
+ return intentReportService.getIntentReportByIntentId(intentId);
}
}
@Param(value = "parentId") String parentId);
List<String> getObjectInstances(@Param(value = "parentId") String parentId);
+
+ int deleteObjectInstances(@Param(value = "parentId") String parentId);
}
package org.onap.usecaseui.intentanalysis.service;
-import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
+import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
public interface IntentReportService {
- IntentReport getIntentReportByIntentId(String intentId);
+ ServiceResult getIntentReportByIntentId(String intentId);
void saveIntentReportByIntentId(String intentId);
}
log.error(msg);
throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
}
- int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(eventModel.getObjectInstances(), intentId);
+ List<String> instances = eventModel.getObjectInstances();
+ List<String> objectInstancesDb = objectInstanceMapper.getObjectInstances(intentId);
+ if (!CollectionUtils.isEmpty(objectInstancesDb)) {
+ instances.removeAll(objectInstancesDb);
+ if (CollectionUtils.isEmpty(instances)) {
+ log.info("The objectInstances already exist in the database");
+ return;
+ }
+ }
+ int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(instances, intentId);
if (objectInstanceNum < 1) {
String msg = "Failed to insert objectInstances to database.";
log.error(msg);
import lombok.extern.slf4j.Slf4j;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
+import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
+import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
@Service
@Slf4j
@Override
@Transactional(rollbackFor = DataBaseException.class)
- public IntentReport getIntentReportByIntentId(String intentId) {
+ public ServiceResult getIntentReportByIntentId(String intentId) {
FulfillmentInfo fulfillmentInfo = getFulfillmentInfo(intentId);
+
+ if (fulfillmentInfo == null) {
+ return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "The intent has not fulfillmentInfo"),
+ new IntentReport());
+ }
fulfillmentInfo.setObjectInstances(getInstances(intentId));
IntentReport intentReport = new IntentReport();
intentReport.setIntentReportId(CommonUtil.getUUid());
intentReport.setReportTime(CommonUtil.getTime());
saveIntentReport(intentReport, fulfillmentInfo);
- return intentReport;
+ return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "Get report success"),
+ intentReport);
}
@Override
log.info("fulfillmentInfo is {}", fulfillmentInfo);
if (fulfillmentInfo == null) {
log.error("get fulfillmentInfo is failed,intentId is {}", intentId);
- String msg = "get fulfillmentInfo is empty, please enter the right intentId";
- throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
}
return fulfillmentInfo;
}
List<String> objectInstances = objectInstanceMapper.getObjectInstances(intentId);
if (CollectionUtils.isEmpty(objectInstances)) {
log.error("get objectInstance is failed,intentId is {}", intentId);
- String msg = "get objectInstance is failed";
- throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
}
- return objectInstances;
+ return objectInstances.stream().distinct().collect(Collectors.toList());
}
private void saveIntentReport(IntentReport intentReport, FulfillmentInfo fulfillmentInfo) {
import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.models.Condition;
import org.onap.usecaseui.intentanalysis.bean.models.Context;
+import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Autowired
private IntentService intentService;
+ @Autowired
+ private ObjectInstanceMapper objectInstanceMapper;
+
@Transactional(rollbackFor = RuntimeException.class)
@Override
public Intent createIntent(Intent intent) {
fulfillmentInfoService.deleteFulfillmentInfo(intentId);
contextService.deleteContextList(intentId);
expectationService.deleteIntentExpectationList(intentId);
+ objectInstanceMapper.deleteObjectInstances(intentId);
if (intentMapper.deleteIntent(intentId) < 1) {
String msg = "Failed to delete intent to database.";
log.error(msg);
</insert>
<select id="getObjectInstances" resultType="java.lang.String">
- select object_instance from object_instance where parent_id = #{parentId}
+ select object_instance from object_instance where parent_id = #{parentId}
</select>
+
+ <delete id="deleteObjectInstances">
+ delete from object_instance where parent_id = #{parentId}
+ </delete>
+
</mapper>
fulfillmentOperation.setObjectInstances(Collections.singletonList(cll.get(0)));
fulfillmentOperation.setOperation("delivery");
componentNotificationService.callBack(fulfillmentOperation);
- IntentReport report = intentReportService.getIntentReportByIntentId("testIntentId111");
+ ServiceResult report = intentReportService.getIntentReportByIntentId("testIntentId111");
Assert.assertNotNull(report);
}
}