View Javadoc
1   package fr.ifremer.quadrige2.synchro.server.pages.admin;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 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 java.util.List;
28  
29  import org.apache.wicket.ajax.AjaxRequestTarget;
30  import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
31  import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
32  import org.apache.wicket.markup.html.basic.Label;
33  import org.apache.wicket.markup.html.list.ListItem;
34  import org.apache.wicket.markup.html.list.ListView;
35  import org.apache.wicket.model.IModel;
36  import org.apache.wicket.model.LoadableDetachableModel;
37  import org.apache.wicket.model.PropertyModel;
38  import org.apache.wicket.model.StringResourceModel;
39  import org.apache.wicket.request.mapper.parameter.PageParameters;
40  import org.apache.wicket.util.time.Duration;
41  
42  import fr.ifremer.quadrige2.synchro.server.components.progression.ProgressionPanel;
43  import fr.ifremer.quadrige2.synchro.server.pages.BasePage;
44  import fr.ifremer.quadrige2.synchro.server.pages.synchro.model.ImportProgressionModel;
45  import fr.ifremer.quadrige2.synchro.server.service.ServiceLocator;
46  import fr.ifremer.quadrige2.synchro.server.vo.synchro.SynchroJobVO;
47  
48  @AuthorizeInstantiation("ROLE_ADMIN")
49  public class JobManagerPage extends BasePage {
50  
51      private static final long serialVersionUID = 1L;
52      
53      public JobManagerPage(PageParameters pageParameters) {
54          super(pageParameters);
55          
56          // Create models (list of progressionModel)
57          LoadableDetachableModel<List<SynchroJobVO>> importJobListModel = new LoadableDetachableModel<List<SynchroJobVO>>() {
58              private static final long serialVersionUID = 1L;
59  
60              @Override
61              protected List<SynchroJobVO> load() {
62                  return ServiceLocator.instance().getSynchroJobService().getImportationJobs();
63              }
64          };
65    
66          LoadableDetachableModel<List<SynchroJobVO>> exportJobListModel = new LoadableDetachableModel<List<SynchroJobVO>>() {
67              private static final long serialVersionUID = 1L;
68  
69              @Override
70              protected List<SynchroJobVO> load() {
71                  return ServiceLocator.instance().getSynchroJobService().getExportationJobs();
72              }
73          };
74   
75          add(new Label("importCount", new PropertyModel<Integer>(importJobListModel, "size")));
76          add(new Label("exportCount", new PropertyModel<Integer>(exportJobListModel, "size")));
77                  
78          // List of import jobs
79          ListView<SynchroJobVO> importListView = new ListView<SynchroJobVO>("importList", importJobListModel) {
80              private static final long serialVersionUID = 1L;
81  
82              @Override
83              protected void populateItem(ListItem<SynchroJobVO> item) {
84                  // User infos
85                  item.add(new Label("userId", new PropertyModel<Integer>(item.getModel(), "user.id")));
86                  item.add(new Label("lastname", new PropertyModel<String>(item.getModel(), "user.lastname")));
87                  item.add(new Label("firstname", new PropertyModel<String>(item.getModel(), "user.firstname")));
88                  
89                  // Progress bar
90                  String jobId = item.getModelObject().getId();
91                  ProgressionPanel progressionPanel = new ProgressionPanel("progress", new ImportProgressionModel(jobId)) {
92                      private static final long serialVersionUID = 1L;
93                      
94                      @Override
95                      public void onComplete(AjaxRequestTarget target) {
96                          stop(target);
97                      }
98                  };
99                  progressionPanel.setOutputMarkupId(true);
100                 progressionPanel.setOutputMarkupPlaceholderTag(true);
101                 item.add(progressionPanel);  
102             }
103         };
104         importListView.setOutputMarkupId(true);
105         add(importListView);
106         
107         // List of export jobs
108         ListView<SynchroJobVO> exportListView = new ListView<SynchroJobVO>("exportList", exportJobListModel) {
109             private static final long serialVersionUID = 1L;
110 
111             @Override
112             protected void populateItem(ListItem<SynchroJobVO> item) {
113                 // User infos
114                 item.add(new Label("userId", new PropertyModel<Integer>(item.getModel(), "user.id")));
115                 item.add(new Label("lastname", new PropertyModel<String>(item.getModel(), "user.lastname")));
116                 item.add(new Label("firstname", new PropertyModel<String>(item.getModel(), "user.firstname")));
117                 
118                 // Progress bar
119                 String jobId = item.getModelObject().getId();
120                 ProgressionPanel progressionPanel = new ProgressionPanel("progress", new ImportProgressionModel(jobId)) {
121                     private static final long serialVersionUID = 1L;
122                     
123                     @Override
124                     public void onComplete(AjaxRequestTarget target) {
125                         stop(target);
126                     }
127                 };
128                 progressionPanel.setOutputMarkupId(true);
129                 progressionPanel.setOutputMarkupPlaceholderTag(true);
130                 item.add(progressionPanel);  
131             }
132         };
133         exportListView.setOutputMarkupId(true);
134         add(exportListView);
135         
136         add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)));
137 
138         // Mask feedback panel, to avoid multiple message)
139         getFeedbackPanel().setVisibilityAllowed(false);
140     }
141     
142     /* -- internal methods -- */
143     protected IModel<String> getTitleModel() {
144         return new StringResourceModel("jobmanager.title", this, null);
145     }
146 
147 
148 }