Search in sources :

Example 1 with Branch

use of com.ramussoft.common.Branch in project ramus by Vitaliy-Yakovchuk.

the class IEngineImpl method getRootBranch.

@Override
public Branch getRootBranch() {
    List<Branch> data = loadBranches();
    Hashtable<Long, Branch> hash = new Hashtable<Long, Branch>();
    for (Branch branch : data) hash.put(branch.getBranchId(), branch);
    Branch root = null;
    for (Branch branch : data) {
        if (branch.getBranchId() == 0l && branch.getParentBranchId() == 0l)
            root = branch;
        if (branch.getBranchId() != 0l)
            hash.get(branch.getParentBranchId()).getChildren().add(branch);
    }
    return root;
}
Also used : Branch(com.ramussoft.common.Branch) Hashtable(java.util.Hashtable)

Example 2 with Branch

use of com.ramussoft.common.Branch in project ramus by Vitaliy-Yakovchuk.

the class IEngineImpl method createBranch.

@Override
public void createBranch(long parent, long branchId, String reason, int type, String module) {
    qualifeirsCache.clear();
    synchronized (branchCreationLock) {
        if (parent == -1l)
            parent = getMainBranch();
        if (reason == null)
            throw new NullPointerException("Reason is null");
        try {
            List<Branch> data = loadBranches();
            Hashtable<Long, Branch> hash = new Hashtable<Long, Branch>();
            for (Branch branch : data) hash.put(branch.getBranchId(), branch);
            PreparedStatement ps = template.getPreparedStatement("INSERT INTO " + IEngineImpl.this.prefix + "branches(branch_id, creation_user, reason, branch_type, module_name, creation_time) VALUES(?, ?, ?, ?, ?, ?)", false);
            ps.setLong(1, branchId);
            String user = "admin";
            ps.setString(2, user);
            ps.setString(3, reason);
            ps.setInt(4, type);
            ps.setString(5, module);
            ps.setTimestamp(6, new Timestamp(new Date().getTime()));
            ps.execute();
            ps.close();
            setActiveBranch(branchId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Branch(com.ramussoft.common.Branch) Hashtable(java.util.Hashtable) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Date(java.util.Date) SQLException(java.sql.SQLException)

Example 3 with Branch

use of com.ramussoft.common.Branch in project ramus by Vitaliy-Yakovchuk.

the class BranchView method createRoot.

protected Node createRoot(Branch rootBranch) {
    Node root = new Node(rootBranch);
    for (Branch b : rootBranch.getChildren()) {
        if (b.getType() == root.branch.getType()) {
            Node e = new Node(b);
            e.parent = root;
            root.children.add(e);
            addNode(root, b);
        } else {
            Node e = createRoot(b);
            Node p = null;
            Node x = root;
            while (x != null) {
                for (Node n : x.children) if (n.branch.getBranchId() == b.getParentBranchId())
                    p = n;
                if (p != null)
                    break;
                x = x.parent;
            }
            if (p == null && root.branch.getBranchId() == b.getParentBranchId())
                p = root;
            e.parent = p;
            p.children.add(e);
            for (int i = e.children.size() - 1; i >= 0; i--) {
                Node n = e.children.get(i);
                if (n.branch.getType() == b.getType()) {
                    n.parent.children.remove(n);
                    n.parent = p;
                    p.children.add(n);
                }
            }
        }
    }
    return root;
}
Also used : Branch(com.ramussoft.common.Branch) TreeNode(javax.swing.tree.TreeNode) TreeTableNode(org.jdesktop.swingx.treetable.TreeTableNode)

Example 4 with Branch

use of com.ramussoft.common.Branch in project ramus by Vitaliy-Yakovchuk.

the class BranchView method addNode.

private void addNode(Node root, Branch br) {
    for (Branch b : br.getChildren()) {
        if (b.getType() == root.branch.getType()) {
            Node e = new Node(b);
            e.parent = root;
            root.children.add(e);
            addNode(root, b);
        } else {
            Node e = createRoot(b);
            Node p = null;
            for (Node n : root.children) if (n.branch.getBranchId() == b.getParentBranchId())
                p = n;
            e.parent = p;
            p.children.add(e);
            for (int i = e.children.size() - 1; i >= 0; i--) {
                Node n = e.children.get(i);
                if (n.branch.getType() == b.getType()) {
                    n.parent.children.remove(n);
                    n.parent = p;
                    p.children.add(n);
                }
            }
        }
    }
}
Also used : Branch(com.ramussoft.common.Branch) TreeNode(javax.swing.tree.TreeNode) TreeTableNode(org.jdesktop.swingx.treetable.TreeTableNode)

Example 5 with Branch

use of com.ramussoft.common.Branch in project ramus by Vitaliy-Yakovchuk.

the class IEngineImpl method loadBranches.

@SuppressWarnings({ "cast" })
protected List<Branch> loadBranches() {
    List<Branch> data = (List<Branch>) template.query("SELECT branch_id, reason, branch_type, creation_user, module_name, creation_time FROM " + prefix + "branches a ", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            Branch branch = new Branch();
            branch.setBranchId(rs.getLong("branch_id"));
            branch.setReason(rs.getString("reason"));
            branch.setType(rs.getInt("branch_type"));
            branch.setUser(rs.getString("creation_user"));
            branch.setModule(rs.getString("module_name"));
            Timestamp ts = rs.getTimestamp("creation_time");
            branch.setCreationTime(new Date(ts.getTime()));
            return branch;
        }
    });
    return data;
}
Also used : Branch(com.ramussoft.common.Branch) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Timestamp(java.sql.Timestamp) Date(java.util.Date) RowMapper(com.ramussoft.jdbc.RowMapper)

Aggregations

Branch (com.ramussoft.common.Branch)5 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 Hashtable (java.util.Hashtable)2 TreeNode (javax.swing.tree.TreeNode)2 TreeTableNode (org.jdesktop.swingx.treetable.TreeTableNode)2 RowMapper (com.ramussoft.jdbc.RowMapper)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1