Search in sources :

Example 1 with ExtensionsSearchResult

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult in project xwiki-platform by xwiki.

the class RepositoryTest method addExtension.

private void addExtension() throws Exception {
    // Create extension
    ExtensionsPage extensionsPage = ExtensionsPage.gotoPage();
    ExtensionInlinePage extensionInline = extensionsPage.contributeExtension(this.baseExtension.getName());
    Assert.assertEquals(this.baseExtension.getName(), extensionInline.getName());
    extensionInline.setDescription(this.baseExtension.getDescription());
    extensionInline.setInstallation("extension installation");
    extensionInline.setLicenseName(this.baseLicense.getName());
    extensionInline.setSource("http://source");
    extensionInline.setSummary(this.baseExtension.getSummary());
    extensionInline.setType(this.baseExtension.getType());
    ExtensionPage extensionPage = extensionInline.clickSaveAndView();
    // Test summary
    getDriver().findElementsWithoutWaiting(By.xpath("//tt[text()=\"" + this.baseExtension.getSummary() + "\"]"));
    Assert.assertFalse(extensionPage.isValidExtension());
    // Add versions
    // TODO: add XR UI to manipulate versions
    getRepositoryTestUtils().addVersionObject(this.baseExtension);
    getRepositoryTestUtils().addVersionObject(this.baseExtension, "10.0", getUtil().getAttachmentURL("Extension", this.baseExtension.getName(), this.baseExtension.getFile().getName()));
    getRepositoryTestUtils().addVersionObject(this.baseExtension, "2.0", "attach:" + this.baseExtension.getFile().getName());
    // Add dependencies
    // TODO: add XR UI to manipulate dependencies
    getRepositoryTestUtils().addDependencies(this.baseExtension, "10.0");
    // Add attachment
    getRepositoryTestUtils().attachFile(this.baseExtension);
    // Wait until all asynchronous tasks are done
    getRepositoryTestUtils().waitUntilReady();
    // Check livetable
    extensionsPage = ExtensionsPage.gotoPage();
    ExtensionsLiveTableElement livetable = extensionsPage.getLiveTable();
    livetable.filterName(this.baseExtension.getName());
    extensionPage = livetable.clickExtensionName(this.baseExtension.getName());
    // Validate extension state
    Assert.assertTrue(extensionPage.isValidExtension());
    // //////////////////////////////////////////
    // Validate REST
    // //////////////////////////////////////////
    // //////////////////////////////////////////
    // 1.0
    // //////////////////////////////////////////
    // Resolve
    ExtensionVersion extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "1.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseExtension.getDescription(), extension.getDescription());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("1.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "1.0").length);
    // //////////////////////////////////////////
    // 2.0
    // //////////////////////////////////////////
    // Resolve
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "2.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseExtension.getDescription(), extension.getDescription());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("2.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "2.0").length);
    // //////////////////////////////////////////
    // 10.0
    // //////////////////////////////////////////
    // Resolve
    extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "10.0");
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
    ExtensionDependency dependency1 = extension.getDependencies().get(0);
    Assert.assertEquals("dependencyid1", dependency1.getId());
    Assert.assertEquals("1.0", dependency1.getConstraint());
    ExtensionDependency dependency2 = extension.getDependencies().get(1);
    Assert.assertEquals("dependencyid2", dependency2.getId());
    Assert.assertEquals("2.0", dependency2.getConstraint());
    // File
    Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), this.baseExtension.getId().getVersion().getValue()).length);
    // //////////////////////////////////////////
    // Search
    // //////////////////////////////////////////
    // Empty search
    extension = searchExtension(this.baseExtension.getId().getId());
    if (extension == null) {
        Assert.fail("Could not find extension [" + this.baseExtension.getId().getId() + "]");
    }
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    // TODO: add support for dependencies in XR search
    // Search pattern
    Map<String, Object[]> queryParams = new HashMap<String, Object[]>();
    queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "macro" });
    ExtensionsSearchResult result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals(0, result.getOffset());
    extension = result.getExtensions().get(0);
    Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
    Assert.assertEquals(this.baseExtension.getType(), extension.getType());
    Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
    Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
    Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
    Assert.assertEquals("10.0", extension.getVersion());
    // Wrong search pattern
    queryParams.clear();
    queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "notexisting" });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(0, result.getTotalHits());
    Assert.assertEquals(0, result.getOffset());
    Assert.assertEquals(0, result.getExtensions().size());
    // Search limit offset
    queryParams.clear();
    queryParams.put(Resources.QPARAM_LIST_START, new Object[] { 1 });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertEquals(1, result.getOffset());
    Assert.assertEquals(result.getTotalHits() - 1, result.getExtensions().size());
    // Search limit nb
    queryParams.clear();
    queryParams.put(Resources.QPARAM_LIST_NUMBER, new Object[] { 0 });
    result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertTrue(result.getTotalHits() >= 1);
    Assert.assertEquals(0, result.getOffset());
    Assert.assertEquals(0, result.getExtensions().size());
}
Also used : ExtensionsSearchResult(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult) ExtensionInlinePage(org.xwiki.repository.test.po.editor.ExtensionInlinePage) ExtensionsPage(org.xwiki.repository.test.po.ExtensionsPage) ExtensionPage(org.xwiki.repository.test.po.ExtensionPage) HashMap(java.util.HashMap) ExtensionsLiveTableElement(org.xwiki.repository.test.po.ExtensionsLiveTableElement) ExtensionDependency(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency) DefaultExtensionDependency(org.xwiki.extension.DefaultExtensionDependency) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)

