UpdateQueryBuilder.kt 2.39 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * search-doc-service
 * Copyright (C) 2020 Memoriav
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
18 19
package org.memobase.helpers

20
import org.memobase.model.FacetContainer
21
import org.memobase.model.LanguageContainer
Jonas Waeber's avatar
Jonas Waeber committed
22
import org.memobase.model.UpdateQuery
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

class UpdateQueryBuilder {
    private val institutionFacetTerm = "institution.facet"
    private val recordSetFacetTerm = "recordSet.facet"

    fun updateInstitutionName(institution: String, names: LanguageContainer): UpdateQuery {
        return UpdateQuery(
            institutionFacetTerm,
            institution,
            "ctx._source['institution'][0]['name']['de'] = params.de; ctx._source['institution'][0]['name']['fr'] = params.fr; ctx._source['institution'][0]['name']['it'] = params.it",
            mapOf(
                Pair("de", names.de[0]),
                Pair("fr", names.fr[0]),
                Pair("it", names.it[0])
            )
        )
    }

    fun updateRecordSetName(recordSet: String, names: LanguageContainer): UpdateQuery {
        return UpdateQuery(
            recordSetFacetTerm,
            recordSet,
45
            "ctx._source['recordSet']['name']['de'] = params.de; ctx._source['recordSet']['name']['fr'] = params.fr; ctx._source['recordSet']['name']['it'] = params.it",
46 47 48 49 50 51 52
            mapOf(
                Pair("de", names.de[0]),
                Pair("fr", names.fr[0]),
                Pair("it", names.it[0])
            )
        )
    }
53

54
    fun updateInstitutionContainers(recordSet: String, targetField: String, institutions: List<FacetContainer>): UpdateQuery {
55 56 57
        return UpdateQuery(
            recordSetFacetTerm,
            recordSet,
58
            "ctx._source['${targetField}'] = params.containers",
59
            mapOf(
60
                Pair("containers", institutions)
61 62 63
            )
        )
    }
64
}