Search in sources :

Example 16 with ScopeDTO

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

the class ApisApiServiceImpl method apisApiIdScopesNamePut.

@Override
public Response apisApiIdScopesNamePut(String apiId, String name, ScopeDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    try {
        String username = RestApiUtil.getLoggedInUsername(request);
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Scope scope = MappingUtil.toScope(body);
        apiPublisher.updateScopeOfTheApi(apiId, scope);
        return Response.ok().entity(body).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while updating the scope of API : " + apiId;
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
        paramList.put(APIMgtConstants.ExceptionsConstants.SCOPE_NAME, body.getName());
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) 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 17 with ScopeDTO

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

the class ScopesApiServiceImpl method updateSharedScope.

/**
 * Update Shared Scope By Id.
 *
 * @param scopeId        Shared Scope Id
 * @param body           Shared Scope DTO
 * @param messageContext CXF Message Context
 * @return Updated Shared Scope DTO
 * @throws APIManagementException if an error occurs while updating shared scope
 */
@Override
public Response updateSharedScope(String scopeId, ScopeDTO body, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    if (StringUtils.isEmpty(scopeId)) {
        throw new APIManagementException("Shared Scope Id cannot be null or empty", ExceptionCodes.SHARED_SCOPE_ID_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);
    }
    Scope existingScope = apiProvider.getSharedScopeByUUID(scopeId, tenantDomain);
    // Override scope Id and name in request body from existing scope
    body.setId(existingScope.getId());
    body.setName(existingScope.getKey());
    Scope scope = SharedScopeMappingUtil.fromDTOToScope(body);
    apiProvider.updateSharedScope(scope, tenantDomain);
    // Get updated shared scope
    scope = apiProvider.getSharedScopeByUUID(scope.getId(), tenantDomain);
    ScopeDTO updatedScopeDTO = SharedScopeMappingUtil.fromScopeToDTO(scope);
    return Response.ok().entity(updatedScopeDTO).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 18 with ScopeDTO

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

the class SharedScopeMappingUtil method fromDTOToScope.

/**
 * Converts ScopeDTO object into Scope object.
 *
 * @param scopeDTO ScopeDTO object
 * @return Scope object
 */
public static Scope fromDTOToScope(ScopeDTO scopeDTO) {
    Scope scope = new Scope();
    scope.setId(scopeDTO.getId());
    scope.setDescription(scopeDTO.getDescription());
    scope.setKey(scopeDTO.getName());
    scope.setName(scopeDTO.getDisplayName());
    if (scopeDTO.getBindings() != null) {
        scope.setRoles(String.join(",", scopeDTO.getBindings()));
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.api.model.Scope)

Example 19 with ScopeDTO

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

the class SharedScopeMappingUtil method fromScopeListToDTO.

/**
 * Converts a list of Scope objects into a SharedScopeListDTO.
 *
 * @param scopeList List of Scope objects
 * @param offset    max number of objects returned
 * @param limit     starting index
 * @return SharedScopeListDTO object
 */
public static ScopeListDTO fromScopeListToDTO(List<Scope> scopeList, int offset, int limit) {
    ScopeListDTO sharedScopeListDTO = new ScopeListDTO();
    List<ScopeDTO> scopeDTOList = sharedScopeListDTO.getList();
    if (scopeList == null) {
        scopeList = new ArrayList<>();
        sharedScopeListDTO.setList(scopeDTOList);
    }
    // identifying the proper start and end indexes
    int size = scopeList.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = Math.min(offset + limit - 1, size - 1);
    for (int i = start; i <= end; i++) {
        scopeDTOList.add(fromScopeToDTO(scopeList.get(i)));
    }
    sharedScopeListDTO.setCount(scopeDTOList.size());
    return sharedScopeListDTO;
}
Also used : ScopeListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeListDTO) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)

Example 20 with ScopeDTO

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

the class SubscriptionValidationDataUtil method fromScopeToScopeDto.

private static ScopeDTO fromScopeToScopeDto(Scope scope) {
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(scope.getKey());
    scopeDTO.setDisplayName(scope.getName());
    scopeDTO.setDescription(scope.getDescription());
    String roles = scope.getRoles();
    if (StringUtils.isNotEmpty(roles) && roles.trim().length() > 0) {
        scopeDTO.setRoles(Arrays.asList(roles.split(",")));
    }
    return scopeDTO;
}
Also used : ScopeDTO(org.wso2.carbon.apimgt.internal.service.dto.ScopeDTO)

Aggregations

Scope (org.wso2.carbon.apimgt.api.model.Scope)11 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)11 ArrayList (java.util.ArrayList)10 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)8 HashMap (java.util.HashMap)7 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 Scope (org.wso2.carbon.apimgt.core.models.Scope)4 JSONObject (org.json.simple.JSONObject)3 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 APICategory (org.wso2.carbon.apimgt.api.model.APICategory)2 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)2