Search in sources :

Example 1 with OwningEntity

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);
    }
}
Also used : OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 2 with OwningEntity

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());
}
Also used : OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 3 with OwningEntity

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));
}
Also used : OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) File(java.io.File) Test(org.junit.Test)

Example 4 with OwningEntity

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());
}
Also used : OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) Test(org.junit.Test)

Example 5 with OwningEntity

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);
        }
    }
}
Also used : OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

OwningEntity (org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity)12 Test (org.junit.Test)7 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)6 File (java.io.File)5 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)4 Project (org.onap.so.bpmn.servicedecomposition.bbobjects.Project)4 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)4 Service (org.onap.so.db.catalog.beans.Service)4 HashMap (java.util.HashMap)3 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)3 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)3 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)3 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)3 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)2 ServiceSubscription (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription)2 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)1 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)1 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)1 NoServiceInstanceFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)1 ResourceNotFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ResourceNotFoundException)1