use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO 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;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertificatesDTO in project carbon-apimgt by wso2.
the class CertificateRestApiUtils method getPaginatedClientCertificates.
/**
* To get the paginated list of client certificates.
*
* @param clientCertificateDTOList Client certificate list.
* @param limit Limit
* @param offset Offset
* @param query query
* @return paginated list of client certificates.
*/
public static ClientCertificatesDTO getPaginatedClientCertificates(List<ClientCertificateDTO> clientCertificateDTOList, int limit, int offset, String query) {
if (log.isDebugEnabled()) {
log.debug(String.format("Filter the client certificates based on the pagination parameters, limit = %d and" + "offset = %d", limit, offset));
}
int certCount = clientCertificateDTOList.size();
List<ClientCertMetadataDTO> clientCertificateList = new ArrayList<>();
ClientCertificatesDTO certificatesDTO = new ClientCertificatesDTO();
certificatesDTO.setCount(certCount > limit ? limit : certCount);
// If the provided offset value exceeds the offset, reset the offset to default.
if (offset > certCount) {
offset = RestApiConstants.PAGINATION_OFFSET_DEFAULT;
}
// Select only the set of Certificates which matches the given limit and offset values.
int start = offset;
int end = certCount > start + limit ? start + limit : certCount;
for (int i = start; i < end; i++) {
ClientCertMetadataDTO clientCertMetadataDTO = new ClientCertMetadataDTO();
ClientCertificateDTO clientCertificateDTO = clientCertificateDTOList.get(i);
clientCertMetadataDTO.setAlias(clientCertificateDTO.getAlias());
clientCertMetadataDTO.setApiId(clientCertificateDTO.getApiIdentifier().toString());
clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName());
clientCertificateList.add(clientCertMetadataDTO);
}
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, certCount);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = getCertificatesPaginatedURL(RestApiConstants.CLIENT_CERTS_GET_PAGINATED_URL, paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = getCertificatesPaginatedURL(RestApiConstants.CLIENT_CERTS_GET_PAGINATED_URL, paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
}
certificatesDTO.setCount(clientCertificateList.size());
certificatesDTO.setCertificates(clientCertificateList);
return certificatesDTO;
}
Aggregations