|
34 | 34 | @Scope("session") |
35 | 35 | public class EntityApiController implements InitializingBean, DisposableBean, FileSystemEventListener { |
36 | 36 |
|
37 | | - @Autowired |
38 | | - private EnvironmentConfiguration environmentConfiguration; |
39 | | - |
40 | | - @Autowired |
41 | | - private DataHubService dataHubService; |
42 | | - |
43 | | - @Autowired |
44 | | - private EntityManagerService entityManagerService; |
45 | | - |
46 | | - @Autowired |
47 | | - private FileSystemWatcherService watcherService; |
48 | | - |
49 | | - @Autowired |
50 | | - private SyncStatusService syncStatusService; |
51 | | - |
52 | | - @RequestMapping(method = RequestMethod.GET) |
53 | | - @ResponseBody |
54 | | - public List<EntityModel> getEntities(HttpSession session) { |
55 | | - LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
56 | | - List<EntityModel> entities = entityManagerService.getEntities(); |
57 | | - loginForm.setEntities(entities); |
58 | | - return entities; |
59 | | - } |
60 | | - |
61 | | - @RequestMapping(value = "display", method = RequestMethod.POST) |
62 | | - @ResponseBody |
63 | | - public EntityModel displayEntity(@RequestBody String entityName, HttpSession session) { |
64 | | - LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
65 | | - loginForm.selectEntity(entityName); |
66 | | - |
67 | | - return loginForm.getSelectedEntity(); |
68 | | - } |
69 | | - |
70 | | - @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { |
71 | | - MediaType.APPLICATION_JSON_UTF8_VALUE }) |
72 | | - @ResponseBody |
73 | | - public LoginForm saveEntity(@RequestBody EntityForm entityForm, BindingResult bindingResult, HttpSession session) { |
74 | | - LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
75 | | - List<EntityModel> entities = loginForm.getEntities(); |
76 | | - |
77 | | - entityForm.validate(entities); |
78 | | - |
79 | | - EntityModel entityModel = entityManagerService.createEntity(entityForm.getEntityName(), |
80 | | - entityForm.getInputFlowName(), entityForm.getHarmonizeFlowName(), entityForm.getPluginFormat(), |
81 | | - entityForm.getDataFormat()); |
82 | | - |
83 | | - entities.add(entityModel); |
84 | | - loginForm.setSelectedEntity(entityModel); |
85 | | - return loginForm; |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * Get a list of entities that has changed. This API does not return until a |
90 | | - * change has occurred. |
91 | | - * |
92 | | - * @param session |
93 | | - * @return |
94 | | - */ |
95 | | - @RequestMapping(value = "status-change", method = RequestMethod.GET) |
96 | | - public LoginForm getStatusChange(HttpServletRequest request) { |
97 | | - HttpSession session = request.getSession(); |
98 | | - |
99 | | - synchronized (syncStatusService) { |
100 | | - try { |
101 | | - syncStatusService.wait(); |
102 | | - } catch (InterruptedException e) { |
103 | | - } |
104 | | - |
105 | | - // refresh the list of entities saved in the session |
106 | | - LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
107 | | - if (null == loginForm) { |
108 | | - loginForm = new LoginForm(); |
109 | | - } |
110 | | - |
111 | | - // add checking if data hub is installed and the server is |
112 | | - // acceptable. Something may have changed the server or removed the |
113 | | - // data hub outside the app |
114 | | - loginForm.setInstalled(dataHubService.isInstalled()); |
115 | | - loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable()); |
116 | | - if (loginForm.isInstalled()) { |
117 | | - List<EntityModel> entities = entityManagerService.getEntities(); |
118 | | - loginForm.setEntities(entities); |
119 | | - loginForm.refreshSelectedEntity(); |
120 | | - } |
121 | | - |
122 | | - // refresh the session loginForm |
123 | | - session.setAttribute("loginForm", loginForm); |
124 | | - |
125 | | - return loginForm; |
126 | | - } |
127 | | - } |
128 | | - |
129 | | - @Override |
130 | | - public void afterPropertiesSet() throws Exception { |
131 | | - String pluginDir = environmentConfiguration.getUserPluginDir(); |
132 | | - watcherService.watch(pluginDir, this); |
133 | | - } |
134 | | - |
135 | | - @Override |
136 | | - public void destroy() throws Exception { |
137 | | - synchronized (syncStatusService) { |
138 | | - syncStatusService.notifyAll(); |
139 | | - } |
140 | | - } |
141 | | - |
142 | | - @Override |
143 | | - public void onWatchEvent(Path path, WatchEvent<Path> event) { |
144 | | - synchronized (syncStatusService) { |
145 | | - syncStatusService.notifyAll(); |
146 | | - } |
147 | | - } |
| 37 | + @Autowired |
| 38 | + private EnvironmentConfiguration environmentConfiguration; |
| 39 | + |
| 40 | + @Autowired |
| 41 | + private DataHubService dataHubService; |
| 42 | + |
| 43 | + @Autowired |
| 44 | + private EntityManagerService entityManagerService; |
| 45 | + |
| 46 | + @Autowired |
| 47 | + private FileSystemWatcherService watcherService; |
| 48 | + |
| 49 | + @Autowired |
| 50 | + private SyncStatusService syncStatusService; |
| 51 | + |
| 52 | + @RequestMapping(method = RequestMethod.GET) |
| 53 | + @ResponseBody |
| 54 | + public List<EntityModel> getEntities(HttpSession session) { |
| 55 | + LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
| 56 | + List<EntityModel> entities = entityManagerService.getEntities(); |
| 57 | + loginForm.setEntities(entities); |
| 58 | + return entities; |
| 59 | + } |
| 60 | + |
| 61 | + @RequestMapping(value = "display", method = RequestMethod.POST) |
| 62 | + @ResponseBody |
| 63 | + public EntityModel displayEntity(@RequestBody String entityName, HttpSession session) { |
| 64 | + LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
| 65 | + loginForm.selectEntity(entityName); |
| 66 | + |
| 67 | + return loginForm.getSelectedEntity(); |
| 68 | + } |
| 69 | + |
| 70 | + @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { |
| 71 | + MediaType.APPLICATION_JSON_UTF8_VALUE }) |
| 72 | + @ResponseBody |
| 73 | + public LoginForm saveEntity(@RequestBody EntityForm entityForm, BindingResult bindingResult, HttpSession session) { |
| 74 | + LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
| 75 | + List<EntityModel> entities = loginForm.getEntities(); |
| 76 | + |
| 77 | + entityForm.validate(entities); |
| 78 | + |
| 79 | + EntityModel entityModel = entityManagerService.createEntity(entityForm.getEntityName(), |
| 80 | + entityForm.getInputFlowName(), entityForm.getHarmonizeFlowName(), entityForm.getPluginFormat(), |
| 81 | + entityForm.getDataFormat()); |
| 82 | + |
| 83 | + entities.add(entityModel); |
| 84 | + loginForm.setSelectedEntity(entityModel); |
| 85 | + return loginForm; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Get a list of entities that has changed. This API does not return until a |
| 90 | + * change has occurred. |
| 91 | + * |
| 92 | + * @param session |
| 93 | + * @return |
| 94 | + */ |
| 95 | + @RequestMapping(value = "status-change", method = RequestMethod.GET) |
| 96 | + public LoginForm getStatusChange(HttpServletRequest request) { |
| 97 | + HttpSession session = request.getSession(); |
| 98 | + |
| 99 | + synchronized (syncStatusService) { |
| 100 | + try { |
| 101 | + syncStatusService.wait(); |
| 102 | + } |
| 103 | + catch (InterruptedException e) { |
| 104 | + } |
| 105 | + |
| 106 | + // refresh the list of entities saved in the session |
| 107 | + LoginForm loginForm = (LoginForm) session.getAttribute("loginForm"); |
| 108 | + if (null == loginForm) { |
| 109 | + loginForm = new LoginForm(); |
| 110 | + } |
| 111 | + |
| 112 | + // add checking if data hub is installed and the server is |
| 113 | + // acceptable. Something may have changed the server or removed the |
| 114 | + // data hub outside the app |
| 115 | + loginForm.setInstalled(dataHubService.isInstalled()); |
| 116 | + loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable()); |
| 117 | + if (loginForm.isInstalled()) { |
| 118 | + List<EntityModel> entities = entityManagerService.getEntities(); |
| 119 | + loginForm.setEntities(entities); |
| 120 | + loginForm.refreshSelectedEntity(); |
| 121 | + } |
| 122 | + |
| 123 | + // refresh the session loginForm |
| 124 | + session.setAttribute("loginForm", loginForm); |
| 125 | + |
| 126 | + return loginForm; |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public void afterPropertiesSet() throws Exception { |
| 132 | + String pluginDir = environmentConfiguration.getUserPluginDir(); |
| 133 | + watcherService.watch(pluginDir, this); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public void destroy() throws Exception { |
| 138 | + synchronized (syncStatusService) { |
| 139 | + syncStatusService.notifyAll(); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void onWatchEvent(Path path, WatchEvent<Path> event) { |
| 145 | + synchronized (syncStatusService) { |
| 146 | + syncStatusService.notifyAll(); |
| 147 | + } |
| 148 | + } |
148 | 149 | } |
0 commit comments