diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java index 27e3534bb49c..f4d14f6f19ed 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java @@ -98,8 +98,9 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; OperationPolicy policyObj = (OperationPolicy) o; - return policyId == policyObj.policyId && policyName == policyObj.policyName && policyVersion == policyObj.policyVersion - && direction.equals(policyObj.direction) && parameters.equals(policyObj.parameters); + return Objects.equals(policyName, policyObj.policyName) && Objects.equals(policyVersion, + policyObj.policyVersion) && Objects.equals(direction, policyObj.direction) && Objects.equals( + parameters, policyObj.parameters) && Objects.equals(policyId, policyObj.policyId); } @Override @@ -113,4 +114,16 @@ public int compareTo(OperationPolicy o) { return this.order - o.getOrder(); } + + @Override + public String toString() { + + return "operationPolicies {" + + ", policyName ='" + policyName + '\'' + + ", policyVersion ='" + policyVersion + '\'' + + ", direction ='" + direction + '\'' + + ", order ='" + order + '\'' + + ", policyId ='" + policyId + '\'' + + '}'; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/URLMapping.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/URLMapping.java index 16464c728f1b..5424825b7c43 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/URLMapping.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/subscription/URLMapping.java @@ -18,9 +18,13 @@ package org.wso2.carbon.apimgt.api.model.subscription; +import org.wso2.carbon.apimgt.api.model.OperationPolicy; + import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; public class URLMapping { @@ -29,6 +33,7 @@ public class URLMapping { private String httpMethod; private String urlPattern; private List scopes = new ArrayList<>(); + private Set operationPolicies = new HashSet<>(); public String getHttpMethod() { @@ -79,6 +84,13 @@ public List getScopes() { return scopes; } + public void setOperationPolicies(OperationPolicy operationPolicy){ + this.operationPolicies.add(operationPolicy); + } + public Set getOperationPolicies(){ + return operationPolicies; + } + @Override public boolean equals(Object o) { @@ -105,6 +117,7 @@ public String toString() { ", authScheme ='" + authScheme + '\'' + ", httpMethod ='" + httpMethod + '\'' + ", urlPattern ='" + urlPattern + '\'' + + ", operationPolicies ='" + operationPolicies + '\'' + '}'; } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/API.java b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/API.java index d2e6e06cbb2f..bc1e4b41b045 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/API.java +++ b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/API.java @@ -17,6 +17,9 @@ package org.wso2.carbon.apimgt.common.analytics.publishers.dto; +import java.util.ArrayList; +import java.util.List; + /** * Api attribute in analytics event. */ @@ -27,6 +30,7 @@ public class API { private String apiVersion; private String apiCreator; private String apiCreatorTenantDomain; + private List uriTemplates = new ArrayList<>(); public String getApiId() { return apiId; @@ -75,4 +79,12 @@ public String getApiCreatorTenantDomain() { public void setApiCreatorTenantDomain(String apiCreatorTenantDomain) { this.apiCreatorTenantDomain = apiCreatorTenantDomain; } + + public List getUriTemplates() { + return uriTemplates; + } + + public void setUriTemplates(List uriTemplates) { + this.uriTemplates = uriTemplates; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/OperationPolicy.java b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/OperationPolicy.java new file mode 100644 index 000000000000..dfbae52b70b6 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/OperationPolicy.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.apimgt.common.analytics.publishers.dto; + +/** + * OperationPolicy object in analytics event. + */ +public class OperationPolicy { + private String policyId; + private String policyName; + private String policyVersion; + private String direction; + private int order; + + public String getPolicyId() { + return policyId; + } + + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/URITemplate.java b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/URITemplate.java new file mode 100644 index 000000000000..fa87cf236701 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.common.analytics/src/main/java/org/wso2/carbon/apimgt/common/analytics/publishers/dto/URITemplate.java @@ -0,0 +1,65 @@ +package org.wso2.carbon.apimgt.common.analytics.publishers.dto; + +import java.util.ArrayList; +import java.util.List; + +/** + * URITemplate attribute in analytics event. + */ +public class URITemplate { + private String uriTemplate; + private String resourceURI; + private String resourceSandboxURI; + private String httpVerb; + + private String authScheme; + private List operationPolicies = new ArrayList<>(); + + public void setOperationPolicies(List operationPolicies) { + this.operationPolicies = operationPolicies; + } + + public List getOperationPolicies() { + return operationPolicies; + } + + public void setHttpVerb(String httpVerb) { + this.httpVerb = httpVerb; + } + + public String getHttpVerb() { + return httpVerb; + } + + public void setUriTemplate(String uriTemplate) { + this.uriTemplate = uriTemplate; + } + + public String getUriTemplate() { + return uriTemplate; + } + + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + + public String getResourceURI() { + return resourceURI; + } + + public void setResourceSandboxURI(String resourceSandboxURI) { + this.resourceSandboxURI = resourceSandboxURI; + } + + public String getResourceSandboxURI() { + return resourceSandboxURI; + } + + public void setAuthScheme(String authScheme) { + this.authScheme = authScheme; + } + + public String getAuthScheme() { + return authScheme; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/SynapseAnalyticsDataProvider.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/SynapseAnalyticsDataProvider.java index 92539b3715d7..7ac0debff486 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/SynapseAnalyticsDataProvider.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/analytics/SynapseAnalyticsDataProvider.java @@ -28,6 +28,8 @@ import org.apache.synapse.core.axis2.Axis2MessageContext; import org.apache.synapse.rest.RESTConstants; import org.apache.synapse.transport.passthru.util.RelayUtils; +import org.wso2.carbon.apimgt.api.model.OperationPolicy; +import org.wso2.carbon.apimgt.api.model.subscription.URLMapping; import org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsCustomDataProvider; import org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider; import org.wso2.carbon.apimgt.common.analytics.exceptions.DataNotFoundException; @@ -38,6 +40,7 @@ import org.wso2.carbon.apimgt.common.analytics.publishers.dto.MetaInfo; import org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation; import org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target; +import org.wso2.carbon.apimgt.common.analytics.publishers.dto.URITemplate; import org.wso2.carbon.apimgt.common.analytics.publishers.dto.enums.EventCategory; import org.wso2.carbon.apimgt.common.analytics.publishers.dto.enums.FaultCategory; import org.wso2.carbon.apimgt.common.analytics.publishers.dto.enums.FaultSubCategory; @@ -58,9 +61,13 @@ import javax.xml.stream.XMLStreamException; import java.io.IOException; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; import static org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS; import static org.wso2.carbon.apimgt.gateway.handlers.analytics.Constants.UNKNOWN_VALUE; @@ -163,6 +170,30 @@ public API getApi() throws DataNotFoundException { api.setApiVersion(apiObj.getApiVersion()); api.setApiCreator(apiObj.getApiProvider()); api.setApiCreatorTenantDomain(MultitenantUtils.getTenantDomain(api.getApiCreator())); + List uriTemplates = new ArrayList<>(); + for (URLMapping uriTemplate : apiObj.getUrlMappings()) { + org.wso2.carbon.apimgt.common.analytics.publishers.dto.URITemplate uriTemplateObj = new org.wso2.carbon.apimgt.common.analytics.publishers.dto.URITemplate(); + if (uriTemplate.getHttpMethod() != null && uriTemplate.getHttpMethod() + .equals(messageContext.getProperty("api.ut.HTTP_METHOD")) && uriTemplate.getUrlPattern() != null + && uriTemplate.getUrlPattern().equals(messageContext.getProperty("api.ut.resource"))) { + uriTemplateObj.setResourceURI(uriTemplate.getUrlPattern()); + uriTemplateObj.setHttpVerb(uriTemplate.getHttpMethod()); + uriTemplateObj.setAuthScheme(uriTemplate.getAuthScheme()); + List operationPolicies = new ArrayList<>(); + for (OperationPolicy operationPolicy : uriTemplate.getOperationPolicies()) { + org.wso2.carbon.apimgt.common.analytics.publishers.dto.OperationPolicy operationPolicyObj = new org.wso2.carbon.apimgt.common.analytics.publishers.dto.OperationPolicy(); + operationPolicyObj.setPolicyVersion(operationPolicy.getPolicyVersion()); + operationPolicyObj.setPolicyName(operationPolicy.getPolicyName()); + operationPolicyObj.setPolicyId(operationPolicy.getPolicyId()); + operationPolicyObj.setDirection(operationPolicy.getDirection()); + operationPolicyObj.setOrder(operationPolicy.getOrder()); + operationPolicies.add(operationPolicyObj); + } + uriTemplateObj.setOperationPolicies(operationPolicies); + uriTemplates.add(uriTemplateObj); + } + } + api.setUriTemplates(uriTemplates); } return api; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java index 0a040bf2d1e3..46dafc25ea46 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java @@ -25,6 +25,7 @@ import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.dto.ConditionDTO; import org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO; +import org.wso2.carbon.apimgt.api.model.OperationPolicy; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; import org.wso2.carbon.apimgt.api.model.policy.EventCountLimit; import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants; @@ -1173,7 +1174,6 @@ private void attachURlMappingDetailsOfApiProduct(Connection connection, API api) } public API getAPIByContextAndVersion(String context, String version, String deployment, boolean isExpand) { - String sql = SubscriptionValidationSQLConstants.GET_API_BY_CONTEXT_AND_VERSION_SQL; String contextWhenContextTemplateIsNull = context; @@ -1260,6 +1260,39 @@ private void attachURLMappingDetails(Connection connection, String revisionId, A } } } + + // Attach the relevant operation policies to the resources. + attachOperationPolicies(connection, revisionId, api); + } + + private void attachOperationPolicies(Connection connection, String revisionId, API api) throws SQLException { + try(PreparedStatement preparedStatement = connection.prepareStatement(SubscriptionValidationSQLConstants.GET_OPERATION_POLICIES_PER_URI_BY_API_SQL)){ + preparedStatement.setInt(1, api.getApiId()); + preparedStatement.setString(2, revisionId); + try(ResultSet resultSet = preparedStatement.executeQuery()){ + while (resultSet.next()){ + String httpMethod = resultSet.getString("HTTP_METHOD"); + String urlPattern = resultSet.getString("URL_PATTERN"); + String policyName = resultSet.getString("POLICY_NAME"); + String policyVersion = resultSet.getString("POLICY_VERSION"); + String direction = resultSet.getString("DIRECTION"); + String policyID = resultSet.getString("POLICY_UUID"); + URLMapping urlMapping = api.getResource(urlPattern, httpMethod); + if(urlMapping!=null){ + if (StringUtils.isNotEmpty(policyID) && StringUtils.isNotEmpty(policyName) + && StringUtils.isNotEmpty(policyVersion) && StringUtils.isNotEmpty(direction)) { + OperationPolicy operationPolicy = new OperationPolicy(); + operationPolicy.setPolicyId(policyID); + operationPolicy.setPolicyName(policyName); + operationPolicy.setPolicyVersion(policyVersion); + operationPolicy.setDirection(direction); + urlMapping.setOperationPolicies(operationPolicy); + } + api.addResource(urlMapping); + } + } + } + } } private boolean isAPIDefaultVersion(Connection connection, String provider, String name, String version) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java index de6206a46e82..6a14a417fe78 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java @@ -573,6 +573,12 @@ public class SubscriptionValidationSQLConstants { "AM_API_RESOURCE_SCOPE_MAPPING.SCOPE_NAME FROM AM_API_URL_MAPPING LEFT JOIN AM_API_RESOURCE_SCOPE_MAPPING" + " ON AM_API_URL_MAPPING.URL_MAPPING_ID=AM_API_RESOURCE_SCOPE_MAPPING.URL_MAPPING_ID WHERE " + "AM_API_URL_MAPPING.API_ID = ? AND AM_API_URL_MAPPING.REVISION_UUID = ?"; + public static final String GET_OPERATION_POLICIES_PER_URI_BY_API_SQL = "SELECT AUM.HTTP_METHOD, AUM.URL_PATTERN, " + + "OP.POLICY_NAME, OP.POLICY_VERSION, OPM.DIRECTION, OPM.POLICY_UUID " + + "FROM AM_API_URL_MAPPING AS AUM INNER JOIN AM_API_OPERATION_POLICY_MAPPING OPM ON AUM.URL_MAPPING_ID = OPM.URL_MAPPING_ID " + + "INNER JOIN AM_OPERATION_POLICY OP ON OPM.POLICY_UUID = OP.POLICY_UUID " + + "INNER JOIN AM_API_OPERATION_POLICY AOP ON OPM.POLICY_UUID = AOP.POLICY_UUID " + + "WHERE AUM.API_ID = ? AND AUM.REVISION_UUID = ?"; public static final String GET_ALL_APIS_BY_ORGANIZATION_AND_DEPLOYMENT_SQL = "SELECT AM_API.API_PROVIDER,AM_API" + ".API_NAME,AM_API.CONTEXT, AM_API.CONTEXT_TEMPLATE, AM_API.API_UUID,AM_API.API_ID,AM_API.API_TIER,AM_API.API_VERSION,AM_API" + diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/OperationPolicyDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/OperationPolicyDTO.java new file mode 100644 index 000000000000..8fdf85451488 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/OperationPolicyDTO.java @@ -0,0 +1,157 @@ +package org.wso2.carbon.apimgt.internal.service.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +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; + + + +public class OperationPolicyDTO { + + private String policyName = null; + private String policyVersion = null; + private String direction = null; + private String policyId = null; + private Integer order = null; + + /** + **/ + public OperationPolicyDTO policyName(String policyName) { + this.policyName = policyName; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("policyName") + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + /** + **/ + public OperationPolicyDTO policyVersion(String policyVersion) { + this.policyVersion = policyVersion; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("policyVersion") + public String getPolicyVersion() { + return policyVersion; + } + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + /** + **/ + public OperationPolicyDTO direction(String direction) { + this.direction = direction; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("direction") + public String getDirection() { + return direction; + } + public void setDirection(String direction) { + this.direction = direction; + } + + /** + **/ + public OperationPolicyDTO policyId(String policyId) { + this.policyId = policyId; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("policyId") + public String getPolicyId() { + return policyId; + } + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + + /** + **/ + public OperationPolicyDTO order(Integer order) { + this.order = order; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("order") + public Integer getOrder() { + return order; + } + public void setOrder(Integer order) { + this.order = order; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + OperationPolicyDTO operationPolicy = (OperationPolicyDTO) o; + return Objects.equals(policyName, operationPolicy.policyName) && + Objects.equals(policyVersion, operationPolicy.policyVersion) && + Objects.equals(direction, operationPolicy.direction) && + Objects.equals(policyId, operationPolicy.policyId) && + Objects.equals(order, operationPolicy.order); + } + + @Override + public int hashCode() { + return Objects.hash(policyName, policyVersion, direction, policyId, order); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class OperationPolicyDTO {\n"); + + sb.append(" policyName: ").append(toIndentedString(policyName)).append("\n"); + sb.append(" policyVersion: ").append(toIndentedString(policyVersion)).append("\n"); + sb.append(" direction: ").append(toIndentedString(direction)).append("\n"); + sb.append(" policyId: ").append(toIndentedString(policyId)).append("\n"); + sb.append(" order: ").append(toIndentedString(order)).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.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/URLMappingDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/URLMappingDTO.java index 702aaa7c5f7a..8e1dd24d7eb6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/URLMappingDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/URLMappingDTO.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.ArrayList; import java.util.List; +import org.wso2.carbon.apimgt.internal.service.dto.OperationPolicyDTO; import javax.validation.constraints.*; @@ -23,6 +24,7 @@ public class URLMappingDTO { private String httpMethod = null; private String urlPattern = null; private List scopes = new ArrayList<>(); + private List operationPolicies = new ArrayList<>(); /** **/ @@ -109,6 +111,23 @@ public void setScopes(List scopes) { this.scopes = scopes; } + /** + **/ + public URLMappingDTO operationPolicies(List operationPolicies) { + this.operationPolicies = operationPolicies; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("operationPolicies") + public List getOperationPolicies() { + return operationPolicies; + } + public void setOperationPolicies(List operationPolicies) { + this.operationPolicies = operationPolicies; + } + @Override public boolean equals(java.lang.Object o) { @@ -123,12 +142,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(throttlingPolicy, urLMapping.throttlingPolicy) && Objects.equals(httpMethod, urLMapping.httpMethod) && Objects.equals(urlPattern, urLMapping.urlPattern) && - Objects.equals(scopes, urLMapping.scopes); + Objects.equals(scopes, urLMapping.scopes) && + Objects.equals(operationPolicies, urLMapping.operationPolicies); } @Override public int hashCode() { - return Objects.hash(authScheme, throttlingPolicy, httpMethod, urlPattern, scopes); + return Objects.hash(authScheme, throttlingPolicy, httpMethod, urlPattern, scopes, operationPolicies); } @Override @@ -141,6 +161,7 @@ public String toString() { sb.append(" httpMethod: ").append(toIndentedString(httpMethod)).append("\n"); sb.append(" urlPattern: ").append(toIndentedString(urlPattern)).append("\n"); sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append(" operationPolicies: ").append(toIndentedString(operationPolicies)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java index e59f15c4c117..333bb1fb47ae 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.cxf.jaxrs.ext.MessageContext; import org.wso2.carbon.apimgt.api.dto.ConditionDTO; +import org.wso2.carbon.apimgt.api.model.OperationPolicy; import org.wso2.carbon.apimgt.api.model.Scope; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; import org.wso2.carbon.apimgt.api.model.policy.EventCountLimit; @@ -55,6 +56,7 @@ import org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyDTO; import org.wso2.carbon.apimgt.internal.service.dto.GlobalPolicyListDTO; import org.wso2.carbon.apimgt.internal.service.dto.GroupIdDTO; +import org.wso2.carbon.apimgt.internal.service.dto.OperationPolicyDTO; import org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO; import org.wso2.carbon.apimgt.internal.service.dto.ScopeDTO; import org.wso2.carbon.apimgt.internal.service.dto.ScopesListDTO; @@ -100,6 +102,17 @@ private static APIDTO fromAPItoDTO(API model) { urlMappingDTO.setThrottlingPolicy(urlMapping.getThrottlingPolicy()); urlMappingDTO.setUrlPattern(urlMapping.getUrlPattern()); urlMappingDTO.setScopes(urlMapping.getScopes()); + List operationPolicyDTOList = new ArrayList<>(); + for(OperationPolicy operationPolicy: urlMapping.getOperationPolicies()) { + OperationPolicyDTO operationPolicyDTO = new OperationPolicyDTO(); + operationPolicyDTO.setPolicyId(operationPolicy.getPolicyId()); + operationPolicyDTO.setPolicyName(operationPolicy.getPolicyName()); + operationPolicyDTO.setPolicyVersion(operationPolicy.getPolicyVersion()); + operationPolicyDTO.setDirection(operationPolicy.getDirection()); + operationPolicyDTO.setOrder(operationPolicy.getOrder()); + operationPolicyDTOList.add(operationPolicyDTO); + } + urlMappingDTO.setOperationPolicies(operationPolicyDTOList); urlMappingsDTO.add(urlMappingDTO); } apidto.setUrlMappings(urlMappingsDTO); @@ -132,6 +145,17 @@ public static APIListDTO fromAPIToAPIListDTO(API model) { urlMappingDTO.setThrottlingPolicy(urlMapping.getThrottlingPolicy()); urlMappingDTO.setUrlPattern(urlMapping.getUrlPattern()); urlMappingDTO.setScopes(urlMapping.getScopes()); + List operationPolicyDTOList = new ArrayList<>(); + for(OperationPolicy operationPolicy: urlMapping.getOperationPolicies()) { + OperationPolicyDTO operationPolicyDTO = new OperationPolicyDTO(); + operationPolicyDTO.setPolicyId(operationPolicy.getPolicyId()); + operationPolicyDTO.setPolicyName(operationPolicy.getPolicyName()); + operationPolicyDTO.setPolicyVersion(operationPolicy.getPolicyVersion()); + operationPolicyDTO.setDirection(operationPolicy.getDirection()); + operationPolicyDTO.setOrder(operationPolicy.getOrder()); + operationPolicyDTOList.add(operationPolicyDTO); + } + urlMappingDTO.setOperationPolicies(operationPolicyDTOList); urlMappingsDTO.add(urlMappingDTO); } apidto.setUrlMappings(urlMappingsDTO); diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml index e40c00fd75e8..c993565bacd3 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml @@ -1371,6 +1371,24 @@ definitions: type: array items: type: string + operationPolicies: + type: array + items: + $ref: '#/definitions/OperationPolicy' + + OperationPolicy: + title: Operation Policy + properties: + policyName: + type: string + policyVersion: + type: string + direction: + type: string + policyId: + type: string + order: + type: integer #----------------------------------------------------- # The pagination resource #-----------------------------------------------------