Example 2 with ExtensionsSearchResult

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult in project xwiki-platform by xwiki.

the class RepositoryTest method searchExtension.

private ExtensionVersion searchExtension(String id) throws Exception {
    Map<String, Object[]> queryParams = new HashMap<String, Object[]>();
    ExtensionsSearchResult result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
    Assert.assertTrue(result.getTotalHits() >= 0);
    Assert.assertEquals(0, result.getOffset());
    ExtensionVersion extension = null;
    for (ExtensionVersion extensionVersion : result.getExtensions()) {
        if (extensionVersion.getId().equals(id)) {
            extension = extensionVersion;
            break;
        }
    }
    return extension;
}
Also used : ExtensionsSearchResult(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult) HashMap(java.util.HashMap) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)

Example 3 with ExtensionsSearchResult

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult in project xwiki-platform by xwiki.

the class ExtensionIT method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // Make sure the extensions we are playing with are not already installed.
    getExtensionTestUtils().finishCurrentJob();
    getExtensionTestUtils().uninstall("alice-xar-extension");
    getExtensionTestUtils().uninstall("bob-xar-extension");
    getExtensionTestUtils().uninstall("scriptServiceJarExtension");
    // Delete the pages that are provided by the XAR extensions we use in tests.
    getUtil().rest().deletePage("ExtensionTest", "Alice");
    assertFalse(getUtil().pageExists("ExtensionTest", "Alice"));
    getUtil().rest().deletePage("ExtensionTest", "Bob");
    assertFalse(getUtil().pageExists("ExtensionTest", "Bob"));
    // Delete from the repository the XAR extensions we use in tests.
    // The extension page name is either the extension name, if specified, or the extension id. Most of the tests
    // don't set the extension name but some do and we end up with two extensions (two pages) with the same id.
    getRepositoryTestUtils().deleteExtension("Alice Wiki Macro");
    getRepositoryTestUtils().deleteExtension("Bob Wiki Macro");
    getRepositoryTestUtils().deleteExtension("alice-xar-extension");
    getRepositoryTestUtils().deleteExtension("bob-xar-extension");
    getRepositoryTestUtils().deleteExtension("scriptServiceJarExtension");
    getRepositoryTestUtils().waitUntilReady();
    // Double check that the XWiki Extension Repository is empty.
    ExtensionsSearchResult searchResult = getUtil().rest().getResource("repository/search", Collections.singletonMap("number", new Object[] { 1 }));
    assertEquals(0, searchResult.getTotalHits());
}
Also used : ExtensionsSearchResult(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult)

Example 4 with ExtensionsSearchResult

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult in project xwiki-platform by xwiki.

the class SearchRESTResource method searchPost.

