Search in sources :

Example 1 with ScopeDTO

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

the class MappingUtil method scopeDto.

/**
 * used to convert {@link Scope} to {@link ScopeDTO}
 * @param scope scope Object
 * @param scopeBindingType type of bindings
 * @return ScopeDTO object
 */
public static ScopeDTO scopeDto(Scope scope, String scopeBindingType) {
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(scope.getName());
    scopeDTO.setDescription(scope.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = new Scope_bindingsDTO();
    scopeBindingsDTO.setType(scopeBindingType);
    if (scope.getBindings() != null) {
        scopeBindingsDTO.setValues(scope.getBindings());
    } else {
        scopeBindingsDTO.setValues(Collections.emptyList());
    }
    scopeDTO.setBindings(scopeBindingsDTO);
    return scopeDTO;
}
Also used : Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO)

Example 2 with ScopeDTO

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

the class MappingUtil method toScope.

/**
 * This method convert {@link ScopeDTO} to {@link Scope}
 * @param body scopeDto Object
 * @return scope object
 */
public static Scope toScope(ScopeDTO body) {
    Scope scope = new Scope();
    scope.setName(body.getName());
    scope.setDescription(body.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = body.getBindings();
    if (scopeBindingsDTO != null) {
        scope.setBindings(scopeBindingsDTO.getValues());
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO)

Example 3 with ScopeDTO

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

the class ApisApiServiceImpl method apisApiIdScopesNameGet.

@Override
public Response apisApiIdScopesNameGet(String apiId, String name, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Scope scope = apiPublisher.getScopeInformationOfApi(apiId, name);
        KeyMgtConfigurations keyManagerConfiguration = APIMConfigurationService.getInstance().getApimConfigurations().getKeyManagerConfigs();
        ScopeDTO scopeDTO = MappingUtil.scopeDto(scope, keyManagerConfiguration.getScopeBindingType());
        return Response.ok().entity(scopeDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving swagger definition 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();
    }
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 4 with ScopeDTO

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

the class ApisApiServiceImpl method apisApiIdScopesPost.

@Override
public Response apisApiIdScopesPost(String apiId, ScopeDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    try {
        String username = RestApiUtil.getLoggedInUsername(request);
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        KeyMgtConfigurations keyManagerConfiguration = APIMConfigurationService.getInstance().getApimConfigurations().getKeyManagerConfigs();
        if (body.getBindings() != null && StringUtils.isNotEmpty(body.getBindings().getType())) {
            if (!keyManagerConfiguration.getScopeBindingType().equalsIgnoreCase(body.getBindings().getType())) {
                String message = "binding type not valid";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(message, 900313L, message);
                return Response.status(Response.Status.PRECONDITION_FAILED).entity(errorDTO).build();
            }
        }
        Scope scope = MappingUtil.toScope(body);
        apiPublisher.addScopeToTheApi(apiId, scope);
        URI location = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + "/scopes/" + scope.getName());
        return Response.created(location).entity(body).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while creating scope" + body.getName();
        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();
    } catch (URISyntaxException e) {
        String errorMessage = "Error while retrieving source URI location of " + body.getName();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
        log.error(errorMessage, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
    }
}
Also used : KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) 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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with ScopeDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.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)

Aggregations

Scope (org.wso2.carbon.apimgt.core.models.Scope)4 HashMap (java.util.HashMap)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 KeyMgtConfigurations (org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations)2 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO)2 Scope_bindingsDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1