Search in sources :

Example 81 with Scope

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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SharedScopeUsageDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) SharedScopeUsage(org.wso2.carbon.apimgt.api.model.SharedScopeUsage)

Example 82 with Scope

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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 83 with Scope

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) URISyntaxException(java.net.URISyntaxException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) URI(java.net.URI)

Example 84 with Scope

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;
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) APIDefinition(org.wso2.carbon.apimgt.api.APIDefinition) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 85 with Scope

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;
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope) ScopeInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ScopeInfoDTO) ArrayList(java.util.ArrayList)

Aggregations

Scope (org.wso2.carbon.apimgt.api.model.Scope)97 HashMap (java.util.HashMap)76 ArrayList (java.util.ArrayList)58 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 Scope (org.wso2.carbon.apimgt.core.models.Scope)41 Map (java.util.Map)39 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)39 LinkedHashSet (java.util.LinkedHashSet)32 LinkedHashMap (java.util.LinkedHashMap)29 HashSet (java.util.HashSet)26 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)25 List (java.util.List)24 Test (org.testng.annotations.Test)23 JSONObject (org.json.simple.JSONObject)22 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 PreparedStatement (java.sql.PreparedStatement)17 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)17 SQLException (java.sql.SQLException)16 Gson (com.google.gson.Gson)15 Connection (java.sql.Connection)15