diff options
Diffstat (limited to 'intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java')
-rw-r--r-- | intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java index 2e7db09..b5b8022 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java @@ -16,16 +16,15 @@ package org.onap.usecaseui.intentanalysis.service.impl; - -import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.onap.usecaseui.intentanalysis.common.ResponseConsts; import org.onap.usecaseui.intentanalysis.exception.DataBaseException; +import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper; +import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.onap.usecaseui.intentanalysis.bean.enums.ContextParentType; import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject; import org.onap.usecaseui.intentanalysis.bean.models.Context; import org.onap.usecaseui.intentanalysis.mapper.ExpectationObjectMapper; @@ -33,13 +32,9 @@ import org.onap.usecaseui.intentanalysis.service.ContextService; import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService; import org.springframework.util.CollectionUtils; - @Service @Slf4j public class ExpectationObjectServiceImpl implements ExpectationObjectService { - - private ContextParentType contextParentType; - @Autowired private ExpectationObjectMapper expectationObjectMapper; @@ -49,6 +44,12 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService { @Autowired private ContextService contextService; + @Autowired + private ObjectInstanceService objectInstanceService; + + @Autowired + private ObjectInstanceMapper objectInstanceMapper; + @Override public void createExpectationObject(ExpectationObject expectationObject, String expectationId) { if (expectationObjectService.getExpectationObject(expectationId) != null) { @@ -56,19 +57,33 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService { log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } - contextService.createContextList(expectationObject.getObjectContexts(), - expectationObjectMapper.selectExpectationObjectId(expectationId)); + + List<String> objectInstance = expectationObject.getObjectInstance(); + if (!CollectionUtils.isEmpty(objectInstance)) { + objectInstanceService.saveObjectInstances(expectationId, objectInstance); + } + if (expectationObjectMapper.insertExpectationObject(expectationObject, expectationId) < 1) { String msg = "Failed to create expectation object to database."; log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } + + String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId); + List<Context> objectContexts = expectationObject.getObjectContexts(); + if(!CollectionUtils.isEmpty(objectContexts)){ + contextService.createContextList(objectContexts, objectId); + } log.info("Successfully created expectation object to database."); } @Override public ExpectationObject getExpectationObject(String expectationId) { ExpectationObject expectationObject = expectationObjectMapper.selectExpectationObject(expectationId); + if (expectationObject == null) { + log.info("get expectationObject is empty,expectationId is {}", expectationId); + return null; + } String expectationObjectId = expectationObjectMapper.selectExpectationObjectId(expectationId); List<Context> contextList = contextService.getContextList(expectationObjectId); if (!CollectionUtils.isEmpty(contextList)) { @@ -76,6 +91,8 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService { } else { log.info(String.format("Expectation object is null, expectationObjectId = %s", expectationObjectId)); } + List<String> objectInstances = objectInstanceMapper.getObjectInstances(expectationId); + expectationObject.setObjectInstance(objectInstances); return expectationObject; } @@ -87,8 +104,9 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService { } else if (expectationObject != null && expectationObjectFromDB == null) { expectationObjectService.createExpectationObject(expectationObject, expectationId); } else if (expectationObject != null) { - contextService.updateContextList(expectationObject.getObjectContexts(), - expectationObjectMapper.selectExpectationObjectId(expectationId)); + String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId); + contextService.updateContextList(expectationObject.getObjectContexts(), objectId); + objectInstanceService.saveObjectInstances(expectationId, expectationObject.getObjectInstance()); if (expectationObjectMapper.updateExpectationObject(expectationObject, expectationId) < 1) { String msg = "Failed to update expectation object to database."; log.error(msg); @@ -103,7 +121,9 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService { public void deleteExpectationObject(String expectationId) { ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId); if (expectationObject != null) { - contextService.deleteContextList(expectationObjectMapper.selectExpectationObjectId(expectationId)); + String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId); + contextService.deleteContextList(objectId); + objectInstanceMapper.deleteObjectInstances(expectationId); if (expectationObjectMapper.deleteExpectationObject(expectationId) < 1) { String msg = "Failed to update expectation object to database."; log.error(msg); |