jnObj.put("page", sspInfo.getPage());
jnObj.put("total", sspInfo.getTotal());
jnObj.put("records", sspInfo.getRecords());
JSONArray jnAry = new JSONArray();
Group grp = null;
JSONObject perJN=null;
StringBuilder sb = new StringBuilder();
for(int i=0, size=allGroups.size(); i<size; i++) {
grp = allGroups.get(i);
perJN = new JSONObject();
perJN.put("id", grp.getId());
perJN.put("groupName", grp.getGroupName());
sb = new StringBuilder();
for(UserGroup ug : grp.getOwnUsers()) {
if(ug.getUserAccount()!=null) {
sb.append( ug.getUserAccount().getAccount() ).append(",");
}
}
perJN.put("ownUsers", sb.toString());
jnAry.add(perJN);
}
jnObj.put("rows", jnAry);
System.out.println( "JSON.toString = \n"+ jnObj.toString() );
res.setContentType("text/json;charset=utf-8");
res.getWriter().write( jnObj.toString() );
// FETCH ALL USERS
} else if(req.getRequestURI().endsWith("allUsers.do")) {
List<UserAccount> allUsers = UserAccountServices.getInstance().listAllUserAccount();
JSONArray jnAry = new JSONArray();
UserAccount account = null;
JSONObject perJN=null;
for(int i=0, size=allUsers.size(); i<size; i++) {
account = allUsers.get(i);
perJN = new JSONObject();
perJN.put("id", account.getId());
perJN.put("account", account.getAccount());
jnAry.add(perJN);
}
System.out.println( "JSON.toString = \n"+ jnAry.toString() );
res.setContentType("text/json;charset=utf-8");
res.getWriter().write( jnAry.toString() );
// SAVE OR UPDATE GROUP
} else if (req.getRequestURI().endsWith("saveOrUpdateGroup.do")) {
//System.out.println("req.URI="+req.getRequestURI());
String id = req.getParameter("id");
String groupName = req.getParameter("groupName");
String ownUsers = req.getParameter("ownUsers");
JSONObject jnObj = new JSONObject();
try {
Group group = new Group(groupName);
if(id!=null&&id.trim().length()!=0) {
group.setId( Long.parseLong(id) );
}
String[] accountAy = null;
if(ownUsers!=null) {
accountAy = ownUsers.split(",");
}