Search in sources :

Example 81 with QueryBuilder

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);
            }
        }
    }
}
Also used : IPluginConfigurator(alien4cloud.plugin.IPluginConfigurator) PluginConfiguration(alien4cloud.plugin.model.PluginConfiguration) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.plugin.exception.PluginConfigurationException) Plugin(alien4cloud.plugin.Plugin)

Example 82 with QueryBuilder

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();
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NodeType(org.alien4cloud.tosca.model.types.NodeType) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 83 with QueryBuilder

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);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 84 with QueryBuilder

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);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 85 with QueryBuilder

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);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Instant(java.time.Instant) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)371 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)245 Test (org.testng.annotations.Test)156 DynamicEntity (org.molgenis.data.support.DynamicEntity)137 SearchResponse (org.elasticsearch.action.search.SearchResponse)58 QueryImpl (org.molgenis.data.support.QueryImpl)36 Map (java.util.Map)32 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)29 HashMap (java.util.HashMap)27 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)27 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)27 IOException (java.io.IOException)23 SearchHit (org.elasticsearch.search.SearchHit)22 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)19 List (java.util.List)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15