Skip to content

Commit d32c4f8

Browse files
committed
Address review comments
1 parent a806e40 commit d32c4f8

File tree

6 files changed

+70
-68
lines changed

6 files changed

+70
-68
lines changed

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,10 @@ private void addAPI(API api, int tenantId) throws APIManagementException {
631631
if (primarySandboxEndpointId == null && primaryProductionEndpointId == null) {
632632
addDefaultPrimaryEndpoints(api, true, false);
633633
} else {
634-
boolean isProductionEndpointFromAPIEndpointConfig = primaryProductionEndpointId != null &&
635-
primaryProductionEndpointId.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID);
636-
boolean isSandboxEndpointFromAPIEndpointConfig = primarySandboxEndpointId != null &&
637-
primarySandboxEndpointId.equals(APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID);
634+
boolean isProductionEndpointFromAPIEndpointConfig = APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(
635+
primaryProductionEndpointId);
636+
boolean isSandboxEndpointFromAPIEndpointConfig = APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(
637+
primarySandboxEndpointId);
638638
if (isProductionEndpointFromAPIEndpointConfig && isSandboxEndpointFromAPIEndpointConfig) {
639639
addDefaultPrimaryEndpoints(api, true, true);
640640
} else if (isProductionEndpointFromAPIEndpointConfig) {
@@ -1190,10 +1190,10 @@ private void updateAPIPrimaryEndpointsMapping(API api) throws APIManagementExcep
11901190
if (primarySandboxEndpointId == null && primaryProductionEndpointId == null) {
11911191
addDefaultPrimaryEndpoints(api, true, false);
11921192
} else {
1193-
boolean isProductionEndpointFromAPIEndpointConfig = primaryProductionEndpointId != null &&
1194-
primaryProductionEndpointId.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID);
1195-
boolean isSandboxEndpointFromAPIEndpointConfig = primarySandboxEndpointId != null &&
1196-
primarySandboxEndpointId.equals(APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID);
1193+
boolean isProductionEndpointFromAPIEndpointConfig = APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(
1194+
primaryProductionEndpointId);
1195+
boolean isSandboxEndpointFromAPIEndpointConfig = APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(
1196+
primarySandboxEndpointId);
11971197

11981198
if (isProductionEndpointFromAPIEndpointConfig && isSandboxEndpointFromAPIEndpointConfig) {
11991199
addDefaultPrimaryEndpoints(api, true, true);
@@ -8315,9 +8315,9 @@ private void populateAPIPrimaryEndpointsMapping(API api, String uuid) throws API
83158315
List<String> endpointIds = apiMgtDAO.getPrimaryEndpointUUIDByAPIId(currentApiUuid);
83168316
if (endpointIds != null && !endpointIds.isEmpty()) {
83178317
for (String endpointId : endpointIds) {
8318-
if (endpointId.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID)) {
8318+
if (APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(endpointId)) {
83198319
api.setPrimaryProductionEndpointId(endpointId);
8320-
} else if (endpointId.equals(APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID)) {
8320+
} else if (APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(endpointId)) {
83218321
api.setPrimarySandboxEndpointId(endpointId);
83228322
}
83238323
}

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

+28-36
Original file line numberDiff line numberDiff line change
@@ -24562,29 +24562,18 @@ public void addPrimaryEndpointMappingsToNewAPI(String existingApiUUID, String ne
2456224562
connection.setAutoCommit(false);
2456324563
try (PreparedStatement addPrimaryMapping = connection.prepareStatement(
2456424564
SQLConstants.APIEndpointsSQLConstants.ADD_PRIMARY_ENDPOINT_MAPPING);
24565-
PreparedStatement getPrimaryEpMappingStmt = connection.prepareStatement(
24566-
SQLConstants.APIEndpointsSQLConstants.GET_API_PRIMARY_ENDPOINT_UUID_BY_API_UUID_AND_KEY_TYPE)) {
24567-
getPrimaryEpMappingStmt.setString(1, existingApiUUID);
24568-
getPrimaryEpMappingStmt.setString(2, organization);
24569-
getPrimaryEpMappingStmt.setString(3, APIConstants.APIEndpoint.PRODUCTION);
24570-
try (ResultSet resultSet = getPrimaryEpMappingStmt.executeQuery()) {
24571-
if (resultSet.next()) {
24572-
addPrimaryMapping.setString(1, newApiUUID);
24573-
addPrimaryMapping.setString(2, resultSet.getString("ENDPOINT_UUID"));
24574-
addPrimaryMapping.addBatch();
24575-
}
24576-
}
24577-
getPrimaryEpMappingStmt.setString(1, existingApiUUID);
24578-
getPrimaryEpMappingStmt.setString(2, organization);
24579-
getPrimaryEpMappingStmt.setString(3, APIConstants.APIEndpoint.SANDBOX);
24580-
try (ResultSet resultSet = getPrimaryEpMappingStmt.executeQuery()) {
24581-
if (resultSet.next()) {
24565+
PreparedStatement getPrimaryEpMappingsStmt = connection.prepareStatement(
24566+
SQLConstants.APIEndpointsSQLConstants.GET_API_PRIMARY_ENDPOINT_UUIDS_BY_API_UUID)) {
24567+
getPrimaryEpMappingsStmt.setString(1, existingApiUUID);
24568+
getPrimaryEpMappingsStmt.setString(2, organization);
24569+
try (ResultSet resultSet = getPrimaryEpMappingsStmt.executeQuery()) {
24570+
while(resultSet.next()) {
2458224571
addPrimaryMapping.setString(1, newApiUUID);
2458324572
addPrimaryMapping.setString(2, resultSet.getString("ENDPOINT_UUID"));
2458424573
addPrimaryMapping.addBatch();
2458524574
}
24575+
addPrimaryMapping.executeBatch();
2458624576
}
24587-
addPrimaryMapping.executeBatch();
2458824577
connection.commit();
2458924578
} catch (SQLException e) {
2459024579
connection.rollback();
@@ -24717,28 +24706,31 @@ private String addAPIEndpoint(String apiUUID, Connection connection, APIEndpoint
2471724706
*/
2471824707
public void addAPIEndpoints(String apiUUID, List<APIEndpointInfo> apiEndpointList, String organization)
2471924708
throws APIManagementException {
24720-
try (Connection connection = APIMgtDBUtil.getConnection()) {
24721-
connection.setAutoCommit(false);
24722-
String dbQuery = SQLConstants.APIEndpointsSQLConstants.ADD_NEW_API_ENDPOINT;
24723-
try (PreparedStatement statement = connection.prepareStatement(dbQuery)) {
24724-
for (APIEndpointInfo apiEndpoint : apiEndpointList) {
24725-
statement.setString(1, apiUUID);
24726-
statement.setString(2, apiEndpoint.getId());
24727-
statement.setString(3, "Current API");
24728-
statement.setString(4, apiEndpoint.getName());
24729-
statement.setString(5, apiEndpoint.getDeploymentStage());
24730-
statement.setBinaryStream(6, fromEndpointConfigMapToBA(apiEndpoint.getEndpointConfig()));
24731-
statement.setString(7, organization);
24732-
statement.addBatch();
24709+
if (!apiEndpointList.isEmpty()) {
24710+
try (Connection connection = APIMgtDBUtil.getConnection()) {
24711+
connection.setAutoCommit(false);
24712+
String dbQuery = SQLConstants.APIEndpointsSQLConstants.ADD_NEW_API_ENDPOINT;
24713+
try (PreparedStatement statement = connection.prepareStatement(dbQuery)) {
24714+
for (APIEndpointInfo apiEndpoint : apiEndpointList) {
24715+
statement.setString(1, apiUUID);
24716+
statement.setString(2, apiEndpoint.getId());
24717+
statement.setString(3, "Current API");
24718+
statement.setString(4, apiEndpoint.getName());
24719+
statement.setString(5, apiEndpoint.getDeploymentStage());
24720+
statement.setBinaryStream(6,
24721+
fromEndpointConfigMapToBA(apiEndpoint.getEndpointConfig()));
24722+
statement.setString(7, organization);
24723+
statement.addBatch();
24724+
}
24725+
statement.executeBatch();
24726+
connection.commit();
24727+
} catch (SQLException e) {
24728+
connection.rollback();
24729+
handleException("Failed to add endpoints to API: " + apiUUID, e);
2473324730
}
24734-
statement.executeBatch();
24735-
connection.commit();
2473624731
} catch (SQLException e) {
24737-
connection.rollback();
2473824732
handleException("Failed to add endpoints to API: " + apiUUID, e);
2473924733
}
24740-
} catch (SQLException e) {
24741-
handleException("Failed to add endpoints to API: " + apiUUID, e);
2474224734
}
2474324735
}
2474424736

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java

+9
Original file line numberDiff line numberDiff line change
@@ -4750,6 +4750,15 @@ public static class APIEndpointsSQLConstants {
47504750
public static final String GET_PRIMARY_ENDPOINT_MAPPINGS =
47514751
"SELECT ENDPOINT_UUID FROM AM_API_PRIMARY_EP_MAPPING WHERE API_UUID = ?";
47524752

4753+
public static final String GET_API_PRIMARY_ENDPOINT_UUIDS_BY_API_UUID =
4754+
"SELECT AME.ENDPOINT_UUID " +
4755+
"FROM AM_API_ENDPOINTS AME INNER JOIN AM_API_PRIMARY_EP_MAPPING AMPM " +
4756+
"ON (AMPM.ENDPOINT_UUID = AME.ENDPOINT_UUID AND AMPM.API_UUID = AME.API_UUID) " +
4757+
"WHERE " +
4758+
"AME.API_UUID = ? " +
4759+
"AND AME.ORGANIZATION = ? " +
4760+
"AND AME.REVISION_UUID = 'Current API'";
4761+
47534762
public static final String GET_API_PRIMARY_ENDPOINT_UUID_BY_API_UUID_AND_KEY_TYPE =
47544763
"SELECT AME.ENDPOINT_UUID " +
47554764
"FROM AM_API_ENDPOINTS AME INNER JOIN AM_API_PRIMARY_EP_MAPPING AMPM " +

Diff for: components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ private static EndpointDTO createEndpointDTO(String stage, String name, Endpoint
672672

673673
EndpointDTO endpoint = new EndpointDTO();
674674
endpoint.setEndpointConfig(endpointConfig);
675-
String defaultEndpointId = stage.equals(APIConstants.APIEndpoint.PRODUCTION) ?
675+
String defaultEndpointId = APIConstants.APIEndpoint.PRODUCTION.equals(stage) ?
676676
APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID :
677677
APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID;
678678
endpoint.setId(defaultEndpointId);

Diff for: 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

+18-17
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ public static void encryptEndpointSecurityApiKeyCredentials(APIEndpointDTO apiEn
10271027
if (endpointConfig != null) {
10281028
if ((endpointConfig.get(APIConstants.ENDPOINT_SECURITY) != null)) {
10291029
Map endpointSecurity = (Map) endpointConfig.get(APIConstants.ENDPOINT_SECURITY);
1030-
if (apiEndpointDTO.getDeploymentStage()
1031-
.equals(APIConstants.APIEndpoint.PRODUCTION) && endpointSecurity.get(
1030+
if (APIConstants.APIEndpoint.PRODUCTION.equals(
1031+
apiEndpointDTO.getDeploymentStage()) && endpointSecurity.get(
10321032
APIConstants.OAuthConstants.ENDPOINT_SECURITY_PRODUCTION) != null) {
10331033
Map endpointSecurityProduction = (Map) endpointSecurity.get(
10341034
APIConstants.OAuthConstants.ENDPOINT_SECURITY_PRODUCTION);
@@ -1061,8 +1061,8 @@ public static void encryptEndpointSecurityApiKeyCredentials(APIEndpointDTO apiEn
10611061
endpointConfig.put(APIConstants.ENDPOINT_SECURITY, endpointSecurity);
10621062
apiEndpointDTO.setEndpointConfig(endpointConfig);
10631063
}
1064-
if (apiEndpointDTO.getDeploymentStage()
1065-
.equals(APIConstants.APIEndpoint.SANDBOX) && endpointSecurity.get(
1064+
if (APIConstants.APIEndpoint.SANDBOX.equals(
1065+
apiEndpointDTO.getDeploymentStage()) && endpointSecurity.get(
10661066
APIConstants.OAuthConstants.ENDPOINT_SECURITY_SANDBOX) != null) {
10671067
Map endpointSecuritySandbox = (Map) endpointSecurity
10681068
.get(APIConstants.OAuthConstants.ENDPOINT_SECURITY_SANDBOX);
@@ -3271,10 +3271,10 @@ public static APIEndpointDTO getAPIEndpoint(String apiUUID, String endpointUUID,
32713271
}.getType();
32723272
Map<String, Object> endpointConfigMap = gson.fromJson(endpointConfig, type);
32733273

3274-
if (endpointUUID.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID)) {
3274+
if (APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(endpointUUID)) {
32753275
apiEndpoint = getAPIEndpointFromEndpointConfig(apiUUID, endpointConfigMap,
32763276
APIConstants.APIEndpoint.PRODUCTION);
3277-
} else if (endpointUUID.equals(APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID)) {
3277+
} else if (APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(endpointUUID)) {
32783278
apiEndpoint = getAPIEndpointFromEndpointConfig(apiUUID, endpointConfigMap,
32793279
APIConstants.APIEndpoint.SANDBOX);
32803280
} else {
@@ -3305,7 +3305,7 @@ public static APIEndpointDTO updateAPIEndpoint(String apiId, String endpointId,
33053305
if (oldEndpointConfig != null) {
33063306
if ((oldEndpointConfig.containsKey(APIConstants.ENDPOINT_SECURITY))) {
33073307
Map oldEndpointSecurity = (Map) oldEndpointConfig.get(APIConstants.ENDPOINT_SECURITY);
3308-
if (apiEndpointDTO.getDeploymentStage().equals(APIConstants.APIEndpoint.PRODUCTION)) {
3308+
if (APIConstants.APIEndpoint.PRODUCTION.equals(apiEndpointDTO.getDeploymentStage())) {
33093309
if (oldEndpointSecurity.get(APIConstants.ENDPOINT_SECURITY_PRODUCTION) != null) {
33103310
Map oldProductionEndpointSecurity = (Map) oldEndpointSecurity.get(
33113311
APIConstants.ENDPOINT_SECURITY_PRODUCTION);
@@ -3324,7 +3324,7 @@ public static APIEndpointDTO updateAPIEndpoint(String apiId, String endpointId,
33243324
APIConstants.ENDPOINT_SECURITY_API_KEY_VALUE).toString();
33253325
}
33263326
}
3327-
} else if (apiEndpointDTO.getDeploymentStage().equals(APIConstants.APIEndpoint.SANDBOX)) {
3327+
} else if (APIConstants.APIEndpoint.SANDBOX.equals(apiEndpointDTO.getDeploymentStage())) {
33283328
if (oldEndpointSecurity.get(APIConstants.ENDPOINT_SECURITY_SANDBOX) != null) {
33293329
Map oldSandboxEndpointSecurity = (Map) oldEndpointSecurity.get(
33303330
APIConstants.ENDPOINT_SECURITY_SANDBOX);
@@ -3359,10 +3359,10 @@ public static APIEndpointDTO updateAPIEndpoint(String apiId, String endpointId,
33593359

33603360
// extract endpoint URL
33613361
Object endpointURLObj;
3362-
if (apiEndpoint.getDeploymentStage().equals(APIConstants.APIEndpoint.PRODUCTION)) {
3362+
if (APIConstants.APIEndpoint.PRODUCTION.equals(apiEndpoint.getDeploymentStage())) {
33633363
endpointURLObj = apiEndpoint.getEndpointConfig()
33643364
.get(APIConstants.APIEndpoint.ENDPOINT_CONFIG_PRODUCTION_ENDPOINTS);
3365-
} else if (apiEndpoint.getDeploymentStage().equals(APIConstants.APIEndpoint.SANDBOX)) {
3365+
} else if (APIConstants.APIEndpoint.SANDBOX.equals(apiEndpoint.getDeploymentStage())) {
33663366
endpointURLObj = apiEndpoint.getEndpointConfig()
33673367
.get(APIConstants.APIEndpoint.ENDPOINT_CONFIG_SANDBOX_ENDPOINTS);
33683368
} else {
@@ -3408,10 +3408,10 @@ public static String addAPIEndpoint(String apiId, APIEndpointDTO apiEndpointDTO,
34083408

34093409
// extract endpoint URL
34103410
Object endpointURLObj;
3411-
if (apiEndpoint.getDeploymentStage().equals(APIConstants.APIEndpoint.PRODUCTION)) {
3411+
if (APIConstants.APIEndpoint.PRODUCTION.equals(apiEndpoint.getDeploymentStage())) {
34123412
endpointURLObj = apiEndpoint.getEndpointConfig()
34133413
.get(APIConstants.APIEndpoint.ENDPOINT_CONFIG_PRODUCTION_ENDPOINTS);
3414-
} else if (apiEndpoint.getDeploymentStage().equals(APIConstants.APIEndpoint.SANDBOX)) {
3414+
} else if (APIConstants.APIEndpoint.SANDBOX.equals(apiEndpoint.getDeploymentStage())) {
34153415
endpointURLObj = apiEndpoint.getEndpointConfig()
34163416
.get(APIConstants.APIEndpoint.ENDPOINT_CONFIG_SANDBOX_ENDPOINTS);
34173417
} else {
@@ -3426,18 +3426,19 @@ public static String addAPIEndpoint(String apiId, APIEndpointDTO apiEndpointDTO,
34263426
ExceptionCodes.API_ENDPOINT_URL_INVALID);
34273427
}
34283428

3429-
if (apiEndpoint.getDeploymentStage()
3430-
.equals(APIConstants.APIEndpoint.PRODUCTION) || apiEndpoint.getDeploymentStage()
3431-
.equals(APIConstants.APIEndpoint.SANDBOX)) {
3429+
if (APIConstants.APIEndpoint.PRODUCTION.equals(
3430+
apiEndpoint.getDeploymentStage()) || APIConstants.APIEndpoint.SANDBOX.equals(
3431+
apiEndpoint.getDeploymentStage())) {
34323432
String apiEndpointId = apiProvider.addAPIEndpoint(apiId, apiEndpoint, organization);
34333433
if (apiEndpointId == null) {
34343434
throw new APIManagementException("Error occurred while getting Endpoint of API " + apiId,
34353435
ExceptionCodes.ERROR_ADDING_API_ENDPOINT);
34363436
}
34373437
return apiEndpointId;
34383438
} else {
3439-
throw new APIManagementException("Invalid deployment stage. Deployment stage should be either " +
3440-
"'PRODUCTION' or 'SANDBOX'", ExceptionCodes.ERROR_ADDING_API_ENDPOINT);
3439+
throw new APIManagementException(
3440+
"Invalid deployment stage. Deployment stage should be either " + "'PRODUCTION' or 'SANDBOX'",
3441+
ExceptionCodes.ERROR_ADDING_API_ENDPOINT);
34413442
}
34423443
}
34433444

Diff for: components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ public Response deleteApiEndpoint(String apiId, String endpointUuid, MessageCont
336336

337337
// Handle scenario where reserved endpoint ID (reserved to track endpoint config in API object) is tried to be
338338
// deleted. This is not allowed. One can delete this only by updating the API endpoint config.
339-
if (endpointUuid.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID) || endpointUuid.equals(
340-
APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID)) {
339+
if (APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(
340+
endpointUuid) || APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(endpointUuid)) {
341341
String errorMessage = String.format(
342342
"Failed to delete API Endpoint with UUID %s. This Endpoint is read only", endpointUuid);
343343
throw new APIManagementException(errorMessage,
@@ -388,8 +388,8 @@ public Response deleteApiEndpoint(String apiId, String endpointUuid, MessageCont
388388
@Override
389389
public Response updateApiEndpoint(String apiId, String endpointId, APIEndpointDTO apIEndpointDTO,
390390
MessageContext messageContext) throws APIManagementException {
391-
if (endpointId.equals(APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID) || endpointId.equals(
392-
APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID)) {
391+
if (APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID.equals(
392+
endpointId) || APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID.equals(endpointId)) {
393393
String errorMessage = String.format(
394394
"Failed to update API Endpoint with UUID %s. This Endpoint is read only", endpointId);
395395
throw new APIManagementException(errorMessage,

0 commit comments

Comments
 (0)