RetentionExpirationExporterController { void performRetentionExpirationExport(String namespace, String businessObjectDefinitionName, File localOutputFile, RegServerAccessParamsDto regServerAccessParamsDto, String udcServerHost) throws Exception { if (localOutputFile.exists()) { throw new IllegalArgumentException(String.format("The specified local output file \"%s\" already exists.", localOutputFile.toString())); } retentionExpirationExporterWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto); BusinessObjectDefinition businessObjectDefinition = retentionExpirationExporterWebClient.getBusinessObjectDefinition(namespace, businessObjectDefinitionName); String businessObjectDefinitionDisplayName = getBusinessObjectDefinitionDisplayName(businessObjectDefinition); 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)); List<BusinessObjectData> businessObjectDataList = new ArrayList<>(); 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); } writeToCsvFile(localOutputFile, businessObjectDefinition.getNamespace(), businessObjectDefinition.getBusinessObjectDefinitionName(), businessObjectDefinitionDisplayName, udcServerHost, businessObjectDataList); }    }
@Test public void testPerformDownloadOutputFileAlreadyExist() throws Exception { File outputFile = new File(LOCAL_OUTPUT_FILE); assertTrue(outputFile.createNewFile()); try { retentionExpirationExporterController .performRetentionExpirationExport(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, outputFile, new RegServerAccessParamsDto(), UDC_SERVICE_HOSTNAME); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("The specified local output file \"%s\" already exists.", outputFile.toString()), e.getMessage()); } }
@Test public void testPerformRetentionExpirationExport() throws Exception { File outputFile = new File(LOCAL_OUTPUT_FILE); RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true) .withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).withTrustSelfSignedCertificate(true) .withDisableHostnameVerification(true).build(); retentionExpirationExporterController .performRetentionExpirationExport(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, outputFile, regServerAccessParamsDto, UDC_SERVICE_HOSTNAME); String expectedUri = String.format("https: String expectedOutputFileContent = ("\"Namespace\",\"Business Object Definition Name\",\"Business Object Format Usage\",\"Business Object Format File Type\"," + "\"Business Object Format Version\",\"Primary Partition Value\",\"Sub-Partition Value 1\",\"Sub-Partition Value 2\"," + "\"Sub-Partition Value 3\",\"Sub-Partition Value 4\",\"Business Object Data Version\",\"Business Object Definition Display Name\"," + "\"Business Object Definition URI\"") + System.lineSeparator() + String .format("\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\"%n", NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, BUSINESS_OBJECT_FORMAT_USAGE, BUSINESS_OBJECT_FORMAT_FILE_TYPE, BUSINESS_OBJECT_FORMAT_VERSION, "primaryPartitionValue", "subPartitionValue1", "subPartitionValue2", "subPartitionValue3", "subPartitionValue4", BUSINESS_OBJECT_DATA_VERSION, BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME, expectedUri) + String .format("\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\"%n", NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, BUSINESS_OBJECT_FORMAT_USAGE, BUSINESS_OBJECT_FORMAT_FILE_TYPE, BUSINESS_OBJECT_FORMAT_VERSION, "primaryPartitionValue", "", "", "", "", BUSINESS_OBJECT_DATA_VERSION, BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME, expectedUri); String outputFileContent; try (FileInputStream inputStream = new FileInputStream(outputFile)) { outputFileContent = IOUtils.toString(inputStream, Charset.defaultCharset()); } assertEquals(expectedOutputFileContent, outputFileContent); }