lib/src/kbasesearchengine/search/ElasticIndexingStorage.java
private boolean updateAccessGroupForVersions(
            String indexName,
            final GUID guid,
            final int lastVersion,
            final Integer accessGroupId,
            final boolean includePublicAccessID,
            final boolean includeAdminAccessID)
            throws IOException, IndexingConflictException {
        /* this method will cause at most 6 script compilations, which seems like a lot...
         * Could make the script always the same and put in ifs but this should be ok for now.
         */
        if (indexName == null) {
            indexName = getAnyIndexPattern();
        }

        // query = {"bool": {"must": [{"term": {"prefix": prefix}?}]}}
        Map<String, Object> query = ImmutableMap.of("bool",
                ImmutableMap.of("must",
                        Arrays.asList(
                                createFilter("term", "prefix", toGUIDPrefix(guid)))));

        // params = {"lastver": lastVersion,
        //           ("accgrp": accessGroupId)?,
        //           ("pubaccgrp": -1)?,
        //           ("pubaccgrp": -2)?}
        StringBuilder source = new StringBuilder();
        final Map<String, Object> params = new HashMap<>();
        params.put("lastver", lastVersion);
        if (accessGroupId != null) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "accgrp"));
            params.put("accgrp", accessGroupId);
        }
        if (includePublicAccessID) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "pubaccgrp"));
            params.put("pubaccgrp", PUBLIC_ACCESS_GROUP);
        }
        if (includeAdminAccessID) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "adminaccgrp"));
            params.put("adminaccgrp", ADMIN_ACCESS_GROUP);
        }
        Map<String, Object> script = new LinkedHashMap<>();
        script.put("source", source.toString());
        script.put("params", ImmutableMap.copyOf(params));

        Map<String, Object> doc = ImmutableMap.of("query", query,
                                                  "script", script);

        String urlPath = "/" + indexName + "/" + getAccessTableName() + "/_update_by_query";
        Response resp = makeRequest("POST", urlPath, doc);
        @SuppressWarnings("unchecked")
        Map<String, Object> data = UObject.getMapper().readValue(
                resp.getEntity().getContent(), Map.class);
        return (Integer)data.get("updated") > 0;
    }
/* calling this method with accessGroupId == null and both booleans false is an error. */
calling this method with accessGroupId == null and both booleans false is an error.
calling this method with accessGroupId == null and both booleans false is an error .
private boolean updateAccessGroupForVersions(
            String indexName,
            final GUID guid,
            final int lastVersion,
            final Integer accessGroupId,
            final boolean includePublicAccessID,
            final boolean includeAdminAccessID)
            throws IOException, IndexingConflictException {
        /* this method will cause at most 6 script compilations, which seems like a lot...
         * Could make the script always the same and put in ifs but this should be ok for now.
         */
        if (indexName == null) {
            indexName = getAnyIndexPattern();
        }
        Map<String, Object> query = ImmutableMap.of("bool",
                ImmutableMap.of("must",
                        Arrays.asList(
                                createFilter("term", "prefix", toGUIDPrefix(guid)))));
        StringBuilder source = new StringBuilder();
        final Map<String, Object> params = new HashMap<>();
        params.put("lastver", lastVersion);
        if (accessGroupId != null) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "accgrp"));
            params.put("accgrp", accessGroupId);
        }
        if (includePublicAccessID) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "pubaccgrp"));
            params.put("pubaccgrp", PUBLIC_ACCESS_GROUP);
        }
        if (includeAdminAccessID) {
            source.append(String.format(UPDATE_ACC_GRP_VERS_TEMPLATE, "adminaccgrp"));
            params.put("adminaccgrp", ADMIN_ACCESS_GROUP);
        }
        Map<String, Object> script = new LinkedHashMap<>();
        script.put("source", source.toString());
        script.put("params", ImmutableMap.copyOf(params));
        Map<String, Object> doc = ImmutableMap.of("query", query,
                                                  "script", script);
        String urlPath = "/" + indexName + "/" + getAccessTableName() + "/_update_by_query";
        Response resp = makeRequest("POST", urlPath, doc);
        @SuppressWarnings("unchecked")
        Map<String, Object> data = UObject.getMapper().readValue(
                resp.getEntity().getContent(), Map.class);
        return (Integer)data.get("updated") > 0;
    }
private boolean updateAccessGroupForVersions ( String indexName , final GUID guid , final int lastVersion , final Integer accessGroupId , final boolean includePublicAccessID , final boolean includeAdminAccessID ) throws IOException , IndexingConflictException { /* this method will cause at most 6 script compilations, which seems like a lot...
         * Could make the script always the same and put in ifs but this should be ok for now.
         */ if ( indexName == null ) { indexName = getAnyIndexPattern ( ) ; } Map < String , Object > query = ImmutableMap . of ( "bool" , ImmutableMap . of ( "must" , Arrays . asList ( createFilter ( "term" , "prefix" , toGUIDPrefix ( guid ) ) ) ) ) ; StringBuilder source = new StringBuilder ( ) ; final Map < String , Object > params = new HashMap < > ( ) ; params . put ( "lastver" , lastVersion ) ; if ( accessGroupId != null ) { source . append ( String . format ( UPDATE_ACC_GRP_VERS_TEMPLATE , "accgrp" ) ) ; params . put ( "accgrp" , accessGroupId ) ; } if ( includePublicAccessID ) { source . append ( String . format ( UPDATE_ACC_GRP_VERS_TEMPLATE , "pubaccgrp" ) ) ; params . put ( "pubaccgrp" , PUBLIC_ACCESS_GROUP ) ; } if ( includeAdminAccessID ) { source . append ( String . format ( UPDATE_ACC_GRP_VERS_TEMPLATE , "adminaccgrp" ) ) ; params . put ( "adminaccgrp" , ADMIN_ACCESS_GROUP ) ; } Map < String , Object > script = new LinkedHashMap < > ( ) ; script . put ( "source" , source . toString ( ) ) ; script . put ( "params" , ImmutableMap . copyOf ( params ) ) ; Map < String , Object > doc = ImmutableMap . of ( "query" , query , "script" , script ) ; String urlPath = "/" + indexName + "/" + getAccessTableName ( ) + "/_update_by_query" ; Response resp = makeRequest ( "POST" , urlPath , doc ) ; @ SuppressWarnings ( "unchecked" ) Map < String , Object > data = UObject . getMapper ( ) . readValue ( resp . getEntity ( ) . getContent ( ) , Map . class ) ; return ( Integer ) data . get ( "updated" ) > 0 ; }
calling this method with accessGroupId == null and both booleans false is an error.
calling this method with accessGroupId == null and both booleans false is an error .
// query = {"bool": {"must": [{"term": {"prefix": prefix}?}]}} // params = {"lastver": lastVersion, //           ("accgrp": accessGroupId)?, //           ("pubaccgrp": -1)?, //           ("pubaccgrp": -2)?}