use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method fromDocumentationListToDTO.
/**
* Converts a List object of Documents into a DTO.
*
* @param documentations List of Documentations
* @param limit maximum number of APIs returns
* @param offset starting index
* @return DocumentListDTO object containing Document DTOs
*/
public static DocumentListDTO fromDocumentationListToDTO(List<Documentation> documentations, int offset, int limit) {
DocumentListDTO documentListDTO = new DocumentListDTO();
List<DocumentDTO> documentDTOs = documentListDTO.getList();
if (documentDTOs == null) {
documentDTOs = new ArrayList<>();
documentListDTO.setList(documentDTOs);
}
// add the required range of objects to be returned
int start = offset < documentations.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= documentations.size() - 1 ? offset + limit - 1 : documentations.size() - 1;
for (int i = start; i <= end; i++) {
documentDTOs.add(fromDocumentationToDTO(documentations.get(i)));
}
documentListDTO.setCount(documentDTOs.size());
return documentListDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAllAPIs.
@Override
public Response getAllAPIs(Integer limit, Integer offset, String sortBy, String sortOrder, String xWSO2Tenant, String query, String ifNoneMatch, String accept, MessageContext messageContext) {
List<API> allMatchedApis = new ArrayList<>();
Object apiListDTO;
// pre-processing
// setting default limit and offset values if they are not set
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
query = query == null ? "" : query;
sortBy = sortBy != null ? sortBy : RestApiConstants.DEFAULT_SORT_CRITERION;
sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DESCENDING_SORT_ORDER;
try {
// revert content search back to normal search by name to avoid doc result complexity and to comply with REST api practices
if (query.startsWith(APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":")) {
query = query.replace(APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":", APIConstants.NAME_TYPE_PREFIX + ":");
}
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// boolean migrationMode = Boolean.getBoolean(RestApiConstants.MIGRATION_MODE);
/*if (migrationMode) { // migration flow
if (!StringUtils.isEmpty(targetTenantDomain)) {
tenantDomain = targetTenantDomain;
}
RestApiUtil.handleMigrationSpecificPermissionViolations(tenantDomain, username);
}*/
Map<String, Object> result;
result = apiProvider.searchPaginatedAPIs(query, organization, offset, limit, sortBy, sortOrder);
Set<API> apis = (Set<API>) result.get("apis");
allMatchedApis.addAll(apis);
apiListDTO = APIMappingUtil.fromAPIListToDTO(allMatchedApis);
// Add pagination section in the response
Object totalLength = result.get("length");
Integer length = 0;
if (totalLength != null) {
length = (Integer) totalLength;
}
APIMappingUtil.setPaginationParams(apiListDTO, query, offset, limit, length);
if (APIConstants.APPLICATION_GZIP.equals(accept)) {
try {
File zippedResponse = GZIPUtils.constructZippedResponse(apiListDTO);
return Response.ok().entity(zippedResponse).header("Content-Disposition", "attachment").header("Content-Encoding", "gzip").build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError(e.getMessage(), e, log);
}
} else {
return Response.ok().entity(apiListDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAllCommentsOfAPI.
@Override
public Response getAllCommentsOfAPI(String apiId, String xWSO2Tenant, Integer limit, Integer offset, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String requestedTenantDomain = RestApiUtil.getRequestedTenantDomain(xWSO2Tenant);
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper apiTypeWrapper = apiProvider.getAPIorAPIProductByUUID(apiId, requestedTenantDomain);
String parentCommentID = null;
CommentList comments = apiProvider.getComments(apiTypeWrapper, parentCommentID, limit, offset);
CommentListDTO commentDTO = CommentMappingUtil.fromCommentListToDTO(comments, includeCommenterInfo);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get comments of API " + apiId, e, log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comments content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getRepliesOfComment.
@Override
public Response getRepliesOfComment(String commentId, String apiId, String xWSO2Tenant, Integer limit, Integer offset, String ifNoneMatch, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String requestedTenantDomain = RestApiUtil.getRequestedTenantDomain(xWSO2Tenant);
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper apiTypeWrapper = apiProvider.getAPIorAPIProductByUUID(apiId, requestedTenantDomain);
CommentList comments = apiProvider.getComments(apiTypeWrapper, commentId, limit, offset);
CommentListDTO commentDTO = CommentMappingUtil.fromCommentListToDTO(comments, includeCommenterInfo);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get comments of API " + apiId, e, log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comments content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIResourcePaths.
@Override
public Response getAPIResourcePaths(String apiId, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
if (apiIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
List<ResourcePath> apiResourcePaths = apiProvider.getResourcePathsOfAPI(apiIdentifier);
ResourcePathListDTO dto = APIMappingUtil.fromResourcePathListToDTO(apiResourcePaths, limit, offset);
APIMappingUtil.setPaginationParamsForAPIResourcePathList(dto, offset, limit, apiResourcePaths.size());
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving resource paths of API : " + apiId, e, log);
} else {
String errorMessage = "Error while retrieving resource paths of API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
Aggregations