Search in sources :

Example 6 with StringUtils.join

use of org.apache.commons.lang3.StringUtils.join in project swift by luastar.

the class ExcelUtils method readXlsSheet.

/**
 * 从sheet中读取数据
 *
 * @param workbook
 * @param sheetConfig
 * @throws Exception
 */
private static void readXlsSheet(HSSFWorkbook workbook, ImportSheet sheetConfig) throws Exception {
    if (workbook == null || sheetConfig == null || sheetConfig.getDataClass() == null || sheetConfig.getColumnList() == null) {
        throw new IllegalArgumentException("excel导入参数错误!");
    }
    // 公式执行器
    CreationHelper createHelper = workbook.getCreationHelper();
    FormulaEvaluator formulaEvaluator = createHelper.createFormulaEvaluator();
    int sheetNum = workbook.getNumberOfSheets();
    if (sheetConfig.getIndex() >= sheetNum) {
        String msg = StrUtils.formatString("sheet【{0}】不存在", sheetConfig.getIndex() + 1);
        throw new RuntimeException(msg);
    }
    HSSFSheet sheet = workbook.getSheetAt(sheetConfig.getIndex());
    int firstRowNum = sheet.getFirstRowNum();
    int lastRowNum = sheet.getLastRowNum();
    if (lastRowNum <= 1) {
        String msg = StrUtils.formatString("sheet【{0}】数据为空", sheet.getSheetName());
        throw new RuntimeException(msg);
    }
    // 通过标题找对应的列
    List<String> columnNotFound = Lists.newArrayList();
    List<ImportColumn> columnList = sheetConfig.getColumnList();
    int columnNum = columnList.size();
    HSSFRow titleRow = sheet.getRow(firstRowNum);
    for (int i = 0; i < columnNum; i++) {
        ImportColumn column = columnList.get(i);
        for (int j = 0; j < columnNum; j++) {
            HSSFCell cell = titleRow.getCell(j);
            if (cell != null && column.getTitle().equals(cell.getStringCellValue())) {
                column.setColumnIndex(j);
            }
        }
        if (column.getColumnIndex() == null) {
            columnNotFound.add(column.getTitle());
        }
    }
    // 找不到对应的列
    if (columnNotFound.size() > 0) {
        String msg = StrUtils.formatString("列【{0}】不存在", StringUtils.join(columnNotFound, ","));
        throw new RuntimeException(msg);
    }
    // 获取数据
    List<ExcelData> dataList = Lists.newArrayList();
    for (int i = firstRowNum + 1; i <= lastRowNum; i++) {
        HSSFRow row = sheet.getRow(i);
        Object data = sheetConfig.getDataClass().newInstance();
        if (row == null) {
            ExcelData excelData = new ExcelData(i, data);
            excelData.setCheckMsg("获取行数据为空");
            dataList.add(excelData);
            continue;
        }
        // 行不为空
        List<String> setPropList = Lists.newArrayList();
        for (int j = 0; j < columnNum; j++) {
            ImportColumn column = columnList.get(j);
            HSSFCell cell = row.getCell(column.getColumnIndex());
            setPropList.add(ExcelUtils.setProperty(column, cell, data, formulaEvaluator));
        }
        ExcelData excelData = new ExcelData(row.getRowNum(), data);
        // 赋值失败的列
        List setErrList = setPropList.stream().filter(rs -> rs != null).collect(Collectors.toList());
        if (!setErrList.isEmpty()) {
            String msg = StrUtils.formatString("获取属性失败:{0}", StringUtils.join(setErrList, ","));
            excelData.setCheckMsg(msg);
        }
        dataList.add(excelData);
    }
    sheetConfig.setDataList(dataList);
}
Also used : CollectionUtils(com.luastar.swift.base.utils.CollectionUtils) PropertyUtils(org.apache.commons.beanutils.PropertyUtils) Logger(org.slf4j.Logger) org.apache.poi.hssf.usermodel(org.apache.poi.hssf.usermodel) ImmutableMap(com.google.common.collect.ImmutableMap) ObjUtils(com.luastar.swift.base.utils.ObjUtils) Date(java.util.Date) StrUtils(com.luastar.swift.base.utils.StrUtils) LoggerFactory(org.slf4j.LoggerFactory) MethodUtils(org.apache.commons.lang3.reflect.MethodUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) org.apache.poi.ss.usermodel(org.apache.poi.ss.usermodel) org.apache.poi.xssf.usermodel(org.apache.poi.xssf.usermodel) BigDecimal(java.math.BigDecimal) List(java.util.List) JSON(com.alibaba.fastjson.JSON) Lists(com.google.common.collect.Lists) java.io(java.io) DateUtils(com.luastar.swift.base.utils.DateUtils) Map(java.util.Map) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) List(java.util.List) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList)

