class CloudInfoFromAAI {

    protected Optional<CloudRegion> getCloudInfoFromAAI(ServiceInstance serviceInstance)
            throws JsonProcessingException {
        Optional<Relationships> relationshipsOp = Optional.empty();
        if (!serviceInstance.getVnfs().isEmpty()) {
            GenericVnf vnf = serviceInstance.getVnfs().get(0);
            org.onap.aai.domain.yang.GenericVnf aaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId());
            AAIResultWrapper vnfWrapper =
                    new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVnf));
            relationshipsOp = getRelationshipsFromWrapper(vnfWrapper);
        } else if (!serviceInstance.getNetworks().isEmpty()) {
            L3Network network = serviceInstance.getNetworks().get(0);
            org.onap.aai.domain.yang.L3Network aaiL3Network = bbInputSetupUtils.getAAIL3Network(network.getNetworkId());
            AAIResultWrapper networkWrapper = new AAIResultWrapper(
                    new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiL3Network));
            relationshipsOp = getRelationshipsFromWrapper(networkWrapper);
        } else {
            logger.debug(
                    "BBInputSetup could not find a cloud region or tenant, since there are no resources under the SI.");
            return Optional.empty();
        }
        if (relationshipsOp.isPresent()) {
            return getRelatedCloudRegionAndTenant(relationshipsOp.get());
        } else {
            logger.debug("BBInputSetup could not find a cloud region or tenant");
            return Optional.empty();
        }
    }

}