1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.scheduler.internal

File SchedulerJobClassDocumentInitializer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
18
2
1
130
61
3
0.17
9
2
1.5

Classes

Class Line # Actions
SchedulerJobClassDocumentInitializer 46 18 0% 3 0
1.0100%
 

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 com.xpn.xwiki.plugin.scheduler.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.LocalDocumentReference;
29    import org.xwiki.sheet.SheetBinder;
30   
31    import com.xpn.xwiki.XWiki;
32    import com.xpn.xwiki.doc.XWikiDocument;
33    import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer;
34    import com.xpn.xwiki.objects.classes.BaseClass;
35    import com.xpn.xwiki.objects.classes.TextAreaClass;
36   
37    /**
38    * Update the XWiki.SchedulerJobClass document with all required information.
39    *
40    * @version $Id: eefa3fce79c5fdda78dd5848d56aa21b36c0fe4e $
41    * @since 6.1M1
42    */
43    @Component
44    @Named("XWiki.SchedulerJobSheet")
45    @Singleton
 
46    public class SchedulerJobClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
47    {
48    /**
49    * The name of the sheet used to display instances of the class.
50    */
51    public static final String SHEET_NAME = "SchedulerJobSheet";
52   
53    /**
54    * Local reference of the XWiki Scheduler Job Class representing a job that can be scheduled by this plugin.
55    */
56    public static final LocalDocumentReference XWIKI_JOB_CLASSREFERENCE = new LocalDocumentReference(
57    XWiki.SYSTEM_SPACE, "SchedulerJobClass");
58   
59    private static final String FIELD_JOBNAME = "jobName";
60   
61    private static final String FIELD_JOBDESCRIPTION = "jobDescription";
62   
63    private static final String FIELD_JOBCLASS = "jobClass";
64   
65    private static final String FIELD_STATUS = "status";
66   
67    private static final String FIELD_CRON = "cron";
68   
69    private static final String FIELD_SCRIPT = "script";
70   
71    private static final String FIELD_CONTEXTUSER = "contextUser";
72   
73    private static final String FIELD_CONTEXTLANG = "contextLang";
74   
75    private static final String FIELD_CONTEXTDATABASE = "contextDatabase";
76   
77    /**
78    * Used to bind a class to a document sheet.
79    */
80    @Inject
81    @Named("class")
82    private SheetBinder classSheetBinder;
83   
84    /**
85    * Default constructor.
86    */
 
87  7 toggle public SchedulerJobClassDocumentInitializer()
88    {
89    // Since we can`t get the main wiki here, this is just to be able to use the Abstract class.
90    // getDocumentReference() returns the actual main wiki document reference.
91  7 super(XWiki.SYSTEM_SPACE, XWIKI_JOB_CLASSREFERENCE.getName());
92    }
93   
 
94  8 toggle @Override
95    public boolean updateDocument(XWikiDocument document)
96    {
97  8 boolean needsUpdate = false;
98   
99    // Add missing class fields
100  8 BaseClass baseClass = document.getXClass();
101   
102  8 needsUpdate |= baseClass.addTextField(FIELD_JOBNAME, "Job Name", 60);
103  8 needsUpdate |= baseClass.addTextAreaField(FIELD_JOBDESCRIPTION, "Job Description", 45, 10);
104  8 needsUpdate |= baseClass.addTextField(FIELD_JOBCLASS, "Job Class", 60);
105  8 needsUpdate |= baseClass.addTextField(FIELD_STATUS, "Status", 30);
106  8 needsUpdate |= baseClass.addTextField(FIELD_CRON, "Cron Expression", 30);
107   
108    // This field contains groovy script and is thus of tpye PureText.
109    // TODO: In the future, add the ability to provide wiki markup so that all script languages can be supported
110    // and not only Groovy. When this is done, convert this field to "Text".
111  8 needsUpdate |= baseClass.addTextAreaField(FIELD_SCRIPT, "Job Script", 60, 10,
112    TextAreaClass.ContentType.PURE_TEXT);
113  8 needsUpdate |= baseClass.addTextField(FIELD_CONTEXTUSER, "Job execution context user", 30);
114  8 needsUpdate |= baseClass.addTextField(FIELD_CONTEXTLANG, "Job execution context lang", 30);
115  8 needsUpdate |= baseClass.addTextField(FIELD_CONTEXTDATABASE, "Job execution context database", 30);
116   
117    // Add missing document fields
118  8 needsUpdate |= setClassDocumentFields(document, "XWiki Scheduler Job Class");
119   
120    // Use SchedulerJobSheet to display documents having SchedulerJobClass objects if no other class sheet is
121    // specified.
122  8 if (this.classSheetBinder.getSheets(document).isEmpty()) {
123  6 String wikiName = document.getDocumentReference().getWikiReference().getName();
124  6 DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, SHEET_NAME);
125  6 needsUpdate |= this.classSheetBinder.bind(document, sheet);
126    }
127   
128  8 return needsUpdate;
129    }
130    }