Skip to content

Commit

Permalink
Improve impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Aug 9, 2023
1 parent 49912fc commit 4138fd0
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@

public class ApiResourceListResponse {

private Integer count;
private Integer totalResults;
private List<PaginationLink> links = new ArrayList<PaginationLink>();

private List<ApiResourceListItem> apiResources = null;


/**
**/
public ApiResourceListResponse count(Integer count) {
public ApiResourceListResponse totalResults(Integer totalResults) {

this.count = count;
this.totalResults = totalResults;
return this;
}

@ApiModelProperty(example = "1", value = "")
@JsonProperty("count")
@JsonProperty("totalResults")
@Valid
public Integer getCount() {
return count;
public Integer getTotalResults() {
return totalResults;
}
public void setCount(Integer count) {
this.count = count;
public void setTotalResults(Integer totalResults) {
this.totalResults = totalResults;
}

/**
Expand Down Expand Up @@ -123,14 +123,14 @@ public boolean equals(java.lang.Object o) {
return false;
}
ApiResourceListResponse apiResourceListResponse = (ApiResourceListResponse) o;
return Objects.equals(this.count, apiResourceListResponse.count) &&
return Objects.equals(this.totalResults, apiResourceListResponse.totalResults) &&
Objects.equals(this.links, apiResourceListResponse.links) &&
Objects.equals(this.apiResources, apiResourceListResponse.apiResources);
}

@Override
public int hashCode() {
return Objects.hash(count, links, apiResources);
return Objects.hash(totalResults, links, apiResources);
}

@Override
Expand All @@ -139,7 +139,7 @@ public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ApiResourceListResponse {\n");

sb.append(" count: ").append(toIndentedString(count)).append("\n");
sb.append(" totalResults: ").append(toIndentedString(totalResults)).append("\n");
sb.append(" links: ").append(toIndentedString(links)).append("\n");
sb.append(" apiResources: ").append(toIndentedString(apiResources)).append("\n");
sb.append("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ public ApiResourcePatchModel addAddedScopesItem(ScopeCreationModel addedScopesIt
}

/**
* This field is not supported yet.
**/
public ApiResourcePatchModel removedScopes(List<String> removedScopes) {

this.removedScopes = removedScopes;
return this;
}

@ApiModelProperty(value = "")
@ApiModelProperty(value = "This field is not supported yet.")
@JsonProperty("removedScopes")
@Valid
public List<String> getRemovedScopes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class ApiResourceSearchPayload {

private List<String> apiResourceIds = new ArrayList<String>();

private List<String> attributes = new ArrayList<String>();
private List<String> requiredAttributes = null;

private String filter;
private Integer limit;

/**
**/
Expand Down Expand Up @@ -66,30 +68,67 @@ public ApiResourceSearchPayload addApiResourceIdsItem(String apiResourceIdsItem)

/**
**/
public ApiResourceSearchPayload attributes(List<String> attributes) {
public ApiResourceSearchPayload requiredAttributes(List<String> requiredAttributes) {

this.attributes = attributes;
this.requiredAttributes = requiredAttributes;
return this;
}

@ApiModelProperty(required = true, value = "")
@JsonProperty("attributes")
@ApiModelProperty(value = "")
@JsonProperty("requiredAttributes")
@Valid
@NotNull(message = "Property attributes cannot be null.")

public List<String> getAttributes() {
return attributes;
public List<String> getRequiredAttributes() {
return requiredAttributes;
}
public void setAttributes(List<String> attributes) {
this.attributes = attributes;
public void setRequiredAttributes(List<String> requiredAttributes) {
this.requiredAttributes = requiredAttributes;
}

public ApiResourceSearchPayload addAttributesItem(String attributesItem) {
this.attributes.add(attributesItem);
public ApiResourceSearchPayload addRequiredAttributesItem(String requiredAttributesItem) {
if (this.requiredAttributes == null) {
this.requiredAttributes = new ArrayList<String>();
}
this.requiredAttributes.add(requiredAttributesItem);
return this;
}

/**
**/
public ApiResourceSearchPayload filter(String filter) {

this.filter = filter;
return this;
}

@ApiModelProperty(example = "name+eq+apiName", value = "")
@JsonProperty("filter")
@Valid
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}

/**
**/
public ApiResourceSearchPayload limit(Integer limit) {

this.limit = limit;
return this;
}

@ApiModelProperty(example = "10", value = "")
@JsonProperty("limit")
@Valid
public Integer getLimit() {
return limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}



@Override
public boolean equals(java.lang.Object o) {
Expand All @@ -102,12 +141,14 @@ public boolean equals(java.lang.Object o) {
}
ApiResourceSearchPayload apiResourceSearchPayload = (ApiResourceSearchPayload) o;
return Objects.equals(this.apiResourceIds, apiResourceSearchPayload.apiResourceIds) &&
Objects.equals(this.attributes, apiResourceSearchPayload.attributes);
Objects.equals(this.requiredAttributes, apiResourceSearchPayload.requiredAttributes) &&
Objects.equals(this.filter, apiResourceSearchPayload.filter) &&
Objects.equals(this.limit, apiResourceSearchPayload.limit);
}

@Override
public int hashCode() {
return Objects.hash(apiResourceIds, attributes);
return Objects.hash(apiResourceIds, requiredAttributes, filter, limit);
}

@Override
Expand All @@ -117,7 +158,9 @@ public String toString() {
sb.append("class ApiResourceSearchPayload {\n");

sb.append(" apiResourceIds: ").append(toIndentedString(apiResourceIds)).append("\n");
sb.append(" attributes: ").append(toIndentedString(attributes)).append("\n");
sb.append(" requiredAttributes: ").append(toIndentedString(requiredAttributes)).append("\n");
sb.append(" filter: ").append(toIndentedString(filter)).append("\n");
sb.append(" limit: ").append(toIndentedString(limit)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Response apiResourcesApiResourceIdGet(@ApiParam(value = "ID of the Api Re
@Path("/{apiResourceId}")
@Consumes({ "application/json" })
@Produces({ "application/json", "application/xml", })
@ApiOperation(value = "Patch Api resource specified by the id", notes = "Patch Api resource specified by the id", response = ApiResourceResponse.class, authorizations = {
@ApiOperation(value = "Patch Api resource specified by the id", notes = "Patch Api resource specified by the id. Patch operation only supports \"name\", \"description\" updating and \"addedScopes\" fields at the moment.", response = ApiResourceResponse.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

Expand All @@ -138,7 +138,8 @@ public Response apiResourcesApiResourceIdGet(@ApiParam(value = "ID of the Api Re
@ApiResponse(code = 403, message = "Forbidden", response = Void.class),
@ApiResponse(code = 404, message = "Not Found", response = Error.class),
@ApiResponse(code = 409, message = "Conflict", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
@ApiResponse(code = 500, message = "Server Error", response = Error.class),
@ApiResponse(code = 501, message = "Not Implemented", response = Error.class)
})
public Response apiResourcesApiResourceIdPatch(@ApiParam(value = "ID of the Api Resource.",required=true) @PathParam("apiResourceId") String apiResourceId, @ApiParam(value = "This represents the Api resource to be patched." ,required=true) @Valid ApiResourcePatchModel apiResourcePatchModel) {

Expand Down Expand Up @@ -231,17 +232,17 @@ public Response apiResourcesApiResourceIdScopesScopeIdDelete(@ApiParam(value = "
@ApiResponse(code = 403, message = "Forbidden", response = Void.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response getApiResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Filter value. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Limit value. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Sort Order ") @QueryParam("sortOrder") String sortOrder) {
public Response getApiResources( @Valid@ApiParam(value = "Base64 encoded cursor value for backward pagination. ") @QueryParam("before") String before, @Valid@ApiParam(value = "Base64 encoded cursor value for forward pagination. ") @QueryParam("after") String after, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Maximum number of records to return. ") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Specifies the required parameters in the response. This parameter is not supported yet") @QueryParam("requiredAttributes") String requiredAttributes) {

return delegate.getApiResources(before, after, filter, limit, sortOrder );
return delegate.getApiResources(before, after, filter, limit, requiredAttributes );
}

@Valid
@POST
@Path("/.search")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Search Api Resources", notes = "Search Api Resource attributes by Api Resource IDs", response = ApiResourceSearchResult.class, responseContainer = "List", authorizations = {
@ApiOperation(value = "Search Api Resources", notes = "Search Api Resource attributes by Api Resource IDs. RequiredAttributes fields currently supports \"scopes\" value. Filter and Limit fields are not supported yet.", response = ApiResourceSearchResult.class, responseContainer = "List", authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

Expand All @@ -252,7 +253,8 @@ public Response getApiResources( @Valid@ApiParam(value = "Base64 encoded curs
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
@ApiResponse(code = 401, message = "Unauthorized", response = Void.class),
@ApiResponse(code = 403, message = "Forbidden", response = Void.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
@ApiResponse(code = 500, message = "Server Error", response = Error.class),
@ApiResponse(code = 501, message = "Not Implemented", response = Error.class)
})
public Response searchApiResources(@ApiParam(value = "This represents the Api resource IDs and attributes to be searched." ,required=true) @Valid ApiResourceSearchPayload apiResourceSearchPayload) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface ApiResourcesApiService {

public Response apiResourcesApiResourceIdScopesScopeIdDelete(String apiResourceId, String scopeId);

public Response getApiResources(String before, String after, String filter, Integer limit, String sortOrder);
public Response getApiResources(String before, String after, String filter, Integer limit, String requiredAttributes);

public Response searchApiResources(ApiResourceSearchPayload apiResourceSearchPayload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ScopesApi {
@ApiResponse(code = 404, message = "Not Found", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response scopesGet( @Valid@ApiParam(value = "Filter value. ") @QueryParam("filter") String filter) {
public Response scopesGet( @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew' and 'eq' operations. ") @QueryParam("filter") String filter) {

return delegate.scopesGet(filter );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@

package org.wso2.carbon.identity.api.server.api.resource.v1.constants;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Constants related to API resource management.
*/
public class ApiResourceManagementEndpointConstants {
public class ApiResourceMgtEndpointConstants {

public static final String API_RESOURCE_MANAGEMENT_PREFIX = "API-RESOURCE-";
public static final String API_RESOURCE_PATH_COMPONENT = "/api-resources";
public static final List<String> ALLOWED_SEARCH_ATTRIBUTES = List.of("description", "type",
"requires_authorization", "scopes");

private static final List<String> allowedAttributeList = new ArrayList<>();
public static final List<String> ALLOWED_SEARCH_ATTRIBUTES = Collections.unmodifiableList(allowedAttributeList);
public static final Integer DEFAULT_LIMIT = 10;
public static final String DEFAULT_SORT_ORDER = "ASC";
public static final String ASC_SORT_ORDER = "ASC";
public static final String DESC_SORT_ORDER = "DESC";

static {
allowedAttributeList.add("description");
allowedAttributeList.add("type");
allowedAttributeList.add("requires_authorization");
allowedAttributeList.add("scopes");
}

/**
* Enum for error messages.
*/
Expand All @@ -47,16 +54,20 @@ public enum ErrorMessage {
ERROR_CODE_API_RESOURCE_NOT_FOUND("60002",
"Unable to find the API resource.",
"Unable to find the API resource with the id: %s in the tenant domain."),
ERROR_CODE_INVALID_REMOVED_SCOPE_NAME("60003",
"Unable to find the given removed scopes in the API resource.",
"One or more removed scopes provided in the request are not available in the API resource."),
ERROR_CODE_INVALID_API_RESOURCE_NAME("60003",
"Invalid API resource name provided.", "API resource name is required."),
ERROR_CODE_INVALID_API_RESOURCE_IDENTIFIER("60004",
"Invalid API resource identifier provided.", "API resource identifier is required."),
ERROR_CODE_INVALID_SCOPE_NAME("60005",
"Invalid scope name provided.", "Scope name is required."),
ERROR_CODE_REMOVED_SCOPES_PATCH_NOT_SUPPORTED("60004",
"Removed scopes patching is not supported yet.",
"Removed scopes patching is not supported yet for API resources."),
ERROR_CODE_INVALID_SEARCH_ATTRIBUTE("60005",
"Invalid search attribute.",
"Invalid search attribute: %s."),


// Server errors.
ERROR_CODE_ADD_API_RESOURCE("65001", "Error while adding api resource.", "Server encountered an error while " +
"adding the api resource."),
Expand All @@ -78,6 +89,8 @@ public enum ErrorMessage {
"error while updating scopes by the api id: %s."),
ERROR_CODE_PATCH_API_RESOURCE("65009", "Error while updating api resource.", "Server encountered an error " +
"while updating the api resource by the id: %s."),
ERROR_CODE_GET_SCOPES_BY_TENANT("65010", "Error while retrieving scopes by tenant domain.",
"Server encountered an error while retrieving scopes by the tenant domain: %s."),
;
private final String code;
private final String message;
Expand Down
Loading

0 comments on commit 4138fd0

Please sign in to comment.