use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method systemScopesGet.
public Response systemScopesGet(MessageContext messageContext) {
try {
Map<String, String> scopeRoleMapping = APIUtil.getRESTAPIScopesForTenantWithoutRoleMappings(MultitenantUtils.getTenantDomain(RestApiCommonUtil.getLoggedInUsername()));
ScopeListDTO scopeListDTO = SystemScopesMappingUtil.fromScopeListToScopeListDTO(scopeRoleMapping);
return Response.ok().entity(scopeListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error when getting the list of scopes-role mapping.";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ScopeListDTO in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method updateRolesForScope.
public Response updateRolesForScope(ScopeListDTO body, MessageContext messageContext) throws APIManagementException {
JSONObject newScopeRoleJson = SystemScopesMappingUtil.createJsonObjectOfScopeMapping(body);
APIUtil.updateTenantConfOfRoleScopeMapping(newScopeRoleJson, RestApiCommonUtil.getLoggedInUsername());
Map<String, String> scopeRoleMapping = APIUtil.getRESTAPIScopesForTenantWithoutRoleMappings(MultitenantUtils.getTenantDomain(RestApiCommonUtil.getLoggedInUsername()));
ScopeListDTO scopeListDTO = SystemScopesMappingUtil.fromScopeListToScopeListDTO(scopeRoleMapping);
return Response.ok().entity(scopeListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.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.admin.v1.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.admin.v1.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