CimGlskTimeSeries.java

/*
 * Copyright (c) 2020, 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/.
 */
package com.powsybl.glsk.cim;

import com.powsybl.glsk.api.GlskPoint;
import com.powsybl.glsk.commons.GlskException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * CIM type GLSK internal object: contains a list of GlskPeriod
 * @author Pengbo Wang {@literal <pengbo.wang@rte-international.com>}
 */
public class CimGlskTimeSeries {

    /**
     * mrid of time series
     */
    private String mRID;
    /**
     * country mrid
     */
    private final String subjectDomainmRID;
    /**
     * curve type A01 or A03
     */
    private String curveType;
    /**
     * list of periods in the time series
     */
    private final List<CimGlskPeriod> cimGlskPeriods;

    /**
     * @param element Time series element
     */
    public CimGlskTimeSeries(Element element) {
        Objects.requireNonNull(element);
        this.mRID = element.getElementsByTagName("mRID").item(0).getTextContent();
        this.subjectDomainmRID = Objects.requireNonNull(element)
                .getElementsByTagName("subject_Domain.mRID")
                .item(0)
                .getTextContent();
        NodeList types = element.getElementsByTagName("curveType");
        this.curveType = types.getLength() == 0 ? "A03" :
                types.item(0).getTextContent();
        if (!this.curveType.equals("A03") && !this.curveType.equals("A01")) {
            throw new GlskException("CurveType not supported: " + this.curveType);
        }

        this.cimGlskPeriods = new ArrayList<>();
        NodeList glskPeriodsElements = element.getElementsByTagName("Period");
        for (int i = 0; i < glskPeriodsElements.getLength(); i++) {
            cimGlskPeriods.add(new CimGlskPeriod((Element) glskPeriodsElements.item(i), subjectDomainmRID, this.curveType));
        }
    }

    /**
     * @return get all glsk point in a time series
     */
    public List<GlskPoint> getGlskPointListInGlskTimeSeries() {
        List<GlskPoint> glskPointList = new ArrayList<>();
        for (CimGlskPeriod p : getGlskPeriods()) {
            List<GlskPoint> list = p.getGlskPoints();
            glskPointList.addAll(list);
        }
        return glskPointList;
    }

    /**
     * @return get all glsk periods
     */
    public List<CimGlskPeriod> getGlskPeriods() {
        return cimGlskPeriods;
    }

    /**
     * @return getter mrid
     */
    public String getmRID() {
        return mRID;
    }

    /**
     * @param mRID setter mrid
     */
    public void setmRID(String mRID) {
        this.mRID = mRID;
    }

    /**
     * @return get curve type
     */
    public String getCurveType() {
        return curveType;
    }

    /**
     * @param curveType setter curve type
     */
    public void setCurveType(String curveType) {
        this.curveType = curveType;
    }
}