Search in sources :

Example 1 with Search

use of org.eclipse.epp.internal.mpc.core.model.Search in project epp.mpc by eclipse.

the class UnmarshallerTest method search.

@Test
public void search() throws IOException, UnmarshalException {
    // from http://www.eclipseplugincentral.net/api/v2/search/apachesolr_search/test?filters=tid:16%20tid:31
    Object model = processResource("resources/search.xml");
    assertNotNull(model);
    assertTrue(model instanceof Marketplace);
    Marketplace marketplace = (Marketplace) model;
    Search search = marketplace.getSearch();
    assertNotNull(search);
    assertEquals("test", search.getTerm());
    assertEquals("http://www.eclipseplugincentral.net/search/apachesolr/test?filters=tid%3A16%20tid%3A31", search.getUrl());
    assertEquals(Integer.valueOf(62), search.getCount());
    assertEquals(7, search.getNode().size());
    INode node = search.getNode().get(0);
    assertEquals("983", node.getId());
    assertEquals("Run All Tests", node.getName());
    assertEquals("http://www.eclipseplugincentral.net/content/run-all-tests", node.getUrl());
    assertEquals("resource", node.getType());
    ICategories categories = node.getCategories();
    assertNotNull(categories);
    assertEquals(1, categories.getCategory().size());
    ICategory category = categories.getCategory().get(0);
    assertEquals("16", category.getId());
    assertEquals("Testing", category.getName());
    assertEquals("http://www.eclipseplugincentral.net/taxonomy/term/16", category.getUrl());
    assertEquals("ipreuss", node.getOwner());
    assertNotNull(node.getBody());
    assertEquals("Allows the execution of JUnit tests for several projects at once.", node.getBody());
    assertTrue(!node.getFoundationmember());
    assertEquals("https://sourceforge.net/projects/e-rat/", node.getHomepageurl());
    assertNull(node.getImage());
    assertEquals("1.0.1", node.getVersion());
    assertEquals("Other", node.getLicense());
    assertEquals("Ilja Preu\u00DF", node.getCompanyname());
    assertEquals("Production/Stable", node.getStatus());
    assertEquals("3.5", node.getEclipseversion());
    assertEquals("https://sourceforge.net/projects/e-rat/support", node.getSupporturl());
    assertEquals("http://e-rat.sf.net/updatesite", node.getUpdateurl());
    assertEquals(Integer.valueOf(136), node.getFavorited());
    assertEquals(Integer.valueOf(299995), node.getInstallsTotal());
    assertEquals(Integer.valueOf(34540), node.getInstallsRecent());
    INode lastNode = search.getNode().get(search.getNode().size() - 1);
    assertEquals("1011", lastNode.getId());
    assertEquals("JUnit Flux", lastNode.getName());
    assertNull(lastNode.getFavorited());
    assertNull(lastNode.getInstallsTotal());
    assertNull(lastNode.getInstallsRecent());
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) INode(org.eclipse.epp.mpc.core.model.INode) ICategories(org.eclipse.epp.mpc.core.model.ICategories) Search(org.eclipse.epp.internal.mpc.core.model.Search) ICategory(org.eclipse.epp.mpc.core.model.ICategory) Test(org.junit.Test)

Example 2 with Search

use of org.eclipse.epp.internal.mpc.core.model.Search in project epp.mpc by eclipse.

the class DefaultMarketplaceService method processSearchRequest.

private SearchResult processSearchRequest(String relativeUrl, String queryText, IProgressMonitor monitor) throws CoreException {
    SearchResult result = new SearchResult();
    if (relativeUrl == null) {
        // empty search
        result.setMatchCount(0);
        result.setNodes(new ArrayList<Node>());
    } else {
        Marketplace marketplace;
        try {
            marketplace = processRequest(relativeUrl, monitor);
        } catch (CoreException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof FileNotFoundException) {
                throw new CoreException(createErrorStatus(NLS.bind(Messages.DefaultMarketplaceService_UnsupportedSearchString, queryText), cause));
            }
            throw ex;
        }
        Search search = marketplace.getSearch();
        if (search != null) {
            result.setMatchCount(search.getCount());
            result.setNodes(search.getNode());
        } else if (marketplace.getCategory().size() == 1) {
            Category category = marketplace.getCategory().get(0);
            result.setMatchCount(category.getNode().size());
            result.setNodes(category.getNode());
        } else {
            throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, relativeUrl));
        }
    }
    return result;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) Search(org.eclipse.epp.internal.mpc.core.model.Search) FileNotFoundException(java.io.FileNotFoundException) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Aggregations

Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)2 Search (org.eclipse.epp.internal.mpc.core.model.Search)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 INode (org.eclipse.epp.mpc.core.model.INode)2 FileNotFoundException (java.io.FileNotFoundException)1 CoreException (org.eclipse.core.runtime.CoreException)1 Category (org.eclipse.epp.internal.mpc.core.model.Category)1 Node (org.eclipse.epp.internal.mpc.core.model.Node)1 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)1 ICategories (org.eclipse.epp.mpc.core.model.ICategories)1 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)1 Test (org.junit.Test)1