All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.cgmes.gl.CgmesGLModel Maven / Gradle / Ivy

There is a newer version: 6.5.1
Show newest version
/**
 * Copyright (c) 2019, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.cgmes.gl;

import com.powsybl.cgmes.model.CgmesNamespace;
import com.powsybl.triplestore.api.PropertyBags;
import com.powsybl.triplestore.api.QueryCatalog;
import com.powsybl.triplestore.api.TripleStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
 *
 * @author Massimo Ferraro {@literal }
 */
public class CgmesGLModel {

    public static final String SUBSTASTION_POSITION_QUERY_KEY = "substationPosition";
    public static final String LINE_POSITION_QUERY_KEY = "linePosition";

    private static final Logger LOG = LoggerFactory.getLogger(CgmesGLModel.class);

    private final TripleStore tripleStore;
    private final QueryCatalog queryCatalog;

    public CgmesGLModel(TripleStore tripleStore) {
        this(tripleStore, new QueryCatalog("CGMES-GL.sparql"));
    }

    public CgmesGLModel(TripleStore tripleStore, QueryCatalog queryCatalog) {
        this.tripleStore = Objects.requireNonNull(tripleStore);
        tripleStore.defineQueryPrefix("cim", CgmesNamespace.CIM_16_NAMESPACE);
        this.queryCatalog = Objects.requireNonNull(queryCatalog);
    }

    private PropertyBags queryTripleStore(String queryKey) {
        String query = queryCatalog.get(queryKey);
        if (query == null) {
            LOG.warn("Query [{}] not found in catalog", queryKey);
            return new PropertyBags();
        }
        return tripleStore.query(query);
    }

    public PropertyBags getSubstationsPosition() {
        LOG.info("Querying triple store for substations positions");
        return queryTripleStore(SUBSTASTION_POSITION_QUERY_KEY);
    }

    public PropertyBags getLinesPositions() {
        LOG.info("Querying triple store for lines positions");
        return queryTripleStore(LINE_POSITION_QUERY_KEY);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy