Search in sources :

Example 1 with Pagination

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with Pagination

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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationListDTO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

Example 3 with Pagination

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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) DocumentListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.DocumentListDTO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 4 with Pagination

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionListDTO)

Example 5 with Pagination

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();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) DocumentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.DocumentListDTO)

Aggregations

ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 JSONObject (org.json.simple.JSONObject)12 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)12 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)11 API (org.wso2.carbon.apimgt.api.model.API)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)8 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)8 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)8 TreeSet (java.util.TreeSet)7 Registry (org.wso2.carbon.registry.core.Registry)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 APINameComparator (org.wso2.carbon.apimgt.impl.utils.APINameComparator)6 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5