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

File DefaultWikiDeleter.java

 

Coverage histogram

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

Code metrics

2
11
1
1
81
44
4
0.36
11
1
4

Classes

Class Line # Actions
DefaultWikiDeleter 43 11 0% 4 2
0.8571428785.7%
 

Contributing tests

This file is covered by 2 tests. .

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.wiki.internal.manager;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
28    import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper;
29    import org.xwiki.wiki.manager.WikiManagerException;
30   
31    import com.xpn.xwiki.XWiki;
32    import com.xpn.xwiki.XWikiContext;
33    import com.xpn.xwiki.XWikiException;
34    import com.xpn.xwiki.doc.XWikiDocument;
35   
36    /**
37    * Default implementation of {@link WikiDeleter}.
38    *
39    * @version $Id: 67308a316c9407e615309fb3b4c6d25e2043773f $
40    */
41    @Component
42    @Singleton
 
43    public class DefaultWikiDeleter implements WikiDeleter
44    {
45    @Inject
46    private Provider<XWikiContext> xcontextProvider;
47   
48    @Inject
49    private WikiDescriptorManager wikiDescriptorManager;
50   
51    @Inject
52    private WikiDescriptorDocumentHelper descriptorDocumentHelper;
53   
 
54  5 toggle @Override
55    public void delete(String wikiId) throws WikiManagerException
56    {
57  5 XWikiContext context = xcontextProvider.get();
58  5 XWiki xwiki = context.getWiki();
59   
60    // Check if we try to delete the main wiki
61  5 if (wikiId.equals(wikiDescriptorManager.getMainWikiId())) {
62  1 throw new WikiManagerException("It's not allowed to delete the main wiki!");
63    }
64   
65    // Delete the database
66  4 try {
67  4 xwiki.getStore().deleteWiki(wikiId, context);
68    } catch (XWikiException e) {
69  0 throw new WikiManagerException(String.format("Error deleting the database [%s]", wikiId), e);
70    }
71   
72    // Delete the descriptor document
73  4 try {
74  4 XWikiDocument descriptorDocument = descriptorDocumentHelper.getDocumentFromWikiId(wikiId);
75  4 xwiki.deleteDocument(descriptorDocument, context);
76    } catch (XWikiException e) {
77  0 throw new WikiManagerException(
78    String.format("Error deleting the Wiki Descriptor Document for database [%s]", wikiId), e);
79    }
80    }
81    }