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;
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations