class RetentionExpirationExporterController {

    void performRetentionExpirationExport(String namespace, String businessObjectDefinitionName, File localOutputFile,
        RegServerAccessParamsDto regServerAccessParamsDto, String udcServerHost) throws Exception
    {
        // Fail if local output file already exists.
        if (localOutputFile.exists())
        {
            throw new IllegalArgumentException(String.format("The specified local output file \"%s\" already exists.", localOutputFile.toString()));
        }

        // Initialize the web client.
        retentionExpirationExporterWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto);

        // Validate that specified business object definition exists.
        BusinessObjectDefinition businessObjectDefinition =
            retentionExpirationExporterWebClient.getBusinessObjectDefinition(namespace, businessObjectDefinitionName);

        // Get business object display name.
        String businessObjectDefinitionDisplayName = getBusinessObjectDefinitionDisplayName(businessObjectDefinition);

        // Create a search request for business object data with the filter on retention expiration option.
        BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
        businessObjectDataSearchKey.setNamespace(namespace);
        businessObjectDataSearchKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
        businessObjectDataSearchKey.setFilterOnRetentionExpiration(true);
        List<BusinessObjectDataSearchKey> businessObjectDataSearchKeys = new ArrayList<>();
        businessObjectDataSearchKeys.add(businessObjectDataSearchKey);
        BusinessObjectDataSearchFilter businessObjectDataSearchFilter = new BusinessObjectDataSearchFilter(businessObjectDataSearchKeys);
        BusinessObjectDataSearchRequest request = new BusinessObjectDataSearchRequest(Collections.singletonList(businessObjectDataSearchFilter));

        // Create a result list for business object data.
        List<BusinessObjectData> businessObjectDataList = new ArrayList<>();

        // Fetch business object data from server until no records found.
        int pageNumber = 1;
        BusinessObjectDataSearchResult businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
        while (CollectionUtils.isNotEmpty(businessObjectDataSearchResult.getBusinessObjectDataElements()))
        {
            LOGGER.info("Fetched {} business object data records from the registration server.",
                CollectionUtils.size(businessObjectDataSearchResult.getBusinessObjectDataElements()));
            businessObjectDataList.addAll(businessObjectDataSearchResult.getBusinessObjectDataElements());
            pageNumber++;
            businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
        }

        // Write business object data to the output CSV file.
        writeToCsvFile(localOutputFile, businessObjectDefinition.getNamespace(), businessObjectDefinition.getBusinessObjectDefinitionName(),
            businessObjectDefinitionDisplayName, udcServerHost, businessObjectDataList);
    }

}