1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
39 |
|
|
40 |
|
@since |
41 |
|
@version |
42 |
|
|
43 |
|
@Component |
44 |
|
@Singleton |
|
|
| 94.4% |
Uncovered Elements: 2 (36) |
Complexity: 9 |
Complexity Density: 0.39 |
|
45 |
|
public class DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter |
46 |
|
{ |
47 |
|
@Inject |
48 |
|
private Provider<XWikiContext> xcontextProvider; |
49 |
|
|
|
|
| 93.5% |
Uncovered Elements: 2 (31) |
Complexity: 7 |
Complexity Density: 0.33 |
|
50 |
1 |
@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 |
|
|
63 |
1 |
List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); |
64 |
1 |
if (objects != null) { |
65 |
1 |
boolean found = false; |
66 |
|
|
67 |
1 |
for (BaseObject object : objects) { |
68 |
7 |
if (object == null) { |
69 |
1 |
continue; |
70 |
|
} |
71 |
|
|
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 |
|
|
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
5 |
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 |
|
|
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
4 |
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 |
|
} |