use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method getSharedScopes.
/**
* Get all shared scopes for tenant.
*
* @param messageContext CXF Message Context
* @return Shared Scopes DTO List
* @throws APIManagementException if an error occurs while retrieving shared scope
*/
@Override
public Response getSharedScopes(Integer limit, Integer offset, MessageContext messageContext) throws APIManagementException {
// pre-processing
// setting default limit and offset values if they are not set
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
List<Scope> scopeList = apiProvider.getAllSharedScopes(tenantDomain);
ScopeListDTO sharedScopeListDTO = SharedScopeMappingUtil.fromScopeListToDTO(scopeList, offset, limit);
SharedScopeMappingUtil.setPaginationParams(sharedScopeListDTO, limit, offset, scopeList.size());
return Response.ok().entity(sharedScopeListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SharedScopeMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a shared ScopeListDTO object given pagination parameters and url parameters.
*
* @param sharedScopeListDTO a ScopeListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(ScopeListDTO sharedScopeListDTO, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getScopesPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getScopesPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
sharedScopeListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SharedScopeMappingUtil method fromScopeListToDTO.
/**
* Converts a list of Scope objects into a SharedScopeListDTO.
*
* @param scopeList List of Scope objects
* @param offset max number of objects returned
* @param limit starting index
* @return SharedScopeListDTO object
*/
public static ScopeListDTO fromScopeListToDTO(List<Scope> scopeList, int offset, int limit) {
ScopeListDTO sharedScopeListDTO = new ScopeListDTO();
List<ScopeDTO> scopeDTOList = sharedScopeListDTO.getList();
if (scopeList == null) {
scopeList = new ArrayList<>();
sharedScopeListDTO.setList(scopeDTOList);
}
// identifying the proper start and end indexes
int size = scopeList.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = Math.min(offset + limit - 1, size - 1);
for (int i = start; i <= end; i++) {
scopeDTOList.add(fromScopeToDTO(scopeList.get(i)));
}
sharedScopeListDTO.setCount(scopeDTOList.size());
return sharedScopeListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method fromScopeListToScopeListDTO.
/**
* Convert list of API Scope to ScopeListDTO
*
* @param scopeRoleMapping Map of a Role Scope Mapping
* @return ScopeListDTO list containing role scope mapping data
*/
public static ScopeListDTO fromScopeListToScopeListDTO(Map<String, String> scopeRoleMapping) throws APIManagementException {
ScopeListDTO scopeListDTO = new ScopeListDTO();
scopeListDTO.setCount(scopeRoleMapping.size());
scopeListDTO.setList(fromRoleScopeMapToRoleScopeDTOList(scopeRoleMapping));
return scopeListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SystemScopesMappingUtil method createJsonObjectOfScopeMapping.
/**
* Extract scope and roles and create JSONObject
*
* @param body body of a Role Scope Mapping
* @return JSONObject role scope mapping data
*/
public static JSONObject createJsonObjectOfScopeMapping(ScopeListDTO body) throws APIManagementException {
JSONObject responseJson = new JSONObject();
JSONArray scopeJson = new JSONArray();
for (ScopeDTO scope : body.getList()) {
JSONObject scopeRoleJson = new JSONObject();
String roles = scope.getRoles().toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "");
if (!roles.isEmpty()) {
scopeRoleJson.put("Name", scope.getName());
scopeRoleJson.put("Roles", roles);
scopeJson.put(scopeRoleJson);
}
}
responseJson.put("Scope", scopeJson);
return responseJson;
}
Aggregations