class BBInputSetup implements JavaDelegate {

    protected void populateVolumeGroup(BBInputSetupParameter parameter) throws Exception {
        String replaceVnfModelCustomizationUUID = null;
        VolumeGroup volumeGroup = null;
        GenericVnf vnf = null;
        String vnfModelCustomizationUUID = null;
        String generatedVnfType = parameter.getVnfType();
        if (generatedVnfType == null || generatedVnfType.isEmpty()) {
            generatedVnfType =
                    parameter.getService().getModelName() + "/" + parameter.getModelInfo().getModelCustomizationName();
        }
        if (parameter.getRelatedInstanceList() != null) {
            for (RelatedInstanceList relatedInstList : parameter.getRelatedInstanceList()) {
                RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
                if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
                    if (parameter.getIsReplace()) {
                        replaceVnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
                    } else {
                        vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
                    }
                    break;
                }
            }
        }
        for (GenericVnf tempVnf : parameter.getServiceInstance().getVnfs()) {
            if (tempVnf.getVnfId().equalsIgnoreCase(parameter.getLookupKeyMap().get(ResourceKey.GENERIC_VNF_ID))) {
                vnf = tempVnf;
                vnfModelCustomizationUUID =
                        bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
                ModelInfo vnfModelInfo = new ModelInfo();
                if (parameter.getIsReplace()) {
                    vnfModelInfo.setModelCustomizationUuid(replaceVnfModelCustomizationUUID);
                    mapCatalogVnf(tempVnf, vnfModelInfo, parameter.getServiceModel().getNewService());
                } else {
                    vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
                    mapCatalogVnf(tempVnf, vnfModelInfo, parameter.getServiceModel().getCurrentService());
                }
                break;
            }
        }
        if (vnf != null && vnfModelCustomizationUUID != null) {
            for (VolumeGroup volumeGroupTemp : vnf.getVolumeGroups()) {
                if (parameter.getLookupKeyMap().get(ResourceKey.VOLUME_GROUP_ID) != null
                        && volumeGroupTemp.getVolumeGroupId()
                                .equalsIgnoreCase(parameter.getLookupKeyMap().get(ResourceKey.VOLUME_GROUP_ID))) {
                    volumeGroup = volumeGroupTemp;
                    if (volumeGroup.getModelInfoVfModule() == null) {
                        throw new Exception(
                                "ModelInfoVfModule is null for VolumeGroup: " + volumeGroup.getVolumeGroupId());
                    }
                    String volumeGroupCustId = volumeGroup.getModelInfoVfModule().getModelCustomizationUUID();
                    ModelInfo modelInfoVolumeGroup = new ModelInfo();
                    modelInfoVolumeGroup.setModelCustomizationId(volumeGroupCustId);
                    if (parameter.getIsReplace() && parameter.getLookupKeyMap().get(ResourceKey.VOLUME_GROUP_ID) != null
                            && volumeGroupTemp.getVolumeGroupId()
                                    .equalsIgnoreCase(parameter.getLookupKeyMap().get(ResourceKey.VOLUME_GROUP_ID))) {
                        mapCatalogVolumeGroup(volumeGroupTemp, modelInfoVolumeGroup,
                                parameter.getServiceModel().getNewService(), replaceVnfModelCustomizationUUID);
                    } else {
                        mapCatalogVolumeGroup(volumeGroupTemp, modelInfoVolumeGroup,
                                parameter.getServiceModel().getCurrentService(), vnfModelCustomizationUUID);
                    }
                    break;
                }
            }
            if (volumeGroup == null && parameter.getBbName().equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString())) {
                volumeGroup = createVolumeGroup(parameter.getLookupKeyMap(), parameter.getResourceId(),
                        parameter.getInstanceName(), generatedVnfType, parameter.getInstanceParams());
                vnf.getVolumeGroups().add(volumeGroup);
                if (parameter.getIsReplace()) {
                    if (parameter.getExecuteBB().getOldVolumeGroupName() != null
                            && !parameter.getExecuteBB().getOldVolumeGroupName().isEmpty()) {
                        volumeGroup.setVolumeGroupName(parameter.getExecuteBB().getOldVolumeGroupName());
                    }
                    mapCatalogVolumeGroup(volumeGroup, parameter.getModelInfo(),
                            parameter.getServiceModel().getNewService(), replaceVnfModelCustomizationUUID);
                } else {
                    mapCatalogVolumeGroup(volumeGroup, parameter.getModelInfo(),
                            parameter.getServiceModel().getCurrentService(), vnfModelCustomizationUUID);
                }
            }
        } else {
            logger.debug("Related VNF instance Id not found: {}",
                    parameter.getLookupKeyMap().get(ResourceKey.GENERIC_VNF_ID));
            throw new Exception("Could not find relevant information for related VNF");
        }
    }

}