class VnfAdapterImpl {

    public void postProcessVnfAdapter(BuildingBlockExecution execution) {
        try {
            String vnfAdapterResponse = execution.getVariable("WorkflowResponse");
            if (!StringUtils.isEmpty(vnfAdapterResponse)) {
                Object vnfRestResponse = unMarshal(vnfAdapterResponse);
                if (vnfRestResponse instanceof CreateVfModuleResponse) {
                    VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
                    String heatStackId = ((CreateVfModuleResponse) vnfRestResponse).getVfModuleStackId();
                    if (!StringUtils.isEmpty(heatStackId)) {
                        vfModule.setHeatStackId(heatStackId);
                        execution.setVariable(HEAT_STACK_ID, heatStackId);
                    }
                    Map<String, String> vfModuleOutputs =
                            ((CreateVfModuleResponse) vnfRestResponse).getVfModuleOutputs();
                    if (vfModuleOutputs != null) {
                        processVfModuleOutputs(execution, vfModuleOutputs);
                    }
                } else if (vnfRestResponse instanceof DeleteVfModuleResponse) {
                    VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
                    GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
                    Boolean vfModuleDelete = ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleDeleted();
                    if (null != vfModuleDelete && vfModuleDelete) {
                        vfModule.setHeatStackId(null);
                        execution.setVariable(HEAT_STACK_ID, null);
                        Map<String, String> vfModuleOutputs =
                                ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleOutputs();
                        if (vfModuleOutputs != null) {
                            processVfModuleOutputs(execution, vfModuleOutputs);
                            if (execution.getVariable(OAM_MANAGEMENT_V4_ADDRESS) != null) {
                                genericVnf.setIpv4OamAddress("");
                                execution.setVariable(OAM_MANAGEMENT_V4_ADDRESS, "");
                            }
                            if (execution.getVariable(OAM_MANAGEMENT_V6_ADDRESS) != null) {
                                genericVnf.setManagementV6Address("");
                                execution.setVariable(OAM_MANAGEMENT_V6_ADDRESS, "");
                            }
                            if (execution.getVariable(CONTRAIL_SERVICE_INSTANCE_FQDN) != null) {
                                vfModule.setContrailServiceInstanceFqdn("");
                                execution.setVariable(CONTRAIL_SERVICE_INSTANCE_FQDN, "");
                            }
                        }
                    }
                } else if (vnfRestResponse instanceof CreateVolumeGroupResponse) {
                    VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
                    String heatStackId = ((CreateVolumeGroupResponse) vnfRestResponse).getVolumeGroupStackId();
                    if (!StringUtils.isEmpty(heatStackId)) {
                        volumeGroup.setHeatStackId(heatStackId);
                        execution.setVariable(HEAT_STACK_ID, heatStackId);
                    } else {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
                                "HeatStackId is missing from create VolumeGroup Vnf Adapter response.");
                    }
                } else if (vnfRestResponse instanceof DeleteVolumeGroupResponse) {
                    VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
                    Boolean volumeGroupDelete = ((DeleteVolumeGroupResponse) vnfRestResponse).getVolumeGroupDeleted();
                    if (null != volumeGroupDelete && volumeGroupDelete) {
                        volumeGroup.setHeatStackId(null);
                        execution.setVariable(HEAT_STACK_ID, null);
                    }
                }
            }
        } catch (Exception ex) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
        }
    }

}