Skip to content

Commit abc6eb5

Browse files
committed
Enhanced sort when setting up profiles
Added sort based on assigned systems or users for a given profile. Closes bastillion-io#204
1 parent d4bf274 commit abc6eb5

7 files changed

Lines changed: 86 additions & 104 deletions

File tree

src/main/java/com/keybox/manage/action/ProfileSystemsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ProfileSystemsAction extends ActionSupport {
4646
public String viewProfileSystems() {
4747
if (profile != null && profile.getId() != null) {
4848
profile = ProfileDB.getProfile(profile.getId());
49-
sortedSet = SystemDB.getSystemSet(sortedSet);
49+
sortedSet = SystemDB.getSystemSet(sortedSet, profile.getId());
5050
}
5151
return SUCCESS;
5252
}

src/main/java/com/keybox/manage/action/ProfileUsersAction.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class ProfileUsersAction extends ActionSupport {
3636

3737
Profile profile;
3838
SortedSet sortedSet=new SortedSet();
39-
List<User> userList;
4039
List<Long> userSelectId;
4140

4241

@@ -48,8 +47,7 @@ public class ProfileUsersAction extends ActionSupport {
4847
public String viewProfileUsers() {
4948
if (profile != null && profile.getId() != null) {
5049
profile = ProfileDB.getProfile(profile.getId());
51-
sortedSet = UserDB.getAdminUserSet(sortedSet);
52-
userList = UserProfileDB.getUsersByProfile(profile.getId());
50+
sortedSet = UserDB.getAdminUserSet(sortedSet, profile.getId());
5351
}
5452
return SUCCESS;
5553
}
@@ -88,15 +86,4 @@ public SortedSet getSortedSet() {
8886
return sortedSet;
8987
}
9088

91-
public void setSortedSet(SortedSet sortedSet) {
92-
this.sortedSet = sortedSet;
93-
}
94-
public List<User> getUserList() {
95-
return userList;
96-
}
97-
98-
public void setUserList(List<User> userList) {
99-
this.userList = userList;
100-
}
101-
10289
}

src/main/java/com/keybox/manage/db/SystemDB.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class SystemDB {
4444
public static final String SORT_BY_USER = "user";
4545
public static final String SORT_BY_HOST = "host";
4646
public static final String STATUS_CD = "status_cd";
47+
public static final String PROFILE_ID = "profile_id";
4748
public static final String SORT_BY_STATUS = STATUS_CD;
4849

4950
private SystemDB() {
@@ -109,6 +110,58 @@ public static SortedSet getUserSystemSet(SortedSet sortedSet, Long userId) {
109110
}
110111

111112

113+
/**
114+
* method to do order by based on the sorted set object for systems
115+
*
116+
* @param sortedSet sorted set object
117+
* @profileId check if system is apart of given profile
118+
* @return sortedSet with list of host systems
119+
*/
120+
public static SortedSet getSystemSet(SortedSet sortedSet, Long profileId) {
121+
List<HostSystem> hostSystemList = new ArrayList<>();
122+
123+
String orderBy = "";
124+
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
125+
orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
126+
}
127+
String sql = "select s.*, m.profile_id from system s left join system_map m on m.system_id = s.id " + orderBy;
128+
129+
Connection con = null;
130+
try {
131+
con = DBUtils.getConn();
132+
PreparedStatement stmt = con.prepareStatement(sql);
133+
ResultSet rs = stmt.executeQuery();
134+
135+
while (rs.next()) {
136+
HostSystem hostSystem = new HostSystem();
137+
hostSystem.setId(rs.getLong("id"));
138+
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
139+
hostSystem.setUser(rs.getString("user"));
140+
hostSystem.setHost(rs.getString("host"));
141+
hostSystem.setPort(rs.getInt("port"));
142+
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
143+
hostSystem.setStatusCd(rs.getString(STATUS_CD));
144+
if (profileId !=null && profileId.equals(rs.getLong(PROFILE_ID))) {
145+
hostSystem.setChecked(true);
146+
} else {
147+
hostSystem.setChecked(false);
148+
}
149+
hostSystemList.add(hostSystem);
150+
}
151+
DBUtils.closeRs(rs);
152+
DBUtils.closeStmt(stmt);
153+
154+
} catch (Exception e) {
155+
log.error(e.toString(), e);
156+
}
157+
finally {
158+
DBUtils.closeConn(con);
159+
}
160+
161+
sortedSet.setItemList(hostSystemList);
162+
return sortedSet;
163+
}
164+
112165
/**
113166
* method to do order by based on the sorted set object for systems
114167
*

src/main/java/com/keybox/manage/db/UserDB.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class UserDB {
4444
public static final String USERNAME = "username";
4545
public static final String USER_TYPE = "user_type";
4646
public static final String AUTH_TYPE = "auth_type";
47+
public static final String PROFILE_ID = "profile_id";
4748

4849
private UserDB() {
4950
}
@@ -99,9 +100,10 @@ public static SortedSet getUserSet(SortedSet sortedSet) {
99100
/**
100101
* returns all admin users based on sort order defined
101102
* @param sortedSet object that defines sort order
103+
* @profileId check if user is apart of given profile
102104
* @return sorted user list
103105
*/
104-
public static SortedSet getAdminUserSet(SortedSet sortedSet) {
106+
public static SortedSet getAdminUserSet(SortedSet sortedSet, Long profileId) {
105107

106108
ArrayList<User> userList = new ArrayList<>();
107109

@@ -110,7 +112,7 @@ public static SortedSet getAdminUserSet(SortedSet sortedSet) {
110112
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
111113
orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
112114
}
113-
String sql = "select * from users where user_type like '" + User.ADMINISTRATOR + "' " + orderBy;
115+
String sql = " select u.*, m.profile_id from users u left join user_map m on m.user_id = u.id where u.user_type like '" + User.ADMINISTRATOR + "' " + orderBy;
114116

115117
Connection con = null;
116118
try {
@@ -127,6 +129,11 @@ public static SortedSet getAdminUserSet(SortedSet sortedSet) {
127129
user.setPassword(rs.getString(PASSWORD));
128130
user.setAuthType(rs.getString(AUTH_TYPE));
129131
user.setUserType(rs.getString(USER_TYPE));
132+
if (profileId != null && profileId.equals(rs.getLong(PROFILE_ID))) {
133+
user.setChecked(true);
134+
} else {
135+
user.setChecked(false);
136+
}
130137
userList.add(user);
131138

132139
}

src/main/java/com/keybox/manage/db/UserProfileDB.java

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -130,68 +130,6 @@ public static List<Profile> getProfilesByUser(Connection con, Long userId) {
130130
return profileList;
131131
}
132132

133-
/**
134-
* get users associated with profile
135-
* @param profileId profile id
136-
* @return user list
137-
*/
138-
public static List<User> getUsersByProfile(Long profileId) {
139-
140-
141-
Connection con = null;
142-
List<User> userList = new ArrayList<>();
143-
try {
144-
con = DBUtils.getConn();
145-
userList = getUsersByProfile(con, profileId);
146-
147-
} catch (Exception e) {
148-
log.error(e.toString(), e);
149-
}
150-
finally {
151-
DBUtils.closeConn(con);
152-
}
153-
return userList;
154-
155-
156-
}
157-
158-
/**
159-
* get users associated with profile
160-
* @param con DB connection
161-
* @param profileId profile id
162-
* @return user list
163-
*/
164-
public static List<User> getUsersByProfile(Connection con, Long profileId) {
165-
166-
ArrayList<User> userList = new ArrayList<>();
167-
168-
169-
try {
170-
PreparedStatement stmt = con.prepareStatement("select * from users u, user_map m where u.id=m.user_id and m.profile_id=? order by last_nm asc");
171-
stmt.setLong(1, profileId);
172-
ResultSet rs = stmt.executeQuery();
173-
174-
while (rs.next()) {
175-
User user = new User();
176-
user.setId(rs.getLong("id"));
177-
user.setFirstNm(rs.getString("first_nm"));
178-
user.setLastNm(rs.getString("last_nm"));
179-
user.setEmail(rs.getString("email"));
180-
user.setUsername(rs.getString("username"));
181-
user.setPassword(rs.getString("password"));
182-
userList.add(user);
183-
}
184-
DBUtils.closeRs(rs);
185-
DBUtils.closeStmt(stmt);
186-
187-
} catch (Exception e) {
188-
log.error(e.toString(), e);
189-
}
190-
191-
return userList;
192-
}
193-
194-
195133
/**
196134
* checks to determine if user belongs to profile
197135
*

src/main/webapp/manage/view_profile_systems.jsp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
});
3232
3333
//select all check boxes
34-
$("#assignSystemsToProfile_systemSelectAll").click(function() {
35-
34+
$("#assignSystemsToProfile_systemSelectAll").click(function(e) {
35+
e.stopImmediatePropagation();
3636
if ($(this).is(':checked')) {
3737
$(".systemSelect").prop('checked', true);
3838
} else {
@@ -58,13 +58,6 @@
5858
$('#<s:property value="sortedSet.orderByField"/>').attr('class', '<s:property value="sortedSet.orderByDirection"/>');
5959
</s:if>
6060
61-
<s:if test="profile.hostSystemList!= null && !profile.hostSystemList.isEmpty()">
62-
<s:iterator var="system" value="profile.hostSystemList" status="stat">
63-
$(':checkbox[value=<s:property value="id"/>]').prop('checked', true);
64-
</s:iterator>
65-
</s:if>
66-
67-
6861
});
6962
</script>
7063

@@ -73,7 +66,6 @@
7366
</head>
7467
<body>
7568

76-
7769
<jsp:include page="../_res/inc/navigation.jsp"/>
7870

7971
<div class="container">
@@ -103,7 +95,7 @@
10395
<thead>
10496

10597
<tr>
106-
<th><s:checkbox name="systemSelectAll" cssClass="systemSelect" theme="simple"/></th>
98+
<th id="<s:property value="@com.keybox.manage.db.SystemDB@PROFILE_ID"/>" class="sort"><s:checkbox name="systemSelectAll" cssClass="systemSelect" theme="simple"/></th>
10799
<th id="<s:property value="@com.keybox.manage.db.SystemDB@SORT_BY_NAME"/>" class="sort">Display Name</th>
108100
<th id="<s:property value="@com.keybox.manage.db.SystemDB@SORT_BY_USER"/>" class="sort">User</th>
109101
<th id="<s:property value="@com.keybox.manage.db.SystemDB@SORT_BY_HOST"/>" class="sort">Host</th>
@@ -117,8 +109,14 @@
117109
<s:iterator var="system" value="sortedSet.itemList" status="stat">
118110
<tr>
119111
<td>
120-
<s:checkboxlist id="systemSelectId_%{id}" list="#{id:''}" name="systemSelectId" cssClass="systemSelect"
121-
theme="simple"/>
112+
<s:if test="checked">
113+
<s:checkboxlist id="systemSelectId_%{id}" list="#{id:''}" name="systemSelectId" cssClass="systemSelect"
114+
theme="simple" checked="true"/>
115+
</s:if>
116+
<s:else>
117+
<s:checkboxlist id="systemSelectId_%{id}" list="#{id:''}" name="systemSelectId" cssClass="systemSelect"
118+
theme="simple"/>
119+
</s:else>
122120
</td>
123121
<td>
124122
<s:property value="displayNm"/>

src/main/webapp/manage/view_profile_users.jsp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
});
3434
3535
//select all check boxes
36-
$("#assignUsersToProfile_userSelectAll").click(function() {
37-
36+
$("#assignUsersToProfile_userSelectAll").click(function(e) {
37+
e.stopImmediatePropagation();
3838
if ($(this).is(':checked')) {
3939
$(".userSelect").prop('checked', true);
4040
} else {
@@ -60,13 +60,6 @@
6060
$('#<s:property value="sortedSet.orderByField"/>').attr('class', '<s:property value="sortedSet.orderByDirection"/>');
6161
</s:if>
6262
63-
<s:if test="userList!= null && !userList.isEmpty()">
64-
<s:iterator var="user" value="userList" status="stat">
65-
$(':checkbox[value=<s:property value="id"/>]').prop('checked', true);
66-
</s:iterator>
67-
</s:if>
68-
69-
7063
});
7164
</script>
7265

@@ -105,7 +98,7 @@
10598
<thead>
10699

107100
<tr>
108-
<th><s:checkbox name="userSelectAll" cssClass="userSelect" theme="simple"/></th>
101+
<th id="<s:property value="@com.keybox.manage.db.UserDB@PROFILE_ID"/>" class="sort"><s:checkbox name="userSelectAll" cssClass="userSelect" theme="simple"/></th>
109102
<th id="<s:property value="@com.keybox.manage.db.UserDB@USERNAME"/>" class="sort">Username
110103
</th>
111104
<s:if test="%{@com.keybox.manage.util.ExternalAuthUtil@externalAuthEnabled}">
@@ -127,8 +120,14 @@
127120
<s:iterator var="user" value="sortedSet.itemList" status="stat">
128121
<tr>
129122
<td>
130-
<s:checkboxlist id="userSelectId_%{id}" list="#{id:''}" name="userSelectId" cssClass="userSelect"
131-
theme="simple"/>
123+
<s:if test="checked">
124+
<s:checkboxlist id="userSelectId_%{id}" list="#{id:''}" name="userSelectId" cssClass="userSelect"
125+
theme="simple" checked="true" />
126+
</s:if>
127+
<s:else>
128+
<s:checkboxlist id="userSelectId_%{id}" list="#{id:''}" name="userSelectId" cssClass="userSelect"
129+
theme="simple"/>
130+
</s:else>
132131
</td>
133132
<td>
134133
<s:if test="userType==\"M\"">

0 commit comments

Comments
 (0)