Class AbstractIssueFetcher
- java.lang.Object
-
- jetbrains.buildServer.issueTracker.AbstractIssueFetcher
-
- All Implemented Interfaces:
IssueFetcher
public abstract class AbstractIssueFetcher extends java.lang.Object implements IssueFetcher
Represents the issue fetcher used byAbstractIssueProvider
. 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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
AbstractIssueFetcher.BatchFetchFunction
An interface represents an action of fetching in a batch.protected static interface
AbstractIssueFetcher.CacheKeyFunction
The cache key function.protected static interface
AbstractIssueFetcher.FetchFunction
An interface represents an action of actual issue fetching.
-
Constructor Summary
Constructors Constructor Description AbstractIssueFetcher(EhCacheUtil cacheUtil)
Deprecated.since 10.0, will be removed in future versions
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.util.Collection<IssueData>
defaultGetIssuesInBatch(java.lang.String host, java.util.Collection<java.lang.String> ids, AbstractIssueFetcher.BatchFetchFunction function)
Method is identical tofetchNonCachedIssues(Collection, CacheKeyFunction, BatchFetchFunction)
, but uses a default key function (id -> url
).protected java.io.InputStream
fetchHttpFile(java.lang.String url, org.apache.commons.httpclient.Credentials credentials)
Deprecated.since 2018.1.IssueData
fetchIssue(java.lang.String host, java.lang.String id, IssueFetcherAuthenticator authenticator)
backward compatibilityjava.util.Collection<IssueData>
fetchIssuesInBatch(java.lang.String host, java.util.Collection<java.lang.String> ids, IssueFetcherAuthenticator authenticator)
backward compatibilityprotected java.util.Collection<IssueData>
fetchNonCachedIssues(java.util.Collection<java.lang.String> ids, AbstractIssueFetcher.CacheKeyFunction keyFunction, AbstractIssueFetcher.BatchFetchFunction fetchFunction)
Performs a specified fetch functionfetchFunction
for a number of issue ids, which are not cached at the moment.java.util.List<java.lang.String>
fetchProjectIds(java.lang.String host, IssueFetcherAuthenticator authenticator)
Fetches all available project ids.protected java.lang.String
getAttribute(org.jdom.Element element, java.lang.String attributeName)
Returns the element's attribute value.protected net.sf.ehcache.Cache
getCache()
protected java.lang.String
getChildContent(org.jdom.Element element, java.lang.String childName)
Returns the content text of the child element.protected net.sf.ehcache.Cache
getErrorCache()
protected IssueData
getFromCacheOrFetch(java.lang.Object key, AbstractIssueFetcher.FetchFunction function)
Returns a cached issue, or performs a slow fetch operation specified by afunction
and returns the result.protected java.io.InputStream
getHttpFile(java.lang.String url, SimpleCredentials credentials, boolean usePreemptiveAuthentication, java.security.KeyStore trustStore)
Deprecated.since 2019.1.protected java.io.InputStream
getHttpFile(java.lang.String url, SimpleCredentials credentials, boolean usePreemptiveAuthentication, java.security.KeyStore trustStore, HTTPRequestBuilder.ResponseConsumer errorsConsumer)
Fetches the document from HTTP resource specified byurl
with specified credentials.protected java.io.InputStream
getHttpFile(java.lang.String url, IssueFetcherAuthenticator authenticator)
Deprecated.since 2018.1.protected java.io.InputStream
getHttpFile(java.lang.String url, IssueFetcherAuthenticator authenticator, java.security.KeyStore trustStore, HTTPRequestBuilder.ResponseConsumer errorsConsumer)
Fetches the document from HTTP resource specified byurl
with specified credentials.java.util.Collection<IssueData>
getIssuesInBatch(java.lang.String host, java.util.Collection<java.lang.String> ids, org.apache.commons.httpclient.Credentials credentials)
Batch fetching.IssueData
getPossiblyExpiredData(java.lang.String host, java.lang.String id)
Returns the cached issue data, no matter if it's expired or not.protected void
handleHttpError(int code, org.apache.commons.httpclient.methods.GetMethod get)
Deprecated.method is deprecated because corresponding methodsfetchHttpFile(String, Credentials)
andgetHttpFile(String, IssueFetcherAuthenticator)
are deprecatedboolean
hasInCache(java.lang.String host, java.lang.String id)
Returns whether the fetcher contains the issue corresponding toid
in its cache.boolean
hasInErrorCache(java.lang.String host, java.lang.String id)
Returns whether the fetcher contains the error retrievingid
in its cache.protected boolean
isFeature(java.lang.String field)
Returns whether the issue is a feature request (by a singlefield
, which can be a type, severity, or any other one).void
removeFromCache(java.lang.String host, java.lang.String id)
Removes the cached entry corresponding to the issueid
.protected java.lang.String
toString(java.lang.Object obj)
An utility method to transform an object to string safely.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.issueTracker.IssueFetcher
getIssue, getUrl
-
-
-
-
Method Detail
-
fetchHttpFile
@NotNull @Deprecated protected java.io.InputStream fetchHttpFile(@NotNull java.lang.String url, @Nullable org.apache.commons.httpclient.Credentials credentials) throws java.io.IOException
Deprecated.since 2018.1. UsegetHttpFile(String, IssueFetcherAuthenticator, KeyStore, HTTPRequestBuilder.ResponseConsumer)
insteadFetches the document from HTTP resource specified byurl
with specified credentials.- Parameters:
url
- the url of file to fetchcredentials
- basic auth credentials (null means no credentials)- Returns:
- result input stream, or null in case of HTTP error
- Throws:
java.io.IOException
- if I/O error occurs
-
getHttpFile
@NotNull @Deprecated protected java.io.InputStream getHttpFile(@NotNull java.lang.String url, @NotNull IssueFetcherAuthenticator authenticator) throws java.io.IOException
Deprecated.since 2018.1. UsegetHttpFile(String, IssueFetcherAuthenticator, KeyStore, HTTPRequestBuilder.ResponseConsumer)
insteadFetches the document from HTTP resource specified byurl
with specified credentials.- Parameters:
url
- the url of file to fetchauthenticator
- authenticator- Returns:
- result input stream, or null in case of HTTP error
- Throws:
java.io.IOException
- if I/O error occurs
-
getHttpFile
@Deprecated protected java.io.InputStream getHttpFile(@NotNull java.lang.String url, @Nullable SimpleCredentials credentials, boolean usePreemptiveAuthentication, @Nullable java.security.KeyStore trustStore) throws java.io.IOException, java.net.URISyntaxException
Deprecated.since 2019.1. UsegetHttpFile(String, IssueFetcherAuthenticator, KeyStore, HTTPRequestBuilder.ResponseConsumer)
insteadFetches the document from HTTP resource specified byurl
with specified credentials.- Parameters:
url
- the url of file to fetchcredentials
- the data for authenticationusePreemptiveAuthentication
- is it necessary to use preemptive authenticationtrustStore
- store with trusted SSL certificates- Returns:
- result input stream
- Throws:
java.io.IOException
- if I/O error occursjava.net.URISyntaxException
- if specified url cannot be converted to valid URI
-
getHttpFile
protected java.io.InputStream getHttpFile(@NotNull java.lang.String url, @Nullable SimpleCredentials credentials, boolean usePreemptiveAuthentication, @Nullable java.security.KeyStore trustStore, @NotNull HTTPRequestBuilder.ResponseConsumer errorsConsumer) throws java.io.IOException, java.net.URISyntaxException
Fetches the document from HTTP resource specified byurl
with specified credentials. If authentication requires setting specific properties to request or uses custom logic implemented in authenticator, usegetHttpFile(String, IssueFetcherAuthenticator, KeyStore, HTTPRequestBuilder.ResponseConsumer)
- Parameters:
url
- the url of file to fetchcredentials
- the data for authenticationusePreemptiveAuthentication
- is it necessary to use preemptive authenticationtrustStore
- store with trusted SSL certificateserrorsConsumer
- the handler of HTTP errors after unsuccessful GET request- Returns:
- result input stream
- Throws:
java.io.IOException
- if I/O error occursjava.net.URISyntaxException
- if specified url cannot be converted to valid URI
-
getHttpFile
protected java.io.InputStream getHttpFile(@NotNull java.lang.String url, @NotNull IssueFetcherAuthenticator authenticator, @Nullable java.security.KeyStore trustStore, @NotNull HTTPRequestBuilder.ResponseConsumer errorsConsumer) throws java.io.IOException, java.net.URISyntaxException
Fetches the document from HTTP resource specified byurl
with specified credentials.- Parameters:
url
- the url of file to fetchauthenticator
- authenticatortrustStore
- store with trusted SSL certificateserrorsConsumer
- the handler of HTTP errors after unsuccessful GET request- Returns:
- result input stream
- Throws:
java.io.IOException
- if I/O error occursjava.net.URISyntaxException
- if specified url cannot be converted to valid URI- Since:
- 2019.1
-
fetchIssue
@NotNull public IssueData fetchIssue(@NotNull java.lang.String host, @NotNull java.lang.String id, @NotNull IssueFetcherAuthenticator authenticator) throws java.lang.Exception
backward compatibility- Specified by:
fetchIssue
in interfaceIssueFetcher
- Parameters:
host
- the server hostid
- issue idauthenticator
- authenticator- Returns:
- the issue corresponding to id
- Throws:
java.lang.Exception
- in case of I/O, parsing or any other error
-
handleHttpError
protected void handleHttpError(int code, @NotNull org.apache.commons.httpclient.methods.GetMethod get) throws java.io.IOException
Deprecated.method is deprecated because corresponding methodsfetchHttpFile(String, Credentials)
andgetHttpFile(String, IssueFetcherAuthenticator)
are deprecatedHandles the HTTP error after unsuccessful GET request.- Parameters:
code
- the response codeget
- get method- Throws:
java.io.IOException
- if I/O error occurs
-
getChildContent
@Nullable protected java.lang.String getChildContent(@NotNull org.jdom.Element element, @NotNull java.lang.String childName)
Returns the content text of the child element.- Parameters:
element
- the parent DOM elementchildName
- child name- Returns:
- the textual content directly held under the child, or null
-
getAttribute
@Nullable protected java.lang.String getAttribute(@NotNull org.jdom.Element element, @NotNull java.lang.String attributeName)
Returns the element's attribute value.- Parameters:
element
- the DOM elementattributeName
- attribute name- Returns:
- the textual value of the specified attribute, or null
-
isFeature
protected boolean isFeature(@Nullable java.lang.String field)
Returns whether the issue is a feature request (by a singlefield
, 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 java.lang.Object key, @NotNull AbstractIssueFetcher.FetchFunction function) throws java.lang.Exception
Returns a cached issue, or performs a slow fetch operation specified by afunction
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:
java.lang.Exception
- if the issue cannot be fetched
-
toString
@Nullable protected java.lang.String toString(@Nullable java.lang.Object obj)
An utility method to transform an object to string safely.- Parameters:
obj
- any object- Returns:
obj.toString()
, or null
-
hasInCache
public boolean hasInCache(@NotNull java.lang.String host, @NotNull java.lang.String id)
Description copied from interface:IssueFetcher
Returns whether the fetcher contains the issue corresponding toid
in its cache.- Specified by:
hasInCache
in interfaceIssueFetcher
- Parameters:
host
- server hostid
- issue id- Returns:
- true if the issue is in cache
- See Also:
IssueFetcher.hasInErrorCache(String, String)
-
hasInErrorCache
public boolean hasInErrorCache(@NotNull java.lang.String host, @NotNull java.lang.String id)
Description copied from interface:IssueFetcher
Returns whether the fetcher contains the error retrievingid
in its cache.- Specified by:
hasInErrorCache
in interfaceIssueFetcher
- Parameters:
host
- server hostid
- issue id- Returns:
- true if the issue is in error cache
- See Also:
IssueFetcher.hasInCache(String, String)
-
removeFromCache
public void removeFromCache(@NotNull java.lang.String host, @NotNull java.lang.String id)
Description copied from interface:IssueFetcher
Removes the cached entry corresponding to the issueid
.- Specified by:
removeFromCache
in interfaceIssueFetcher
- Parameters:
host
- server hostid
- issue id
-
getCache
@NotNull protected net.sf.ehcache.Cache getCache()
-
getErrorCache
@NotNull protected net.sf.ehcache.Cache getErrorCache()
-
getPossiblyExpiredData
public IssueData getPossiblyExpiredData(@NotNull java.lang.String host, @NotNull java.lang.String id)
Description copied from interface:IssueFetcher
Returns the cached issue data, no matter if it's expired or not.- Specified by:
getPossiblyExpiredData
in interfaceIssueFetcher
- Parameters:
host
- server hostid
- issue id- Returns:
- the cached issue data (if exists), or
null
-
getIssuesInBatch
@Nullable public java.util.Collection<IssueData> getIssuesInBatch(@NotNull java.lang.String host, @NotNull java.util.Collection<java.lang.String> ids, @Nullable org.apache.commons.httpclient.Credentials credentials)
Batch fetching.- Specified by:
getIssuesInBatch
in interfaceIssueFetcher
- Parameters:
host
- server hostids
- issue idscredentials
- basic auth credentials (null
means no credentials)- Returns:
- the cached issue data (if exists), or
null
-
fetchIssuesInBatch
@Nullable public java.util.Collection<IssueData> fetchIssuesInBatch(@NotNull java.lang.String host, @NotNull java.util.Collection<java.lang.String> ids, @NotNull IssueFetcherAuthenticator authenticator)
backward compatibility- Specified by:
fetchIssuesInBatch
in interfaceIssueFetcher
- Parameters:
host
- server hostids
- issue idsauthenticator
- authenticator- Returns:
- the cached issue data (if exists), or
null
-
fetchNonCachedIssues
@NotNull protected java.util.Collection<IssueData> fetchNonCachedIssues(@NotNull java.util.Collection<java.lang.String> ids, @NotNull AbstractIssueFetcher.CacheKeyFunction keyFunction, @NotNull AbstractIssueFetcher.BatchFetchFunction fetchFunction)
Performs a specified fetch functionfetchFunction
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 fetchkeyFunction
- the function used to get a cache key by issue idfetchFunction
- general fetch function- Returns:
- the collection of fetch data
-
defaultGetIssuesInBatch
@NotNull protected java.util.Collection<IssueData> defaultGetIssuesInBatch(@NotNull java.lang.String host, @NotNull java.util.Collection<java.lang.String> ids, @NotNull AbstractIssueFetcher.BatchFetchFunction function)
Method is identical tofetchNonCachedIssues(Collection, CacheKeyFunction, BatchFetchFunction)
, but uses a default key function (id -> url
).- Parameters:
host
- the remote issue tracker hostids
- the ids to fetch (can be immutable)function
- general fetch function- Returns:
- the collection of fetch data
-
fetchProjectIds
@Nullable public java.util.List<java.lang.String> fetchProjectIds(@NotNull java.lang.String host, @NotNull IssueFetcherAuthenticator authenticator)
Description copied from interface:IssueFetcher
Fetches all available project ids.- Specified by:
fetchProjectIds
in interfaceIssueFetcher
- Parameters:
host
- server hostauthenticator
- authenticator- Returns:
- see above
-
-