Search in sources :

Example 1 with SystemHelper

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);
}
Also used : DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) Date(java.util.Date) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IndexUpdateCallback(org.codelibs.fess.ds.IndexUpdateCallback) ArrayList(java.util.ArrayList) DataStore(org.codelibs.fess.ds.DataStore) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) SystemHelper(org.codelibs.fess.helper.SystemHelper) GroovyUtil(org.codelibs.fess.util.GroovyUtil) Map(java.util.Map) SystemHelper(org.codelibs.fess.helper.SystemHelper) HashMap(java.util.HashMap) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Date(java.util.Date)

Example 2 with SystemHelper

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();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 3 with SystemHelper

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");
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper)

Example 4 with 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)));
    }
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper)

Example 5 with SystemHelper

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;
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) HashSet(java.util.HashSet)

Aggregations

SystemHelper (org.codelibs.fess.helper.SystemHelper)42 StringUtil (org.codelibs.core.lang.StringUtil)17 ComponentUtil (org.codelibs.fess.util.ComponentUtil)17 Constants (org.codelibs.fess.Constants)15 ArrayList (java.util.ArrayList)14 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)14 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)13 HashMap (java.util.HashMap)11 List (java.util.List)10 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 OptionalThing (org.dbflute.optional.OptionalThing)8 Stream (java.util.stream.Stream)7 Resource (javax.annotation.Resource)7 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)7 Secured (org.codelibs.fess.annotation.Secured)7 CrudMode (org.codelibs.fess.app.web.CrudMode)7 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)7 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)7 OptionalEntity (org.dbflute.optional.OptionalEntity)7