source: trunk/www/views/jobs/view_job.jsp @ 3593

Last change on this file since 3593 was 3593, checked in by Nicklas Nordborg, 16 years ago

Fixes #692: Jobs that are part of an experiment should use permissions from that experiment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.7 KB
Line 
1<%-- $Id: view_job.jsp 3593 2007-07-24 07:55:04Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.SystemItems"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Job"
35  import="net.sf.basedb.core.BasicItem"
36  import="net.sf.basedb.core.Nameable"
37  import="net.sf.basedb.core.File"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.PluginDefinition"
43  import="net.sf.basedb.core.PluginConfiguration"
44  import="net.sf.basedb.core.ParameterInfo"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.util.Values"
50  import="net.sf.basedb.util.formatter.Formatter"
51  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
52  import="java.util.Date"
53  import="java.util.Map"
54  import="java.util.Set"
55  import="java.util.List"
56  import="java.util.Collections"
57%>
58<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
59<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
60<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
61<%!
62  private static final Item itemType = Item.JOB;
63  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
64%>
65<%
66final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
67final String ID = sc.getId();
68final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
69final int itemId = cc.getId();
70final String tab = Values.getString(request.getParameter("tab"), "properties");
71final float scale = Base.getScale(sc);
72final DbControl dc = sc.newDbControl();
73try
74{
75  Job job = Job.getById(dc, itemId);
76  String title = "View job -- " + HTML.encodeTags(job.getName());;
77 
78  final boolean writePermission = job.hasPermission(Permission.WRITE);
79  final boolean deletePermission = job.hasPermission(Permission.DELETE);
80 
81  boolean readCurrentConfig = true;
82  PluginConfiguration currentConfig = null;
83  try
84  {
85    currentConfig = job.getPluginConfiguration();
86  }
87  catch (PermissionDeniedException ex)
88  {
89    readCurrentConfig = false;
90  }
91
92  int parameterVersion = job.getParameterVersion();
93  int latestParameterVersion = currentConfig == null ? parameterVersion : currentConfig.getParameterVersion();
94
95  final Job.Status status = job.getStatus();
96  final boolean autoUpdate = status == Job.Status.WAITING || 
97    status == Job.Status.PREPARED || status == Job.Status.EXECUTING;
98  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
99  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
100  %>
101
102  <base:page type="popup" title="<%=title%>"> 
103  <base:head scripts="tabcontrol.js" styles="tabcontrol.css,progressbar.css">
104  <script language="JavaScript">
105  function autoUpdate()
106  {
107    var autoUpdate = <%=autoUpdate ? "true" : "false"%>;
108    if (autoUpdate)
109    {
110      setTimeout('location.reload()', 10000);
111    }
112  }
113  function restartJob()
114  {
115    var parameterVersion = <%=parameterVersion%>;
116    var latestVersion = <%=latestParameterVersion%>;
117    var useLatestConfiguration = 0;
118    if (parameterVersion != latestVersion)
119    {
120      var msg = 'The configuration parameters for the plugin has changed since\n';
121      msg += 'the job was added to the job queue. Do you want to use the new\n';
122      msg += 'configuration parameters?\n\n';
123      msg += 'Ok / Yes = Use the new parameters (version = '+latestVersion + ')\n';
124      msg += 'Cancel / No = Use the current parameters (version = ' + parameterVersion + ')';
125      if (confirm(msg)) useLatestConfiguration = 1;
126    }
127    location.href = 'index.jsp?ID=<%=ID%>&cmd=RestartJob&item_id=<%=itemId%>&useLatestConfiguration='+useLatestConfiguration;
128  }
129  </script>
130  </base:head>
131  <base:body onload="autoUpdate()">
132   
133    <h3 class="docked"><%=title%> <base:help tabcontrol="main" /></h3>
134    <t:tabcontrol id="main" active="<%=tab%>" position="bottom" contentstyle="<%="height: "+(int)(scale*320)+"px;"%>">
135    <t:tab id="properties" title="Properties" helpid="job.view.properties">
136
137      <%
138      if (job.isRemoved())
139      {
140        %>
141        <div class="itemstatus">
142          <base:icon image="deleted.gif" 
143            visible="<%=job.isRemoved()%>"> This item has been flagged for deletion<br></base:icon>
144        </div>
145        <%
146      }
147      %>
148      <table class="form" cellspacing=0>
149      <tr>
150        <td class="prompt">Name</td>
151        <td><%=HTML.encodeTags(job.getName())%></td>
152      </tr>
153      <tr>
154        <td class="prompt">Description</td>
155        <td><%=HTML.niceFormat(job.getDescription())%></td>
156      </tr>
157      <tr valign="top">
158        <td class="prompt">Priority</td>
159        <td>
160          <%=job.getPriority()%> (1 = highest, 10 = lowest)
161        </td>
162      </tr>
163      <tr valign="top">
164        <td class="prompt">Status</td>
165        <td>
166          <%=job.getStatus()%>: <%=HTML.niceFormat(job.getStatusMessage())%>
167        </td>
168      </tr>
169      <tr valign=top>
170        <td class="prompt">Percent complete</td>
171        <td>
172          <table border=0 cellspacing=0 cellpadding=0>
173          <tr>
174          <td width="100">
175            <table width="100" class="progressbar" border=0 cellspacing=0 cellpadding=0>
176            <tr>
177              <%
178              int percent = job.getPercentComplete();
179              if (percent > 0) 
180              {
181                %>
182                <td width="<%=percent%>%" class="done">&nbsp;</td>
183                <% 
184              }
185              if (percent < 100) 
186              { 
187                %>
188                <td width="<%=100-percent%>%" class="remain">&nbsp;</td>
189                <%
190              }
191              %>
192            </tr>
193            </table>
194          </td>
195          <td>&nbsp;<%=percent%>%</td>
196          </tr>
197          </table>
198        </td>
199      </tr>
200      <tr valign="top">
201        <td class="prompt">Created</td>
202        <td>
203          <%=dateTimeFormatter.format(job.getCreated())%>
204        </td>
205      </tr>
206      <tr valign="top">
207        <td class="prompt">Started</td>
208        <td>
209          <%=dateTimeFormatter.format(job.getStarted())%>
210        </td>
211      </tr>
212      <tr valign="top">
213        <td class="prompt">Ended</td>
214        <td>
215          <%=dateTimeFormatter.format(job.getEnded())%>
216        </td>
217      </tr>
218      <tr valign="top">
219        <td class="prompt">Server</td>
220        <td>
221          <%=HTML.encodeTags(job.getServer())%>
222        </td>
223      </tr>
224      <tr valign="top">
225        <td class="prompt">User</td>
226        <td>
227          <base:propertyvalue item="<%=job%>" property="owner.name" />
228        </td>
229      </tr>
230      <tr valign="top">
231        <td class="prompt">Experiment</td>
232        <td>
233          <base:propertyvalue item="<%=job%>" property="experiment.name" />
234        </td>
235      </tr>
236      <tr valign="top">
237        <td class="prompt">Plugin</td>
238        <td>
239          <base:propertyvalue item="<%=job%>" property="pluginDefinition.name" />
240        </td>
241      </tr>
242      <tr valign="top">
243        <td class="prompt">Configuration</td>
244        <td>
245          <base:propertyvalue item="<%=job%>" property="pluginConfiguration.name" />
246        </td>
247      </tr>
248      </table>
249      </t:tab>
250     
251      <%
252      if (job.getStackTrace() != null)
253      {
254        %>
255        <t:tab id="stacktrace" title="Stack trace" helpid="job.view.stacktrace">
256          <div style="font-family: monospace">
257          <%=HTML.niceFormat(job.getStackTrace())%>
258          </div>
259        </t:tab>
260        <%
261      }
262      %>
263 
264      <t:tab id="parameters" title="Parameters" helpid="job.view.parameters">
265        <h4>Job parameters</h4>
266        <table class="form" cellspacing=0>
267        <%
268        List<String> names = new java.util.ArrayList<String>(job.getParameterNames());
269        Collections.sort(names);
270        for (String name : names)
271        {
272          StringBuilder sb = new StringBuilder();
273          String displayValue = "";
274          String description = "";
275          try
276          {
277            ParameterInfo pi = job.getParameterInfo(name);
278            if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
279            description = HTML.encodeTags(pi.getDescription());
280            List<?> values = pi.getValues();
281            int i = 0;
282            for (Object value : values)
283            {
284              if (value != null)
285              {
286                if (i > 0) sb.append(", ");
287                i++;
288                if (value instanceof BasicItem)
289                {
290                  BasicItem item = (BasicItem)value;
291                  String itemName = "";
292                  if (item instanceof File)
293                  {
294                    itemName = ((File)item).getPath().toString();
295                  }
296                  else if (item instanceof Nameable)
297                  {
298                    itemName = ((Nameable)item).getName();
299                  }
300                  else
301                  {
302                    itemName = item.toString();
303                  }
304                  sb.append(HTML.encodeTags(itemName));
305                }
306                else if (value instanceof Date)
307                {
308                  sb.append(dateFormatter.format((Date)value));
309                }
310                else
311                {
312                  sb.append(HTML.encodeTags(value.toString()));
313                }
314              }
315            }
316            displayValue = sb.toString();
317          }
318          catch (Throwable ex)
319          {
320            displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
321          }
322          %>
323          <tr>
324            <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
325            <td>
326              <%=displayValue%>
327            </td>
328          </tr>
329          <%
330        }
331        %>
332        </table>
333
334        <%
335        if (!readCurrentConfig)
336        {
337          %>
338          <h4>Plugin configuration parameters</h4>
339          <i>- denied -</i>
340          <%
341        }
342        else if (currentConfig != null)
343        {
344          %>
345          <h4>Plugin configuration parameters</h4>
346          <table class="form" cellspacing=0>
347          <tr>
348            <td class="prompt"><span 
349              title="The version of the parmeters used for this job, current version in paranthesis">Parameter version</span></td>
350            <td><%=parameterVersion%> (<%=latestParameterVersion %>)</td>
351          </tr>
352          <%
353          names = new java.util.ArrayList<String>(currentConfig.getParameterNames(parameterVersion));
354          Collections.sort(names);
355          for (String name : names)
356          {
357            StringBuilder sb = new StringBuilder();
358            String displayValue = "";
359            String description = "";
360            try
361            {
362              ParameterInfo pi = currentConfig.getParameterInfo(name, parameterVersion);
363              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
364              description = HTML.encodeTags(pi.getDescription());
365              List<?> values = pi.getValues();
366              int i = 0;
367              for (Object value : values)
368              {
369                if (value != null)
370                {
371                  if (i > 0) sb.append(", ");
372                  i++;
373                  if (value instanceof BasicItem)
374                  {
375                    BasicItem item = (BasicItem)value;
376                    String itemName = "";
377                    if (item instanceof File)
378                    {
379                      itemName = ((File)item).getPath().toString();
380                    }
381                    else if (item instanceof Nameable)
382                    {
383                      itemName = ((Nameable)item).getName();
384                    }
385                    else
386                    {
387                      itemName = item.toString();
388                    }
389                    sb.append(HTML.encodeTags(itemName));
390                  }
391                  else if (value instanceof Date)
392                  {
393                    sb.append(dateFormatter.format((Date)value));
394                  }
395                  else
396                  {
397                    sb.append(HTML.encodeTags(value.toString()));
398                  }
399                }
400              }
401              displayValue = sb.toString();
402            }
403            catch (Throwable ex)
404            {
405              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
406            }
407            %>
408            <tr>
409              <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
410              <td>
411                <%=displayValue%>
412              </td>
413            </tr>
414            <%
415          }
416          %>
417          </table>
418          <%
419        }
420        %>
421       
422      </t:tab>
423      </t:tabcontrol>
424 
425    <base:buttongroup align="center">
426      <%
427      if (autoUpdate)
428      {
429        %>
430        <base:button onclick="location.reload()" title="Refresh" image="refresh.gif" />
431        <%
432      }
433      %>
434      <%
435      if (job.getStatus() == Job.Status.ERROR && job.getJobType() == Job.Type.RUN_PLUGIN)
436      {
437        %>
438        <base:button onclick="restartJob()" title="Restart job" image="refresh.gif" />
439        <%
440      }
441      %>
442      <base:button onclick="window.close()" title="Close" />
443     
444    </base:buttongroup>
445    <center>
446    <%
447    if (autoUpdate)
448    {
449      %>
450      <i>(This page will automatically refresh itself every 10 seconds)</i>
451      <%
452    }
453    %></center>
454  </base:body>
455  </base:page>
456  <%
457}
458finally
459{
460  if (dc != null) dc.close();
461}
462
463%>
Note: See TracBrowser for help on using the repository browser.