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();
}
}
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);
}
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;
}
Aggregations