Strategic Pattern v2


/ Published in: Java
Save to your folder(s)

strategic pattern with spring testing


Copy this code and paste it in your HTML
  1. public abstract class Dashboard {
  2.  
  3. public Dashboard(){}
  4.  
  5. @Autowired
  6. private ActionBulletinService actionBulletinService;
  7.  
  8. WorkFlowDashboardBehavior behavior;
  9.  
  10.  
  11. public List<OrderDetail> retrieveDashBoardList(UserMaster user, List<UserRole> roles){
  12. return actionBulletinService.retrieveTaskListByUserIdByRoleList(user.getId() , roles );
  13. }
  14.  
  15. public void commonMethod() {
  16. System.out.println("All different dashboard share this same method !");
  17. }
  18.  
  19. public void setWorkFlowDashboard(WorkFlowDashboardBehavior dashBoardBehavior){
  20. behavior = dashBoardBehavior;
  21. }
  22. }
  23.  
  24.  
  25. @Configurable
  26. @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
  27. public class RnoBehavior implements WorkFlowDashboardBehavior{
  28.  
  29. @Autowired
  30. private ActionBulletinService actionBulletinService;
  31.  
  32. public RnoBehavior( ){
  33.  
  34. }
  35.  
  36. @Override
  37. public void WorkFlowBehaviour() {
  38. System.out.println("@@@@@@@@@@@@@@@@@ rno Behavior");
  39.  
  40. }
  41.  
  42. }
  43.  
  44.  
  45.  
  46. @Configurable
  47. @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
  48. public class TeamLeadDashBoard extends Dashboard{
  49.  
  50. public TeamLeadDashBoard(){
  51. behavior = new TeamLeadBehavior();
  52. }
  53.  
  54. @Override
  55. public void commonMethod(){
  56. System.out.println("@@@@ This is TeamLeadDashboard");
  57. }
  58. }
  59.  
  60. public interface WorkFlowDashboardBehavior {
  61.  
  62. public void WorkFlowBehaviour();
  63. }
  64.  
  65.  
  66.  
  67. @Scope("session")
  68. public class ActionBulletinManagedBean extends BasePageBean{
  69.  
  70. private static final long serialVersionUID = 1L;
  71.  
  72. @Autowired
  73. private ActionBulletinService actionBulletinService;
  74.  
  75. @Autowired
  76. @Getter @Setter
  77. private ActionBulletinPojo actionBulletinPojo;
  78.  
  79. @Autowired
  80. private Dashboard board ;
  81.  
  82. @PostConstruct
  83. @Override
  84. public void init() throws Exception {
  85.  
  86. setPageId(PageIds.BACKENDUSR_USER_MGNT);
  87.  
  88. actionBulletinPojo = null;
  89. actionBulletinPojo = new ActionBulletinPojo ();
  90.  
  91. actionBulletinPojo.backendTaskList = new ArrayList<OrderDetail>();
  92.  
  93. manageDashBoard();
  94.  
  95. }
  96.  
  97. public void manageDashBoard(){
  98. board = new TeamLeadDashBoard();
  99. board.commonMethod();
  100. actionBulletinPojo.setBackendTaskList(board.retrieveDashBoardList(getCurrentUser(), getCurrentUserRoles()));
  101. }
  102.  
  103.  
  104. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.