Search in sources :

Example 16 with HongsExemption

use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.

the class SearchEntity method revert.

@Override
public void revert() {
    super.revert();
    if (WRITES.isEmpty()) {
        return;
    }
    try {
        IndexWriter iw = getWriter();
        synchronized (iw) {
            iw.rollback();
        }
    } catch (HongsException ex) {
        throw ex.toExemption();
    } catch (IOException ex) {
        throw new HongsExemption(1056, ex);
    } finally {
        WRITES.clear();
        DOCK = null;
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) HongsException(io.github.ihongs.HongsException) HongsExemption(io.github.ihongs.HongsExemption) IOException(java.io.IOException)

Example 17 with HongsExemption

use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.

the class SystemCmdlet method getTin.

private static Date getTin(String ds, Date dt) {
    Matcher dm = TIN_FMT_PAT.matcher(ds);
    if (!dm.matches()) {
        return getTim(ds, dt);
    }
    try {
        String dz;
        dz = dm.group(1);
        if (dz != null) {
            return new SimpleDateFormat("yyyy/MM/ddTHH:mm:ss").parse(dz);
        }
        dz = dm.group(2);
        if (dz != null) {
            return new SimpleDateFormat("yyyy/MM/dd").parse(dz);
        }
        dz = dm.group(3);
        if (dz != null) {
            return new SimpleDateFormat("HH:mm:ss").parse(dz);
        }
        dz = dm.group(4);
        if (dz != null) {
            return new SimpleDateFormat("HH:mm").parse(dz);
        }
        return null;
    } catch (ParseException ex) {
        throw new HongsExemption(ex);
    }
}
Also used : Matcher(java.util.regex.Matcher) HongsExemption(io.github.ihongs.HongsExemption) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with HongsExemption

use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.

the class SearchQuery method wdr.

@Override
public Query wdr(String k, Object v) {
    if (null == v) {
        throw new NullPointerException("Query for " + k + " must be string, but null");
    }
    if ("".equals(v)) {
        throw new NullPointerException("Query for " + k + " can not be empty string");
    }
    QueryParser qp = new QueryParser("$" + k, ana != null ? ana : new StandardAnalyzer());
    String s = v.toString();
    // 是否转义
    if (des == null || !des) {
        s = QueryParser.escape(s);
    }
    // 词间关系
    if (dor == null || !dor) {
        qp.setDefaultOperator(QueryParser.AND_OPERATOR);
    } else {
        qp.setDefaultOperator(QueryParser.OR_OPERATOR);
    }
    // 其他设置
    if (phr != null)
        qp.setPhraseSlop(phr);
    if (fms != null)
        qp.setFuzzyMinSim(fms);
    if (fpl != null)
        qp.setFuzzyPrefixLength(fpl);
    if (sow != null)
        qp.setSplitOnWhitespace(sow);
    // if (art != null) qp.setAnalyzeRangeTerms(art);
    if (alw != null)
        qp.setAllowLeadingWildcard(alw);
    // if (let != null) qp.setLowercaseExpandedTerms   (let);
    if (epi != null)
        qp.setEnablePositionIncrements(epi);
    if (agp != null)
        qp.setAutoGeneratePhraseQueries(agp);
    try {
        Query q2 = qp.parse(s);
        return q2;
    } catch (ParseException e) {
        throw new HongsExemption(e);
    }
}
Also used : QueryParser(org.apache.lucene.queryparser.classic.QueryParser) Query(org.apache.lucene.search.Query) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) HongsExemption(io.github.ihongs.HongsExemption) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 19 with HongsExemption

use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.

the class Data method getFields.

/**
 * 获取字段
 * 当前表单不在管理区之内时,
 * 会用当前表单覆盖管理表单,
 * 配置文件不存在则抛出异常 404
 * @return
 */
@Override
public Map getFields() {
    try {
        return gotFields();
    } catch (NullPointerException ex) {
    // 使用超类管理字段
    // 拿不到就进行填充
    }
    /**
     * 字段以 centra/data 的字段为基础
     * 但可在 centre/data 重设部分字段
     *
     * 配置文件不得放在资源包里面
     * 此处会校验表单文件是否存在
     */
    Map fields = null;
    Map fieldx = null;
    String cnf = conf;
    do {
        try {
            fields = FormSet.getInstance(cnf).getForm(form);
        } catch (HongsException ex) {
            if (ex.getErrno() != 910 && ex.getErrno() != 912) {
                // 非表单缺失
                throw ex.toExemption();
            }
            break;
        }
        if (fields == null) {
            break;
        }
        cnf = getBgConf();
        if (cnf.equals(conf)) {
            break;
        }
        try {
            fieldx = FormSet.getInstance(cnf).getForm(form);
        } catch (HongsException ex) {
            if (ex.getErrno() != 910 && ex.getErrno() != 912) {
                // 非表单缺失
                throw ex.toExemption();
            }
            break;
        }
        if (fieldx == null) {
            break;
        }
        if (fieldx.isEmpty()) {
            break;
        }
        /**
         * 注意:
         * 1. 不可破坏原始配置
         * 2. 当前的覆盖后台的
         */
        fieldx = new LinkedHashMap(fieldx);
        for (Object ot : fields.entrySet()) {
            Map.Entry et = (Map.Entry) ot;
            String fn = (String) et.getKey();
            Map fc = (Map) et.getValue();
            Map fx = (Map) fieldx.get(fn);
            if (fx != null) {
                fx = new LinkedHashMap(fx);
                fx.putAll(fc);
                fieldx.put(fn, fx);
            } else {
                fieldx.put(fn, fc);
            }
        }
        fields = fieldx;
    } while (false);
    if (null == fields) {
        throw new HongsExemption(910, "Data form '" + conf + "." + form + "' is not exists").setLocalizedContent("matrix.form.not.exists").setLocalizedContext("matrix");
    }
    setFields(fields);
    return fields;
}
Also used : HongsException(io.github.ihongs.HongsException) HongsExemption(io.github.ihongs.HongsExemption) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with HongsExemption

use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.

the class ActionHelper method updateHelper.

/**
 * 供 ActionDriver 重设助手
 * @param req
 * @param rsp
 */
public final void updateHelper(HttpServletRequest req, HttpServletResponse rsp) {
    this.request = req;
    this.response = rsp;
    try {
        if (null != this.request) {
            this.request.setCharacterEncoding("UTF-8");
        }
        if (null != this.response) {
            this.response.setCharacterEncoding("UTF-8");
        }
    } catch (UnsupportedEncodingException ex) {
        throw new HongsExemption(1111, "Can not set encoding.", ex);
    }
    this.outputStream = null;
    this.outputWriter = null;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HongsExemption(io.github.ihongs.HongsExemption)

Aggregations

HongsExemption (io.github.ihongs.HongsExemption)44 HongsException (io.github.ihongs.HongsException)15 IOException (java.io.IOException)12 HashMap (java.util.HashMap)10 Map (java.util.Map)9 LinkedHashMap (java.util.LinkedHashMap)7 HashSet (java.util.HashSet)6 Core (io.github.ihongs.Core)5 ActionHelper (io.github.ihongs.action.ActionHelper)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ArrayList (java.util.ArrayList)5 File (java.io.File)4 List (java.util.List)4 CoreConfig (io.github.ihongs.CoreConfig)3 FileInputStream (java.io.FileInputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 Matcher (java.util.regex.Matcher)3