Example 7 with StringUtils.join

use of org.apache.commons.lang3.StringUtils.join in project fess by codelibs.

the class SearchLogHelper method addSearchLog.

public void addSearchLog(final SearchRequestParams params, final LocalDateTime requestedTime, final String queryId, final String query, final int pageStart, final int pageSize, final QueryResponseList queryResponseList) {
    final RoleQueryHelper roleQueryHelper = ComponentUtil.getRoleQueryHelper();
    final UserInfoHelper userInfoHelper = ComponentUtil.getUserInfoHelper();
    final SearchLog searchLog = new SearchLog();
    if (ComponentUtil.getFessConfig().isUserInfo()) {
        final String userCode = userInfoHelper.getUserCode();
        if (userCode != null) {
            searchLog.setUserSessionId(userCode);
        }
    }
    searchLog.setRoles(roleQueryHelper.build(params.getType()).stream().toArray(n -> new String[n]));
    searchLog.setQueryId(queryId);
    searchLog.setHitCount(queryResponseList.getAllRecordCount());
    searchLog.setResponseTime(queryResponseList.getExecTime());
    searchLog.setQueryTime(queryResponseList.getQueryTime());
    searchLog.setSearchWord(StringUtils.abbreviate(query, 1000));
    searchLog.setSearchQuery(StringUtils.abbreviate(queryResponseList.getSearchQuery(), 1000));
    searchLog.setRequestedAt(requestedTime);
    searchLog.setQueryOffset(pageStart);
    searchLog.setQueryPageSize(pageSize);
    ComponentUtil.getRequestManager().findUserBean(FessUserBean.class).ifPresent(user -> {
        searchLog.setUser(user.getUserId());
    });
    final HttpServletRequest request = LaRequestUtil.getRequest();
    searchLog.setClientIp(StringUtils.abbreviate(ComponentUtil.getViewHelper().getClientIp(request), 100));
    searchLog.setReferer(StringUtils.abbreviate(request.getHeader("referer"), 1000));
    searchLog.setUserAgent(StringUtils.abbreviate(request.getHeader("user-agent"), 255));
    final Object accessType = request.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
    if (Constants.SEARCH_LOG_ACCESS_TYPE_JSON.equals(accessType)) {
        searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_JSON);
    } else if (Constants.SEARCH_LOG_ACCESS_TYPE_XML.equals(accessType)) {
        searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_XML);
    } else if (Constants.SEARCH_LOG_ACCESS_TYPE_OTHER.equals(accessType)) {
        searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_OTHER);
    } else {
        searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_WEB);
    }
    final Object languages = request.getAttribute(Constants.REQUEST_LANGUAGES);
    if (languages != null) {
        searchLog.setLanguages(StringUtils.join((String[]) languages, ","));
    } else {
        searchLog.setLanguages("");
    }
    @SuppressWarnings("unchecked") final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) request.getAttribute(Constants.FIELD_LOGS);
    if (fieldLogMap != null) {
        for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
            for (final String value : logEntry.getValue()) {
                searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, 1000));
            }
        }
    }
    searchLogQueue.add(searchLog);
}
Also used : QueryResponseList(org.codelibs.fess.util.QueryResponseList) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) OptionalThing(org.dbflute.optional.OptionalThing) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) StringUtils(org.apache.commons.lang3.StringUtils) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SearchRequestParams(org.codelibs.fess.entity.SearchRequestParams) Map(java.util.Map) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog) UserInfo(org.codelibs.fess.es.log.exentity.UserInfo) Script(org.elasticsearch.script.Script) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) StringUtil(org.codelibs.core.lang.StringUtil) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) SearchService(org.codelibs.fess.app.service.SearchService) List(java.util.List) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) QueryResponseList(org.codelibs.fess.util.QueryResponseList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) Map(java.util.Map)

