From f78fbaee8d7f2e73defbb315025bd9fb40fdb2e7 Mon Sep 17 00:00:00 2001 From: Naduni Pamudika Date: Fri, 3 Jan 2025 11:18:30 +0530 Subject: [PATCH] Add publisher rest API changes to support GW visibility --- .../api/model/APIRevisionDeployment.java | 10 +++++++++ .../carbon/apimgt/impl/dao/ApiMgtDAO.java | 1 + .../impl/dao/constants/SQLConstants.java | 4 ++-- .../publisher/ApisApiServiceImplUtils.java | 5 +++-- .../src/main/resources/publisher-api.yaml | 6 +++++ .../v1/dto/APIRevisionDeploymentDTO.java | 22 ++++++++++++++++++- .../api/publisher/v1/dto/EnvironmentDTO.java | 22 ++++++++++++++++++- .../v1/common/mappings/APIMappingUtil.java | 1 + .../mappings/EnvironmentMappingUtil.java | 1 + .../publisher/v1/impl/ApisApiServiceImpl.java | 5 +++-- .../src/main/resources/publisher-api.yaml | 6 +++++ .../src/main/resources/sql/db2.sql | 1 + .../src/main/resources/sql/h2.sql | 1 + .../src/main/resources/sql/mssql.sql | 1 + .../src/main/resources/sql/mysql.sql | 1 + .../src/main/resources/sql/mysql_cluster.sql | 1 + .../src/main/resources/sql/oracle.sql | 1 + .../src/main/resources/sql/oracle_23c.sql | 1 + .../src/main/resources/sql/oracle_rac.sql | 1 + .../src/main/resources/sql/postgresql.sql | 1 + 20 files changed, 84 insertions(+), 8 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIRevisionDeployment.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIRevisionDeployment.java index b27d156081b9..30b9b5b9d5fa 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIRevisionDeployment.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIRevisionDeployment.java @@ -33,6 +33,8 @@ public class APIRevisionDeployment implements Serializable { private String deployedTime; private String successDeployedTime; + private String visibility; + public int getId() { return id; } @@ -96,4 +98,12 @@ public WorkflowStatus getStatus() { public void setStatus(WorkflowStatus status) { this.status = status; } + + public String getVisibility() { + return visibility; + } + + public void setVisibility(String visibility) { + this.visibility = visibility; + } } 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 0cbbd5e06b6c..53b67ed14091 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 @@ -18043,6 +18043,7 @@ public void addAPIRevisionDeployment(String apiRevisionId, List vhosts = new ArrayList(); private List endpointURIs = new ArrayList(); @@ -160,6 +161,23 @@ public void setProvider(String provider) { this.provider = provider; } + /** + **/ + public EnvironmentDTO visibility(String visibility) { + this.visibility = visibility; + return this; + } + + + @ApiModelProperty(example = "Role1, Role2", value = "") + @JsonProperty("visibility") + public String getVisibility() { + return visibility; + } + public void setVisibility(String visibility) { + this.visibility = visibility; + } + /** **/ public EnvironmentDTO showInApiConsole(Boolean showInApiConsole) { @@ -249,6 +267,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(gatewayType, environment.gatewayType) && Objects.equals(serverUrl, environment.serverUrl) && Objects.equals(provider, environment.provider) && + Objects.equals(visibility, environment.visibility) && Objects.equals(showInApiConsole, environment.showInApiConsole) && Objects.equals(vhosts, environment.vhosts) && Objects.equals(endpointURIs, environment.endpointURIs) && @@ -257,7 +276,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, displayName, type, gatewayType, serverUrl, provider, showInApiConsole, vhosts, endpointURIs, additionalProperties); + return Objects.hash(id, name, displayName, type, gatewayType, serverUrl, provider, visibility, showInApiConsole, vhosts, endpointURIs, additionalProperties); } @Override @@ -272,6 +291,7 @@ public String toString() { sb.append(" gatewayType: ").append(toIndentedString(gatewayType)).append("\n"); sb.append(" serverUrl: ").append(toIndentedString(serverUrl)).append("\n"); sb.append(" provider: ").append(toIndentedString(provider)).append("\n"); + sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n"); sb.append(" showInApiConsole: ").append(toIndentedString(showInApiConsole)).append("\n"); sb.append(" vhosts: ").append(toIndentedString(vhosts)).append("\n"); sb.append(" endpointURIs: ").append(toIndentedString(endpointURIs)).append("\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/mappings/APIMappingUtil.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/APIMappingUtil.java index 7138879d5a67..146cebac0cba 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/APIMappingUtil.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/APIMappingUtil.java @@ -3437,6 +3437,7 @@ public static APIRevisionDeploymentDTO fromAPIRevisionDeploymenttoDTO(APIRevisio + model.getSuccessDeployedTime(), e); } } + apiRevisionDeploymentDTO.setVisibility(model.getVisibility()); return apiRevisionDeploymentDTO; } 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/EnvironmentMappingUtil.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/EnvironmentMappingUtil.java index 67f419e1052a..414323dc7fa8 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/EnvironmentMappingUtil.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/EnvironmentMappingUtil.java @@ -59,6 +59,7 @@ public static EnvironmentDTO fromEnvironmentToDTO(Environment environment) { environmentDTO.setServerUrl(environment.getServerURL()); environmentDTO.setShowInApiConsole(environment.isShowInConsole()); environmentDTO.setProvider(environment.getProvider()); + environmentDTO.setVisibility(environment.getVisibility()); environmentDTO.setVhosts(environment.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO) .collect(Collectors.toList())); environmentDTO.setAdditionalProperties(fromAdditionalPropertiesToAdditionalPropertiesDTO 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 da6a6d7ab74a..92e047e36f95 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 @@ -4571,7 +4571,7 @@ private APIDTO importAsyncAPISpecification(InputStream definition, String defini public Response updateAPIDeployment(String apiId, String deploymentId, APIRevisionDeploymentDTO apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException { APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider(); - + String organization = RestApiUtil.getValidatedOrganization(messageContext); //validate if api exists APIInfo apiInfo = CommonUtils.validateAPIExistence(apiId); //validate API update operation permitted based on the LC state @@ -4581,8 +4581,9 @@ public Response updateAPIDeployment(String apiId, String deploymentId, APIRevisi String vhost = apIRevisionDeploymentDTO.getVhost(); Boolean displayOnDevportal = apIRevisionDeploymentDTO.isDisplayOnDevportal(); String decodedDeploymentName = ApisApiServiceImplUtils.getDecodedDeploymentName(deploymentId); + Map environments = APIUtil.getEnvironments(organization); APIRevisionDeployment apiRevisionDeployment = ApisApiServiceImplUtils.mapApiRevisionDeployment(revisionId, vhost, - displayOnDevportal, decodedDeploymentName); + displayOnDevportal, decodedDeploymentName, environments.get(decodedDeploymentName).getVisibility()); apiProvider.updateAPIDisplayOnDevportal(apiId, revisionId, apiRevisionDeployment); APIRevisionDeployment apiRevisionDeploymentsResponse = apiProvider. getAPIRevisionDeployment(decodedDeploymentName, revisionId); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml index abd313167b27..3f9c3ad949c2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml @@ -10586,6 +10586,9 @@ components: pattern: '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' type: string example: mg.wso2.com + visibility: + type: string + example: Role1, Role2 displayOnDevportal: type: boolean example: true @@ -11835,6 +11838,9 @@ components: provider: type: string example: wso2 + visibility: + type: string + example: Role1, Role2 showInApiConsole: type: boolean example: true diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql index 22860ef86d35..d63dffeef300 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql @@ -2990,6 +2990,7 @@ CREATE TABLE AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL SMALLINT DEFAULT 0, DEPLOYED_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON DELETE CASCADE) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql index 23148e3a0149..b0966959f453 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql @@ -2218,6 +2218,7 @@ CREATE TABLE IF NOT EXISTS AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL BOOLEAN DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON UPDATE CASCADE ON DELETE CASCADE ); diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql index 1be3b54343d2..0be3c5f2249f 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql @@ -2480,6 +2480,7 @@ CREATE TABLE AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL BIT DEFAULT 0, DEPLOYED_TIME DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON UPDATE CASCADE ON DELETE CASCADE ); 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 f75d4dfc0f8f..27db04f7d1da 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 @@ -2253,6 +2253,7 @@ CREATE TABLE IF NOT EXISTS AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL BOOLEAN DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON UPDATE CASCADE ON DELETE CASCADE )ENGINE INNODB; diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql index e634d6cdc8dc..b2a568df80f9 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql @@ -2397,6 +2397,7 @@ CREATE TABLE IF NOT EXISTS AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL BOOLEAN DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON UPDATE CASCADE ON DELETE CASCADE )ENGINE=NDB; diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql index 4355a9842b81..a6c15e3a9c86 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql @@ -3477,6 +3477,7 @@ CREATE TABLE AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL INTEGER DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON DELETE CASCADE) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql index 13b20362d783..64ab72add3e8 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_23c.sql @@ -3477,6 +3477,7 @@ CREATE TABLE AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL INTEGER DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON DELETE CASCADE) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql index eba0242a4a7d..0a027fce8d76 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql @@ -3449,6 +3449,7 @@ CREATE TABLE AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL INTEGER DEFAULT 0, DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON DELETE CASCADE) / diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql index bb26be31702e..e04e848e082e 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql @@ -2567,6 +2567,7 @@ CREATE TABLE IF NOT EXISTS AM_DEPLOYMENT_REVISION_MAPPING ( REVISION_STATUS VARCHAR(255) NULL, DISPLAY_ON_DEVPORTAL BOOLEAN DEFAULT '0', DEPLOYED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + GW_VISIBILITY VARCHAR(2048) NULL, PRIMARY KEY (NAME, REVISION_UUID), FOREIGN KEY (REVISION_UUID) REFERENCES AM_REVISION(REVISION_UUID) ON UPDATE CASCADE ON DELETE CASCADE );