use of org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity in project so by onap.
the class AAICreateTasks method createOwningEntity.
/**
* This method is used for creating OwningEntity A&AI.
*
* @param execution
* @throws @return
*/
public void createOwningEntity(BuildingBlockExecution execution) {
try {
ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
OwningEntity owningEntity = serviceInstance.getOwningEntity();
if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId()) && Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
execution.setVariable("ErrorCreateOEAAI", EXCEPTION_NAME_AND_ID_ARE_NULL);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "EXCEPTION_NAME_AND_ID_ARE_NULL");
} else if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId()) && !Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
org.onap.aai.domain.yang.OwningEntity aaiEntity = aaiSIResources.getOwningEntityByName(owningEntity.getOwningEntityName());
owningEntity.setOwningEntityId(aaiEntity.getOwningEntityId());
owningEntity.setOwningEntityName(owningEntity.getOwningEntityName());
aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
} else {
owningEntity.setOwningEntityId(UUID.randomUUID().toString());
aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
}
} else {
if (aaiSIResources.existsOwningEntity(owningEntity)) {
aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance);
} else {
if (Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) {
String msg = "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName.";
logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue(), msg);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
} else {
if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) {
logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID, "BPMN", ErrorCode.UnknownError.getValue(), EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, EXCEPTION_NAME_EXISTS_WITH_DIFFERENT_ID);
} else {
aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance);
}
}
}
}
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity in project so by onap.
the class BBInputSetupTest method testMapOwningEntity.
@Test
public void testMapOwningEntity() throws JsonProcessingException {
org.onap.aai.domain.yang.OwningEntity expectedAAI = new org.onap.aai.domain.yang.OwningEntity();
OwningEntity expected = new OwningEntity();
AAIResultWrapper vnfWrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(expectedAAI));
doReturn(expected).when(bbInputSetupMapperLayer).mapAAIOwningEntity(isA(org.onap.aai.domain.yang.OwningEntity.class));
ServiceInstance serviceInstance = new ServiceInstance();
SPY_bbInputSetup.mapOwningEntity(Arrays.asList(new AAIResultWrapper[] { vnfWrapper }), serviceInstance);
assertEquals(expected, serviceInstance.getOwningEntity());
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity in project so by onap.
the class BBInputSetupMapperLayerTest method testMapAAIOwningEntity.
@Test
public void testMapAAIOwningEntity() throws IOException {
OwningEntity expected = mapper.readValue(new File(RESOURCE_PATH + "OwningEntity.json"), OwningEntity.class);
org.onap.aai.domain.yang.OwningEntity entityAAI = new org.onap.aai.domain.yang.OwningEntity();
entityAAI.setOwningEntityId("owningEntityId");
entityAAI.setOwningEntityName("owningEntityName");
OwningEntity actual = bbInputSetupMapperLayer.mapAAIOwningEntity(entityAAI);
assertThat(actual, sameBeanAs(expected));
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity in project so by onap.
the class AAIObjectMapperTest method owningEntityMap.
@Test
public void owningEntityMap() {
OwningEntity oe = new OwningEntity();
oe.setOwningEntityId("abc");
oe.setOwningEntityName("bbb");
org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(oe);
assertEquals(AAIOwningEntity.getOwningEntityId(), oe.getOwningEntityId());
assertEquals(AAIOwningEntity.getOwningEntityName(), oe.getOwningEntityName());
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity in project so by onap.
the class BBInputSetup method mapOwningEntity.
protected void mapOwningEntity(List<AAIResultWrapper> owningEntities, ServiceInstance serviceInstance) {
if (!owningEntities.isEmpty()) {
AAIResultWrapper owningEntityWrapper = owningEntities.get(0);
Optional<org.onap.aai.domain.yang.OwningEntity> aaiOwningEntityOp = owningEntityWrapper.asBean(org.onap.aai.domain.yang.OwningEntity.class);
if (aaiOwningEntityOp.isPresent()) {
OwningEntity owningEntity = this.mapperLayer.mapAAIOwningEntity(aaiOwningEntityOp.get());
serviceInstance.setOwningEntity(owningEntity);
}
}
}
Aggregations