Example 8 with StringUtils.join

use of org.apache.commons.lang3.StringUtils.join in project knime-core by knime.

the class TableStoreFormatRegistry method createInstance.

private static TableStoreFormatRegistry createInstance() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    List<TableStoreFormat> formatList = Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).map(cfe -> readFormat(cfe)).filter(f -> f != null).sorted(Comparator.comparing(f -> f.getClass().getSimpleName(), (a, b) -> {
        // sort formats so that the "KNIME standard" format comes first.
        if (Objects.equals(a, b)) {
            return 0;
        } else if (DefaultTableStoreFormat.class.getName().equals(a)) {
            return -1;
        } else if (DefaultTableStoreFormat.class.getName().equals(b)) {
            return +1;
        } else {
            return a.compareTo(b);
        }
    })).collect(Collectors.toList());
    boolean hasFallback = formatList.stream().anyMatch(f -> f.getClass().equals(DefaultTableStoreFormat.class));
    CheckUtils.checkState(hasFallback, "No fallback table format registered, expected '%s' but not present in '%s'", DefaultTableStoreFormat.class.getName(), StringUtils.join(formatList.stream().map(f -> f.getClass().getName()).iterator(), ", "));
    return new TableStoreFormatRegistry(formatList);
}
Also used : KNIMEConstants(org.knime.core.node.KNIMEConstants) DataTableSpec(org.knime.core.data.DataTableSpec) CoreException(org.eclipse.core.runtime.CoreException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) Objects(java.util.Objects) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) List(java.util.List) Stream(java.util.stream.Stream) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Comparator(java.util.Comparator) CheckUtils(org.knime.core.node.util.CheckUtils) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 9 with StringUtils.join

use of org.apache.commons.lang3.StringUtils.join in project elasticsearch-maven-plugin by alexcojocaru.

the class ForkedInstance method getStartScriptCommand.

protected CommandLine getStartScriptCommand() {
    CommandLine cmd = ProcessUtil.buildCommandLine("bin/elasticsearch");
    // Write the PID to a file, to be used to shut down the instance.
    // The option ("-p") and the pid file name ("pid") must be provides as separate argument
    // otherwise, if they are provided as one ("-p pid"), with the way the Java command line
    // arguments are parsed, the actual file name will be ' pid' (with a leading space),
    // which creates issues on Windows.
    cmd.addArgument("-p", false);
    cmd.addArgument("pid", false);
    cmd.addArgument("-Ecluster.name=" + config.getClusterConfiguration().getClusterName(), false);
    cmd.addArgument("-Ehttp.port=" + config.getHttpPort(), false);
    cmd.addArgument("-Etransport.tcp.port=" + config.getTransportPort(), false);
    // If there are multiple nodes, I need to tell each about the other,
    // in order to form a cluster.
    List<String> hosts = config.getClusterConfiguration().getInstanceConfigurationList().stream().filter(config -> config != this.config).map(config -> "127.0.0.1:" + config.getTransportPort()).collect(Collectors.toList());
    if (hosts.isEmpty() == false) {
        String hostsString = StringUtils.join(hosts, ',');
        cmd.addArgument("-Ediscovery.zen.ping.unicast.hosts=" + hostsString, false);
    }
    if (config.getClusterConfiguration().isAutoCreateIndex() == false) {
        cmd.addArgument("-Eaction.auto_create_index=false", false);
    }
    cmd.addArgument("-Ehttp.cors.enabled=true");
    if (config.getSettings() != null) {
        config.getSettings().forEach((key, value) -> cmd.addArgument("-E" + key + '=' + value));
    }
    return cmd;
}
Also used : List(java.util.List) InstanceSetupSequence(com.github.alexcojocaru.mojo.elasticsearch.v2.step.InstanceSetupSequence) InstanceStepSequence(com.github.alexcojocaru.mojo.elasticsearch.v2.step.InstanceStepSequence) FilesystemUtil(com.github.alexcojocaru.mojo.elasticsearch.v2.util.FilesystemUtil) Collector(java.util.stream.Collector) CommandLine(org.apache.commons.exec.CommandLine) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ProcessUtil(com.github.alexcojocaru.mojo.elasticsearch.v2.util.ProcessUtil) File(java.io.File) CommandLine(org.apache.commons.exec.CommandLine)

