Search in sources :

Example 1 with ScopeListDTO

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

the class ApisApiServiceImpl method apisApiIdScopesGet.

@Override
public Response apisApiIdScopesGet(String apiId, String ifNoneMatch, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Map<String, String> scopeSet = apiPublisher.getScopesForApi(apiId);
        ScopeListDTO scopeListDTO = MappingUtil.toScopeListDto(scopeSet);
        return Response.ok().entity(scopeListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving scopes of API : " + apiId;
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 2 with ScopeListDTO

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

the class TestMappingUtilTestCase method testScopeMappingUtil.

@Test
public void testScopeMappingUtil() {
    Map<String, String> scopeMap = new HashMap<>();
    scopeMap.put("apim:api-read", "read apis");
    ScopeListDTO scopeListDTO = MappingUtil.toScopeListDto(scopeMap);
    Assert.assertEquals(scopeListDTO.getCount().intValue(), 1);
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 3 with ScopeListDTO

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

the class MappingUtil method toScopeListDto.

/**
 * This method used to convert scope map
 *
 * @param scopeMap map of scopes
 * @return ScopeListDTO object
 */
public static ScopeListDTO toScopeListDto(Map<String, String> scopeMap) {
    ScopeListDTO scopeListDTO = new ScopeListDTO();
    scopeMap.forEach((name, description) -> {
        scopeListDTO.addListItem(new ScopeList_listDTO().name(name).description(description));
    });
    scopeListDTO.setCount(scopeMap.size());
    return scopeListDTO;
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO) ScopeList_listDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeList_listDTO)

Aggregations

ScopeListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeListDTO)3 HashMap (java.util.HashMap)2 Test (org.testng.annotations.Test)1 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1 ScopeList_listDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeList_listDTO)1