View Javadoc
1   package fr.ifremer.quadrige3.synchro.server.pages.admin;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Synchro server
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  
27  import fr.ifremer.quadrige3.synchro.server.components.progression.ProgressionPanel;
28  import fr.ifremer.quadrige3.synchro.server.pages.BasePage;
29  import fr.ifremer.quadrige3.synchro.server.service.ServiceLocator;
30  import fr.ifremer.quadrige3.synchro.server.vo.synchro.SynchroJobVO;
31  import org.apache.wicket.ajax.AjaxRequestTarget;
32  import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
33  import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
34  import org.apache.wicket.markup.html.basic.Label;
35  import org.apache.wicket.markup.html.list.ListItem;
36  import org.apache.wicket.markup.html.list.ListView;
37  import org.apache.wicket.model.IModel;
38  import org.apache.wicket.model.LoadableDetachableModel;
39  import org.apache.wicket.model.PropertyModel;
40  import org.apache.wicket.model.StringResourceModel;
41  import org.apache.wicket.request.mapper.parameter.PageParameters;
42  import org.apache.wicket.util.time.Duration;
43  
44  import java.util.List;
45  
46  @AuthorizeInstantiation("ROLE_ADMIN")
47  public class JobManagerPage extends BasePage {
48  
49      private static final long serialVersionUID = 1L;
50      
51      public JobManagerPage(PageParameters pageParameters) {
52          super(pageParameters);
53          
54          // Create models (list of progressionModel)
55          LoadableDetachableModel<List<SynchroJobVO>> importJobListModel = new LoadableDetachableModel<List<SynchroJobVO>>() {
56              private static final long serialVersionUID = 1L;
57  
58              @Override
59              protected List<SynchroJobVO> load() {
60                  return ServiceLocator.instance().getSynchroJobService().getImportationJobs();
61              }
62          };
63    
64          LoadableDetachableModel<List<SynchroJobVO>> exportJobListModel = new LoadableDetachableModel<List<SynchroJobVO>>() {
65              private static final long serialVersionUID = 1L;
66  
67              @Override
68              protected List<SynchroJobVO> load() {
69                  return ServiceLocator.instance().getSynchroJobService().getExportationJobs();
70              }
71          };
72   
73          add(new Label("importCount", new PropertyModel<Integer>(importJobListModel, "size")));
74          add(new Label("exportCount", new PropertyModel<Integer>(exportJobListModel, "size")));
75                  
76          // List of import jobs
77          ListView<SynchroJobVO> importListView = new ListView<SynchroJobVO>("importList", importJobListModel) {
78              private static final long serialVersionUID = 1L;
79  
80              @Override
81              protected void populateItem(ListItem<SynchroJobVO> item) {
82                  // User infos
83                  item.add(new Label("userId", new PropertyModel<Integer>(item.getModel(), "user.id")));
84                  item.add(new Label("lastname", new PropertyModel<String>(item.getModel(), "user.lastname")));
85                  item.add(new Label("firstname", new PropertyModel<String>(item.getModel(), "user.firstname")));
86                  
87                  // Progress bar
88                  String jobId = item.getModelObject().getId();
89                  ProgressionPanel progressionPanel = new ProgressionPanel("progress", new ImportProgressionModel(jobId)) {
90                      private static final long serialVersionUID = 1L;
91                      
92                      @Override
93                      public void onComplete(AjaxRequestTarget target) {
94                          stop(target);
95                      }
96                  };
97                  progressionPanel.setOutputMarkupId(true);
98                  progressionPanel.setOutputMarkupPlaceholderTag(true);
99                  item.add(progressionPanel);  
100             }
101         };
102         importListView.setOutputMarkupId(true);
103         add(importListView);
104         
105         // List of export jobs
106         ListView<SynchroJobVO> exportListView = new ListView<SynchroJobVO>("exportList", exportJobListModel) {
107             private static final long serialVersionUID = 1L;
108 
109             @Override
110             protected void populateItem(ListItem<SynchroJobVO> item) {
111                 // User infos
112                 item.add(new Label("userId", new PropertyModel<Integer>(item.getModel(), "user.id")));
113                 item.add(new Label("lastname", new PropertyModel<String>(item.getModel(), "user.lastname")));
114                 item.add(new Label("firstname", new PropertyModel<String>(item.getModel(), "user.firstname")));
115                 
116                 // Progress bar
117                 String jobId = item.getModelObject().getId();
118                 ProgressionPanel progressionPanel = new ProgressionPanel("progress", new ImportProgressionModel(jobId)) {
119                     private static final long serialVersionUID = 1L;
120                     
121                     @Override
122                     public void onComplete(AjaxRequestTarget target) {
123                         stop(target);
124                     }
125                 };
126                 progressionPanel.setOutputMarkupId(true);
127                 progressionPanel.setOutputMarkupPlaceholderTag(true);
128                 item.add(progressionPanel);  
129             }
130         };
131         exportListView.setOutputMarkupId(true);
132         add(exportListView);
133         
134         add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)));
135 
136         // Mask feedback panel, to avoid multiple message)
137         getFeedbackPanel().setVisibilityAllowed(false);
138     }
139     
140     /* -- internal methods -- */
141     protected IModel<String> getTitleModel() {
142         return new StringResourceModel("jobmanager.title", this, null);
143     }
144 
145 
146 }