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;
}
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);
}
}
}
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;
}
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);
}
}
}
}
}
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;
}
Aggregations