use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class PluginController method tryReusePreviousVersionConf.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void tryReusePreviousVersionConf(Plugin plugin) {
// search for a previous version
// TODO manage the case there are many previous versions
QueryBuilder macthNameQuerybuilder = QueryBuilders.matchQuery("descriptor.id", plugin.getDescriptor().getId());
QueryBuilder idQueryBuilder = QueryBuilders.idsQuery(MappingBuilder.indexTypeFromClass(Plugin.class)).ids(plugin.getId());
QueryBuilder boolQuery = QueryBuilders.boolQuery().must(macthNameQuerybuilder).mustNot(idQueryBuilder);
Plugin oldVersionPlugin = alienDAO.customFind(Plugin.class, boolQuery);
if (oldVersionPlugin != null && oldVersionPlugin.isConfigurable()) {
// get the configuration type
Class<?> configType = pluginManager.getConfigurationType(plugin.getId());
PluginConfiguration oldPluginConf = alienDAO.findById(PluginConfiguration.class, oldVersionPlugin.getId());
// try to de-serialize it into the config of the new version
if (oldPluginConf != null && oldPluginConf.getConfiguration() != null) {
try {
Object configObject = JsonUtil.readObject(JsonUtil.toString(oldPluginConf.getConfiguration()), configType);
IPluginConfigurator configurator = pluginManager.getConfiguratorFor(plugin.getId());
configurator.setConfiguration(configObject);
PluginConfiguration pluginConf = new PluginConfiguration(plugin.getId(), configObject);
alienDAO.save(pluginConf);
} catch (IOException e) {
log.warn("Plugin [" + plugin.getId() + "]: Failed to re-use the configuration of the previous version " + oldVersionPlugin.getId() + ". The configuration beans are not comptible", e);
} catch (PluginConfigurationException e) {
log.warn("Plugin [" + plugin.getId() + "]: Failed to re-use the configuration of the previous version " + oldVersionPlugin.getId() + ". Error while applying the configuration", e);
}
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class SuggestionController method nodeTypeSuggest.
@ApiIgnore
@RequestMapping(value = "/nodetypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String[]> nodeTypeSuggest(@RequestParam("text") String searchText, @RequestParam(value = "isAbstract", required = false) Boolean isAbstract) {
if (searchText == null || searchText.trim().isEmpty()) {
return RestResponseBuilder.<String[]>builder().data(new String[0]).build();
}
searchText = StringUtils.lowerCase(searchText);
QueryBuilder queryOnText = QueryBuilders.regexpQuery("elementId", ".*?" + searchText + ".*");
// FIXME the way of getting the highest version of a component has changed
// QueryBuilder queryOnHighest = QueryBuilders.termQuery("highestVersion", true);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(queryOnText);
QueryBuilder query = boolQueryBuilder;
if (isAbstract != null) {
query = boolQueryBuilder.must(QueryBuilders.termQuery("abstract", isAbstract));
}
return RestResponseBuilder.<String[]>builder().data(dao.selectPath(dao.getIndexForType(NodeType.class), new String[] { MappingBuilder.indexTypeFromClass(NodeType.class) }, query, SortOrder.ASC, "elementId", 0, 10)).build();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleEqualsTextNull.
@Test
public void generateOneQueryRuleEqualsTextNull() {
String value = null;
Query<Entity> q = new QueryImpl<>().eq(textAttrName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(boolQuery().mustNot(existsQuery(textAttrName)));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleInInt.
@Test
public void generateOneQueryRuleInInt() {
Integer value1 = 1;
Integer value2 = 2;
Iterable<Object> values = Arrays.asList(value1, value2);
Query<Entity> q = new QueryImpl<>().in(intAttrName, values);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(termsQuery(intAttrName, new Object[] { value1, value2 }));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleEqualsDateTime.
@Test
public void generateOneQueryRuleEqualsDateTime() throws ParseException {
Instant value = Instant.parse("2015-05-22T06:12:13Z");
Query<Entity> q = new QueryImpl<>().eq(dateTimeAttrName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(termQuery(dateTimeAttrName, value.toString()));
assertQueryBuilderEquals(query, expectedQuery);
}
Aggregations