From 3c320c6280d070ac10131c150b081c143c4bdc32 Mon Sep 17 00:00:00 2001 From: HiranyaKavishani Date: Thu, 15 Aug 2024 14:00:05 +0530 Subject: [PATCH] Fixing Error when getting Choreo Connect Runtime Artifacts --- .../carbon/apimgt/impl/dao/ApiMgtDAO.java | 1 - .../MicroGatewayArtifactGenerator.java | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java index 06decdd09709..369167e51e51 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java @@ -15320,7 +15320,6 @@ public List getProductMappingsForAPI(API api) throws APIMana APIProductResource productMapping = new APIProductResource(); productMapping.setProductIdentifier(apiProductIdentifier); productMapping.setUriTemplate(uriTemplate); - productMappings.add(productMapping); } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/gatewayartifactsynchronizer/MicroGatewayArtifactGenerator.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/gatewayartifactsynchronizer/MicroGatewayArtifactGenerator.java index 1d1f8510d49f..6b28f6abe0da 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/gatewayartifactsynchronizer/MicroGatewayArtifactGenerator.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/gatewayartifactsynchronizer/MicroGatewayArtifactGenerator.java @@ -116,13 +116,15 @@ public RuntimeArtifactDto generateGatewayArtifact(List ap // adding env_properties.json Map> environmentSpecificAPIProperties = getEnvironmentSpecificAPIProperties(apiRuntimeArtifactDtoList); - String environmentSpecificAPIPropertyFile = Paths.get(tempDirectory.getAbsolutePath(), - APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE).toString(); - CommonUtil.writeDtoToFile(environmentSpecificAPIPropertyFile, ExportFormat.JSON, - APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE, - APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_KEY_NAME, - environmentSpecificAPIProperties); + if (environmentSpecificAPIProperties != null) { + String environmentSpecificAPIPropertyFile = Paths.get(tempDirectory.getAbsolutePath(), + APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE).toString(); + CommonUtil.writeDtoToFile(environmentSpecificAPIPropertyFile, ExportFormat.JSON, + APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE, + APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_KEY_NAME, + environmentSpecificAPIProperties); + } CommonUtil.archiveDirectory(tempDirectory.getAbsolutePath()); FileUtils.deleteQuietly(tempDirectory); RuntimeArtifactDto runtimeArtifactDto = new RuntimeArtifactDto(); @@ -150,7 +152,10 @@ private Map> getEnvironmentSpecificAPIPropertie List apiIds = apiRuntimeArtifactDtoList.stream() .map(APIRuntimeArtifactDto::getApiId) .collect(Collectors.toList()); - return environmentSpecificAPIPropertyDao.getEnvironmentSpecificAPIPropertiesOfAPIs(apiIds); + if (!apiIds.isEmpty()) { + return environmentSpecificAPIPropertyDao.getEnvironmentSpecificAPIPropertiesOfAPIs(apiIds); + } + return null; } @Override