use of org.wso2.carbon.apimgt.rest.api.publisher.v1.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.v1.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.v1.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.v1.dto.ScopeDTO in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImpl method updateScope.
/**
* This method will be used to update a Scope in the authorization server.
*
* @param scope Scope object
* @throws APIManagementException if an error occurs while updating the scope
*/
@Override
public void updateScope(Scope scope) throws APIManagementException {
String scopeKey = scope.getKey();
try {
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setDisplayName(scope.getName());
scopeDTO.setDescription(scope.getDescription());
if (StringUtils.isNotBlank(scope.getRoles()) && scope.getRoles().trim().split(",").length > 0) {
scopeDTO.setBindings(Arrays.asList(scope.getRoles().trim().split(",")));
}
scopeClient.updateScope(scopeDTO, scope.getKey());
} catch (KeyManagerClientException e) {
String errorMessage = "Error occurred while updating scope: " + scopeKey;
handleException(errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method getAPIScopesFromScopeDTOs.
/**
* Convert ScopeDTO List to APIScopesDTO List adding the attribute 'isShared'.
*
* @param scopeDTOS ScopeDTO List
* @return APIScopeDTO List
* @throws APIManagementException if an error occurs while converting ScopeDTOs to APIScopeDTOs
*/
private static List<APIScopeDTO> getAPIScopesFromScopeDTOs(List<ScopeDTO> scopeDTOS) throws APIManagementException {
List<APIScopeDTO> apiScopeDTOS = new ArrayList<>();
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain);
scopeDTOS.forEach(scopeDTO -> {
APIScopeDTO apiScopeDTO = new APIScopeDTO();
apiScopeDTO.setScope(scopeDTO);
apiScopeDTO.setShared(allSharedScopeKeys.contains(scopeDTO.getName()) ? Boolean.TRUE : Boolean.FALSE);
apiScopeDTOS.add(apiScopeDTO);
});
return apiScopeDTOS;
}
Aggregations