use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentListToDTO.
/**
* Wraps a List of Comments to a CommentListDTO
*
* @param commentList list of comments
* @return CommentListDTO
*/
public static CommentListDTO fromCommentListToDTO(CommentList commentList, boolean includeCommenterInfo) {
CommentListDTO commentListDTO = new CommentListDTO();
List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
commentListDTO.setCount(commentList.getCount());
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(commentList.getPagination().getLimit());
paginationDTO.setOffset(commentList.getPagination().getOffset());
paginationDTO.setTotal(commentList.getPagination().getTotal());
paginationDTO.setNext(commentList.getPagination().getNext());
paginationDTO.setPrevious(commentList.getPagination().getPrevious());
commentListDTO.setPagination(paginationDTO);
Map<String, Map<String, String>> userClaimsMap = new HashMap<>();
for (Comment comment : commentList.getList()) {
try {
if (includeCommenterInfo) {
userClaimsMap = retrieveUserClaims(comment.getUser(), userClaimsMap);
listOfCommentDTOs.add(fromCommentToDTOWithUserInfo(comment, userClaimsMap));
} else {
listOfCommentDTOs.add(fromCommentToDTO(comment));
}
} catch (APIManagementException e) {
log.error("Error while creating comments list", e);
}
}
commentListDTO.setList(listOfCommentDTOs);
return commentListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a DocumentListDTO object given pagination parameters and url parameters
*
* @param documentListDTO a DocumentListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(DocumentListDTO documentListDTO, String apiId, int offset, int limit, int size) {
// acquiring pagination parameters and setting pagination urls
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
documentListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class TagMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a TagListDTO object given pagination parameters and url parameters
*
* @param tagListDTO a TagListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(TagListDTO tagListDTO, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
tagListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a AdditionalSubscriptionInfoListDTO object given pagination parameters and url
* parameters
*
* @param additionalSubscriptionInfoListDTO a AdditionalSubscriptionInfoListDTO object
* @param apiId uuid/id of API
* @param groupId group id of the applications to be returned
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO, String apiId, String groupId, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
}
PaginationDTO pagination = new PaginationDTO();
pagination.setOffset(offset);
pagination.setLimit(limit);
pagination.setNext(paginatedNext);
pagination.setPrevious(paginatedPrevious);
pagination.setTotal(size);
additionalSubscriptionInfoListDTO.setPagination(pagination);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIClientCertificates.
@Override
public Response getAPIClientCertificates(String apiId, Integer limit, Integer offset, String alias, MessageContext messageContext) {
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
List<ClientCertificateDTO> certificates = new ArrayList<>();
String query = CertificateRestApiUtils.buildQueryString("alias", alias, "apiId", apiId);
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
int tenantId = APIUtil.getInternalOrganizationId(organization);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
int totalCount = apiProvider.getClientCertificateCount(tenantId);
if (totalCount > 0) {
APIIdentifier apiIdentifier = null;
if (StringUtils.isNotEmpty(apiId)) {
API api = apiProvider.getAPIbyUUID(apiId, organization);
apiIdentifier = api.getId();
}
certificates = apiProvider.searchClientCertificates(tenantId, alias, apiIdentifier, organization);
}
ClientCertificatesDTO certificatesDTO = CertificateRestApiUtils.getPaginatedClientCertificates(certificates, limit, offset, query);
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(limit);
paginationDTO.setOffset(offset);
paginationDTO.setTotal(totalCount);
certificatesDTO.setPagination(paginationDTO);
return Response.status(Response.Status.OK).entity(certificatesDTO).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving the client certificates.", e, log);
}
return null;
}
Aggregations