Skip to content

Commit 63326ef

Browse files
authored
Merge pull request wso2#13439 from tharikaGitHub/bug-fixing
Add several bug fixes
2 parents cbb5a4a + edc076d commit 63326ef

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Environment implements Serializable {
5353
private String description;
5454
private boolean isReadOnly;
5555
private String mode = GatewayMode.WRITE_ONLY.getMode();
56-
private int apiDiscoveryScheduledWindow = 60;
56+
private int apiDiscoveryScheduledWindow = 0;
5757
private List<VHost> vhosts = new ArrayList<>();
5858
private String provider;
5959
private String gatewayType;

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,10 +3778,10 @@ private Map<String, String> getHostWithSchemeMappingForEnvironment(API api, Stri
37783778
}
37793779
String externalReference = APIUtil.getApiExternalApiMappingReferenceByApiId(api.getUuid(),
37803780
environment.getUuid());
3781-
String httpUrl = isExternalGateway && gatewayDeployer != null ?
3781+
String httpUrl = (isExternalGateway && gatewayDeployer != null && externalReference != null) ?
37823782
gatewayDeployer.getAPIExecutionURL(externalReference, GatewayDeployer.HttpScheme.HTTP) :
37833783
vhost.getHttpUrl();
3784-
String httpsUrl = isExternalGateway && gatewayDeployer != null?
3784+
String httpsUrl = (isExternalGateway && gatewayDeployer != null && externalReference != null) ?
37853785
gatewayDeployer.getAPIExecutionURL(externalReference, GatewayDeployer.HttpScheme.HTTPS) :
37863786
vhost.getHttpsUrl();
37873787
if (StringUtils.containsIgnoreCase(api.getTransports(),

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15682,7 +15682,7 @@ public List<Environment> getAllEnvironments(String tenantDomain) throws APIManag
1568215682
}
1568315683
int scheduledTime = rs.getInt("SCHEDULED_TIME");
1568415684
if (rs.wasNull()) {
15685-
scheduledTime = 60;
15685+
scheduledTime = 0;
1568615686
}
1568715687
Map<String, String> additionalProperties = new HashMap();
1568815688
try (InputStream configuration = rs.getBinaryStream("CONFIGURATION")) {
@@ -15746,7 +15746,7 @@ public Environment getEnvironment(String tenantDomain, String uuid) throws APIMa
1574615746
}
1574715747
int scheduledTime = rs.getInt("SCHEDULED_TIME");
1574815748
if (rs.wasNull()) {
15749-
scheduledTime = 60;
15749+
scheduledTime = 0;
1575015750
}
1575115751
Map<String, String> additionalProperties = new HashMap();
1575215752
try (InputStream configuration = rs.getBinaryStream("CONFIGURATION")) {
@@ -15807,8 +15807,11 @@ public Environment addEnvironment(String tenantDomain, Environment environment)
1580715807
String configurationJson = new Gson().toJson(environment.getAdditionalProperties());
1580815808
prepStmt.setBinaryStream(8, new ByteArrayInputStream(configurationJson.getBytes()));
1580915809
prepStmt.setString(9, tenantDomain);
15810-
prepStmt.setString(10, (StringUtils.isEmpty(environment.getMode()) ? GatewayMode.WRITE_ONLY.getMode() : environment.getMode()));
15811-
prepStmt.setInt(11, environment.getApiDiscoveryScheduledWindow());
15810+
prepStmt.setString(10, (StringUtils.isEmpty(environment.getMode()) ?
15811+
GatewayMode.WRITE_ONLY.getMode() :
15812+
environment.getMode()));
15813+
prepStmt.setInt(11, (StringUtils.isEmpty(environment.getMode()) || GatewayMode.WRITE_ONLY.getMode()
15814+
.equals(environment.getMode())) ? 0 : environment.getApiDiscoveryScheduledWindow());
1581215815
prepStmt.executeUpdate();
1581315816

1581415817
GatewayVisibilityPermissionConfigurationDTO permissionDTO = environment.getPermissions();

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public static API fromDTOtoAPI(APIDTO dto, String provider) throws APIManagement
226226
context = updateContextWithVersion(dto.getVersion(), originalContext, context);
227227
model.setContext(context);
228228
model.setDescription(dto.getDescription());
229-
model.setDisplayName(dto.getDisplayName());
229+
model.setDisplayName((dto.getDisplayName() != null && !dto.getDisplayName().trim().isEmpty())
230+
? dto.getDisplayName() : dto.getName());
230231

231232
Object endpointConfig = dto.getEndpointConfig();
232233
if (endpointConfig != null) {
@@ -819,8 +820,10 @@ public static API fromMCPServerDTOtoAPI(MCPServerDTO dto, String provider) throw
819820
model.getMetadata().put(APIConstants.MCP.PROTOCOL_VERSION_KEY, protocolVersion);
820821
}
821822
String displayName = dto.getDisplayName();
822-
if (displayName != null && !displayName.isEmpty()) {
823+
if (displayName != null && !displayName.trim().isEmpty()) {
823824
model.setDisplayName(displayName);
825+
} else {
826+
model.setDisplayName(dto.getName());
824827
}
825828

826829
try {
@@ -1647,7 +1650,8 @@ public static APIDTO fromAPItoDTO(API model, boolean preserveCredentials,
16471650
}
16481651
APIDTO dto = new APIDTO();
16491652
dto.setName(model.getId().getApiName());
1650-
dto.setDisplayName(model.getDisplayName() != null ? model.getDisplayName() : model.getId().getApiName());
1653+
dto.setDisplayName((model.getDisplayName() != null && !model.getDisplayName().trim().isEmpty())
1654+
? model.getDisplayName() : model.getId().getApiName());
16511655
dto.setVersion(model.getId().getVersion());
16521656
String providerName = model.getId().getProviderName();
16531657
dto.setProvider(APIUtil.replaceEmailDomainBack(providerName));
@@ -3944,6 +3948,8 @@ public static APIProductDTO fromAPIProducttoDTO(APIProduct product, boolean pres
39443948
productDto.setName(product.getId().getName());
39453949
productDto.setDisplayName(
39463950
product.getDisplayName() != null ? product.getDisplayName() : product.getId().getName());
3951+
productDto.setDisplayName((product.getDisplayName() != null && !product.getDisplayName().trim().isEmpty())
3952+
? product.getDisplayName() : product.getId().getName());
39473953
productDto.setProvider(APIUtil.replaceEmailDomainBack(product.getId().getProviderName()));
39483954
productDto.setId(product.getUuid());
39493955
productDto.setVersion(product.getId().getVersion());
@@ -4209,7 +4215,8 @@ public static APIProduct fromDTOtoAPIProduct(APIProductDTO dto, String provider)
42094215
product.setID(id);
42104216
product.setUuid(dto.getId());
42114217
product.setDescription(dto.getDescription());
4212-
product.setDisplayName(dto.getDisplayName() != null ? dto.getDisplayName() : dto.getName());
4218+
product.setDisplayName((dto.getDisplayName() != null && !dto.getDisplayName().trim().isEmpty())
4219+
? dto.getDisplayName() : dto.getName());
42134220

42144221
String context = dto.getContext();
42154222
final String originalContext = context;

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,9 @@ private static API prepareForUpdateApi(API originalAPI, APIDTO apiDtoToUpdate, A
927927
}
928928
apiToUpdate.setWsdlUrl(apiDtoToUpdate.getWsdlUrl());
929929
apiToUpdate.setGatewayType(apiDtoToUpdate.getGatewayType());
930-
apiToUpdate.setDisplayName(apiDtoToUpdate.getDisplayName());
930+
apiToUpdate.setDisplayName((apiDtoToUpdate.getDisplayName() != null
931+
&& !apiDtoToUpdate.getDisplayName().trim().isEmpty()) ? apiDtoToUpdate.getDisplayName()
932+
: apiDtoToUpdate.getName());
931933

932934
//validate API categories
933935
List<APICategory> apiCategories = apiToUpdate.getApiCategories();
@@ -1126,7 +1128,9 @@ public static API prepareForUpdateApi(API originalAPI, MCPServerDTO apiDtoToUpda
11261128
SwaggerData swaggerData = new SwaggerData(apiToUpdate);
11271129
String definitionToAdd = new OAS3Parser().generateAPIDefinition(swaggerData);
11281130
apiToUpdate.setSwaggerDefinition(definitionToAdd);
1129-
apiToUpdate.setDisplayName(apiDtoToUpdate.getDisplayName());
1131+
apiToUpdate.setDisplayName((apiDtoToUpdate.getDisplayName() != null
1132+
&& !apiDtoToUpdate.getDisplayName().trim().isEmpty()) ? apiDtoToUpdate.getDisplayName()
1133+
: apiDtoToUpdate.getName());
11301134

11311135
apiToUpdate.setOrganization(originalAPI.getOrganization());
11321136
apiToUpdate.setSubtype(originalAPI.getSubtype());
@@ -2978,7 +2982,6 @@ public static API prepareToCreateAPIByDTO(APIDTOTypeWrapper apiDtoTypeWrapper, A
29782982
api.setSubtype(apiDtoTypeWrapper.getResolvedApiSubtype());
29792983
api.setAiConfiguration(apiDtoTypeWrapper.getAiConfiguration());
29802984
api.setInitiatedFromGateway(apiDtoTypeWrapper.getInitiatedFromGateway());
2981-
api.setDisplayName(apiDtoTypeWrapper.getDisplayName());
29822985
if (apiDtoTypeWrapper.isMCPServerDTO()) {
29832986
String protocolVersion = apiDtoTypeWrapper.getProtocolVersion();
29842987
api.getMetadata().put(APIConstants.MCP.PROTOCOL_VERSION_KEY,

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/mappings/APIMappingUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@ private static APIEndpointURLsDTO fromAPIRevisionToEndpoints(APIDTO apidto, Envi
684684
} else {
685685
String externalReference = APIUtil.getApiExternalApiMappingReferenceByApiId(apidto.getId(),
686686
environment.getUuid());
687-
String httpUrl = gatewayDeployer != null ?
687+
String httpUrl = (gatewayDeployer != null && externalReference != null) ?
688688
gatewayDeployer.getAPIExecutionURL(externalReference, GatewayDeployer.HttpScheme.HTTP) :
689689
vHost.getHttpUrl();
690-
String httpsUrl = gatewayDeployer != null ?
690+
String httpsUrl = (gatewayDeployer != null && externalReference != null) ?
691691
gatewayDeployer.getAPIExecutionURL(externalReference, GatewayDeployer.HttpScheme.HTTPS) :
692692
vHost.getHttpsUrl();
693693
if (apidto.getTransport().contains(APIConstants.HTTP_PROTOCOL)) {

0 commit comments

Comments
 (0)