Class AbstractIssueFetcher

  • All Implemented Interfaces:
    IssueFetcher

    public abstract class AbstractIssueFetcher
    extends Object
    implements IssueFetcher
    Represents the issue fetcher used by AbstractIssueProvider. This class contains commonly used routines for downloading and parsing XML.

    It also uses caching of the fetched issues (invalidated after certain time period) to improve overall performance.

    Author:
    Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
    • Constructor Detail

      • AbstractIssueFetcher

        @Deprecated
        public AbstractIssueFetcher​(@NotNull
                                    EhCacheUtil cacheUtil)
        Deprecated.
        since 10.0, will be removed in future versions
    • Method Detail

      • getChildContent

        @Nullable
        protected String getChildContent​(@NotNull
                                         org.jdom.Element element,
                                         @NotNull
                                         String childName)
        Returns the content text of the child element.
        Parameters:
        element - the parent DOM element
        childName - child name
        Returns:
        the textual content directly held under the child, or null
      • getAttribute

        @Nullable
        protected String getAttribute​(@NotNull
                                      org.jdom.Element element,
                                      @NotNull
                                      String attributeName)
        Returns the element's attribute value.
        Parameters:
        element - the DOM element
        attributeName - attribute name
        Returns:
        the textual value of the specified attribute, or null
      • isFeature

        protected boolean isFeature​(@Nullable
                                    String field)
        Returns whether the issue is a feature request (by a single field, which can be a type, severity, or any other one).

        The implementation is default (simply checks that field equals to "feature" or "enhancement" ignoring the case), may not be applicable for a particular issue tracking system.

        Parameters:
        field - the field that determines feature attribute
        Returns:
        true if the issue is a feature based on a field
      • getFromCacheOrFetch

        @NotNull
        protected IssueData getFromCacheOrFetch​(@NotNull
                                                Object key,
                                                @NotNull
                                                AbstractIssueFetcher.FetchFunction function)
                                         throws Exception
        Returns a cached issue, or performs a slow fetch operation specified by a function and returns the result.

        Note that if the issue cannot be fetched, a null value is still put in cache, so the issue won't be requested until the cache entry is expired.

        Use this method to implement a IssueFetcher.getIssue(String, String, Credentials) method. Example:

           @NotNull
           public Issue getIssue(@NotNull String host, @NotNull String id,
                                 @Nullable final Credentials credentials) {
             final String url = composeUrl(host, id);
             return getFromCacheOrFetch(url, new FetchFunction() {
               @NotNull
               public Issue fetch() throws Exception {
                 return doFetch(url, credentials);
               }
             });
           }
         
        Parameters:
        key - the issue key (usually an URL corresponding to an issue)
        function - a function called when the cache doesn't contain the result
        Returns:
        an issue
        Throws:
        Exception - if the issue cannot be fetched
      • toString

        @Nullable
        protected String toString​(@Nullable
                                  Object obj)
        An utility method to transform an object to string safely.
        Parameters:
        obj - any object
        Returns:
        obj.toString(), or null
      • removeFromCache

        public void removeFromCache​(@NotNull
                                    String host,
                                    @NotNull
                                    String id)
        Description copied from interface: IssueFetcher
        Removes the cached entry corresponding to the issue id.
        Specified by:
        removeFromCache in interface IssueFetcher
        Parameters:
        host - server host
        id - issue id
      • getCache

        @NotNull
        protected net.sf.ehcache.Cache getCache()
      • getErrorCache

        @NotNull
        protected net.sf.ehcache.Cache getErrorCache()
      • getPossiblyExpiredData

        public IssueData getPossiblyExpiredData​(@NotNull
                                                String host,
                                                @NotNull
                                                String id)
        Description copied from interface: IssueFetcher
        Returns the cached issue data, no matter if it's expired or not.
        Specified by:
        getPossiblyExpiredData in interface IssueFetcher
        Parameters:
        host - server host
        id - issue id
        Returns:
        the cached issue data (if exists), or null
      • getIssuesInBatch

        @Nullable
        public Collection<IssueData> getIssuesInBatch​(@NotNull
                                                      String host,
                                                      @NotNull
                                                      Collection<String> ids,
                                                      @Nullable
                                                      org.apache.commons.httpclient.Credentials credentials)
        Batch fetching.
        Specified by:
        getIssuesInBatch in interface IssueFetcher
        Parameters:
        host - server host
        ids - issue ids
        credentials - basic auth credentials (null means no credentials)
        Returns:
        the cached issue data (if exists), or null
      • fetchNonCachedIssues

        @NotNull
        protected Collection<IssueData> fetchNonCachedIssues​(@NotNull
                                                             Collection<String> ids,
                                                             @NotNull
                                                             AbstractIssueFetcher.CacheKeyFunction keyFunction,
                                                             @NotNull
                                                             AbstractIssueFetcher.BatchFetchFunction fetchFunction)
        Performs a specified fetch function fetchFunction for a number of issue ids, which are not cached at the moment.

        For this purpose ids must be mutable.

        Parameters:
        ids - the collection of ids to fetch
        keyFunction - the function used to get a cache key by issue id
        fetchFunction - general fetch function
        Returns:
        the collection of fetch data