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

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

Fixes #583: Allow changing the array design of a raw bioasay when it has raw data

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.4 KB
Line 
1<%-- $Id: view_job.jsp 3523 2007-06-20 12:32:41Z 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">Plugin</td>
226        <td>
227          <base:propertyvalue item="<%=job%>" property="pluginDefinition.name" />
228        </td>
229      </tr>
230      <tr valign=top>
231        <td class="prompt">Configuration</td>
232        <td>
233          <base:propertyvalue item="<%=job%>" property="pluginConfiguration.name" />
234        </td>
235      </tr>
236      </table>
237      </t:tab>
238     
239      <%
240      if (job.getStackTrace() != null)
241      {
242        %>
243        <t:tab id="stacktrace" title="Stack trace" helpid="job.view.stacktrace">
244          <div style="font-family: monospace">
245          <%=HTML.niceFormat(job.getStackTrace())%>
246          </div>
247        </t:tab>
248        <%
249      }
250      %>
251 
252      <t:tab id="parameters" title="Parameters" helpid="job.view.parameters">
253        <h4>Job parameters</h4>
254        <table class="form" cellspacing=0>
255        <%
256        List<String> names = new java.util.ArrayList<String>(job.getParameterNames());
257        Collections.sort(names);
258        for (String name : names)
259        {
260          StringBuilder sb = new StringBuilder();
261          String displayValue = "";
262          String description = "";
263          try
264          {
265            ParameterInfo pi = job.getParameterInfo(name);
266            if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
267            description = HTML.encodeTags(pi.getDescription());
268            List<?> values = pi.getValues();
269            int i = 0;
270            for (Object value : values)
271            {
272              if (value != null)
273              {
274                if (i > 0) sb.append(", ");
275                i++;
276                if (value instanceof BasicItem)
277                {
278                  BasicItem item = (BasicItem)value;
279                  String itemName = "";
280                  if (item instanceof File)
281                  {
282                    itemName = ((File)item).getPath().toString();
283                  }
284                  else if (item instanceof Nameable)
285                  {
286                    itemName = ((Nameable)item).getName();
287                  }
288                  else
289                  {
290                    itemName = item.toString();
291                  }
292                  sb.append(HTML.encodeTags(itemName));
293                }
294                else if (value instanceof Date)
295                {
296                  sb.append(dateFormatter.format((Date)value));
297                }
298                else
299                {
300                  sb.append(HTML.encodeTags(value.toString()));
301                }
302              }
303            }
304            displayValue = sb.toString();
305          }
306          catch (Throwable ex)
307          {
308            displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
309          }
310          %>
311          <tr>
312            <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
313            <td>
314              <%=displayValue%>
315            </td>
316          </tr>
317          <%
318        }
319        %>
320        </table>
321
322        <%
323        if (!readCurrentConfig)
324        {
325          %>
326          <h4>Plugin configuration parameters</h4>
327          <i>- denied -</i>
328          <%
329        }
330        else if (currentConfig != null)
331        {
332          %>
333          <h4>Plugin configuration parameters</h4>
334          <table class="form" cellspacing=0>
335          <tr>
336            <td class="prompt"><span 
337              title="The version of the parmeters used for this job, current version in paranthesis">Parameter version</span></td>
338            <td><%=parameterVersion%> (<%=latestParameterVersion %>)</td>
339          </tr>
340          <%
341          names = new java.util.ArrayList<String>(currentConfig.getParameterNames(parameterVersion));
342          Collections.sort(names);
343          for (String name : names)
344          {
345            StringBuilder sb = new StringBuilder();
346            String displayValue = "";
347            String description = "";
348            try
349            {
350              ParameterInfo pi = currentConfig.getParameterInfo(name, parameterVersion);
351              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
352              description = HTML.encodeTags(pi.getDescription());
353              List<?> values = pi.getValues();
354              int i = 0;
355              for (Object value : values)
356              {
357                if (value != null)
358                {
359                  if (i > 0) sb.append(", ");
360                  i++;
361                  if (value instanceof BasicItem)
362                  {
363                    BasicItem item = (BasicItem)value;
364                    String itemName = "";
365                    if (item instanceof File)
366                    {
367                      itemName = ((File)item).getPath().toString();
368                    }
369                    else if (item instanceof Nameable)
370                    {
371                      itemName = ((Nameable)item).getName();
372                    }
373                    else
374                    {
375                      itemName = item.toString();
376                    }
377                    sb.append(HTML.encodeTags(itemName));
378                  }
379                  else if (value instanceof Date)
380                  {
381                    sb.append(dateFormatter.format((Date)value));
382                  }
383                  else
384                  {
385                    sb.append(HTML.encodeTags(value.toString()));
386                  }
387                }
388              }
389              displayValue = sb.toString();
390            }
391            catch (Throwable ex)
392            {
393              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
394            }
395            %>
396            <tr>
397              <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
398              <td>
399                <%=displayValue%>
400              </td>
401            </tr>
402            <%
403          }
404          %>
405          </table>
406          <%
407        }
408        %>
409       
410      </t:tab>
411      </t:tabcontrol>
412 
413    <base:buttongroup align="center">
414      <%
415      if (autoUpdate)
416      {
417        %>
418        <base:button onclick="location.reload()" title="Refresh" image="refresh.gif" />
419        <%
420      }
421      %>
422      <%
423      if (job.getStatus() == Job.Status.ERROR && job.getJobType() == Job.Type.RUN_PLUGIN)
424      {
425        %>
426        <base:button onclick="restartJob()" title="Restart job" image="refresh.gif" />
427        <%
428      }
429      %>
430      <base:button onclick="window.close()" title="Close" />
431     
432    </base:buttongroup>
433    <center>
434    <%
435    if (autoUpdate)
436    {
437      %>
438      <i>(This page will automatically refresh itself every 10 seconds)</i>
439      <%
440    }
441    %></center>
442  </base:body>
443  </base:page>
444  <%
445}
446finally
447{
448  if (dc != null) dc.close();
449}
450
451%>
Note: See TracBrowser for help on using the repository browser.