use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPIs.
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<CompositeAPI> getCompositeAPIs(Set<String> roles, String user, int offset, int limit) throws APIMgtDAOException {
// TODO: 6/5/17 Implement pagination support when implementing pagination support for
// other list operations.
final String query = COMPOSITE_API_SUMMARY_SELECT + " WHERE API_TYPE_ID = " + "(SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?) AND PROVIDER = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, ApiType.COMPOSITE.toString());
statement.setString(2, user);
return getCompositeAPISummaryList(connection, statement);
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite APIs", e);
}
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
/**
* Retrieves all applications that qualifies for the search query
*
* @param query Search query
* @param limit Max number of applications to return
* @param offset Starting position of pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return A list of qualifying application DTOs as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsGet(String query, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
ApplicationListDTO applicationListDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
List<Application> allMatchedApps = new ArrayList<>();
if (StringUtils.isBlank(query)) {
allMatchedApps = apiConsumer.getApplications(username);
} else {
Application application = apiConsumer.getApplicationByName(username, query);
if (application != null) {
allMatchedApps = new ArrayList<>();
allMatchedApps.add(application);
}
}
// allMatchedApps are already sorted to application name
applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(allMatchedApps, limit, offset);
ApplicationMappingUtil.setPaginationParams(applicationListDTO, limit, offset, allMatchedApps.size());
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving applications";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_NAME, query);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(applicationListDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request minor version header
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
DocumentListDTO documentListDTO = null;
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<DocumentInfo> documentInfoResults = apiStore.getAllDocumentation(apiId, offset, limit);
documentListDTO = DocumentationMappingUtil.fromDocumentationListToDTO(documentInfoResults, offset, limit);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving documentation for given apiId " + 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();
}
return Response.ok().entity(documentListDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Retrieve all subscriptions for a particular API
*
* @param apiId ID of the API
* @param limit Maximum subscriptions to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-Match header value
* @param request ms4j request object
* @return List of qualifying subscriptions DTOs as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
List<Subscription> subscriptionList;
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (StringUtils.isNotEmpty(apiId)) {
subscriptionList = apiPublisher.getSubscriptionsByAPI(apiId);
SubscriptionListDTO subscriptionListDTO = MappingUtil.fromSubscriptionListToDTO(subscriptionList, limit, offset);
return Response.ok().entity(subscriptionListDTO).build();
} else {
RestApiUtil.handleBadRequest("API ID can not be null", log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscriptions 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();
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<DocumentInfo> documentInfos = apiPublisher.getAllDocumentation(apiId, offset, limit);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
return Response.status(Response.Status.OK).entity(documentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting list of documents" + 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();
}
}
Aggregations