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

File DefaultSearchSuggestCustomConfigDeleter.java

 

Coverage histogram

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

Code metrics

10
23
3
1
111
64
9
0.39
7.67
3
3

Classes

Class Line # Actions
DefaultSearchSuggestCustomConfigDeleter 45 23 0% 9 2
0.944444494.4%
 

Contributing tests

This file is covered by 1 test. .

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.workspacesmigrator.internal;
21   
22    import java.util.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Provider;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.model.reference.DocumentReference;
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    import com.xpn.xwiki.objects.BaseObject;
36   
37    /**
38    * Default implementation for {$link SearchSuggestCustomConfigDeleter}.
39    *
40    * @since 5.3RC1
41    * @version $Id: d269c688111eb2f324817c80d3343eba345a1c7a $
42    */
43    @Component
44    @Singleton
 
45    public class DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter
46    {
47    @Inject
48    private Provider<XWikiContext> xcontextProvider;
49   
 
50  1 toggle @Override
51    public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException
52    {
53  1 XWikiContext xcontext = xcontextProvider.get();
54  1 XWiki xwiki = xcontext.getWiki();
55   
56  1 DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig");
57  1 DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE,
58    "SearchSuggestSourceClass");
59   
60  1 XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext);
61   
62    // Get the config objects
63  1 List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass);
64  1 if (objects != null) {
65  1 boolean found = false;
66    // Find the object to remove
67  1 for (BaseObject object : objects) {
68  7 if (object == null) {
69  1 continue;
70    }
71    // Look if the object is to remove
72  6 String name = object.getStringValue("name");
73  6 if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) {
74  5 String query = object.getStringValue("query");
75  5 String engine = object.getStringValue("engine");
76  5 String url = object.getStringValue("url");
77   
78  5 if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) {
79  3 searchConfigDoc.removeXObject(object);
80  3 found = true;
81    }
82    }
83    }
84   
85  1 if (found) {
86  1 xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install",
87    xcontext);
88    }
89    }
90    }
91   
92    /**
93    * Check if the object is the the config object for SolR.
94    */
 
95  5 toggle private boolean isSolrObject(String query, String engine, String url)
96    {
97  5 return engine != null && engine.equals("solr") && query.equals(
98    "class:XWiki.XWikiServerClass AND propertyname:wikiprettyname AND propertyvalue__:(__INPUT__*)")
99    && url.equals("xwiki:WorkspaceManager.WorkspacesSuggestSolrService");
100    }
101   
102    /**
103    * Check if the object is the the config object for lucene.
104    */
 
105  4 toggle private boolean isLuceneObject(String query, String engine, String url)
106    {
107  4 return (engine == null || engine.equals("lucene")) && query.equals(
108    "XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND object:WorkspaceManager.WorkspaceClass")
109    && url.equals("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService");
110    }
111    }