Search in sources :

Example 1 with AvailableApiBean

use of io.apiman.manager.api.beans.summary.AvailableApiBean in project apiman by apiman.

the class TestCdiFactory method provideApiCatalog.

@Produces
@ApplicationScoped
public static IApiCatalog provideApiCatalog(IPluginRegistry pluginRegistry) {
    return new IApiCatalog() {

        /**
         * @see io.apiman.manager.api.core.IApiCatalog#search(java.lang.String, java.lang.String)
         */
        @Override
        public List<AvailableApiBean> search(String keyword, String namespace) {
            List<AvailableApiBean> rval = new ArrayList<>();
            AvailableApiBean asb = new AvailableApiBean();
            asb.setName("Test API 1");
            asb.setDescription("The first test API.");
            asb.setEndpoint("http://api1.example.org/api");
            asb.setEndpointType(EndpointType.rest);
            rval.add(asb);
            asb = new AvailableApiBean();
            asb.setName("Test API 2");
            asb.setDescription("The second test API.");
            asb.setEndpoint("http://api2.example.org/api");
            asb.setEndpointType(EndpointType.rest);
            rval.add(asb);
            return rval;
        }

        /**
         * @see io.apiman.manager.api.core.IApiCatalog#getNamespaces(java.lang.String)
         */
        @Override
        public List<ApiNamespaceBean> getNamespaces(String currentUser) {
            List<ApiNamespaceBean> rval = new ArrayList<>();
            ApiNamespaceBean bean = new ApiNamespaceBean();
            bean.setCurrent(true);
            bean.setName("current");
            bean.setOwnedByUser(true);
            rval.add(bean);
            bean = new ApiNamespaceBean();
            bean.setCurrent(false);
            bean.setName("ns1");
            bean.setOwnedByUser(true);
            rval.add(bean);
            bean = new ApiNamespaceBean();
            bean.setCurrent(false);
            bean.setName("ns2");
            bean.setOwnedByUser(false);
            rval.add(bean);
            bean = new ApiNamespaceBean();
            bean.setCurrent(false);
            bean.setName("ns3");
            bean.setOwnedByUser(false);
            rval.add(bean);
            return rval;
        }
    };
}
Also used : ApiNamespaceBean(io.apiman.manager.api.beans.summary.ApiNamespaceBean) IApiCatalog(io.apiman.manager.api.core.IApiCatalog) ArrayList(java.util.ArrayList) AvailableApiBean(io.apiman.manager.api.beans.summary.AvailableApiBean) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 2 with AvailableApiBean

use of io.apiman.manager.api.beans.summary.AvailableApiBean in project apiman by apiman.

the class SearchResourceImpl method searchApiCatalog.

@Override
public // TODO(msavy): push into service layer.
SearchResultsBean<AvailableApiBean> searchApiCatalog(SearchCriteriaBean criteria) throws InvalidSearchCriteriaException {
    SearchResultsBean<AvailableApiBean> rval = new SearchResultsBean<>();
    if (criteria.getFilters().isEmpty()) {
        return rval;
    }
    // First criteria is the name search keyword
    SearchCriteriaFilterBean bean = criteria.getFilters().get(0);
    if (bean == null) {
        return rval;
    }
    if (!bean.getName().equals("name")) {
        // $NON-NLS-1$
        return rval;
    }
    String keyword = bean.getValue();
    // Second criteria is the namespace
    String namespace = null;
    if (criteria.getFilters().size() >= 2) {
        bean = criteria.getFilters().get(1);
        if (bean != null && bean.getName().equals("namespace") && bean.getOperator() == SearchCriteriaFilterOperator.eq) {
            // $NON-NLS-1$
            namespace = bean.getValue();
        }
    }
    List<AvailableApiBean> catalogEntries = apiCatalog.search(keyword, namespace);
    List<AvailableApiBean> apis = new ArrayList<>();
    // Hide sensitive data like endpoint if the user has no permission to create an new API
    if (securityContext.getPermittedOrganizations(PermissionType.apiEdit).isEmpty() && !securityContext.isAdmin()) {
        for (AvailableApiBean api : catalogEntries) {
            AvailableApiBean entry = new AvailableApiBean();
            entry.setId(api.getId());
            entry.setIcon(api.getIcon());
            entry.setRouteEndpoint(api.getRouteEndpoint());
            entry.setEndpointType(api.getEndpointType());
            entry.setName(api.getName());
            entry.setDescription(api.getDescription());
            entry.setDefinitionType(api.getDefinitionType());
            entry.setNamespace(api.getNamespace());
            entry.setTags(api.getTags());
            entry.setInternal(api.isInternal());
            apis.add(entry);
        }
    } else {
        apis.addAll(catalogEntries);
    }
    PagingBean paging = criteria.getPaging();
    if (paging == null) {
        paging = new PagingBean();
        paging.setPage(1);
        paging.setPageSize(500);
    }
    int page = paging.getPage();
    int pageSize = paging.getPageSize();
    int start = (page - 1) * pageSize;
    int totalSize = apis.size();
    if (start <= totalSize) {
        int end = Math.min(start + pageSize, apis.size());
        rval.getBeans().addAll(apis.subList(start, end));
    }
    rval.setTotalSize(totalSize);
    return rval;
}
Also used : PagingBean(io.apiman.manager.api.beans.search.PagingBean) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ArrayList(java.util.ArrayList) AvailableApiBean(io.apiman.manager.api.beans.summary.AvailableApiBean) SearchCriteriaFilterBean(io.apiman.manager.api.beans.search.SearchCriteriaFilterBean)

Aggregations

AvailableApiBean (io.apiman.manager.api.beans.summary.AvailableApiBean)2 ArrayList (java.util.ArrayList)2 PagingBean (io.apiman.manager.api.beans.search.PagingBean)1 SearchCriteriaFilterBean (io.apiman.manager.api.beans.search.SearchCriteriaFilterBean)1 SearchResultsBean (io.apiman.manager.api.beans.search.SearchResultsBean)1 ApiNamespaceBean (io.apiman.manager.api.beans.summary.ApiNamespaceBean)1 IApiCatalog (io.apiman.manager.api.core.IApiCatalog)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1