org.codelibs.fess.ds.atlassian.ConfluenceDataStore 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.io.ByteArrayInputStream;
import java.io.InputStream;
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.crawler.extractor.Extractor;
import org.codelibs.fess.crawler.extractor.impl.HtmlExtractor;
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.confluence.ConfluenceClient;
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 ConfluenceDataStore 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";
// scripts
protected static final String CONTENT = "content";
protected static final String CONTENT_TITLE = "title";
protected static final String CONTENT_BODY = "body";
protected static final String CONTENT_COMMENTS = "comments";
protected static final String CONTENT_LAST_MODIFIED = "last_modified";
protected static final String CONTENT_VIEW_URL = "view_url";
protected static final int CONTENT_LIMIT = 25;
protected Extractor extractor;
protected String getName() {
return "ConfluenceDataStore";
}
@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 confluenceHome = getConfluenceHome(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);
boolean basic = false;
if (confluenceHome.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 ConfluenceClient client =
basic ? new ConfluenceClient(AtlassianClient.builder().basicAuth(confluenceHome, userName, password).build())
: new ConfluenceClient(AtlassianClient.builder().oAuthToken(confluenceHome, accessToken -> {
accessToken.consumerKey = consumerKey;
accessToken.signer = AtlassianClientBuilder.getOAuthRsaSigner(privateKey);
accessToken.transport = new ApacheHttpTransport();
accessToken.verifier = verifier;
accessToken.temporaryToken = temporaryToken;
}).build());
extractor = new HtmlExtractor();
for (int start = 0;; start += CONTENT_LIMIT) {
// get contents
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy