| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.activeinstalls.internal.server; |
| 21 |
|
|
| 22 |
|
import java.util.Map; |
| 23 |
|
|
| 24 |
|
import javax.inject.Inject; |
| 25 |
|
import javax.inject.Singleton; |
| 26 |
|
|
| 27 |
|
import org.xwiki.activeinstalls.internal.JestClientManager; |
| 28 |
|
import org.xwiki.activeinstalls.server.DataManager; |
| 29 |
|
import org.xwiki.component.annotation.Component; |
| 30 |
|
import org.xwiki.properties.ConverterManager; |
| 31 |
|
|
| 32 |
|
import com.google.gson.JsonObject; |
| 33 |
|
|
| 34 |
|
import io.searchbox.action.Action; |
| 35 |
|
import io.searchbox.client.JestResult; |
| 36 |
|
import io.searchbox.core.Count; |
| 37 |
|
import io.searchbox.core.Search; |
| 38 |
|
import io.searchbox.params.Parameters; |
| 39 |
|
import io.searchbox.params.SearchType; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@version |
| 45 |
|
@since |
| 46 |
|
|
| 47 |
|
@Component |
| 48 |
|
@Singleton |
| |
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 49 |
|
public class DefaultDataManager implements DataManager |
| 50 |
|
{ |
| 51 |
|
@Inject |
| 52 |
|
private JestClientManager jestClientManager; |
| 53 |
|
|
| 54 |
|
@Inject |
| 55 |
|
private ConverterManager converterManager; |
| 56 |
|
|
| |
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 57 |
1 |
@Override... |
| 58 |
|
public JsonObject countInstalls(String indexType, String fullQuery, Map<String, Object> parameters) |
| 59 |
|
throws Exception |
| 60 |
|
{ |
| 61 |
1 |
Count.Builder countBuilder = new Count.Builder() |
| 62 |
|
.query(fullQuery) |
| 63 |
|
.addIndex(JestClientManager.INDEX) |
| 64 |
|
.addType(indexType); |
| 65 |
|
|
| 66 |
|
|
| 67 |
1 |
for (Map.Entry<String, Object> parameterEntry : parameters.entrySet()) { |
| 68 |
0 |
countBuilder.setParameter(parameterEntry.getKey(), parameterEntry.getValue()); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
1 |
return executeActionQuery(countBuilder.build(), fullQuery).getJsonObject(); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 74 |
30 |
@Override... |
| 75 |
|
public JsonObject searchInstalls(String indexType, String fullQuery, Map<String, Object> parameters) |
| 76 |
|
throws Exception |
| 77 |
|
{ |
| 78 |
30 |
Search.Builder searchBuilder = new Search.Builder(fullQuery) |
| 79 |
|
.addIndex(JestClientManager.INDEX) |
| 80 |
|
.addType(indexType); |
| 81 |
|
|
| 82 |
|
|
| 83 |
30 |
if (parameters.containsKey(Parameters.SEARCH_TYPE)) { |
| 84 |
27 |
SearchType searchType = this.converterManager.convert(SearchType.class, |
| 85 |
|
parameters.get(Parameters.SEARCH_TYPE)); |
| 86 |
27 |
searchBuilder.setSearchType(searchType); |
| 87 |
|
} |
| 88 |
30 |
for (Map.Entry<String, Object> parameterEntry : parameters.entrySet()) { |
| 89 |
27 |
if (!parameterEntry.getKey().equals(Parameters.SEARCH_TYPE)) { |
| 90 |
0 |
searchBuilder.setParameter(parameterEntry.getKey(), parameterEntry.getValue()); |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
|
|
| 94 |
30 |
return executeActionQuery(searchBuilder.build(), fullQuery).getJsonObject(); |
| 95 |
|
} |
| 96 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 97 |
31 |
private JestResult executeActionQuery(Action action, String fullQuery) throws Exception... |
| 98 |
|
{ |
| 99 |
31 |
JestResult result = this.jestClientManager.getClient().execute(action); |
| 100 |
|
|
| 101 |
31 |
if (!result.isSucceeded()) { |
| 102 |
0 |
throw new Exception(String.format("Error while executing [%s] query [%s]: [%s], Reason: [%s]", |
| 103 |
|
action.getClass().getSimpleName(), fullQuery, result.getErrorMessage(), result.getJsonString())); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
31 |
return result; |
| 107 |
|
} |
| 108 |
|
} |