Search in sources :

Example 1 with APIScopeDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getAPIScopesFromScopeDTOs.

/**
 * Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
 *
 * @param scopeDTOS ScopeDTO List
 * @return APIScopeDTO List
 * @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
 */
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS) throws APIManagementException {
    List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
    scopeDTOS.forEach(scopeDTO -> {
        APIScopeDTO apiScopeDTO = new APIScopeDTO();
        apiScopeDTO.setScope(scopeDTO);
        apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
        apiScopeDTOS.add(apiScopeDTO);
    });
    return apiScopeDTOS;
}
Also used : APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 2 with APIScopeDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getAPIScopesFromScopeDTOs.

/**
 * Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
 *
 * @param scopeDTOS ScopeDTO List
 * @return APIScopeDTO List
 * @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
 */
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS, APIProvider apiProvider) throws APIManagementException {
    List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
    scopeDTOS.forEach(scopeDTO -> {
        APIScopeDTO apiScopeDTO = new APIScopeDTO();
        apiScopeDTO.setScope(scopeDTO);
        apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
        apiScopeDTOS.add(apiScopeDTO);
    });
    return apiScopeDTOS;
}
Also used : APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) ArrayList(java.util.ArrayList)

Example 3 with APIScopeDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getScopes.

/**
 * This method returns the oauth scopes according to the given list of scopes.
 *
 * @param apiDTO list of APIScopes
 * @return scope set
 */
public static Set<Scope> getScopes(APIDTO apiDTO) {
    Set<Scope> scopeSet = new LinkedHashSet<>();
    for (APIScopeDTO apiScopeDTO : apiDTO.getScopes()) {
        Scope scope = new Scope();
        ScopeDTO scopeDTO = apiScopeDTO.getScope();
        scope.setKey(scopeDTO.getName());
        scope.setName(scopeDTO.getDisplayName());
        scope.setDescription(scopeDTO.getDescription());
        scope.setRoles(String.join(",", scopeDTO.getBindings()));
        scopeSet.add(scope);
    }
    return scopeSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)

Example 4 with APIScopeDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getScopes.

/**
 * This method returns the oauth scopes according to the given list of scopes.
 *
 * @param apiProductDTO list of scopes
 * @return scope set
 */
private static Set<Scope> getScopes(APIProductDTO apiProductDTO) {
    Set<Scope> scopeSet = new LinkedHashSet<>();
    for (APIScopeDTO apiScopeDTO : apiProductDTO.getScopes()) {
        Scope scope = new Scope();
        ScopeDTO scopeDTO = apiScopeDTO.getScope();
        scope.setKey(scopeDTO.getName());
        scope.setName(scopeDTO.getDisplayName());
        scope.setDescription(scopeDTO.getDescription());
        scope.setRoles(String.join(",", scopeDTO.getBindings()));
        scopeSet.add(scope);
    }
    return scopeSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)

Aggregations

APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)4 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Scope (org.wso2.carbon.apimgt.api.model.Scope)2 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1