@@ -24548,6 +24548,42 @@ public void deleteAPIEndpointsByApiUUID(String apiUUID) throws APIManagementExce
24548
24548
}
24549
24549
}
24550
24550
24551
+ /**
24552
+ * Add primary endpoint mappings to new API version
24553
+ *
24554
+ * @param existingApiUUID Existing API UUID
24555
+ * @param newApiUUID New API UUID
24556
+ * @param organization Organization
24557
+ * @throws APIManagementException if an error occurs while adding primary endpoint mappings
24558
+ */
24559
+ public void addPrimaryEndpointMappingsToNewAPI(String existingApiUUID, String newApiUUID, String organization)
24560
+ throws APIManagementException {
24561
+ try (Connection connection = APIMgtDBUtil.getConnection()) {
24562
+ connection.setAutoCommit(false);
24563
+ try (PreparedStatement addPrimaryMapping = connection.prepareStatement(
24564
+ SQLConstants.APIEndpointsSQLConstants.ADD_PRIMARY_ENDPOINT_MAPPING);
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()) {
24571
+ addPrimaryMapping.setString(1, newApiUUID);
24572
+ addPrimaryMapping.setString(2, resultSet.getString("ENDPOINT_UUID"));
24573
+ addPrimaryMapping.addBatch();
24574
+ }
24575
+ addPrimaryMapping.executeBatch();
24576
+ }
24577
+ connection.commit();
24578
+ } catch (SQLException e) {
24579
+ connection.rollback();
24580
+ handleException("Error while adding primary endpoint mappings to API : " + newApiUUID, e);
24581
+ }
24582
+ } catch (SQLException e) {
24583
+ handleException("Error while adding primary endpoint mappings to API : " + newApiUUID, e);
24584
+ }
24585
+ }
24586
+
24551
24587
/**
24552
24588
* Update endpoint using the provided apiEndpoint object.
24553
24589
*
@@ -24576,7 +24612,7 @@ public APIEndpointInfo updateAPIEndpoint(String apiUUID, APIEndpointInfo apiEndp
24576
24612
} else {
24577
24613
// Update API Endpoint
24578
24614
try (Connection connection = APIMgtDBUtil.getConnection()) {
24579
- apiEndpointUpdated = updateAPIEndpoint(connection, endpointUUID, apiEndpoint, organization);
24615
+ apiEndpointUpdated = updateAPIEndpoint(connection, apiUUID, endpointUUID, apiEndpoint, organization);
24580
24616
} catch (SQLException e) {
24581
24617
handleException("Failed to update the endpoint with ID " + endpointUUID, e);
24582
24618
}
@@ -24588,22 +24624,24 @@ public APIEndpointInfo updateAPIEndpoint(String apiUUID, APIEndpointInfo apiEndp
24588
24624
* Update API endpoint with provided UUID
24589
24625
*
24590
24626
* @param connection DB connection
24627
+ * @param apiUUID API UUID
24591
24628
* @param endpointUUID Endpoint identifier
24592
24629
* @param apiEndpoint Endpoint content
24593
24630
* @param organization Organization
24594
24631
* @return Updated endpoint content
24595
24632
* @throws SQLException if an SQL error occurs while updating API endpoint
24596
24633
* @throws APIManagementException if an error occurs while updating API endpoint
24597
24634
*/
24598
- private APIEndpointInfo updateAPIEndpoint(Connection connection, String endpointUUID, APIEndpointInfo apiEndpoint ,
24599
- String organization) throws SQLException, APIManagementException {
24635
+ private APIEndpointInfo updateAPIEndpoint(Connection connection, String apiUUID, String endpointUUID ,
24636
+ APIEndpointInfo apiEndpoint, String organization) throws SQLException, APIManagementException {
24600
24637
connection.setAutoCommit(false);
24601
24638
try (PreparedStatement statement = connection.prepareStatement(
24602
24639
SQLConstants.APIEndpointsSQLConstants.UPDATE_API_ENDPOINT_BY_UUID)) {
24603
24640
statement.setString(1, apiEndpoint.getName());
24604
24641
statement.setBinaryStream(2, fromEndpointConfigMapToBA(apiEndpoint.getEndpointConfig()));
24605
24642
statement.setString(3, endpointUUID);
24606
- statement.setString(4, organization);
24643
+ statement.setString(4, apiUUID);
24644
+ statement.setString(5, organization);
24607
24645
if (statement.executeUpdate() > 0) {
24608
24646
return apiEndpoint;
24609
24647
}
@@ -24622,7 +24660,7 @@ private APIEndpointInfo updateAPIEndpoint(Connection connection, String endpoint
24622
24660
* @param apiEndpoint Endpoint content
24623
24661
* @param organization Organization
24624
24662
* @return UUID of the added API endpoint
24625
- * @throws APIManagementException if failed to add API endpoint
24663
+ * @throws APIManagementException if failed to add API endpoint
24626
24664
*/
24627
24665
public String addAPIEndpoint(String apiUUID, APIEndpointInfo apiEndpoint, String organization)
24628
24666
throws APIManagementException {
@@ -24658,6 +24696,44 @@ private String addAPIEndpoint(String apiUUID, Connection connection, APIEndpoint
24658
24696
return null;
24659
24697
}
24660
24698
24699
+ /**
24700
+ * Add endpoints to the API
24701
+ *
24702
+ * @param apiUUID UUID of API
24703
+ * @param apiEndpointList List of endpoints to be added
24704
+ * @param organization Organization
24705
+ * @throws APIManagementException if failed to add endpoints
24706
+ */
24707
+ public void addAPIEndpoints(String apiUUID, List<APIEndpointInfo> apiEndpointList, String organization)
24708
+ throws APIManagementException {
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);
24730
+ }
24731
+ } catch (SQLException e) {
24732
+ handleException("Failed to add endpoints to API: " + apiUUID, e);
24733
+ }
24734
+ }
24735
+ }
24736
+
24661
24737
/**
24662
24738
* Add API primary endpoint mappings
24663
24739
*
@@ -24788,21 +24864,21 @@ public void addDefaultPrimaryEndpointMappings(API api, boolean isProductionEndpo
24788
24864
if (isProductionEndpoint) {
24789
24865
// add primary production endpoint mapping
24790
24866
addPrimaryMapping.setString(1, apiUUID);
24791
- addPrimaryMapping.setString(2,
24792
- apiUUID + APIConstants.APIEndpoint.PRIMARY_ENDPOINT_ID_SEPARATOR + APIConstants.APIEndpoint.PRODUCTION);
24867
+ addPrimaryMapping.setString(2, APIConstants.APIEndpoint.DEFAULT_PROD_ENDPOINT_ID);
24793
24868
addPrimaryMapping.addBatch();
24794
24869
}
24795
24870
24796
24871
if (isSandboxEndpoint) {
24797
24872
// add primary sandbox endpoint mapping
24798
24873
addPrimaryMapping.setString(1, apiUUID);
24799
- addPrimaryMapping.setString(2,
24800
- apiUUID + APIConstants.APIEndpoint.PRIMARY_ENDPOINT_ID_SEPARATOR + APIConstants.APIEndpoint.SANDBOX);
24874
+ addPrimaryMapping.setString(2, APIConstants.APIEndpoint.DEFAULT_SANDBOX_ENDPOINT_ID);
24801
24875
addPrimaryMapping.addBatch();
24802
24876
}
24803
24877
24804
- addPrimaryMapping.executeBatch();
24805
- connection.commit();
24878
+ if (isProductionEndpoint || isSandboxEndpoint) {
24879
+ addPrimaryMapping.executeBatch();
24880
+ connection.commit();
24881
+ }
24806
24882
} catch (SQLException e) {
24807
24883
connection.rollback();
24808
24884
handleException("Error while adding primary endpoint mappings for API : " + apiUUID, e);
0 commit comments