use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.
the class AbstractDataStoreImpl method store.
@Override
public void store(final DataConfig config, final IndexUpdateCallback callback, final Map<String, String> initParamMap) {
final Map<String, String> configParamMap = config.getHandlerParameterMap();
final Map<String, String> configScriptMap = config.getHandlerScriptMap();
final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final Date documentExpires = crawlingInfoHelper.getDocumentExpires(config);
final FessConfig fessConfig = ComponentUtil.getFessConfig();
initParamMap.putAll(configParamMap);
final Map<String, String> paramMap = initParamMap;
// default values
final Map<String, Object> defaultDataMap = new HashMap<>();
// cid
final String configId = config.getConfigId();
if (configId != null) {
defaultDataMap.put(fessConfig.getIndexFieldConfigId(), configId);
}
// expires
if (documentExpires != null) {
defaultDataMap.put(fessConfig.getIndexFieldExpires(), documentExpires);
}
// segment
defaultDataMap.put(fessConfig.getIndexFieldSegment(), initParamMap.get(Constants.SESSION_ID));
// created
defaultDataMap.put(fessConfig.getIndexFieldCreated(), systemHelper.getCurrentTime());
// boost
defaultDataMap.put(fessConfig.getIndexFieldBoost(), config.getBoost().toString());
// label: labelType
final List<String> labelTypeList = new ArrayList<>();
for (final String labelType : config.getLabelTypeValues()) {
labelTypeList.add(labelType);
}
defaultDataMap.put(fessConfig.getIndexFieldLabel(), labelTypeList);
// role: roleType
final List<String> roleTypeList = new ArrayList<>();
stream(config.getPermissions()).of(stream -> stream.forEach(p -> roleTypeList.add(p)));
defaultDataMap.put(fessConfig.getIndexFieldRole(), roleTypeList);
// mimetype
defaultDataMap.put(fessConfig.getIndexFieldMimetype(), mimeType);
// title
// content
// cache
// digest
// host
// site
// url
// anchor
// content_length
// last_modified
// id
storeData(config, callback, paramMap, configScriptMap, defaultDataMap);
}
use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.
the class PingEsJob method execute.
public String execute() {
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final StringBuilder resultBuf = new StringBuilder();
final String notificationTo = fessConfig.getNotificationTo();
final PingResponse ping = fessEsClient.ping();
final int status = ping.getStatus();
if (systemHelper.isChangedClusterState(status)) {
if (StringUtil.isNotBlank(notificationTo)) {
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
EsStatusPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
postcard.addTo(notificationTo);
postcard.setHostname(systemHelper.getHostname());
postcard.setClustername(ping.getClusterName());
postcard.setClusterstatus(ping.getClusterStatus());
});
} catch (final Exception e) {
logger.warn("Failed to send a test mail.", e);
}
}
resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
} else {
if (status == 0) {
resultBuf.append(ping.getClusterName()).append(" is alive.");
} else {
resultBuf.append(ping.getClusterName()).append(" is not available.");
}
}
return resultBuf.toString();
}
use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.
the class LdapManagerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ComponentUtil.register(new SystemHelper(), "systemHelper");
}
use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.
the class LdapManager method updateSearchRoles.
protected void updateSearchRoles(final Set<String> roleSet, final String entryDn) {
final String name = getSearchRoleName(entryDn);
if (StringUtil.isBlank(name)) {
return;
}
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final boolean isRole = entryDn.toLowerCase(Locale.ROOT).indexOf("ou=role") != -1;
if (isRole) {
if (fessConfig.isLdapRoleSearchRoleEnabled()) {
roleSet.add(systemHelper.getSearchRoleByRole(normalizePermissionName(name)));
}
} else if (fessConfig.isLdapRoleSearchGroupEnabled()) {
roleSet.add(systemHelper.getSearchRoleByGroup(normalizePermissionName(name)));
}
}
use of org.codelibs.fess.helper.SystemHelper in project fess by codelibs.
the class LdapManager method getRoles.
public String[] getRoles(final LdapUser ldapUser, final String bindDn, final String accountFilter, final String groupFilter, final Consumer<String[]> lazyLoading) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final Set<String> roleSet = new HashSet<>();
if (fessConfig.isLdapRoleSearchUserEnabled()) {
roleSet.add(normalizePermissionName(systemHelper.getSearchRoleByUser(ldapUser.getName())));
}
// LDAP: cn=%s
// AD: (&(objectClass=user)(sAMAccountName=%s))
final String filter = String.format(accountFilter, ldapUser.getName());
if (logger.isDebugEnabled()) {
logger.debug("Account Filter: {}", filter);
}
final Set<String> subRoleSet = new HashSet<>();
search(bindDn, filter, new String[] { fessConfig.getLdapMemberofAttribute() }, () -> ldapUser.getEnvironment(), result -> {
processSearchRoles(result, entryDn -> {
updateSearchRoles(roleSet, entryDn);
if (StringUtil.isNotBlank(groupFilter)) {
subRoleSet.add(entryDn);
}
});
});
if (logger.isDebugEnabled()) {
logger.debug("role: {}", roleSet);
}
final String[] roles = roleSet.toArray(new String[roleSet.size()]);
if (!subRoleSet.isEmpty()) {
TimeoutManager.getInstance().addTimeoutTarget(() -> {
processSubRoles(ldapUser, bindDn, subRoleSet, groupFilter, roleSet);
if (logger.isDebugEnabled()) {
logger.debug("role(lazy loading): {}", roleSet);
}
lazyLoading.accept(roleSet.toArray(new String[roleSet.size()]));
}, 0, false);
}
return roles;
}
Aggregations