code cleanup
This commit is contained in:
parent
33c67b3a2b
commit
492bfec26e
16 changed files with 67 additions and 61 deletions
|
@ -96,7 +96,7 @@ public abstract class BaseApiManager implements WebApiManager {
|
|||
buf.append("; charset=");
|
||||
final String enc;
|
||||
if (encoding == null) {
|
||||
enc = LaRequestUtil.getOptionalRequest().map(req -> req.getCharacterEncoding()).orElse(Constants.UTF_8);
|
||||
enc = LaRequestUtil.getOptionalRequest().map(HttpServletRequest::getCharacterEncoding).orElse(Constants.UTF_8);
|
||||
} else {
|
||||
enc = encoding;
|
||||
}
|
||||
|
|
|
@ -452,7 +452,7 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
RenderDataUtil.register(data, "name", name);
|
||||
final Map<String, String> tags = new HashMap<>();
|
||||
getObjectTags(getObjectName(path, name)).entrySet().forEach(e -> {
|
||||
int index = tags.size() / 2 + 1;
|
||||
final int index = tags.size() / 2 + 1;
|
||||
tags.put("name" + index, e.getKey());
|
||||
tags.put("value" + index, e.getValue());
|
||||
});
|
||||
|
|
|
@ -114,7 +114,7 @@ public class SearchForm extends SearchRequestParams {
|
|||
|
||||
@Override
|
||||
public GeoInfo getGeoInfo() {
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> createGeoInfo(req))
|
||||
return LaRequestUtil.getOptionalRequest().map(this::createGeoInfo)
|
||||
.orElseGet(() -> ComponentUtil.getQueryHelper().getDefaultGeoInfo());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.codelibs.fess.app.web.base.login;
|
|||
import static org.codelibs.core.stream.StreamUtil.split;
|
||||
import static org.codelibs.core.stream.StreamUtil.stream;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.entity.FessUser;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
|
|
|
@ -95,7 +95,7 @@ public class FileListIndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
@Override
|
||||
public void store(final DataStoreParams paramMap, final Map<String, Object> dataMap) {
|
||||
final CrawlerStatsHelper crawlerStatsHelper = ComponentUtil.getCrawlerStatsHelper();
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof StatsKeyObject sko ? sko : null;
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof final StatsKeyObject sko ? sko : null;
|
||||
if (keyObj != null) {
|
||||
crawlerStatsHelper.runOnThread(keyObj);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class FileListIndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
return;
|
||||
}
|
||||
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof StatsKeyObject sko ? sko : null;
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof final StatsKeyObject sko ? sko : null;
|
||||
|
||||
final long maxAccessCount = getMaxAccessCount(paramMap, dataMap);
|
||||
long counter = 0;
|
||||
|
@ -206,7 +206,7 @@ public class FileListIndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
final CrawlerClient client) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final CrawlerStatsHelper crawlerStatsHelper = ComponentUtil.getCrawlerStatsHelper();
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof StatsKeyObject sko ? sko : null;
|
||||
final StatsKeyObject keyObj = paramMap.get(Constants.CRAWLER_STATS_KEY) instanceof final StatsKeyObject sko ? sko : null;
|
||||
try (final ResponseData responseData = client.execute(RequestDataBuilder.newRequestData().get().url(url).build())) {
|
||||
if (responseData.getRedirectLocation() != null) {
|
||||
return responseData.getRedirectLocation();
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DataStoreParams {
|
|||
}
|
||||
|
||||
public String getAsString(final String key) {
|
||||
if (params.get(key) instanceof String strValue) {
|
||||
if (params.get(key) instanceof final String strValue) {
|
||||
return strValue;
|
||||
}
|
||||
final Object value = params.get(key);
|
||||
|
|
|
@ -32,7 +32,7 @@ public class CrawlerEngineClient extends FesenClient {
|
|||
protected Client createClient() {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final String[] hosts =
|
||||
split(address, ",").get(stream -> stream.map(s -> s.trim()).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
split(address, ",").get(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
final Builder builder = Settings.builder().putList("http.hosts", hosts).put("processors", fessConfig.getCrawlerHttpProcessors())
|
||||
.put("http.heartbeat_interval", fessConfig.getElasticsearchHeartbeatIntervalAsInteger().longValue());
|
||||
final String username = fessConfig.getElasticsearchUsername();
|
||||
|
|
|
@ -349,7 +349,7 @@ public class SearchEngineClient implements Client {
|
|||
|
||||
protected Client createHttpClient(final FessConfig fessConfig, final String host) {
|
||||
final String[] hosts =
|
||||
split(host, ",").get(stream -> stream.map(s -> s.trim()).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
split(host, ",").get(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
final Builder builder = Settings.builder().putList("http.hosts", hosts).put("processors", fessConfig.availableProcessors())
|
||||
.put("http.heartbeat_interval", fessConfig.getElasticsearchHeartbeatIntervalAsInteger().longValue());
|
||||
final String username = fessConfig.getElasticsearchUsername();
|
||||
|
|
|
@ -43,41 +43,41 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void processStartCrawling(Object... objs) {
|
||||
protected void processStartCrawling(final Object... objs) {
|
||||
super.processStartCrawling(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().begin(urlQueue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processCleanupCrawling(Object... objs) {
|
||||
protected void processCleanupCrawling(final Object... objs) {
|
||||
super.processCleanupCrawling(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().done(urlQueue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processProcessChildUrlByException(Object... objs) {
|
||||
protected void processProcessChildUrlByException(final Object... objs) {
|
||||
super.processProcessChildUrlByException(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().record(urlQueue, StatsAction.CHILD_URL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processProcessChildUrlsByException(Object... objs) {
|
||||
protected void processProcessChildUrlsByException(final Object... objs) {
|
||||
super.processProcessChildUrlsByException(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().record(urlQueue, StatsAction.CHILD_URLS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processFinishedCrawling(Object... objs) {
|
||||
protected void processFinishedCrawling(final Object... objs) {
|
||||
super.processFinishedCrawling(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().record(urlQueue, StatsAction.FINISHED);
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
}
|
||||
|
||||
super.processCrawlingAccessException(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().record(urlQueue, StatsAction.ACCESS_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class CrawlerLogHelper extends LogHelperImpl {
|
|||
}
|
||||
|
||||
super.processCrawlingException(objs);
|
||||
if (objs.length > 1 && objs[1] instanceof UrlQueue<?> urlQueue) {
|
||||
if (objs.length > 1 && objs[1] instanceof final UrlQueue<?> urlQueue) {
|
||||
ComponentUtil.getCrawlerStatsHelper().record(urlQueue, StatsAction.ACCESS_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class CrawlerStatsHelper {
|
|||
statsCache = CacheBuilder.newBuilder().maximumSize(maxCacheSize).expireAfterWrite(cacheExpireAfterWrite, TimeUnit.MILLISECONDS)
|
||||
.build(new CacheLoader<String, StatsObject>() {
|
||||
@Override
|
||||
public StatsObject load(String key) {
|
||||
public StatsObject load(final String key) {
|
||||
return new StatsObject();
|
||||
}
|
||||
});
|
||||
|
@ -74,17 +74,17 @@ public class CrawlerStatsHelper {
|
|||
final StatsObject data = e.getValue();
|
||||
final Long begin = data.remove(BEGIN_KEY);
|
||||
if (begin != null) {
|
||||
printStats(e.getKey(), data, begin.longValue(), false);
|
||||
printStats(e.getKey(), data, begin, false);
|
||||
}
|
||||
});
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public void begin(final Object keyObj) {
|
||||
getCacheKey(keyObj).ifPresent(key -> {
|
||||
try {
|
||||
statsCache.get(key);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
|
||||
buf.append('\t').append("action:begin");
|
||||
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
|
||||
|
@ -104,7 +104,7 @@ public class CrawlerStatsHelper {
|
|||
if (data != null) {
|
||||
data.put(escapeValue(action), System.currentTimeMillis());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
|
||||
buf.append('\t').append("action:record");
|
||||
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
|
||||
|
@ -121,10 +121,10 @@ public class CrawlerStatsHelper {
|
|||
statsCache.invalidate(key);
|
||||
final Long begin = data.remove(BEGIN_KEY);
|
||||
if (begin != null) {
|
||||
printStats(keyObj, data, begin.longValue(), true);
|
||||
printStats(keyObj, data, begin, true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
|
||||
buf.append('\t').append("action:done");
|
||||
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
|
||||
|
@ -140,7 +140,7 @@ public class CrawlerStatsHelper {
|
|||
if (data != null) {
|
||||
statsCache.invalidate(key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
|
||||
buf.append('\t').append("action:done");
|
||||
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
|
||||
|
@ -166,7 +166,7 @@ public class CrawlerStatsHelper {
|
|||
if (data != null) {
|
||||
data.increment();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
final StringBuilder buf = createStringBuffer(keyObj, System.currentTimeMillis());
|
||||
buf.append('\t').append("action:record");
|
||||
buf.append('\t').append("error:").append(escapeValue(e.getLocalizedMessage()).replaceAll("\\s", " "));
|
||||
|
@ -184,32 +184,34 @@ public class CrawlerStatsHelper {
|
|||
}
|
||||
|
||||
protected String getUrl(final Object keyObj) {
|
||||
if (keyObj instanceof UrlQueue<?> urlQueue) {
|
||||
if (keyObj instanceof final UrlQueue<?> urlQueue) {
|
||||
return escapeValue(urlQueue.getUrl());
|
||||
} else if (keyObj instanceof StatsKeyObject statsKey) {
|
||||
}
|
||||
if (keyObj instanceof final StatsKeyObject statsKey) {
|
||||
return escapeValue(statsKey.getUrl());
|
||||
} else if (keyObj instanceof String key) {
|
||||
} else if (keyObj instanceof final String key) {
|
||||
return escapeValue(key);
|
||||
} else if (keyObj instanceof Number key) {
|
||||
} else if (keyObj instanceof final Number key) {
|
||||
return key.toString();
|
||||
}
|
||||
return "-";
|
||||
}
|
||||
|
||||
protected OptionalThing<String> getCacheKey(final Object keyObj) {
|
||||
if (keyObj instanceof UrlQueue<?> urlQueue) {
|
||||
if (keyObj instanceof final UrlQueue<?> urlQueue) {
|
||||
return OptionalThing.of(urlQueue.getId().toString());
|
||||
} else if (keyObj instanceof StatsKeyObject statsKey) {
|
||||
}
|
||||
if (keyObj instanceof final StatsKeyObject statsKey) {
|
||||
return OptionalThing.of(statsKey.getId());
|
||||
} else if (keyObj instanceof String key) {
|
||||
} else if (keyObj instanceof final String key) {
|
||||
return OptionalThing.of(key);
|
||||
} else if (keyObj instanceof Number key) {
|
||||
} else if (keyObj instanceof final Number key) {
|
||||
return OptionalThing.of(key.toString());
|
||||
}
|
||||
return OptionalThing.empty();
|
||||
}
|
||||
|
||||
protected String escapeValue(String action) {
|
||||
protected String escapeValue(final String action) {
|
||||
return action.replace('\t', ' ');
|
||||
}
|
||||
|
||||
|
@ -217,15 +219,15 @@ public class CrawlerStatsHelper {
|
|||
statsLogger.info(buf.toString());
|
||||
}
|
||||
|
||||
public void setLoggerName(String loggerName) {
|
||||
public void setLoggerName(final String loggerName) {
|
||||
this.loggerName = loggerName;
|
||||
}
|
||||
|
||||
public void setMaxCacheSize(long maxCacheSize) {
|
||||
public void setMaxCacheSize(final long maxCacheSize) {
|
||||
this.maxCacheSize = maxCacheSize;
|
||||
}
|
||||
|
||||
public void setCacheExpireAfterWrite(long cacheExpireAfterWrite) {
|
||||
public void setCacheExpireAfterWrite(final long cacheExpireAfterWrite) {
|
||||
this.cacheExpireAfterWrite = cacheExpireAfterWrite;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class CurlHelper {
|
|||
}
|
||||
|
||||
final String[] hosts = split(ResourceUtil.getFesenHttpUrl(), ",")
|
||||
.get(stream -> stream.map(s -> s.trim()).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
.get(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).toArray(n -> new String[n]));
|
||||
nodeManager = new NodeManager(hosts, node -> request(new CurlRequest(Method.GET, node.getUrl("/"))));
|
||||
nodeManager.setHeartbeatInterval(fessConfig.getElasticsearchHeartbeatIntervalAsInteger().longValue());
|
||||
}
|
||||
|
|
|
@ -208,15 +208,14 @@ public class IndexingHelper {
|
|||
return entityList.size() <= (exceeded ? maxSearchDocSize : numFound);
|
||||
});
|
||||
return entityList;
|
||||
} else {
|
||||
return searchEngineClient.getDocumentList(fessConfig.getIndexDocumentUpdateIndex(), requestBuilder -> {
|
||||
requestBuilder.setQuery(queryBuilder).setSize((int) numFound);
|
||||
if (fields != null) {
|
||||
requestBuilder.setFetchSource(fields, null);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return searchEngineClient.getDocumentList(fessConfig.getIndexDocumentUpdateIndex(), requestBuilder -> {
|
||||
requestBuilder.setQuery(queryBuilder).setSize((int) numFound);
|
||||
if (fields != null) {
|
||||
requestBuilder.setFetchSource(fields, null);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public long deleteBySessionId(final String sessionId) {
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
package org.codelibs.fess.sso.oic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -197,11 +201,13 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
|
|||
attributes.put("exp", jsonParser.getText());
|
||||
break;
|
||||
case "groups":
|
||||
List<String> list = new ArrayList<String>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
|
||||
final String group = jsonParser.getText();
|
||||
list.add(group);
|
||||
logger.debug(group);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("groups: {}", list);
|
||||
}
|
||||
attributes.put("groups", list.toArray(new String[list.size()]));
|
||||
break;
|
||||
|
|
|
@ -339,7 +339,7 @@ public class FessFunctions {
|
|||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
LaRequestUtil.getOptionalRequest().map(req -> req.getContextPath()).filter(s -> s.length() > 1).ifPresent(s -> sb.append(s));
|
||||
LaRequestUtil.getOptionalRequest().map(HttpServletRequest::getContextPath).filter(s -> s.length() > 1).ifPresent(s -> sb.append(s));
|
||||
sb.append(input);
|
||||
if (input.indexOf('?') == -1) {
|
||||
try {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class HotThreadMonitorTarget extends MonitorTarget {
|
|||
.setThreads(threads).setTimeout(timeout).setType(type).execute().actionGet(timeout);
|
||||
append(buf, "cluster_name", () -> response.getClusterName().value()).append(',');
|
||||
final String hotThreads = response.getNodesMap().entrySet().stream().map(e -> {
|
||||
StringBuilder tempBuf = new StringBuilder();
|
||||
final StringBuilder tempBuf = new StringBuilder();
|
||||
append(tempBuf, StringEscapeUtils.escapeJson(e.getKey()), () -> StringEscapeUtils.escapeJson(e.getValue().getHotThreads()));
|
||||
return tempBuf.toString();
|
||||
}).collect(Collectors.joining(","));
|
||||
|
|
|
@ -65,7 +65,7 @@ public abstract class MonitorTarget implements TimeoutTarget {
|
|||
exception.printStackTrace(writer);
|
||||
writer.flush();
|
||||
append(buf, "exception", () -> StringEscapeUtils.escapeJson(new String(baos.toByteArray(), Constants.CHARSET_UTF_8)));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
append(buf, "exception", () -> StringEscapeUtils.escapeJson(e.getMessage()));
|
||||
}
|
||||
return buf;
|
||||
|
|
Loading…
Add table
Reference in a new issue