@POST
public ExtensionsSearchResult searchPost(ExtensionQuery query) throws QueryException {
    ExtensionsSearchResult result = this.extensionObjectFactory.createExtensionsSearchResult();
    Query solrQuery = this.queryManager.createQuery(toSolrStatement(query.getQuery()), "solr");
    // /////////////////
    // Search only in the current wiki
    // /////////////////
    solrQuery.setWiki(this.xcontextProvider.get().getWikiId());
    // /////////////////
    // Limit and offset
    // /////////////////
    solrQuery.setLimit(query.getLimit());
    solrQuery.setOffset(query.getOffset());
    if (query instanceof SecureQuery) {
        // Show only what the current user has the right to see
        ((SecureQuery) query).checkCurrentUser(true);
    }
    // /////////////////
    // Boost
    // /////////////////
    solrQuery.bindValue("qf", DEFAULT_BOOST);
    // /////////////////
    // Fields
    // /////////////////
    solrQuery.bindValue("fl", DEFAULT_FL);
    // /////////////////
    // Ordering
    // /////////////////
    // Convert extension ordering into solr ordering
    List<String> sortClauses = new ArrayList<>(query.getSortClauses().size() + 1);
    for (SortClause sortClause : query.getSortClauses()) {
        String solrField = XWikiRepositoryModel.toSolrField(sortClause.getField());
        if (solrField != null) {
            sortClauses.add(solrField + ' ' + sortClause.getOrder().name().toLowerCase());
        }
    }
    // Set default ordering
    if (StringUtils.isEmpty(query.getQuery())) {
        // Sort by rating by default when search query is empty
        sortClauses.add(XWikiRepositoryModel.toSolrOrderField(RatingExtension.FIELD_AVERAGE_VOTE) + " desc");
        sortClauses.add(XWikiRepositoryModel.toSolrOrderField(RatingExtension.FIELD_TOTAL_VOTES) + " desc");
    } else {
        // Sort by score by default when search query is not empty
        sortClauses.add("score desc");
    }
    solrQuery.bindValue("sort", sortClauses);
    // /////////////////
    // Filtering
    // /////////////////
    List<String> fq = new ArrayList<>(query.getFilters().size() + 1);
    // TODO: should be filter only on current wiki ?
    // We want only valid extensions documents
    fq.add(XWikiRepositoryModel.SOLRPROP_EXTENSION_VALIDEXTENSION + ":true");
    // Request filters
    for (Filter fiter : query.getFilters()) {
        String solrField = XWikiRepositoryModel.toSolrField(fiter.getField());
        if (solrField != null) {
            StringBuilder builder = new StringBuilder();
            builder.append(solrField);
            builder.append(':');
            if (fiter.getComparison() == COMPARISON.EQUAL) {
                builder.append(fiter.getValueString());
            } else {
                builder.append('*' + fiter.getValueString() + '*');
            }
            fq.add(builder.toString());
        }
    }
    solrQuery.bindValue("fq", fq);
    // /////////////////
    // Execute
    // /////////////////
    QueryResponse response = (QueryResponse) solrQuery.execute().get(0);
    SolrDocumentList documents = response.getResults();
    result.setOffset((int) documents.getStart());
    result.setTotalHits((int) documents.getNumFound());
    // other searches behavior
    if (query.getLimit() != 0) {
        for (SolrDocument document : documents) {
            result.getExtensions().add(createExtensionVersionFromSolrDocument(document));
        }
    }
    return result;
}
Also used : ExtensionsSearchResult(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult) SolrDocument(org.apache.solr.common.SolrDocument) Query(org.xwiki.query.Query) SecureQuery(org.xwiki.query.SecureQuery) ExtensionQuery(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionQuery) SortClause(org.xwiki.extension.repository.xwiki.model.jaxb.SortClause) Filter(org.xwiki.extension.repository.xwiki.model.jaxb.Filter) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SecureQuery(org.xwiki.query.SecureQuery) POST(javax.ws.rs.POST)

Aggregations

ExtensionsSearchResult (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult)4 HashMap (java.util.HashMap)2 ExtensionVersion (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)2 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)1 ExtensionDependency (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency)1 ExtensionQuery (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionQuery)1 Filter (org.xwiki.extension.repository.xwiki.model.jaxb.Filter)1 SortClause (org.xwiki.extension.repository.xwiki.model.jaxb.SortClause)1 Query (org.xwiki.query.Query)1 SecureQuery (org.xwiki.query.SecureQuery)1 ExtensionPage (org.xwiki.repository.test.po.ExtensionPage)1 ExtensionsLiveTableElement (org.xwiki.repository.test.po.ExtensionsLiveTableElement)1 ExtensionsPage (org.xwiki.repository.test.po.ExtensionsPage)1 ExtensionInlinePage (org.xwiki.repository.test.po.editor.ExtensionInlinePage)1