Merge branch '10.3.x' of github.com:codelibs/fess into 10.3.x

This commit is contained in:
Shinsuke Sugaya 2016-10-16 22:25:19 +09:00
commit ea3f8baa83
2 changed files with 13 additions and 37 deletions

View file

@ -17,7 +17,6 @@ package org.codelibs.fess.ds.impl;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -36,6 +35,8 @@ import org.codelibs.fess.ds.IndexUpdateCallback;
import org.codelibs.fess.es.config.exentity.CrawlingConfig;
import org.codelibs.fess.es.config.exentity.CrawlingConfigWrapper;
import org.codelibs.fess.es.config.exentity.DataConfig;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.util.ComponentUtil;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -84,6 +85,7 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
}
}
headerList.add(new RequestHeader("Authorization", "token " + authToken));
headerList.add(new RequestHeader("Accept", "application/vnd.github.v3.raw"));
paramMap.put(HcHttpClient.REQUERT_HEADERS_PROPERTY, headerList.toArray(new RequestHeader[headerList.size()]));
return paramMap;
}
@ -156,16 +158,12 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
if (!isPrivate) {
return Collections.singletonList("Rguest");
}
@SuppressWarnings("unchecked")
final List<String> collaboratorList = (List<String>) repository.get(COLLABORATORS_PARAM);
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
collaboratorList.add(owner);
return collaboratorList.stream().map(user -> "1" + user).collect(Collectors.toList());
}
private List<String> createLabelList(final String owner, final String name) {
final List<String> labelList = new ArrayList<String>();
Collections.addAll(labelList, "GitBucket", owner + "/" + name);
return labelList;
return collaboratorList.stream().map(user -> systemHelper.getSearchRoleByUser(user)).collect(Collectors.toList());
}
private List<Object> parseList(final InputStream is) { // TODO This function should be moved to CurlResponse
@ -188,12 +186,12 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
}
final Map<String, Object> dataMap = new HashMap<>();
dataMap.putAll(defaultDataMap);
// FIXME Use DocumentHelper
// dataMap.putAll(ComponentUtil.getDocumentHelper().processRequest(crawlingConfig, paramMap.get("crawlingInfoId"), url));
dataMap.putAll(processContentRequest(authToken, apiUrl, viewUrl));
dataMap.putAll(ComponentUtil.getDocumentHelper().processRequest(crawlingConfig, paramMap.get("crawlingInfoId"),
apiUrl + "?large_file=true"));
dataMap.put("title", FilenameUtils.getName(apiUrl));
dataMap.put("url", viewUrl);
dataMap.put("role", roleList);
dataMap.put("label", createLabelList(owner, name));
// TODO scriptMap
@ -202,31 +200,6 @@ public class GitBucketDataStoreImpl extends AbstractDataStoreImpl {
return;
}
private Map<String, String> processContentRequest(final String authToken, final String apiUrl, final String viewUrl) { // FIXME should be replaced by DocumentHelper
final Map<String, String> dataMap = new HashMap<>();
try (CurlResponse curlResponse = Curl.get(apiUrl).header("Authorization", "token " + authToken).execute()) {
final Map<String, Object> map = curlResponse.getContentAsMap();
String content = StringUtil.EMPTY;
;
if (map.containsKey("content")) {
content = (String) map.get("content");
}
if (map.containsKey("encoding") && map.get("encoding").equals("base64")) {
content = new String(Base64.getDecoder().decode(content));
}
dataMap.put("title", FilenameUtils.getName(apiUrl));
dataMap.put("url", viewUrl);
dataMap.put("content", content);
return dataMap;
} catch (final Exception e) {
logger.warn("Failed to get " + apiUrl, e);
return Collections.emptyMap();
}
}
protected void collectFileNames(final String rootURL, final String authToken, final String owner, final String name, final String path,
final int depth, final long readInterval, Consumer<String> consumer) {

View file

@ -16,6 +16,7 @@ ${packaging.scripts.header}
# Sets the default values for fess variables used in this script
FESS_USER="${packaging.fess.user}"
FESS_GROUP="${packaging.fess.group}"
FESS_USER_HOME="${packaging.fess.var.dir}"
# Source the default env file
FESS_ENV_FILE="${packaging.env.file}"
@ -44,6 +45,7 @@ case "$1" in
--ingroup "$FESS_GROUP" \
--disabled-password \
--shell /bin/false \
-d "$FESS_USER_HOME" \
"$FESS_USER"
echo " OK"
fi
@ -69,6 +71,7 @@ case "$1" in
--gid "$FESS_GROUP" \
--shell /sbin/nologin \
--comment "fess user" \
-d "$FESS_USER_HOME" \
"$FESS_USER"
echo " OK"
fi