Example 10 with StringUtils.join

use of org.apache.commons.lang3.StringUtils.join in project eol-globi-data by jhpoelen.

the class StudyImporterForHurlbert method importInteraction.

protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
    try {
        Taxon predatorTaxon = new TaxonImpl(predatorName);
        Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
        setBasisOfRecordAsLiterature(predatorSpecimen);
        Taxon preyTaxon = new TaxonImpl(preyTaxonName);
        String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
        if (NumberUtils.isDigits(preyNameId)) {
            preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
        }
        Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
        setBasisOfRecordAsLiterature(preySpecimen);
        String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
        if (StringUtils.isNotBlank(preyStage)) {
            Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
            preySpecimen.setLifeStage(lifeStage);
        }
        String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
        if (StringUtils.isNotBlank(preyPart)) {
            Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
            preySpecimen.setBodyPart(term);
        }
        Date date = addCollectionDate(record, study);
        nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
        nodeFactory.setUnixEpochProperty(preySpecimen, date);
        LocationImpl location = new LocationImpl(null, null, null, null);
        String longitude = columnValueOrNull(record, "Longitude_dd");
        String latitude = columnValueOrNull(record, "Latitude_dd");
        if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
            try {
                LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
                String altitude = columnValueOrNull(record, "Altitude_mean_m");
                Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
                location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
            } catch (InvalidLocationException e) {
                getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
            }
        }
        String locationRegion = columnValueOrNull(record, "Location_Region");
        String locationSpecific = columnValueOrNull(record, "Location_Specific");
        location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
        Location locationNode = nodeFactory.getOrCreateLocation(location);
        String habitat_type = columnValueOrNull(record, "Habitat_type");
        List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
        nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
        preySpecimen.caughtIn(locationNode);
        predatorSpecimen.caughtIn(locationNode);
        predatorSpecimen.ate(preySpecimen);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
    }
}
Also used : TsvParser(com.univocity.parsers.tsv.TsvParser) DateUtil(org.eol.globi.util.DateUtil) StringUtils(org.apache.commons.lang.StringUtils) CitationUtil(org.globalbioticinteractions.dataset.CitationUtil) Arrays(java.util.Arrays) Record(com.univocity.parsers.common.record.Record) Term(org.eol.globi.domain.Term) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) Map(java.util.Map) LatLng(org.eol.globi.geo.LatLng) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) InvalidLocationException(org.eol.globi.util.InvalidLocationException) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) List(java.util.List) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Study(org.eol.globi.domain.Study) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) InvalidLocationException(org.eol.globi.util.InvalidLocationException) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Specimen(org.eol.globi.domain.Specimen) StringUtils(org.apache.commons.lang.StringUtils) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)34 List (java.util.List)30 Collectors (java.util.stream.Collectors)23 ArrayList (java.util.ArrayList)21 Map (java.util.Map)17 HashMap (java.util.HashMap)15 Set (java.util.Set)14 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 IOException (java.io.IOException)13 HashSet (java.util.HashSet)11 Arrays (java.util.Arrays)10 Collections (java.util.Collections)10 Date (java.util.Date)9 File (java.io.File)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 InputStream (java.io.InputStream)5 java.util (java.util)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Path (java.nio.file.Path)4