2015-11-10 5 views
1

Я обновил свой запрос до моего текущего состояния.
У меня осталось только 1 ошибка, и я не знаю, как ее решить.
Сначала это мой код:Запрос на просмотр запроса Плагин реализован класс

package com.example.plugins.tutorial; 

import com.atlassian.jira.issue.Issue; 
import com.atlassian.jira.issue.IssueFactory; 
import com.atlassian.jira.issue.search.SearchException; 
import com.atlassian.jira.issue.search.SearchProviderFactory; 
import com.atlassian.jira.issue.search.SearchRequest; 
import com.atlassian.jira.issue.views.util.IssueWriterHitCollector; 
import com.atlassian.jira.plugin.searchrequestview.AbstractSearchRequestView; 
import com.atlassian.jira.plugin.searchrequestview.SearchRequestParams; 
import com.atlassian.jira.security.JiraAuthenticationContext; 
import com.atlassian.jira.util.JiraVelocityUtils; 
import com.atlassian.sal.api.search.SearchProvider; 
import com.atlassian.jira.issue.search.providers.LuceneSearchProvider; 

import org.apache.lucene.search.IndexSearcher; 
import org.apache.lucene.search.Collector; 

import java.io.IOException; 
import java.io.Writer; 
import java.util.Collections; 
import java.util.HashMap; 
import java.util.Map; 


public class TestSearch extends AbstractSearchRequestView 
{ 
    private final JiraAuthenticationContext authenticationContext; 
    private final SearchProviderFactory searchProviderFactory; 
    private final IssueFactory issueFactory; 
    private final SearchProvider searchProvider; 

    public TestSearch(JiraAuthenticationContext authenticationContext, SearchProviderFactory searchProviderFactory, 
     IssueFactory issueFactory, SearchProvider searchProvider) 
{ 
    this.authenticationContext = authenticationContext; 
    this.searchProviderFactory = searchProviderFactory; 
    this.issueFactory = issueFactory; 
    this.searchProvider = searchProvider; 
} 

public void writeSearchResults(final SearchRequest searchRequest, final SearchRequestParams searchRequestParams, final Writer writer) 
{ 
    final Map defaultParams = JiraVelocityUtils.getDefaultVelocityParams(authenticationContext); 

    //Need to put the filtername into the velocity context. This may be null if this is an anoymous filter. 
    final Map headerParams = new HashMap(defaultParams); 
    headerParams.put("filtername", searchRequest.getName()); 
    try 
    { 
     //First we need to write the header 
     writer.write(descriptor.getHtml("header", headerParams)); 

     //now lets write the search results. This basically iterates over each issue in the search results and writes 
     //it to the writer using the format defined by this plugin. To ensure that this doesn't result in huge 
     //memory consumption only one issue should be loaded into memory at a time. This can be guaranteed by using a 
     //Hitcollector. 
     final IndexSearcher searcher = searchProviderFactory.getSearcher(SearchProviderFactory.ISSUE_INDEX); 
     final Map issueParams = new HashMap(defaultParams); 
     //This hit collector is responsible for writing out each issue as it is encountered in the search results. 
     //It will be called for each search result by the underlying Lucene search code. 
     final Collector hitCollector = new IssueWriterHitCollector(searcher, writer, issueFactory) 
     { 
      protected void writeIssue(Issue issue, Writer writer) throws IOException 
      { 
       //put the current issue into the velocity context and render the single issue view 
       issueParams.put("issue", issue); 
       writer.write(descriptor.getHtml("singleissue", issueParams)); 
      } 
     }; 
     //now run the search that's defined in the issue navigator and pass in the hitcollector from above which will 
     //write out each issue in the format specified in this plugin. 
     searchProvider.searchAndSort(searchRequest.getQuery(), authenticationContext.getLoggedInUser(), hitCollector, searchRequestParams.getPagerFilter()); 

     //finally lets write the footer. 
     writer.write(descriptor.getHtml("footer", Collections.emptyMap())); 
    } 
    catch (IOException e) 
    { 
     throw new RuntimeException(e); 
    } 
    catch (SearchException e) 
    { 
     throw new RuntimeException(e); 
    } 
} 
} 

Моя проблема заключается в searchAndSort не работает

searchProvider.searchAndSort(searchRequest.getQuery(), authenticationContext.getLoggedInUser(), hitCollector, searchRequestParams.getPagerFilter()); 

затмение показывает мне ошибку, что «Метод searchAndSort не определено для типа SearchProvider».

тот же вопрос, и второй пример с той же ошибки:

