2 * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.usecaseui.intentanalysis.service.impl;
19 import lombok.extern.slf4j.Slf4j;
20 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
21 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
22 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
23 import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
24 import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Service;
27 import org.springframework.util.CollectionUtils;
29 import java.util.ArrayList;
30 import java.util.List;
34 public class ObjectInstanceServiceImpl implements ObjectInstanceService {
36 private ObjectInstanceMapper objectInstanceMapper;
39 public void saveObjectInstances(String intentId, FulfillmentInfo eventModel) {
40 List<String> instances = new ArrayList<>(eventModel.getObjectInstances());
41 List<String> objectInstancesDb = objectInstanceMapper.getObjectInstances(intentId);
42 if (!CollectionUtils.isEmpty(objectInstancesDb)) {
43 instances.removeAll(objectInstancesDb);
44 if (CollectionUtils.isEmpty(instances)) {
45 log.info("The objectInstances already exist in the database");
49 int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(instances, intentId);
50 if (objectInstanceNum < 1) {
51 String msg = "Failed to insert objectInstances to database.";
53 throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);