class BBInputSetup implements JavaDelegate {

    protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
            Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
        ServiceInstance serviceInstance = new ServiceInstance();
        String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
        serviceInstance.setServiceInstanceId(serviceInstanceId);
        Customer customer = new Customer();
        List<GenericVnf> genericVnfs = serviceInstance.getVnfs();

        String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
        if (vnfId != null) {
            org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
            GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
            genericVnfs.add(genericVnf);
        }
        String instanceGroupId = lookupKeyMap.get(ResourceKey.INSTANCE_GROUP_ID);
        if (instanceGroupId != null && !instanceGroupId.isEmpty()) {
            org.onap.aai.domain.yang.InstanceGroup aaiInstancegroup =
                    bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
            InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstancegroup);
            instanceGroup.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);

            if (serviceInstanceId == null) {
                Optional<org.onap.aai.domain.yang.ServiceInstance> aaiServiceInstanceOpt =
                        bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup(instanceGroupId);
                if (aaiServiceInstanceOpt.isPresent()) {
                    org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = aaiServiceInstanceOpt.get();
                    serviceInstance = this.mapperLayer.mapAAIServiceInstanceIntoServiceInstance(aaiServiceInstance);
                    WorkflowResourceIds workflowResourceIds = executeBB.getWorkflowResourceIds();
                    workflowResourceIds.setServiceInstanceId(serviceInstance.getServiceInstanceId());
                    lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, workflowResourceIds.getServiceInstanceId());
                } else {
                    throw new NoServiceInstanceFoundException("Related ServiceInstance not found in A&AI.");
                }
            }
            RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
            if (relatedInstanceList != null) {
                for (RelatedInstanceList relatedInstList : relatedInstanceList) {
                    RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
                    if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
                        org.onap.aai.domain.yang.GenericVnf aaiVnf =
                                bbInputSetupUtils.getAAIGenericVnf(relatedInstance.getInstanceId());
                        GenericVnf vnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiVnf);
                        instanceGroup.getVnfs().add(vnf);
                    }
                }
            }

            serviceInstance.getInstanceGroups().add(instanceGroup);
            customer.setServiceSubscription(new ServiceSubscription());
        }
        BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestDetails(requestDetails)
                .setServiceInstance(serviceInstance).setExecuteBB(executeBB).setRequestAction(requestAction)
                .setCustomer(customer).build();
        return this.populateGBBWithSIAndAdditionalInfo(parameter);
    }

}