@Override 
public void writeSearchResults(final SearchRequest searchRequest,final SearchRequestParams searchRequestParams,final Writer writer) throws SearchException 
{ 
    final Map defaultParams = JiraVelocityUtils.getDefaultVelocityParams(authenticationContext); 
    final Map headerParams = new HashMap(defaultParams); 
    headerParams.put("filtername", searchRequest.getName()); 
    headerParams.put("user", authenticationContext.getLoggedInUser()); 
    try 
    { 
     //Header 
     writer.write(descriptor.getHtml("header", headerParams)); 
     //Body 
     final IndexSearcher searcher = searchProviderFactory.getSearcher(SearchProviderFactory.ISSUE_INDEX);   
     final Map issueParams = new HashMap(defaultParams); 
     final Collector hitCollector = new IssueWriterHitCollector(searcher, writer, issueFactory) 
     { 
      protected void writeIssue(Issue issue, Writer writer) throws IOException 
      { 
       //put the current issue into the velocity context and render the single issue view 
       issueParams.put("issue", issue); 
       writer.write(descriptor.getHtml("body", issueParams)); 
      } 
     }; 
     searchProvider.searchAndSort(searchRequest.getQuery(), authenticationContext.getLoggedInUser(), hitCollector, searchRequestParams.getPagerFilter()); 
     //Footer 
     writer.write(descriptor.getHtml("footer", MapBuilder.build("user", authenticationContext.getLoggedInUser()))); 
    } 
    catch (IOException e) 
    { 
     throw new RuntimeException(e); 
    } 
    catch (SearchException e) 
    { 
     throw new RuntimeException(e); 
    } 
} 

Та же проблема с searchAndSort ...

Было бы очень хорошо, если бы кто-то может помочь.

ответ

1

Я решил это, я импортировал ложный SearchProvider и теперь его работы. для других людей, которые имеют те же проблемы и хотят, чтобы сделать поисковый запрос вида плагиной ведьма возвращает вопросы в HTML, вы можете иметь свой код:

package com.example.plugins.tutorial; 

import com.atlassian.jira.util.collect.MapBuilder; 
import com.atlassian.jira.issue.Issue; 
import com.atlassian.jira.issue.IssueFactory; 
import com.atlassian.jira.issue.search.SearchException; 
import com.atlassian.jira.issue.search.SearchProviderFactory; 
import com.atlassian.jira.issue.search.SearchRequest; 
import com.atlassian.jira.issue.views.util.IssueWriterHitCollector; 
import com.atlassian.jira.plugin.searchrequestview.AbstractSearchRequestView; 
import com.atlassian.jira.plugin.searchrequestview.SearchRequestParams; 
import com.atlassian.jira.security.JiraAuthenticationContext; 
import com.atlassian.jira.util.JiraVelocityUtils; 
import com.atlassian.jira.issue.search.SearchProvider; 

import org.apache.lucene.search.IndexSearcher; 
import org.apache.lucene.search.Collector; 

import java.io.IOException; 
import java.io.Writer; 
import java.util.Collections; 
import java.util.HashMap; 
import java.util.Map; 

public class NextTestSearch extends AbstractSearchRequestView { 

private final JiraAuthenticationContext authenticationContext; 
private final SearchProviderFactory searchProviderFactory; 
private final IssueFactory issueFactory; 
private final SearchProvider searchProvider; 

public NextTestSearch(JiraAuthenticationContext authenticationContext, SearchProviderFactory searchProviderFactory, 
     IssueFactory issueFactory, SearchProvider searchProvider) 
{ 
    this.authenticationContext = authenticationContext; 
    this.searchProviderFactory = searchProviderFactory; 
    this.issueFactory = issueFactory; 
    this.searchProvider = searchProvider; 
} 

@Override 
public void writeSearchResults(final SearchRequest searchRequest,final SearchRequestParams searchRequestParams,final Writer writer) throws SearchException 
{ 
    final Map defaultParams = JiraVelocityUtils.getDefaultVelocityParams(authenticationContext); 
    final Map headerParams = new HashMap(defaultParams); 
    headerParams.put("filtername", searchRequest.getName()); 
    headerParams.put("user", authenticationContext.getLoggedInUser()); 
    try 
    { 
     //Header 
     writer.write(descriptor.getHtml("header", headerParams)); 
     //Body 
     final IndexSearcher searcher = searchProviderFactory.getSearcher(SearchProviderFactory.ISSUE_INDEX);   
     final Map issueParams = new HashMap(defaultParams); 
     final Collector hitCollector = new IssueWriterHitCollector(searcher, writer, issueFactory) 
     { 
      protected void writeIssue(Issue issue, Writer writer) throws IOException 
      { 
       //put the current issue into the velocity context and render the single issue view 
       issueParams.put("issue", issue); 
       writer.write(descriptor.getHtml("body", issueParams)); 
      } 
     }; 
     searchProvider.searchAndSort(searchRequest.getQuery(), authenticationContext.getLoggedInUser(), hitCollector, searchRequestParams.getPagerFilter()); 
     //Footer 
     writer.write(descriptor.getHtml("footer", MapBuilder.build("user", authenticationContext.getLoggedInUser()))); 
    } 
    catch (IOException e) 
    { 
     throw new RuntimeException(e); 
    } 
    catch (SearchException e) 
    { 
     throw new RuntimeException(e); 
    } 
} 
} 

остальное, что нужно для плагина должен работать в officele tutorial, This is the Link есть учебник, но исходный код java устарел.

 Смежные вопросы

  • Нет связанных вопросов^_^