1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest

File XWikiJobResource.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
14
1
1
88
42
4
0.29
14
1
4

Classes

Class Line # Actions
XWikiJobResource 41 14 0% 4 3
0.8421052784.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rest;
21   
22    import java.io.UnsupportedEncodingException;
23    import java.net.URLDecoder;
24    import java.util.ArrayList;
25    import java.util.List;
26   
27    import javax.inject.Inject;
28    import javax.ws.rs.WebApplicationException;
29    import javax.ws.rs.core.Response;
30   
31    import org.xwiki.job.Job;
32    import org.xwiki.job.JobExecutor;
33    import org.xwiki.job.JobStatusStore;
34    import org.xwiki.job.event.status.JobStatus;
35   
36    /**
37    * Base class for all job-related resources.
38    *
39    * @version $Id: 1f11a44b5f42fd7e7c7fd0ef891d32a3524c7464 $
40    */
 
41    public class XWikiJobResource extends XWikiResource
42    {
43    /**
44    * Used to retrieve the job that is currently being executed.
45    */
46    @Inject
47    protected JobExecutor jobExecutor;
48   
49    /**
50    * Used to retrieve the job status.
51    */
52    @Inject
53    protected JobStatusStore jobStore;
54   
 
55  42 toggle protected JobStatus getRealJobStatus(String jobId) throws WebApplicationException
56    {
57  42 JobStatus jobStatus;
58   
59  42 String[] idArray = jobId.split("/");
60   
61  42 List<String> id = new ArrayList<>(idArray.length);
62   
63    // Unescape id sections
64  42 for (String idElement : idArray) {
65  126 try {
66  126 id.add(URLDecoder.decode(idElement, "UTF8"));
67    } catch (UnsupportedEncodingException e) {
68  0 throw new WebApplicationException(e);
69    }
70    }
71   
72    // Search job
73  42 Job job = this.jobExecutor.getJob(id);
74  42 if (job == null) {
75  27 jobStatus = this.jobStore.getJobStatus(id);
76    } else {
77  15 jobStatus = job.getStatus();
78    }
79   
80  42 if (jobStatus == null) {
81  0 throw new WebApplicationException(Response.Status.NOT_FOUND);
82    }
83   
84  42 return jobStatus;
85   
86    }
87   
88    }