| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.wiki.template.internal; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.Collection; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
import javax.inject.Inject; |
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Provider; |
| 29 |
|
import javax.inject.Singleton; |
| 30 |
|
|
| 31 |
|
import org.xwiki.component.annotation.Component; |
| 32 |
|
import org.xwiki.query.Query; |
| 33 |
|
import org.xwiki.query.QueryManager; |
| 34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
| 35 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 36 |
|
import org.xwiki.wiki.manager.WikiManager; |
| 37 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
| 38 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupException; |
| 39 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupProvider; |
| 40 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJob; |
| 41 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJobException; |
| 42 |
|
import org.xwiki.wiki.provisioning.WikiProvisioningJobExecutor; |
| 43 |
|
import org.xwiki.wiki.template.WikiTemplateManager; |
| 44 |
|
import org.xwiki.wiki.template.WikiTemplateManagerException; |
| 45 |
|
import org.xwiki.wiki.template.WikiTemplatePropertyGroup; |
| 46 |
|
|
| 47 |
|
import com.xpn.xwiki.XWikiContext; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@link |
| 51 |
|
|
| 52 |
|
@version |
| 53 |
|
@since |
| 54 |
|
|
| 55 |
|
@Component |
| 56 |
|
@Singleton |
| |
|
| 44.2% |
Uncovered Elements: 24 (43) |
Complexity: 15 |
Complexity Density: 0.43 |
|
| 57 |
|
public class DefaultWikiTemplateManager implements WikiTemplateManager |
| 58 |
|
{ |
| 59 |
|
|
| 60 |
|
@link |
| 61 |
|
|
| 62 |
|
@Inject |
| 63 |
|
private Provider<XWikiContext> xcontextProvider; |
| 64 |
|
|
| 65 |
|
@Inject |
| 66 |
|
@Named("default") |
| 67 |
|
private WikiManager wikiManager; |
| 68 |
|
|
| 69 |
|
@Inject |
| 70 |
|
private WikiDescriptorManager wikiDescriptorManager; |
| 71 |
|
|
| 72 |
|
@Inject |
| 73 |
|
private QueryManager queryManager; |
| 74 |
|
|
| 75 |
|
@Inject |
| 76 |
|
private WikiProvisioningJobExecutor wikiProvisionerExecutor; |
| 77 |
|
|
| 78 |
|
@Inject |
| 79 |
|
@Named("template") |
| 80 |
|
private WikiPropertyGroupProvider templateWikiPropertyGroupProvider; |
| 81 |
|
|
| 82 |
|
private String errorMessageNoDescriptor = "Failed to get the descriptor for [%s]."; |
| 83 |
|
|
| |
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 84 |
4 |
@Override... |
| 85 |
|
public Collection<WikiDescriptor> getTemplates() throws WikiTemplateManagerException |
| 86 |
|
{ |
| 87 |
4 |
List<WikiDescriptor> result = new ArrayList<WikiDescriptor>(); |
| 88 |
|
|
| 89 |
4 |
try { |
| 90 |
4 |
Query query = this.queryManager.createQuery( |
| 91 |
|
"from doc.object(WikiManager.WikiTemplateClass) as descriptor where doc.name like 'XWikiServer%' " |
| 92 |
|
+ "and descriptor.iswikitemplate = 1", Query.XWQL); |
| 93 |
4 |
query.setWiki(xcontextProvider.get().getMainXWiki()); |
| 94 |
4 |
List<String> documentNames = query.execute(); |
| 95 |
|
|
| 96 |
4 |
if (documentNames != null && !documentNames.isEmpty()) { |
| 97 |
3 |
for (String documentName : documentNames) { |
| 98 |
3 |
String id = documentName.substring("XWiki.XWikiServer".length()).toLowerCase(); |
| 99 |
3 |
result.add(wikiDescriptorManager.getById(id)); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
} catch (Exception e) { |
| 103 |
0 |
throw new WikiTemplateManagerException("Failed to locate XWiki.XWikiServerClass documents", e); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
4 |
return result; |
| 107 |
|
} |
| 108 |
|
|
| |
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 109 |
3 |
@Override... |
| 110 |
|
public void setTemplate(String wikiId, boolean value) throws WikiTemplateManagerException |
| 111 |
|
{ |
| 112 |
3 |
try { |
| 113 |
|
|
| 114 |
3 |
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId); |
| 115 |
|
|
| 116 |
3 |
WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup( |
| 117 |
|
WikiTemplatePropertyGroupProvider.GROUP_NAME); |
| 118 |
|
|
| 119 |
3 |
group.setTemplate(value); |
| 120 |
|
|
| 121 |
3 |
templateWikiPropertyGroupProvider.save(group, wikiId); |
| 122 |
|
} catch (WikiPropertyGroupException e) { |
| 123 |
0 |
throw new WikiTemplateManagerException(String.format("Failed to save the property group [%s]", |
| 124 |
|
WikiTemplatePropertyGroupProvider.GROUP_NAME), e); |
| 125 |
|
} catch (WikiManagerException e) { |
| 126 |
0 |
throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 130 |
0 |
@Override... |
| 131 |
|
public boolean isTemplate(String wikiId) throws WikiTemplateManagerException |
| 132 |
|
{ |
| 133 |
0 |
try { |
| 134 |
|
|
| 135 |
0 |
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId); |
| 136 |
|
|
| 137 |
0 |
WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup( |
| 138 |
|
WikiTemplatePropertyGroupProvider.GROUP_NAME); |
| 139 |
|
|
| 140 |
0 |
return group.isTemplate(); |
| 141 |
|
} catch (WikiManagerException e) { |
| 142 |
0 |
throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e); |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 146 |
0 |
@Override... |
| 147 |
|
public WikiProvisioningJob createWikiFromTemplate(String newWikiId, String newWikiAlias, String templateId, |
| 148 |
|
String ownerId, boolean failOnExist) throws WikiTemplateManagerException |
| 149 |
|
{ |
| 150 |
0 |
try { |
| 151 |
|
|
| 152 |
0 |
WikiDescriptor descriptor = wikiManager.create(newWikiId, newWikiAlias, failOnExist); |
| 153 |
|
|
| 154 |
|
|
| 155 |
0 |
descriptor.setOwnerId(ownerId); |
| 156 |
0 |
wikiDescriptorManager.saveDescriptor(descriptor); |
| 157 |
|
|
| 158 |
|
|
| 159 |
0 |
return applyTemplate(newWikiId, templateId); |
| 160 |
|
} catch (WikiManagerException e) { |
| 161 |
0 |
throw new WikiTemplateManagerException(e.getMessage(), e); |
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 165 |
0 |
@Override... |
| 166 |
|
public WikiProvisioningJob applyTemplate(String wikiId, String templateId) throws WikiTemplateManagerException |
| 167 |
|
{ |
| 168 |
0 |
try { |
| 169 |
0 |
return wikiProvisionerExecutor.createAndExecuteJob(wikiId, TemplateWikiProvisioningJob.JOBTYPE, templateId); |
| 170 |
|
} catch (WikiProvisioningJobException e) { |
| 171 |
0 |
throw new WikiTemplateManagerException(e.getMessage(), e); |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 175 |
0 |
@Override... |
| 176 |
|
public WikiProvisioningJob getWikiProvisioningJob(List<String> jobId) throws WikiTemplateManagerException |
| 177 |
|
{ |
| 178 |
0 |
try { |
| 179 |
0 |
return wikiProvisionerExecutor.getJob(jobId); |
| 180 |
|
} catch (WikiProvisioningJobException e) { |
| 181 |
0 |
throw new WikiTemplateManagerException(e.getMessage(), e); |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
} |