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 6841ab42dda2..3a3bd0c09728 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 @@ -6979,7 +6979,7 @@ public boolean isPolicyMappingDeploymentExists(String gatewayPolicyMappingId, St @Override public boolean hasExistingDeployments(String tenantDomain, String gatewayLabel) throws APIManagementException { return !StringUtils.isBlank( - apiMgtDAO.getGatewayPolicyMappingByGatewayLabel(tenantDomain, gatewayLabel)); + apiMgtDAO.getGatewayPolicyMappingByGatewayLabel(gatewayLabel, tenantDomain)); } @Override 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/GatewayPoliciesApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/GatewayPoliciesApiServiceImpl.java index e310efe3dfc0..1dc6700a231e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/GatewayPoliciesApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/GatewayPoliciesApiServiceImpl.java @@ -128,9 +128,13 @@ public Response engageGlobalPolicy(String gatewayPolicyMappingId, // checks whether the gateway policy mapping exists in the particular gateway for (GatewayPolicyDeploymentDTO gatewayPolicyDeploymentDTO : gatewayPolicyDeploymentDTOList) { String gwName = gatewayPolicyDeploymentDTO.getGatewayLabel(); - if (apiProvider.hasExistingDeployments(organization, gwName)) { + boolean isDeployment = gatewayPolicyDeploymentDTO.isGatewayDeployment(); + if (isDeployment && apiProvider.hasExistingDeployments(organization, gwName)) { RestApiUtil.handleBadRequest("Gateway policy mapping is already deployed in the gateway: " + gwName, log); + } else if (!isDeployment && !apiProvider.hasExistingDeployments(organization, gwName)) { + RestApiUtil.handleBadRequest("Gateway policy mapping is not deployed in the gateway: " + gwName, + log); } } List operationPolicyDataList = apiProvider.getGatewayPolicyDataListByPolicyId( 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 b2d796182956..5efcbd01c27c 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 @@ -8375,6 +8375,8 @@ paths: $ref: '#/components/responses/Forbidden' 404: $ref: '#/components/responses/NotFound' + 412: + $ref: '#/components/responses/PreconditionFailed' 500: $ref: '#/components/responses/InternalServerError' security: @@ -8463,7 +8465,9 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/GatewayPolicyDeployment' + type: array + items: + $ref: '#/components/schemas/GatewayPolicyDeployment' 400: $ref: '#/components/responses/BadRequest' 404: