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