Search in sources :

Example 56 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class AuthKit method getCrypt.

/**
 * 获取特征加密字符串
 * @param pswd
 * @return
 * @throws HongsException
 */
public static String getCrypt(String pswd) throws HongsException {
    try {
        MessageDigest m = MessageDigest.getInstance("MD5");
        byte[] pzwd = m.digest(pswd.getBytes());
        byte[] pxwd = new byte[pzwd.length * 2];
        for (int i = 0, j = 0; i < pzwd.length; i++) {
            byte pzbt = pzwd[i];
            pxwd[j++] = PAZZ[pzbt >>> 4 & 15];
            pxwd[j++] = PAZZ[pzbt & 15];
        }
        return new String(pxwd);
    } catch (NoSuchAlgorithmException ex) {
        throw new HongsException.Common(ex);
    }
}
Also used : HongsException(app.hongs.HongsException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 57 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Dept method permit.

protected void permit(String id, Map data) throws HongsException {
    String pid = null;
    if (data != null) {
        // 权限限制, 仅能赋予当前登录用户所有的权限
        if (data.containsKey("roles")) {
            data.put("rtime", System.currentTimeMillis() / 1000);
            List list = Synt.asList(data.get("roles"));
            AuthKit.cleanDeptRoles(list, id);
            if (list.isEmpty()) {
                throw new HongsException.Notice("ex.master.user.dept.error").setLocalizedContext("master");
            }
            data.put("roles", list);
        }
        // 部门限制, 默认顶级, 是否可操作在下方判断
        pid = Synt.declare(data.get("pid"), "");
        if ("".equals(pid))
            pid = Cnst.ADM_GID;
    } else {
        // 删除限制, 如果部门下有用户则中止当前操作
        User user = new User();
        List list = user.table.fetchMore(user.fetchCase().gotJoin("depts").from("a_master_user_dept").by(FetchCase.INNER).on("`depts`.`user_id` = `user`.`id`").filter("`depts`.`dept_id` = ?", id).limit(1));
        if (list.size() != 0) {
            throw new HongsException.Notice("ex.master.dept.have.users").setLocalizedContext("master");
        }
    }
    if (id == null && pid == null) {
        throw new NullPointerException("id and pid cannot be all null");
    }
    if (id != null || pid != null) {
        // 超级管理员可操作任何部门
        ActionHelper helper = Core.getInstance(ActionHelper.class);
        String uid = (String) helper.getSessibute(Cnst.UID_SES);
        if (Cnst.ADM_UID.equals(uid)) {
            return;
        }
        // 超级管理组可操作任何部门
        // 但禁止操作顶级部门
        Set cur = AuthKit.getUserDepts(uid);
        if (cur.contains(Cnst.ADM_GID) && !Cnst.ADM_GID.equals(id)) {
            return;
        }
        // 仅可以操作下级部门
        for (Object gid : cur) {
            Set cld = new HashSet(this.getChildIds((String) gid, true));
            if (null != pid && (gid.equals(pid) || cld.contains(pid))) {
                return;
            }
            if (null != id && cld.contains(id)) {
                return;
            }
        }
        throw new HongsException.Notice("ex.master.dept.unit.error").setLocalizedContext("master");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HongsException(app.hongs.HongsException) ActionHelper(app.hongs.action.ActionHelper) List(java.util.List) HashSet(java.util.HashSet)

Example 58 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class DataAction method redo.

@Action("revert/update")
@CommitSuccess
public void redo(ActionHelper helper) throws HongsException {
    String id = helper.getParameter(Cnst.ID_KEY);
    if (null == id || "".equals(id)) {
        throw new HongsException(0x1100, "id required");
    }
    Data sr = (Data) getEntity(helper);
    Map rd = helper.getRequestData();
    sr.redo(id, rd);
    helper.reply("");
}
Also used : HongsException(app.hongs.HongsException) Data(app.hongs.serv.matrix.Data) HashMap(java.util.HashMap) Map(java.util.Map) Action(app.hongs.action.anno.Action) SearchAction(app.hongs.dh.search.SearchAction) CommitSuccess(app.hongs.action.anno.CommitSuccess)

Example 59 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Data method save.

public void save(String id, Map rd) throws HongsException {
    String fid = getFormId();
    Table table = getTable();
    String where = "`id`=? AND `form_id`=? AND `etime`=?";
    Object[] param = new String[] { id, fid, "0" };
    long ctime = System.currentTimeMillis() / 1000;
    time = ctime;
    // 删除当前数据
    if (rd == null) {
        if (table != null) {
            Map ud = new HashMap();
            ud.put("etime", ctime);
            ud.put("state", 0);
            table.update(ud, where, param);
        }
        super.del(id);
        return;
    }
    // 获取旧的数据
    Map dd;
    if (table != null) {
        dd = table.fetchCase().filter(where, param).select("data,ctime").one();
        if (!dd.isEmpty()) {
            if (ctime <= Synt.declare(dd.get("ctime"), 0L)) {
                throw new HongsException(0x1100, "等会儿, 不要急");
            }
            dd = (Map) app.hongs.util.Data.toObject(dd.get("data").toString());
        }
    } else {
        dd = get(id);
    }
    // 合并新旧数据
    int i = 0;
    Map<String, Map> fields = getFields();
    for (String fn : fields.keySet()) {
        if ("id".equals(fn)) {
            dd.put(fn, id);
        } else if (rd.containsKey(fn)) {
            Object fr = Synt.defoult(rd.get(fn), "");
            Object fo = Synt.defoult(dd.get(fn), "");
            dd.put(fn, fr);
            if (!equals(fr, fo) && !fn.equals("muid") && !fn.equals("mtime")) {
                // 需要排除修改环境数据
                i++;
            }
        }
    }
    // 无更新不存储
    if (i == 0) {
        return;
    }
    dd.put("name", getName(dd));
    dd.put("word", getWord(dd));
    if (table != null) {
        Map ud = new HashMap();
        ud.put("etime", ctime);
        Map nd = new HashMap();
        nd.put("ctime", ctime);
        nd.put("etime", 0);
        nd.put(/**
         */
        "id", id);
        nd.put("form_id", fid);
        nd.put("user_id", rd.get("user_id"));
        nd.put("name", dd.get("name"));
        nd.put("memo", rd.get("memo"));
        nd.put("data", app.hongs.util.Data.toString(dd));
        table.update(ud, where, param);
        table.insert(nd);
    }
    // ** 保存到索引库 **/
    Document doc = new Document();
    dd.put(Cnst.ID_KEY, id);
    docAdd(doc, dd);
    setDoc(id, doc);
}
Also used : Table(app.hongs.db.Table) HashMap(java.util.HashMap) HongsException(app.hongs.HongsException) Document(org.apache.lucene.document.Document) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Data method redo.

public void redo(String id, Map rd) throws HongsException {
    long ctime = System.currentTimeMillis() / 1000;
    long rtime = Synt.declare(rd.get("rtime"), 0L);
    // ** 获取旧的数据 **/
    String fid = getFormId();
    Table table = getTable();
    String where = "`id`=? AND `form_id`=? AND `ctime`=?";
    Object[] param = new Object[] { id, fid, rtime };
    if (table == null) {
        throw new HongsException(0x1100, "此资源不支持恢复");
    }
    Map dd = table.fetchCase().filter(where, param).select("data, name, etime").orderBy("ctime DESC").one();
    if (dd.isEmpty()) {
        throw new HongsException(0x1100, "恢复数据源不存在");
    }
    if (Synt.declare(dd.get("etime"), 0L) == 0L) {
        throw new HongsException(0x1100, "活跃数据不可操作");
    }
    // ** 保存到数据库 **/
    Map ud = new HashMap();
    ud.put("etime", ctime);
    rd.put("ctime", ctime);
    rd.put("rtime", rtime);
    rd.put("etime", 0);
    rd.put("name", dd.get("name"));
    rd.put("data", dd.get("data"));
    where = "`id`=? AND `form_id`=? AND `etime`=?";
    param = new Object[] { id, fid, 0 };
    table.update(ud, where, param);
    table.insert(rd);
    // ** 保存到索引库 **/
    dd = (Map) app.hongs.util.Data.toObject(dd.get("data").toString());
    Document doc = new Document();
    dd.put(Cnst.ID_KEY, id);
    docAdd(doc, dd);
    setDoc(id, doc);
}
Also used : Table(app.hongs.db.Table) HongsException(app.hongs.HongsException) HashMap(java.util.HashMap) Document(org.apache.lucene.document.Document) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HongsException (app.hongs.HongsException)89 Map (java.util.Map)42 HashMap (java.util.HashMap)34 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 Set (java.util.Set)15 List (java.util.List)13 File (java.io.File)11 SQLException (java.sql.SQLException)10 FileNotFoundException (java.io.FileNotFoundException)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 PreparedStatement (java.sql.PreparedStatement)8 Iterator (java.util.Iterator)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 HongsExpedient (app.hongs.HongsExpedient)7 FormSet (app.hongs.action.FormSet)7 Table (app.hongs.db.Table)7