Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.25 KB | None | 0 0
  1. @Entity
  2. @Table ( name = "USERS")
  3. public class User {
  4.  
  5. private Long id;
  6. private String name;
  7. private String username;
  8. private String password;
  9. private String sourceIp;
  10. private Device device;
  11. private List<Product> productsEntitled;
  12.  
  13. <s:url id="remoteurl" action="loadUsersJson"/>
  14. <s:url id="editurl" action="editGridUserEntry"/>
  15. <s:url id="selectproductsurl" action="loadProductsJson"/>
  16.  
  17.  
  18. <sjg:grid gridModel="users"
  19. id="gridUsers"
  20. dataType="json"
  21. width="1150"
  22. href="%{remoteurl}"
  23. draggable="true"
  24. pager="true"
  25. resizable="true"
  26. navigatorAddOptions="{height:525, width:425, readAfterSubmit:true, draggable:true, resizable:true}"
  27. navigatorEditOptions="{height:525, width:425, reloadAfterSubmit:true, draggable:true, resizable:true}"
  28. navigatorDeleteOptions="{height:200, width:200, reloadAfterSubmit:true, draggable:true, resizable:true}"
  29. editurl="%{editurl}"
  30. navigator="true"
  31. navigatorEdit="true"
  32. navigatorAdd="true"
  33. navigatorView="true"
  34. navigatorDelete="true"
  35. rowList="10,15,20"
  36. rowNum="15"
  37. multiselect="false"
  38. onSelectRowTopics="rowselect">
  39.  
  40. <sjg:gridColumn name="id" editable="true" index="id" hidden="true" key="true" title="ID"/>
  41. <sjg:gridColumn name="name" index="name" editable="true" edittype="text" title="NAME"/>
  42. <sjg:gridColumn name="sourceIp" index="sourceIp" editable="true" edittype="text" title="SOURCE IP"/>
  43. <sjg:gridColumn name="username" index="username" editable="true" edittype="text" title="USERNAME"/>
  44. <sjg:gridColumn name="password" index="password" editable="true" edittype="password" title="PASSWORD"/>
  45. <sjg:gridColumn name="role" index="role" editable="true" edittype="select" editoptions="{value:'Admin:Admin;User:User;'}" title="ROLE"/>
  46.  
  47. <sjg:gridColumn name="deviceId" jsonmap="device.id" key="true" hidden="true" editable="text" title="DEVICE ID"/>
  48. <sjg:gridColumn name="deviceIp" jsonmap="device.ip" editable="true" edittype="text" title="DEVICE IP"/>
  49.  
  50. <sjg:gridColumn name="productsEntitledListModel"
  51. width="300"
  52. editable="true"
  53. edittype="select"
  54. editoptions="{dataUrl: '%{selectproductsurl}', multiple:true, buildSelect:customBuildSelect}"
  55. title="PRODUCTS"/>
  56.  
  57. </sjg:grid>
  58.  
  59. import java.util.List;
  60.  
  61. import javax.servlet.http.HttpServletRequest;
  62.  
  63. import org.apache.commons.logging.Log;
  64. import org.apache.commons.logging.LogFactory;
  65. import org.apache.struts2.interceptor.ServletRequestAware;
  66.  
  67. import com.opensymphony.xwork2.ActionSupport;
  68.  
  69.  
  70. public class AdminAction extends ActionSupport implements ServletRequestAware {
  71.  
  72. private static final long serialVersionUID = -1090720652366248768L;
  73. private static final Log logger = LogFactory.getLog(AdminAction.class);
  74.  
  75. private HttpServletRequest request;
  76. private AuthenticationTicket ticket;
  77. private AdminService adminService;
  78. private List<User> users;
  79. private List<Product> products;
  80. //private List<String>productsAllList;
  81. private String userId;
  82.  
  83. public String getUserId() {
  84. return userId;
  85. }
  86.  
  87. public void setUserId(String userId) {
  88. this.userId = userId;
  89. }
  90.  
  91. public List<Product> getProducts() {
  92. return products;
  93. }
  94.  
  95. public void setProducts(List<Product> products) {
  96. this.products = products;
  97. }
  98.  
  99. public AuthenticationTicket getTicket() {
  100. return ticket;
  101. }
  102.  
  103. public List<User> getUsers() {
  104. return users;
  105. }
  106.  
  107. public void setUsers(List<User> users) {
  108. this.users = users;
  109. }
  110.  
  111. public void setTicket(AuthenticationTicket ticket) {
  112. this.ticket = ticket;
  113. }
  114.  
  115. @Override
  116. public void setServletRequest(HttpServletRequest request) {
  117.  
  118. this.request = request;
  119.  
  120. }
  121.  
  122. public String redirectUsersTab() {
  123. return "users";
  124. }
  125.  
  126. public String redirectProductsTab() {
  127. return "products";
  128. }
  129.  
  130. private void initAdminService () {
  131.  
  132. logger.debug("initAdminService()...");
  133.  
  134. if (adminService == null) {
  135. adminService = (AdminService)ServiceFinder.getContext(request).getBean("adminService");
  136. }
  137.  
  138. }
  139.  
  140. public String loadUsersJson() {
  141.  
  142. initAdminService();
  143.  
  144. this.users = adminService.getUsersAll();
  145.  
  146. return "success";
  147. }
  148.  
  149. public String loadProductsJson() {
  150.  
  151. initAdminService();
  152.  
  153. this.products = adminService.getProductsAll();
  154.  
  155. return "success";
  156. }
  157.  
  158. //TODO: clean up
  159. public String getAllProductsList() {
  160.  
  161. logger.debug("testParam, userId: " + this.userId);
  162.  
  163. initAdminService();
  164.  
  165.  
  166. List<Product> temp = adminService.getProductsAll();
  167.  
  168. if (userId != null) {
  169.  
  170. User userTemp = new User();
  171. userTemp.setId(new Long(userId));
  172.  
  173. List<Product> prodEntitled = adminService.getProductsByUser(userTemp);
  174.  
  175. logger.debug("Products entitled: " + prodEntitled);
  176. }
  177.  
  178. //TODO: merge prod and prod entitled to Model to populate the grid
  179.  
  180. products = temp;
  181. /*
  182. if (temp != null && temp.size() > 0) {
  183.  
  184. this.productsAllList = new ArrayList<String>();
  185.  
  186. for (Product p : temp) {
  187. this.productsAllList.add(p.getName());
  188. }
  189. }
  190. */
  191.  
  192. //logger.debug("this.productsAllList: " + this.productsAllList);
  193.  
  194.  
  195. return "success";
  196. }
  197.  
  198. }
  199.  
  200. import java.util.ArrayList;
  201. import java.util.List;
  202.  
  203. import javax.servlet.http.HttpServletRequest;
  204.  
  205. import org.apache.commons.logging.Log;
  206. import org.apache.commons.logging.LogFactory;
  207. import org.apache.struts2.interceptor.ServletRequestAware;
  208.  
  209. import com.opensymphony.xwork2.ActionSupport;
  210.  
  211.  
  212. public class EditUsersGridAction extends ActionSupport implements ServletRequestAware {
  213.  
  214. private static final Log logger = LogFactory.getLog(EditUsersGridAction.class);
  215. private static final long serialVersionUID = -5485382508029951644L;
  216.  
  217. private HttpServletRequest request;
  218.  
  219. private AdminService adminService;
  220. private String oper = "";
  221. private Long id;
  222. private String name;
  223. private String sourceIp;
  224. private String password;
  225. private String username;
  226. private Long deviceId;
  227. private String deviceIp;
  228. private String devicePortDescription;
  229. private String devicePortLayer;
  230. private String deviceType;
  231. private List<Product>productsEntitled;
  232. private List<GridColumnListModel> productsEntitledListModel;
  233. private List<Product>productsAvailable;
  234.  
  235.  
  236. public List<GridColumnListModel> getProductsEntitledListModel() {
  237.  
  238. try {
  239.  
  240. if (productsEntitled != null && productsEntitled.size() > 0) {
  241.  
  242. productsEntitledListModel = new ArrayList<EditUsersGridAction.GridColumnListModel>();
  243.  
  244. for (Product p : productsEntitled) {
  245.  
  246. GridColumnListModel tmp = new GridColumnListModel();
  247.  
  248. tmp.setName(p.getName());
  249. tmp.setValue(p);
  250.  
  251. productsEntitledListModel.add(tmp);
  252. }
  253.  
  254. return this.productsEntitledListModel;
  255. }else {
  256. return null;
  257. }
  258.  
  259. } catch (Exception ex) {
  260. logger.error("Exception in getProductsEntitledString", ex);
  261. return null;
  262. }
  263. }
  264.  
  265. public void setProductsEntitledListModel(List<GridColumnListModel> productsEntitledListModel) {
  266. this.productsEntitledListModel = productsEntitledListModel;
  267. }
  268.  
  269. public Long getDeviceId() {
  270. return deviceId;
  271. }
  272.  
  273. public void setDeviceId(Long deviceId) {
  274. this.deviceId = deviceId;
  275. }
  276.  
  277. public String getDeviceIp() {
  278. return deviceIp;
  279. }
  280.  
  281. public void setDeviceIp(String deviceIp) {
  282. this.deviceIp = deviceIp;
  283. }
  284.  
  285. public String getDevicePortDescription() {
  286. return devicePortDescription;
  287. }
  288.  
  289. public void setDevicePortDescription(String devicePortDescription) {
  290. this.devicePortDescription = devicePortDescription;
  291. }
  292.  
  293. public String getDevicePortLayer() {
  294. return devicePortLayer;
  295. }
  296.  
  297. public void setDevicePortLayer(String devicePortLayer) {
  298. this.devicePortLayer = devicePortLayer;
  299. }
  300.  
  301. public String getDeviceType() {
  302. return deviceType;
  303. }
  304.  
  305. public void setDeviceType(String deviceType) {
  306. this.deviceType = deviceType;
  307. }
  308.  
  309. public String getOper() {
  310. return oper;
  311. }
  312.  
  313. public void setOper(String oper) {
  314. this.oper = oper;
  315. }
  316.  
  317. public Long getId() {
  318. return id;
  319. }
  320.  
  321. public void setId(Long id) {
  322. this.id = id;
  323. }
  324.  
  325. public String getName() {
  326. return name;
  327. }
  328.  
  329. public void setName(String name) {
  330. this.name = name;
  331. }
  332.  
  333. public String getSourceIp() {
  334. return sourceIp;
  335. }
  336.  
  337. public void setSourceIp(String sourceIp) {
  338. this.sourceIp = sourceIp;
  339. }
  340.  
  341. public String getPassword() {
  342. return password;
  343. }
  344.  
  345. public void setPassword(String password) {
  346. this.password = password;
  347. }
  348.  
  349. public String getUsername() {
  350. return username;
  351. }
  352.  
  353. public void setUsername(String username) {
  354. this.username = username;
  355. }
  356.  
  357. public List<Product> getProductsEntitled() {
  358. return productsEntitled;
  359. }
  360.  
  361. public void setProductsEntitled(List<Product> productsEntitled) {
  362. this.productsEntitled = productsEntitled;
  363. }
  364.  
  365. public List<Product> getProductsAvailable() {
  366. return productsAvailable;
  367. }
  368.  
  369. public void setProductsAvailable(List<Product> productsAvailable) {
  370. this.productsAvailable = productsAvailable;
  371. }
  372.  
  373. public HttpServletRequest getRequest() {
  374. return request;
  375. }
  376.  
  377. public void setRequest(HttpServletRequest request) {
  378. this.request = request;
  379. }
  380.  
  381. @Override
  382. public void setServletRequest(HttpServletRequest request) {
  383. this.request = request;
  384.  
  385. }
  386.  
  387. private void initAdminService () {
  388.  
  389. logger.debug("initAdminService()...");
  390.  
  391. if (adminService == null) {
  392. adminService = (AdminService)ServiceFinder.getContext(request).getBean("adminService");
  393. }
  394.  
  395. }
  396.  
  397. public String execute() throws Exception {
  398.  
  399. logger.debug("#### IN EditGridUsersAction ###");
  400.  
  401. initAdminService();
  402.  
  403. productsAvailable = adminService.getProductsAll();
  404.  
  405. User user = new User();
  406.  
  407. user.setName(name);
  408. user.setPassword(password);
  409. user.setUsername(username);
  410. user.setSourceIp(sourceIp);
  411.  
  412. Device device = new Device();
  413.  
  414. device.setId(deviceId);
  415. device.setIp(deviceIp);
  416. device.setPortDescription(devicePortDescription);
  417. device.setType(deviceType);
  418.  
  419. user.setDevice(device);
  420.  
  421. if (id != null) {
  422. user.setId(id);
  423. }
  424.  
  425. if (oper.equalsIgnoreCase("add")) {
  426.  
  427. logger.debug("products selected");
  428. //user.setProductsEntitled(adminService.getProductsAll());
  429. adminService.addUser(user);
  430.  
  431. } else if ( oper.equalsIgnoreCase("edit")) {
  432.  
  433. //TODO: convert model to products and add to user
  434. logger.debug("now in edit");
  435.  
  436. List<Product> tempProd = new ArrayList<Product>();
  437.  
  438. for (GridColumnListModel gridColModel : productsEntitledListModel) {
  439. tempProd.add(gridColModel.getValue());
  440. }
  441.  
  442. user.setProductsEntitled(tempProd);
  443. adminService.updateUser(user);
  444.  
  445. //return "input";
  446.  
  447. }else if (oper.equalsIgnoreCase("del")) {
  448. logger.debug("in delete");
  449. adminService.deleteUser(user);
  450. }
  451.  
  452. return "success";
  453. }
  454.  
  455. public class GridColumnListModel {
  456.  
  457. private String name;
  458. private Product value;
  459.  
  460. public String getName() {
  461. return name;
  462. }
  463.  
  464. public void setName(String name) {
  465. this.name = name;
  466. }
  467.  
  468. public Product getValue() {
  469. return value;
  470. }
  471.  
  472. public void setValue(Product value) {
  473. this.value = value;
  474. }
  475.  
  476.  
  477. }
  478.  
  479. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement