diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java index d9148d07cdc7..5923fbe4a3f4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java @@ -65,6 +65,7 @@ public interface APIProvider extends APIManager { */ Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws APIManagementException; + void deleteCustomBackendByID(String backendUUID, String apiUUID, String type) throws APIManagementException; /** * @param apiTypeWrapper Api type wrapper @@ -317,7 +318,8 @@ List getSubscriptionsOfAPI(String apiName, String apiVersion, Str API updateAPI(API api, API existingAPI) throws APIManagementException, FaultGatewaysException; void updateCustomBackend(API api,String type, InputStream sequence, String fileName, String customBackendUUID) throws APIManagementException; - Map getCustomBackendOfAPIByUUID(String customBackendUUID, String apiUUID, boolean isInfoOnly) throws APIManagementException; + Map getCustomBackendOfAPIByUUID(String customBackendUUID, String apiUUID, String type, boolean isInfoOnly) throws APIManagementException; + InputStream getCustomBackendSequenceOfAPIByUUID(String apiUUID, String backendUUID, String type) throws APIManagementException; void updateCustomBackendByRevisionID(String apiUUID, String type, String revision, String seqName, String backendUUID) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java index 1fea1b82b71c..dd94b5c68931 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java @@ -23,7 +23,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import jdk.internal.util.xml.impl.Input; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.util.AXIOMUtil; import org.apache.axis2.Constants; @@ -35,6 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.util.ClientUtils; +import org.apache.solr.common.util.Hash; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -1050,23 +1050,50 @@ public void updateCustomBackend(API api, String type, InputStream sequence, Stri } @Override - public Map getCustomBackendOfAPIByUUID(String customBackendUUID, String apiUUID, boolean isInfoOnly) throws APIManagementException { - return apiMgtDAO.getCustomBackendOfAPIByUUID(customBackendUUID, apiUUID, isInfoOnly); + public Map getCustomBackendOfAPIByUUID(String customBackendUUID, String apiUUID, String type, boolean isInfoOnly) throws APIManagementException { + return apiMgtDAO.getCustomBackendOfAPIByUUID(customBackendUUID, apiUUID, type, isInfoOnly); } - @Override - public void updateCustomBackendByRevisionID(String apiUUID, String type, String revision, - String seqName, String backendUUID) throws APIManagementException { + @Override public void updateCustomBackendByRevisionID(String apiUUID, String type, String revision, String seqName, + String backendUUID) throws APIManagementException { String customBackendUUID = UUID.randomUUID().toString(); - InputStream sequence = apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(backendUUID, apiUUID); + InputStream sequence = apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(backendUUID, apiUUID, type); apiMgtDAO.updateCustomBackendByRevision(apiUUID, seqName, sequence, type, revision, customBackendUUID); } + @Override public InputStream getCustomBackendSequenceOfAPIByUUID(String apiUUID, String backendUUID, String type) + throws APIManagementException { + return apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(backendUUID, apiUUID, type); + } + @Override public void addNewCustomBackendForRevision(String revisionUUID, String updatedBackendUUID, String apiUUID, Map config) throws APIManagementException { - InputStream sequence = apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(updatedBackendUUID, apiUUID); - config.put("sequence", sequence); - apiMgtDAO.addNewCustomBackendForAPIRevision(apiUUID, revisionUUID, config); + if (config.get("production") != null) { + InputStream sequence = apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(updatedBackendUUID, apiUUID, + "PRODUCTION"); + if (config.get("production") instanceof HashMap) { + String seqName = ((HashMap) config.get("production")).get("sequence_name").toString(); + String backendUUID = ((HashMap) config.get("production")).get("sequence_id").toString(); + apiMgtDAO.addNewCustomBackendForAPIRevision(apiUUID, revisionUUID, "PRODUCTION", seqName, sequence, + backendUUID); + } + } + + if (config.get("SANDBOX") != null) { + InputStream sequence = apiMgtDAO.getCustomBackendSequenceOfAPIByUUID(updatedBackendUUID, apiUUID, + "SANDBOX"); + if (config.get("sandbox") instanceof HashMap) { + String seqName = ((HashMap) config.get("sandbox")).get("sequence_name").toString(); + String backendUUID = ((HashMap) config.get("sandbox")).get("sequence_id").toString(); + apiMgtDAO.addNewCustomBackendForAPIRevision(apiUUID, revisionUUID, "SANDBOX", seqName, sequence, + backendUUID); + } + } + } + + @Override public void deleteCustomBackendByID(String backendUUID, String apiUUID, String type) + throws APIManagementException { + apiMgtDAO.deleteCustomBackend(apiUUID, backendUUID, type); } private void validateKeyManagers(API api) throws APIManagementException { @@ -6494,7 +6521,7 @@ public void deleteAPIRevision(String apiId, String apiRevisionId, String organiz ERROR_DELETING_API_REVISION,apiRevision.getApiUUID())); } apiMgtDAO.deleteAPIRevision(apiRevision); - apiMgtDAO.deleteCustomBackend(apiId, apiRevisionId); + apiMgtDAO.deleteCustomBackendByRevision(apiId, apiRevisionId); gatewayArtifactsMgtDAO.deleteGatewayArtifact(apiRevision.getApiUUID(), apiRevision.getRevisionUUID()); if (artifactSaver != null) { try { 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 627ad6b9a2df..b2a812db7562 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 @@ -20,7 +20,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import jdk.internal.util.xml.impl.Input; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; @@ -11194,7 +11193,7 @@ public Map retrieveCustomBackendOfAPIRevision(String apiUUID, St return map; } - public InputStream getCustomBackendSequenceOfAPIByUUID(String backendUUID, String apiUUID) throws APIManagementException { + public InputStream getCustomBackendSequenceOfAPIByUUID(String backendUUID, String apiUUID, String type) throws APIManagementException { String sqlQuery = SQLConstants.CustomBackendConstants.GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID; ResultSet rs = null; InputStream sequence = null; @@ -11220,27 +11219,31 @@ public InputStream getCustomBackendSequenceOfAPIByUUID(String backendUUID, Strin return sequence; } - public Map getCustomBackendOfAPIByUUID(String backendUUID, String apiUUID, boolean isInfo) throws APIManagementException { + public Map getCustomBackendOfAPIByUUID(String backendUUID, String apiUUID, String type, + boolean isInfo) throws APIManagementException { String sqlQuery; - Map endpointConfig = new HashMap<>(); + Map endpointConfig = new HashMap<>(); boolean isRevisioned = checkAPIUUIDIsARevisionUUID(apiUUID) != null; - if(isRevisioned) { + if (isRevisioned) { sqlQuery = SQLConstants.CustomBackendConstants.GET_REVISION_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID; } else { sqlQuery = SQLConstants.CustomBackendConstants.GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID; } ResultSet resultSet = null; try (Connection connection = APIMgtDBUtil.getConnection(); - PreparedStatement ps = connection.prepareStatement(sqlQuery)) { + PreparedStatement ps = connection.prepareStatement(sqlQuery)) { ps.setString(1, backendUUID); ps.setString(2, apiUUID); + ps.setString(3, type); resultSet = ps.executeQuery(); while (resultSet.next()) { - if(!isInfo) { + if (!isInfo) { try (InputStream in = resultSet.getBinaryStream("SEQUENCE")) { - endpointConfig.put("sequence", IOUtils.toString(in)); + endpointConfig.put("sequence", in); } catch (IOException ex) { - handleException("Error reading Sequence Content of Custom Backend: " + backendUUID + " API: " + apiUUID, ex); + handleException( + "Error reading Sequence Content of Custom Backend: " + backendUUID + " API: " + apiUUID, + ex); } } endpointConfig.put("type", resultSet.getString("TYPE")); @@ -17055,6 +17058,9 @@ public void addAPIRevision(APIRevision apiRevision) throws APIManagementExceptio // Retrieve API ID APIIdentifier apiIdentifier = APIUtil.getAPIIdentifierFromUUID(apiRevision.getApiUUID()); + + // Insert Custom Backend if Provided + int apiId = getAPIID(apiRevision.getApiUUID(), connection); int tenantId = APIUtil.getTenantId(APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName())); String tenantDomain = APIUtil.getTenantDomainFromTenantId(tenantId); @@ -17183,6 +17189,8 @@ public void addAPIRevision(APIRevision apiRevision) throws APIManagementExceptio insertScopeResourceMappingStatement.executeBatch(); insertProductResourceMappingStatement.executeBatch(); revisionAPIPolicies(apiRevision, tenantDomain, uriTemplateMap, connection); + // Add Custom Backend + revisionCustomBackend(apiRevision, connection); // Adding to AM_API_CLIENT_CERTIFICATE String getClientCertificatesQuery = SQLConstants.APIRevisionSqlConstants.GET_CLIENT_CERTIFICATES_OF_KEY_TYPE; @@ -20861,6 +20869,7 @@ public void updateCustomBackend(String apiUUID, String sequenceName, InputStream connection.setAutoCommit(false); prepStmt.setString(1, apiUUID); prepStmt.setString(2, backendUUID); + prepStmt.setString(3, type); prepStmt.executeUpdate(); addCustomBackend(apiUUID, sequenceName, null, sequence, type, connection, backendUUID); connection.commit(); @@ -20869,13 +20878,14 @@ public void updateCustomBackend(String apiUUID, String sequenceName, InputStream } } - public void deleteCustomBackend(String apiUUID, String revisionId) throws APIManagementException { - String deleteCustomBackedQuery = SQLConstants.CustomBackendConstants.DELETE_CUSTOM_BACKEND_BY_REVISION; + public void deleteCustomBackend(String apiUUID, String type, String backendUUID) throws APIManagementException { + String deleteCustomBackedQuery = SQLConstants.CustomBackendConstants.DELETE_CUSTOM_BACKEND; try (Connection connection = APIMgtDBUtil.getConnection(); PreparedStatement prepStmt = connection.prepareStatement(deleteCustomBackedQuery)) { connection.setAutoCommit(false); prepStmt.setString(1, apiUUID); - prepStmt.setString(2, revisionId); + prepStmt.setString(2, backendUUID); + prepStmt.setString(3, type); prepStmt.executeUpdate(); connection.commit(); } catch (SQLException e) { @@ -20883,6 +20893,24 @@ public void deleteCustomBackend(String apiUUID, String revisionId) throws APIMan } } + public void deleteCustomBackendByRevision(String apiUUID, String revisionUUID) throws APIManagementException { + boolean isRevisioned = checkAPIUUIDIsARevisionUUID(apiUUID) != null; + String deleteSqlQuery = SQLConstants.CustomBackendConstants.DELETE_CUSTOM_BACKEND_BY_REVISION; + if(isRevisioned) { + try (Connection con = APIMgtDBUtil.getConnection(); + PreparedStatement ps = con.prepareStatement(deleteSqlQuery)) { + con.setAutoCommit(false); + ps.setString(1, apiUUID); + ps.executeUpdate(); + con.commit(); + } catch (SQLException ex) { + handleException("Error deleting Custom Backend for Revision: "+ apiUUID, ex); + } + } else { + throw new APIManagementException("Invalid Revision Id: "+ apiUUID); + } + } + public void updateCustomBackendByRevision(String apiUUID, String sequenceName, InputStream sequence, String type, String revision, String backendUUID) throws APIManagementException { String deleteCustomBackedQuery = SQLConstants.CustomBackendConstants.DELETE_CUSTOM_BACKEND_BY_REVISION; @@ -20899,22 +20927,19 @@ public void updateCustomBackendByRevision(String apiUUID, String sequenceName, I } } - public void addNewCustomBackendForAPIRevision(String apiUUID, String revisionID, Map endpointConfig) throws APIManagementException { + public void addNewCustomBackendForAPIRevision(String apiUUID, String revisionID, String type, String seqName, InputStream sequence, String backendUUID) throws APIManagementException { String addSqlQuery = SQLConstants.CustomBackendConstants.ADD_CUSTOM_BACKEND; try (Connection con = APIMgtDBUtil.getConnection(); PreparedStatement ps = con.prepareStatement(addSqlQuery)) { - String backendUUID = endpointConfig.get("sequence_id").toString(); - InputStream sequence = (InputStream) endpointConfig.get("sequence"); - String type = endpointConfig.get("type").toString(); - String sequenceName = endpointConfig.get("sequence_name").toString(); con.setAutoCommit(false); ps.setString(1, backendUUID); ps.setString(2, apiUUID); ps.setBinaryStream(3, sequence); ps.setString(4, type); ps.setString(5, revisionID); - ps.setString(6, sequenceName); + ps.setString(6, seqName); ps.executeUpdate(); + con.commit(); } catch (SQLException ex) { handleException("Error when inserting Custom Backend data for API: " + apiUUID, ex); } @@ -20929,6 +20954,9 @@ public void addCustomBackend(String apiUUID, String sequenceName, String revisio prepStmt.setString(2, apiUUID); prepStmt.setBinaryStream(3, sequence); prepStmt.setString(4, type); + if (revision == null) { + revision = "0"; + } prepStmt.setString(5, revision); prepStmt.setString(6, sequenceName); prepStmt.executeUpdate(); @@ -21121,6 +21149,33 @@ private List getAPIPolicyMapping(String apiUUID, String revisio return policyList; } + private void revisionCustomBackend(APIRevision apiRevision, Connection connection) + throws SQLException, APIManagementException { + String addCBSqlQuery = SQLConstants.CustomBackendConstants.ADD_CUSTOM_BACKEND; + String getCBSQLQuery = SQLConstants.CustomBackendConstants.GET_ALL_API_SPECIFIC_CUSTOM_BACKENDS; + ResultSet rs = null; + try (Connection con = APIMgtDBUtil.getConnection(); + PreparedStatement getPstmt = con.prepareStatement(getCBSQLQuery); + PreparedStatement addPstmt = con.prepareStatement(addCBSqlQuery)) { + con.setAutoCommit(false); + getPstmt.setString(1, apiRevision.getApiUUID()); + rs = getPstmt.executeQuery(); + while (rs.next()) { + addPstmt.setString(1, rs.getString("ID")); + addPstmt.setString(2, apiRevision.getApiUUID()); + addPstmt.setBinaryStream(3, rs.getBinaryStream("SEQUENCE")); + addPstmt.setString(4, rs.getString("TYPE")); + addPstmt.setString(5, apiRevision.getRevisionUUID()); + addPstmt.setString(6, rs.getString("NAME")); + addPstmt.addBatch(); + } + addPstmt.executeBatch(); + } catch (SQLException ex) { + handleException("Error while adding Custom Backends to the database of API: " + apiRevision.getApiUUID(), + ex); + } + } + /** * Create a revision of API policis. This will clone the policy and policy mapping with each revision * diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index 0277df9a6526..3d567b8f2074 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -4404,13 +4404,14 @@ public static class SystemConfigsConstants { public static class CustomBackendConstants { public static final String ADD_CUSTOM_BACKEND = "INSERT INTO AM_API_CUSTOM_BACKEND (ID,API_UUID,SEQUENCE,TYPE,REVISION_UUID,NAME) " + "VALUES (?,?,?,?,?,?)"; - public static final String DELETE_CUSTOM_BACKEND = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND ID = ? AND REVISION_UUID IS NULL"; - public static final String DELETE_CUSTOM_BACKEND_BY_REVISION = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = ?"; + public static final String DELETE_CUSTOM_BACKEND = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND ID = ? AND TYPE = ? AND REVISION_UUID = 0"; + public static final String DELETE_CUSTOM_BACKEND_BY_REVISION = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE REVISION_UUID = ?"; public static final String DELETE_CUSTOM_BACKEND_BY_API = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ?"; public static final String GET_CUSTOM_BACKEND_OF_API_REVISION = "SELECT NAME, SEQUENCE, TYPE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = ?"; public static final String GET_CUSTOM_BACKEND_OF_API_DEFAULT_REVISION = "SELECT ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID IS NULL"; - public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ?"; - public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND API_UUID = ? AND REVISION_UUID IS NULL"; + public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ? AND ACB.TYPE = ?"; + public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.API_UUID = ? AND ACB.REVISION_UUID = 0 AND ACB.TYPE = ?"; + public static final String GET_ALL_API_SPECIFIC_CUSTOM_BACKENDS = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.API_UUID = ? AND ACB.REVISION_UUID = 0"; public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_META_DATA_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ?"; public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_META_DATA_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND API_UUID = ?"; public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_SEQUENCE_FROM_SEQUENCE_ID = "SELECT ACB.SEQUENCE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND API_UUID = ?"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml index 22c32227ea48..045a2df045f4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml @@ -487,6 +487,7 @@ paths: -H "Content-Type: application/json" -d @data.json "https://127.0.0.1:9443/api/am/publisher/v4/apis/7a2298c4-c905-403f-8fac-38c73301631f/topics"' + /apis/{apiId}/custom-backend/{customBackendId}: get: tags: @@ -576,6 +577,34 @@ paths: source: 'curl -k -X DELETE -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://127.0.0.1:9443/api/am/publisher/v4/apis/7a2298c4-c905-403f-8fac-38c73301631f/custom-backend/7a2298c4-c915-483f-8fac-38c73301631f"' + /apis/{apiId}/custom-backend/{customBackendId}/content: + get: + tags: + - API Custom Backend Sequence + summary: Download an API Specific Custom Backend + description: | + This operation can be used to download a particular API specific Custom Backend. + operationId: getAPISpecificOperationPolicyContentByPolicyId + parameters: + - $ref: '#/components/parameters/apiId' + - $ref: '#/components/parameters/customBackendId' + responses: + 200: + description: | + OK. + Custom Backend returned. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + content: + application/zip: + schema: + type: string + format: binary + /apis/{apiId}/custom-backend: put: tags: diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/CustomBackendDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/CustomBackendDTO.java new file mode 100644 index 000000000000..395cb3e890e2 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/CustomBackendDTO.java @@ -0,0 +1,142 @@ +package org.wso2.carbon.apimgt.rest.api.publisher.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.File; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class CustomBackendDTO { + + private String sequenceId = null; + private String sequenceName = null; + private String sequenceType = null; + private File sequence = null; + + /** + **/ + public CustomBackendDTO sequenceId(String sequenceId) { + this.sequenceId = sequenceId; + return this; + } + + + @ApiModelProperty(example = "943d3002-000c-42d3-a1b9-d6559f8a4d49", value = "") + @JsonProperty("sequenceId") + public String getSequenceId() { + return sequenceId; + } + public void setSequenceId(String sequenceId) { + this.sequenceId = sequenceId; + } + + /** + **/ + public CustomBackendDTO sequenceName(String sequenceName) { + this.sequenceName = sequenceName; + return this; + } + + + @ApiModelProperty(example = "943d3002-000c-42d3-a1b9-d6559f8a4d49-SANDBOX", value = "") + @JsonProperty("sequenceName") + public String getSequenceName() { + return sequenceName; + } + public void setSequenceName(String sequenceName) { + this.sequenceName = sequenceName; + } + + /** + **/ + public CustomBackendDTO sequenceType(String sequenceType) { + this.sequenceType = sequenceType; + return this; + } + + + @ApiModelProperty(example = "SANDBOX", value = "") + @JsonProperty("sequenceType") + public String getSequenceType() { + return sequenceType; + } + public void setSequenceType(String sequenceType) { + this.sequenceType = sequenceType; + } + + /** + **/ + public CustomBackendDTO sequence(File sequence) { + this.sequence = sequence; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("sequence") + public File getSequence() { + return sequence; + } + public void setSequence(File sequence) { + this.sequence = sequence; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + CustomBackendDTO customBackend = (CustomBackendDTO) o; + return Objects.equals(sequenceId, customBackend.sequenceId) && + Objects.equals(sequenceName, customBackend.sequenceName) && + Objects.equals(sequenceType, customBackend.sequenceType) && + Objects.equals(sequence, customBackend.sequence); + } + + @Override + public int hashCode() { + return Objects.hash(sequenceId, sequenceName, sequenceType, sequence); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class CustomBackendDTO {\n"); + + sb.append(" sequenceId: ").append(toIndentedString(sequenceId)).append("\n"); + sb.append(" sequenceName: ").append(toIndentedString(sequenceName)).append("\n"); + sb.append(" sequenceType: ").append(toIndentedString(sequenceType)).append("\n"); + sb.append(" sequence: ").append(toIndentedString(sequence)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapseArtifactGenerator.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapseArtifactGenerator.java index abe5153019e0..e6aaea5f17ff 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapseArtifactGenerator.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/SynapseArtifactGenerator.java @@ -114,10 +114,7 @@ public RuntimeArtifactDto generateGatewayArtifact(List ap tenantDomain, extractedFolderPath); } else { APIDTO apidto = ImportUtils.retrievedAPIDto(extractedFolderPath); - // Update the EndpointConfig if it's a Custom Backend - // updateCustomBackendOfAPI(apidto, runTimeArtifact.getRevision()); API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider()); - api.setUUID(apidto.getId()); if (APIConstants.APITransportType.GRAPHQL.toString().equals(api.getType())) { APIDefinition parser = new OAS3Parser(); @@ -138,7 +135,7 @@ public RuntimeArtifactDto generateGatewayArtifact(List ap gatewayAPIDTO = TemplateBuilderUtil.retrieveGatewayAPIDto(api, environment, tenantDomain, apidto, extractedFolderPath); } else if (api.getType() != null && - (APIConstants.APITransportType.HTTP.toString ().equals(api.getType()) + (APIConstants.APITransportType.HTTP.toString().equals(api.getType()) || APIConstants.API_TYPE_SOAP.equals(api.getType()) || APIConstants.API_TYPE_SOAPTOREST.equals(api.getType()) || APIConstants.APITransportType.WEBHOOK.toString() @@ -182,28 +179,6 @@ public RuntimeArtifactDto generateGatewayArtifact(List ap return runtimeArtifactDto; } - private void updateCustomBackendOfAPI(APIDTO apidto, String revisionID) throws APIManagementException { - Object endpointConfig = apidto.getEndpointConfig(); - // update the sequence name generated - if (endpointConfig != null) { - if (endpointConfig instanceof HashMap) { - if (APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( - ((HashMap) endpointConfig).get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE))) { - // Get Endpoint Configurations from the DB - Map conf = apiMgtDao.retrieveCustomBackendOfAPIRevision(apidto.getId(), revisionID); - if (conf == null) { - throw new APIManagementException( - "Cannot find the Custom Backend for the API: " + apidto.getId() + " , Revision: " - + revisionID); - } - ((HashMap) endpointConfig).put("sequence", conf.get("sequence")); - ((HashMap) endpointConfig).put("type", conf.get("type")); - } - } - apidto.setEndpointConfig(endpointConfig); - } - } - /** * Generate gateway policy artifact. * diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java index 71c9edced5cf..8f416e17aba4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java @@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.eclipse.jetty.util.IO; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -69,6 +70,7 @@ import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AdvertiseInfoDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CustomBackendDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ProductAPIDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePolicyInfoDTO; @@ -221,7 +223,7 @@ public static File exportApi(APIProvider apiProvider, APIIdentifier apiIdentifie // TODO: Add Custom Backend to the Archive JsonObject endpointConfig = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject(); if(APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(endpointConfig.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString())) { - addCustomBackendToAPI(archivePath, apiProvider, api, currentApiUuid, endpointConfig); + addCustomBackendToArchive(archivePath, apiProvider, api, currentApiUuid, endpointConfig); } addGatewayEnvironmentsToArchive(archivePath, apiDtoToReturn.getId(), exportFormat, apiProvider); @@ -636,20 +638,27 @@ public static void addEndpointCertificatesToArchive(String archivePath, APIDTO a } } - public static void addCustomBackendToAPI(String archivePath, + public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, API api, String currentApiUuid, JsonObject endpointConfig) throws APIManagementException { - String exportedCustomBackend = null; try { - String backendUUID = endpointConfig.get("sequence_id").getAsString(); + JsonElement prodElement = endpointConfig.get("production"); CommonUtil.createDirectory(archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY); - String customBackendName = APIUtil.getCustomBackendName(api.getUuid(), endpointConfig.get("type").getAsString()); - Map endpointConfigMap = apiProvider.getCustomBackendOfAPIByUUID(backendUUID, currentApiUuid, false); - if(endpointConfigMap != null) { - exportCustomBackend(customBackendName, endpointConfigMap, archivePath); + if(prodElement != null) { + String backendUUID = prodElement.getAsJsonObject().get("sequence_id").getAsString(); + String sequenceName = prodElement.getAsJsonObject().get("sequence_name").getAsString(); + InputStream sequence = apiProvider.getCustomBackendSequenceOfAPIByUUID(backendUUID, api.getUuid(), "PRODUCTION"); + exportCustomBackend(sequenceName, IOUtils.toString(sequence), archivePath); + } + JsonElement sandElement = endpointConfig.get("sandbox"); + if(sandElement != null) { + String backendUUID = sandElement.getAsJsonObject().get("sequence_id").getAsString(); + String sequenceName = sandElement.getAsJsonObject().get("sequence_name").getAsString(); + InputStream sequence = apiProvider.getCustomBackendSequenceOfAPIByUUID(backendUUID, api.getUuid(), "SANDBOX"); + exportCustomBackend(sequenceName, IOUtils.toString(sequence), archivePath); } } catch (IOException | APIImportExportException ex) { - + throw new APIManagementException("Error adding Custom Backends to the API Directory: " + api.getUuid(), ex); } } @@ -761,12 +770,9 @@ public static void exportPolicyData(String policyFileName, OperationPolicyData p } } - public static void exportCustomBackend(String customBackendFileName, Map endpointConfig, String archivePath) throws APIImportExportException, IOException { + public static void exportCustomBackend(String customBackendFileName, String sequence, String archivePath) throws APIImportExportException, IOException { String customBackendName = archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY + File.separator + customBackendFileName; - if(endpointConfig != null && endpointConfig.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE) != null && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(endpointConfig.get( - API_ENDPOINT_CONFIG_PROTOCOL_TYPE))) { - CommonUtil.writeFile(customBackendName + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML, endpointConfig.get("sequence")); - } + CommonUtil.writeFile(customBackendName + APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION_XML, sequence); } /** diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java index a8790e3043b9..5d28889e9975 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java @@ -18,6 +18,7 @@ import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentListDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CustomBackendDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorDTO; @@ -377,6 +378,27 @@ public Response createNewAPIVersion( @NotNull @Size(max=30) @ApiParam(value = "V return delegate.createNewAPIVersion(newVersion, apiId, defaultVersion, serviceVersion, securityContext); } + @DELETE + @Path("/{apiId}/custom-backend/{customBackendId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Delete Custom Backend of the API", notes = "This operation can be used to remove the Custom Backend of the API", response = Void.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:api_delete", description = "Delete API"), + @AuthorizationScope(scope = "apim:api_manage", description = "Manage all API related operations"), + @AuthorizationScope(scope = "apim:api_import_export", description = "Import and export APIs related operations") + }) + }, tags={ "APIs", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. Resource successfully deleted. ", response = Void.class), + @ApiResponse(code = 403, message = "Forbidden. The request must be conditional but no condition has been specified.", response = ErrorDTO.class), + @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), + @ApiResponse(code = 409, message = "Conflict. Specified resource already exists.", response = ErrorDTO.class), + @ApiResponse(code = 412, message = "Precondition Failed. The request has not been performed because one of the preconditions is not met.", response = ErrorDTO.class) }) + public Response customBackendDelete(@ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId, @ApiParam(value = "Custom Backend ID ",required=true) @PathParam("customBackendId") String customBackendId, @ApiParam(value = "Validator for conditional requests; based on ETag. " )@HeaderParam("If-Match") String ifMatch) throws APIManagementException{ + return delegate.customBackendDelete(apiId, customBackendId, ifMatch, securityContext); + } + @PUT @Path("/{apiId}/custom-backend") @Consumes({ "multipart/form-data" }) @@ -1310,6 +1332,27 @@ public Response getAuditReportOfAPI(@ApiParam(value = "**API ID** consisting of return delegate.getCommentOfAPI(commentId, apiId, xWSO2Tenant, ifNoneMatch, includeCommenterInfo, replyLimit, replyOffset, securityContext); } + @GET + @Path("/{apiId}/custom-backend/{customBackendId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get Custom Backend of the API", notes = "This operation can be used to get Custom Backend data of the API", response = CustomBackendDTO.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:api_view", description = "View API"), + @AuthorizationScope(scope = "apim:api_manage", description = "Manage all API related operations"), + @AuthorizationScope(scope = "apim:api_import_export", description = "Import and export APIs related operations"), + @AuthorizationScope(scope = "apim:api_product_import_export", description = "Import and export API Products related operations") + }) + }, tags={ "APIs", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. Requested API Custom Backend is returned ", response = CustomBackendDTO.class), + @ApiResponse(code = 304, message = "Not Modified. Empty body because the client has already the latest version of the requested resource (Will be supported in future). ", response = Void.class), + @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), + @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) }) + public Response getCustomBackendData(@ApiParam(value = "Custom Backend ID ",required=true) @PathParam("customBackendId") String customBackendId, @ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId) throws APIManagementException{ + return delegate.getCustomBackendData(customBackendId, apiId, securityContext); + } + @GET @Path("/{apiId}/generated-mock-scripts") diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java index 033389c88f79..1e44fdae9483 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java @@ -27,6 +27,7 @@ import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentListDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CustomBackendDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorDTO; @@ -79,6 +80,7 @@ public interface ApisApiService { public Response createAPI(APIDTO APIDTO, String openAPIVersion, MessageContext messageContext) throws APIManagementException; public Response createAPIRevision(String apiId, APIRevisionDTO apIRevisionDTO, MessageContext messageContext) throws APIManagementException; public Response createNewAPIVersion(String newVersion, String apiId, Boolean defaultVersion, String serviceVersion, MessageContext messageContext) throws APIManagementException; + public Response customBackendDelete(String apiId, String customBackendId, String ifMatch, MessageContext messageContext) throws APIManagementException; public Response customBackendUpdate(String apiId, String ifMatch, InputStream sequenceInputStream, Attachment sequenceDetail, String type, MessageContext messageContext) throws APIManagementException; public Response deleteAPI(String apiId, String ifMatch, MessageContext messageContext) throws APIManagementException; public Response deleteAPIClientCertificateByAlias(String alias, String apiId, MessageContext messageContext) throws APIManagementException; @@ -126,6 +128,7 @@ public interface ApisApiService { public Response getAmazonResourceNamesOfAPI(String apiId, MessageContext messageContext) throws APIManagementException; public Response getAuditReportOfAPI(String apiId, String accept, MessageContext messageContext) throws APIManagementException; public Response getCommentOfAPI(String commentId, String apiId, String xWSO2Tenant, String ifNoneMatch, Boolean includeCommenterInfo, Integer replyLimit, Integer replyOffset, MessageContext messageContext) throws APIManagementException; + public Response getCustomBackendData(String customBackendId, String apiId, MessageContext messageContext) throws APIManagementException; public Response getGeneratedMockScriptsOfAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException; public Response getGraphQLPolicyComplexityOfAPI(String apiId, MessageContext messageContext) throws APIManagementException; public Response getGraphQLPolicyComplexityTypesOfAPI(String apiId, MessageContext messageContext) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java index dc9c9655ee1d..8b89e2f42dff 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java @@ -163,6 +163,34 @@ public Response getAllAPIs(Integer limit, Integer offset, String sortBy, String return null; } + @Override public Response getCustomBackendData(String customBackendId, String apiId, MessageContext messageContext) + throws APIManagementException { + APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider(); + + //validate if api exists + CommonUtils.validateAPIExistence(apiId); + String type = "SANDBOX"; + + Map endpointConfig = apiProvider.getCustomBackendOfAPIByUUID(customBackendId, apiId, type, + true); + CustomBackendDTO backendDTO = new CustomBackendDTO(); + backendDTO.setSequenceName(endpointConfig.get("sequence_name").toString()); + backendDTO.setSequenceId(endpointConfig.get("sequence_id").toString()); + backendDTO.setSequenceType(endpointConfig.get("type").toString()); + return Response.ok().entity(backendDTO).build(); + } + + @Override public Response customBackendDelete(String apiId, String customBackendId, String ifMatch, + MessageContext messageContext) throws APIManagementException { + APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider(); + + //validate if api exists + CommonUtils.validateAPIExistence(apiId); + String type = "SANDBOX"; + apiProvider.deleteCustomBackendByID(apiId, customBackendId, type); + return Response.ok().entity(null).build(); + } + @Override public Response createAPI(APIDTO body, String oasVersion, MessageContext messageContext) throws APIManagementException{ @@ -3764,20 +3792,6 @@ public Response createAPIRevision(String apiId, APIRevisionDTO apIRevisionDTO, M //adding the api revision String revisionId = apiProvider.addAPIRevision(apiRevision, organization); - Object endpointConfig = apiDto.getEndpointConfig(); - - if (endpointConfig != null && endpointConfig instanceof HashMap) { - String endpointType = ((HashMap) endpointConfig).get("endpoint_type").toString(); - if (endpointType != null && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(endpointType)) { - String sequenceName = ((HashMap) endpointConfig).get("sequence_name").toString(); - String sequenceEndpointType = ((HashMap) endpointConfig).get("sequence_type").toString(); - String backendUUID = ((HashMap) endpointConfig).get("sequence_id").toString(); - // Update Custom Backend table - apiProvider.addNewCustomBackendForRevision(revisionId, backendUUID, apiId, - (HashMap) endpointConfig); - } - } - //Retrieve the newly added APIRevision to send in the response payload APIRevision createdApiRevision = apiProvider.getAPIRevision(revisionId); APIRevisionDTO createdApiRevisionDTO = APIMappingUtil.fromAPIRevisiontoDTO(createdApiRevision); diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql index 11dff57f1f47..78c782396c83 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql @@ -1524,11 +1524,11 @@ CREATE TABLE IF NOT EXISTS AM_API ( CREATE TABLE IF NOT EXISTS AM_API_CUSTOM_BACKEND ( ID VARCHAR(60) NOT NULL, API_UUID VARCHAR(256) NOT NULL, - REVISION_UUID VARCHAR(256), + REVISION_UUID VARCHAR(256) DEFAULT '0', SEQUENCE LONGBLOB, NAME VARCHAR(256) NOT NULL, TYPE VARCHAR(120) NOT NULL, - PRIMARY KEY (ID, API_UUID, REVISION_UUID), + PRIMARY KEY (ID, API_UUID, REVISION_UUID, TYPE), FOREIGN KEY (API_UUID) REFERENCES AM_API(API_UUID) ON DELETE CASCADE )ENGINE INNODB;