use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method getSharedScopeUsages.
@Override
public Response getSharedScopeUsages(String scopeId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
if (StringUtils.isEmpty(scopeId)) {
throw new APIManagementException("Scope Id cannot be null or empty", ExceptionCodes.SHARED_SCOPE_ID_NOT_SPECIFIED);
}
SharedScopeUsage sharedScopeUsage = apiProvider.getSharedScopeUsage(scopeId, tenantId);
SharedScopeUsageDTO sharedScopeUsageDTO = SharedScopeMappingUtil.fromSharedScopeUsageToDTO(sharedScopeUsage);
return Response.ok().entity(sharedScopeUsageDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method getSharedScope.
/**
* Get shared scope by Id.
*
* @param scopeId UUID of the scope
* @param messageContext CXF Message Context
* @return Shared Scope DTO
* @throws APIManagementException If an error occurs while getting shared scope
*/
@Override
public Response getSharedScope(String scopeId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
if (StringUtils.isEmpty(scopeId)) {
throw new APIManagementException("Scope Id cannot be null or empty", ExceptionCodes.SHARED_SCOPE_ID_NOT_SPECIFIED);
}
Scope scope = apiProvider.getSharedScopeByUUID(scopeId, tenantDomain);
ScopeDTO scopeDTO = SharedScopeMappingUtil.fromScopeToDTO(scope);
return Response.ok().entity(scopeDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.
the class ScopesApiServiceImpl method addSharedScope.
/**
* Add Shared Scope.
*
* @param body Scope DTO object to add
* @param messageContext CXF Message Context
* @return Created Scope as DTO
* @throws APIManagementException If an error occurs while adding shared scope.
*/
@Override
public Response addSharedScope(ScopeDTO body, MessageContext messageContext) throws APIManagementException {
String scopeName = body.getName();
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
if (StringUtils.isEmpty(scopeName)) {
throw new APIManagementException("Shared Scope Name cannot be null or empty", ExceptionCodes.SHARED_SCOPE_NAME_NOT_SPECIFIED);
}
if (StringUtils.isEmpty(body.getDisplayName())) {
throw new APIManagementException("Shared scope Display Name cannot be null or empty", ExceptionCodes.SHARED_SCOPE_DISPLAY_NAME_NOT_SPECIFIED);
}
if (apiProvider.isScopeKeyExist(scopeName, APIUtil.getTenantIdFromTenantDomain(tenantDomain))) {
throw new APIManagementException(ExceptionCodes.from(ExceptionCodes.SCOPE_ALREADY_REGISTERED, scopeName));
}
Scope scopeToAdd = SharedScopeMappingUtil.fromDTOToScope(body);
String sharedScopeId = apiProvider.addSharedScope(scopeToAdd, tenantDomain);
// Get registered shared scope
Scope createdScope = apiProvider.getSharedScopeByUUID(sharedScopeId, tenantDomain);
ScopeDTO createdScopeDTO = SharedScopeMappingUtil.fromScopeToDTO(createdScope);
String createdScopeURIString = RestApiConstants.RESOURCE_PATH_SHARED_SCOPES_SCOPE_ID.replace(RestApiConstants.SHARED_SCOPE_ID_PARAM, createdScopeDTO.getId());
URI createdScopeURI = new URI(createdScopeURIString);
return Response.created(createdScopeURI).entity(createdScopeDTO).build();
} catch (URISyntaxException e) {
throw new APIManagementException("Error while creating shared scope: " + scopeName, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.
the class SettingsApiServiceImpl method GetScopeList.
/**
* This method returns the scope list from the publisher-api.yaml
* @return List<String> scope list
* @throws APIManagementException
*/
private List<String> GetScopeList() throws APIManagementException {
String definition = null;
try {
definition = IOUtils.toString(RestApiUtil.class.getResourceAsStream("/publisher-api.yaml"), "UTF-8");
} catch (IOException e) {
log.error("Error while reading the swagger definition", e);
}
APIDefinition parser = OASParserUtil.getOASParser(definition);
Set<Scope> scopeSet = parser.getScopes(definition);
List<String> scopeList = new ArrayList<>();
for (Scope entry : scopeSet) {
scopeList.add(entry.getKey());
}
return scopeList;
}
use of org.wso2.carbon.apimgt.api.model.Scope in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method getScopeInfoDTO.
public static List<ScopeInfoDTO> getScopeInfoDTO(Set<Scope> scopes) {
List<ScopeInfoDTO> scopeDto = new ArrayList<ScopeInfoDTO>();
for (Scope scope : scopes) {
ScopeInfoDTO scopeInfoDTO = new ScopeInfoDTO();
scopeInfoDTO.setKey(scope.getKey());
scopeInfoDTO.setName(scope.getName());
scopeInfoDTO.setDescription(scope.getDescription());
if (StringUtils.isNotBlank(scope.getRoles())) {
scopeInfoDTO.setRoles(Arrays.asList(scope.getRoles().trim().split(",")));
}
scopeDto.add(scopeInfoDTO);
}
return scopeDto;
}
Aggregations