org.codelibs.fess.ds.atlassian.JiraDataStore Maven / Gradle / Ivy
/*
* Copyright 2012-2018 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.ds.atlassian;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import com.google.api.client.http.apache.ApacheHttpTransport;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.crawler.exception.CrawlingAccessException;
import org.codelibs.fess.ds.AbstractDataStore;
import org.codelibs.fess.ds.atlassian.api.AtlassianClient;
import org.codelibs.fess.ds.atlassian.api.AtlassianClientBuilder;
import org.codelibs.fess.ds.atlassian.api.jira.JiraClient;
import org.codelibs.fess.ds.callback.IndexUpdateCallback;
import org.codelibs.fess.es.config.exentity.DataConfig;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JiraDataStore extends AbstractDataStore {
private static final Logger logger = LoggerFactory.getLogger(JiraDataStore.class);
// parameters
protected static final String HOME_PARAM = "home";
protected static final String CONSUMER_KEY_PARAM = "oauth.consumer_key";
protected static final String PRIVATE_KEY_PARAM = "oauth.private_key";
protected static final String SECRET_PARAM = "oauth.secret";
protected static final String ACCESS_TOKEN_PARAM = "oauth.access_token";
protected static final String USERNAME_PARAM = "basicauth.username";
protected static final String PASSWORD_PARAM = "basicauth.password";
protected static final String JQL_PARAM = "issue.jql";
// scripts
protected static final String ISSUE = "issue";
protected static final String ISSUE_SUMMARY = "summary";
protected static final String ISSUE_DESCRIPTION = "description";
protected static final String ISSUE_COMMENTS = "comments";
protected static final String ISSUE_LAST_MODIFIED = "last_modified";
protected static final String ISSUE_VIEW_URL = "view_url";
protected static final int ISSUE_MAX_RESULTS = 50;
protected String getName() {
return "JiraDataStore";
}
@Override
protected void storeData(final DataConfig dataConfig, final IndexUpdateCallback callback, final Map paramMap,
final Map scriptMap, final Map defaultDataMap) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String jiraHome = getJiraHome(paramMap);
final String userName = getUserName(paramMap);
final String password = getPassword(paramMap);
final String consumerKey = getConsumerKey(paramMap);
final String privateKey = getPrivateKey(paramMap);
final String verifier = getSecret(paramMap);
final String temporaryToken = getAccessToken(paramMap);
final long readInterval = getReadInterval(paramMap);
final String jql = getJql(paramMap);
boolean basic = false;
if (jiraHome.isEmpty()) {
logger.warn("parameter \"" + HOME_PARAM + "\" is required");
return;
} else if (!userName.isEmpty() && !password.isEmpty()) {
basic = true;
} else if (consumerKey.isEmpty() || privateKey.isEmpty() || verifier.isEmpty() || temporaryToken.isEmpty()) {
logger.warn("parameter \"" + USERNAME_PARAM + "\" and \"" + PASSWORD_PARAM + "\" or \"" + CONSUMER_KEY_PARAM + "\", \""
+ PRIVATE_KEY_PARAM + "\", \"" + SECRET_PARAM + "\" and \"" + ACCESS_TOKEN_PARAM + "\" are required");
return;
}
final JiraClient client = basic ? new JiraClient(AtlassianClient.builder().basicAuth(jiraHome, userName, password).build())
: new JiraClient(AtlassianClient.builder().oAuthToken(jiraHome, accessToken -> {
accessToken.consumerKey = consumerKey;
accessToken.signer = AtlassianClientBuilder.getOAuthRsaSigner(privateKey);
accessToken.transport = new ApacheHttpTransport();
accessToken.verifier = verifier;
accessToken.temporaryToken = temporaryToken;
}).build());
for (int startAt = 0;; startAt += ISSUE_MAX_RESULTS) {
// get issues
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy