From b5fb4fd0d29002abf4f89bb455f1e61261b8d512 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 14:14:35 +0200 Subject: [PATCH 01/21] fixed documentation --- .../edu/ie3/datamodel/io/processor/ProcessorProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/processor/ProcessorProvider.java b/src/main/java/edu/ie3/datamodel/io/processor/ProcessorProvider.java index 2301f1c20..36d2e82c2 100644 --- a/src/main/java/edu/ie3/datamodel/io/processor/ProcessorProvider.java +++ b/src/main/java/edu/ie3/datamodel/io/processor/ProcessorProvider.java @@ -130,12 +130,12 @@ private Collection> allProcessors() { Collection> resultingProcessors = new ArrayList<>(); // todo add missing processors here - // AssetInput + // Input Entity Processor for (Class cls : InputEntityProcessor.eligibleEntityClasses) { resultingProcessors.add(new InputEntityProcessor(cls)); } - // SystemParticipantResults + // Result Entity Processor for (Class cls : ResultEntityProcessor.eligibleEntityClasses) { resultingProcessors.add(new ResultEntityProcessor(cls)); } From 86c54e41906fbacb2bce011522e23a5f06a97f49 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 14:40:27 +0200 Subject: [PATCH 02/21] adapted Jenkinsfile for builds without PR --- Jenkinsfile | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7812f5cf8..216f4da3c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -314,23 +314,36 @@ if (env.BRANCH_NAME == "master") { getFeatureBranchProps() node { - // curl the api to get debugging details - def jsonObj = getGithubPRJsonObj(env.CHANGE_ID, orgNames.get(0), projects.get(0)) - // This displays colors using the 'xterm' ansi color map. + def repoName = "" + // init variables depending of this build is triggered by a branch with PR or without PR + if (env.CHANGE_ID == null) { + // no PR exists + featureBranchName = env.BRANCH_NAME + repoName = orgNames.get(0) + "/" + projects.get(0) + } else { + // PR exists + /// curl the api to get debugging details + def jsonObj = getGithubPRJsonObj(env.CHANGE_ID, orgNames.get(0), projects.get(0)) + + featureBranchName = jsonObj.head.ref + repoName = jsonObj.head.repo.full_name + + } + + ansiColor('xterm') { try { // set java version setJavaVersion(javaVersionId) /// set the build name - featureBranchName = jsonObj.head.ref currentBuild.displayName = featureBranchName + " (" + currentBuild.displayName + ")" // notify rocket chat about the started feature branch run rocketSend channel: rocketChatChannel, emoji: ':jenkins_triggered:', message: "feature branch build triggered:\n" + - "*repo:* ${jsonObj.head.repo.full_name}\n" + + "*repo:* ${repoName}\n" + "*branch:* ${featureBranchName}\n" rawMessage: true @@ -383,7 +396,7 @@ if (env.BRANCH_NAME == "master") { // notify rocket chat rocketSend channel: rocketChatChannel, emoji: ':jenkins_party:', message: "feature branch test successful!\n" + - "*repo:* ${jsonObj.head.repo.full_name}\n" + + "*repo:* ${repoName}\n" + "*branch:* ${featureBranchName}\n" rawMessage: true } @@ -401,7 +414,7 @@ if (env.BRANCH_NAME == "master") { // notify rocket chat rocketSend channel: rocketChatChannel, emoji: ':jenkins_explode:', message: "feature branch test failed!\n" + - "*repo:* ${jsonObj.head.repo.full_name}\n" + + "*repo:* ${repoName}\n" + "*branch:* ${featureBranchName}\n" rawMessage: true } From ce6a95ad5864c107ed44ce03c75122fc71483369 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 15:06:08 +0200 Subject: [PATCH 03/21] added interfaces for classes holding nodes or types --- .../java/edu/ie3/datamodel/models/Nodes.java | 19 +++++++++++++++++++ .../java/edu/ie3/datamodel/models/Type.java | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/edu/ie3/datamodel/models/Nodes.java create mode 100644 src/main/java/edu/ie3/datamodel/models/Type.java diff --git a/src/main/java/edu/ie3/datamodel/models/Nodes.java b/src/main/java/edu/ie3/datamodel/models/Nodes.java new file mode 100644 index 000000000..d5de9711c --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/models/Nodes.java @@ -0,0 +1,19 @@ +package edu.ie3.datamodel.models; + +import edu.ie3.datamodel.models.input.NodeInput; + +import java.util.List; + + +/** + * //ToDo: Class Description + * // todo: UML + * + * @version 0.1 + * @since 31.03.20 + */ +public interface Nodes { + + List getNodes(); + +} diff --git a/src/main/java/edu/ie3/datamodel/models/Type.java b/src/main/java/edu/ie3/datamodel/models/Type.java new file mode 100644 index 000000000..9840fcda5 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/models/Type.java @@ -0,0 +1,17 @@ +package edu.ie3.datamodel.models; + +import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput; + + +/** + * //ToDo: Class Description + * // todo uml + * + * @version 0.1 + * @since 31.03.20 + */ +public interface Type { + + SystemParticipantTypeInput getType(); + +} From 4cb0463db064bcba6bd880399ce646cc91a67832 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 15:06:26 +0200 Subject: [PATCH 04/21] added Nodes interface to corresponding classes --- .../models/input/MeasurementUnitInput.java | 265 +++++++++-------- .../input/connector/ConnectorInput.java | 177 +++++------ .../input/connector/Transformer3WInput.java | 276 +++++++++--------- .../input/graphics/NodeGraphicInput.java | 116 ++++---- .../input/system/SystemParticipantInput.java | 152 +++++----- 5 files changed, 517 insertions(+), 469 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java index bfc3c92ba..6da254467 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java @@ -2,133 +2,146 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.models.input; +import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.OperationTime; -import java.util.Objects; -import java.util.UUID; - -/** Model of a measuring unit attached to a certain {@link NodeInput}. */ -public class MeasurementUnitInput extends AssetInput { - /** Grid node, the asset is attached to */ - private final NodeInput node; - - /** True, if the voltage magnitude is measured */ - private final boolean vMag; - - /** True, if the voltage angle is measured */ - private final boolean vAng; - - /** True, if the nodal residual active power is measured */ - private final boolean p; - - /** True, if the reactive power is measured */ - private final boolean q; - - /** - * Constructor for an operated measurement unit - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param node Grid node, the asset is attached to - * @param vMag True, if the voltage magnitude is measured - * @param vAng True, if the voltage angle is measured - * @param p True, if the nodal residual active power is measured - * @param q True, if the reactive power is measured - */ - public MeasurementUnitInput( - UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput node, - boolean vMag, - boolean vAng, - boolean p, - boolean q) { - super(uuid, operationTime, operator, id); - this.node = node; - this.vMag = vMag; - this.vAng = vAng; - this.p = p; - this.q = q; - } - - /** - * Constructor for a non-operated measurement unit - * - * @param uuid of the input entity - * @param id of the asset - * @param node Grid node, the asset is attached to - * @param vMag True, if the voltage magnitude is measured - * @param vAng True, if the voltage angle is measured - * @param p True, if the nodal residual active power is measured - * @param q True, if the reactive power is measured - */ - public MeasurementUnitInput( - UUID uuid, String id, NodeInput node, boolean vMag, boolean vAng, boolean p, boolean q) { - super(uuid, id); - this.node = node; - this.vMag = vMag; - this.vAng = vAng; - this.p = p; - this.q = q; - } - - public NodeInput getNode() { - return node; - } - - public boolean getVMag() { - return vMag; - } - - public boolean getVAng() { - return vAng; - } - - public boolean getP() { - return p; - } - - public boolean getQ() { - return q; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - MeasurementUnitInput that = (MeasurementUnitInput) o; - return Objects.equals(node, that.node) - && Objects.equals(vMag, that.vMag) - && Objects.equals(vAng, that.vAng) - && Objects.equals(p, that.p) - && Objects.equals(q, that.q); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, vMag, vAng, p, q); - } - - @Override - public String toString() { - return "MeasurementUnitInput{" - + "node=" - + node - + ", vMag=" - + vMag - + ", vAng=" - + vAng - + ", p=" - + p - + ", q=" - + q - + '}'; - } + +import java.util.*; + + +/** + * Model of a measuring unit attached to a certain {@link NodeInput}. + */ +public class MeasurementUnitInput extends AssetInput implements Nodes { + /** + * Grid node, the asset is attached to + */ + private final NodeInput node; + + /** + * True, if the voltage magnitude is measured + */ + private final boolean vMag; + + /** + * True, if the voltage angle is measured + */ + private final boolean vAng; + + /** + * True, if the nodal residual active power is measured + */ + private final boolean p; + + /** + * True, if the reactive power is measured + */ + private final boolean q; + + /** + * Constructor for an operated measurement unit + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param node Grid node, the asset is attached to + * @param vMag True, if the voltage magnitude is measured + * @param vAng True, if the voltage angle is measured + * @param p True, if the nodal residual active power is measured + * @param q True, if the reactive power is measured + */ + public MeasurementUnitInput(UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput node, + boolean vMag, + boolean vAng, + boolean p, + boolean q) { + super(uuid, operationTime, operator, id); + this.node = node; + this.vMag = vMag; + this.vAng = vAng; + this.p = p; + this.q = q; + } + + /** + * Constructor for a non-operated measurement unit + * + * @param uuid of the input entity + * @param id of the asset + * @param node Grid node, the asset is attached to + * @param vMag True, if the voltage magnitude is measured + * @param vAng True, if the voltage angle is measured + * @param p True, if the nodal residual active power is measured + * @param q True, if the reactive power is measured + */ + public MeasurementUnitInput(UUID uuid, + String id, + NodeInput node, + boolean vMag, + boolean vAng, + boolean p, + boolean q) { + super(uuid, id); + this.node = node; + this.vMag = vMag; + this.vAng = vAng; + this.p = p; + this.q = q; + } + + public NodeInput getNode() { + return node; + } + + public boolean getVMag() { + return vMag; + } + + public boolean getVAng() { + return vAng; + } + + public boolean getP() { + return p; + } + + public boolean getQ() { + return q; + } + + @Override + public boolean equals(Object o) { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + if(!super.equals(o)) + return false; + MeasurementUnitInput that = (MeasurementUnitInput) o; + return Objects.equals(node, that.node) && Objects.equals(vMag, that.vMag) && Objects.equals(vAng, that.vAng) && + Objects.equals(p, that.p) && Objects.equals(q, that.q); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, vMag, vAng, p, q); + } + + @Override + public String toString() { + return "MeasurementUnitInput{" + "node=" + node + ", vMag=" + vMag + ", vAng=" + vAng + ", p=" + p + ", q=" + + q + '}'; + } + + @Override + public List getNodes() { + return Collections.unmodifiableList(Collections.singletonList(node)); + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java index bb2ee53cb..d5ee89960 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java @@ -2,104 +2,111 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.models.input.connector; +import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; -import java.util.Objects; -import java.util.UUID; -/** Describes an asset that connects two {@link NodeInput}s */ -public abstract class ConnectorInput extends AssetInput { - /** Grid node at one side of the connector */ - private final NodeInput nodeA; - /** Grid node at the other side of the connector */ - private final NodeInput nodeB; - /** Amount of parallelDevices */ - private final int noOfParallelDevices; +import java.util.*; - /** - * Constructor for an operated connector - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param nodeA Grid node at one side of the connector - * @param nodeB Grid node at the other side of the connector - * @param noOfParallelDevices Amount of parallel devices - */ - public ConnectorInput( - UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput nodeA, - NodeInput nodeB, - int noOfParallelDevices) { - super(uuid, operationTime, operator, id); - this.nodeA = nodeA; - this.nodeB = nodeB; - this.noOfParallelDevices = noOfParallelDevices; - } - /** - * Constructor for a non-operated connector - * - * @param uuid of the input entity - * @param id of the asset - * @param nodeA Grid node at one side of the connector - * @param nodeB Grid node at the other side of the connector - * @param noOfParallelDevices Amount of parallel devices - */ - public ConnectorInput( - UUID uuid, String id, NodeInput nodeA, NodeInput nodeB, int noOfParallelDevices) { - super(uuid, id); - this.nodeA = nodeA; - this.nodeB = nodeB; - this.noOfParallelDevices = noOfParallelDevices; - } +/** + * Describes an asset that connects two {@link NodeInput}s + */ +public abstract class ConnectorInput extends AssetInput implements Nodes { + /** + * Grid node at one side of the connector + */ + private final NodeInput nodeA; + /** + * Grid node at the other side of the connector + */ + private final NodeInput nodeB; + /** + * Amount of parallelDevices + */ + private final int noOfParallelDevices; - public NodeInput getNodeA() { - return nodeA; - } + /** + * Constructor for an operated connector + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param nodeA Grid node at one side of the connector + * @param nodeB Grid node at the other side of the connector + * @param noOfParallelDevices Amount of parallel devices + */ + public ConnectorInput(UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput nodeA, + NodeInput nodeB, + int noOfParallelDevices) { + super(uuid, operationTime, operator, id); + this.nodeA = nodeA; + this.nodeB = nodeB; + this.noOfParallelDevices = noOfParallelDevices; + } - public NodeInput getNodeB() { - return nodeB; - } + /** + * Constructor for a non-operated connector + * + * @param uuid of the input entity + * @param id of the asset + * @param nodeA Grid node at one side of the connector + * @param nodeB Grid node at the other side of the connector + * @param noOfParallelDevices Amount of parallel devices + */ + public ConnectorInput(UUID uuid, String id, NodeInput nodeA, NodeInput nodeB, int noOfParallelDevices) { + super(uuid, id); + this.nodeA = nodeA; + this.nodeB = nodeB; + this.noOfParallelDevices = noOfParallelDevices; + } - public int getNoOfParallelDevices() { - return noOfParallelDevices; - } + public NodeInput getNodeA() { + return nodeA; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - ConnectorInput that = (ConnectorInput) o; - return noOfParallelDevices == that.noOfParallelDevices - && nodeA.equals(that.nodeA) - && nodeB.equals(that.nodeB); - } + public NodeInput getNodeB() { + return nodeB; + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), nodeA, nodeB, noOfParallelDevices); - } + public List getNodes() { + return Collections.unmodifiableList(Arrays.asList(nodeA, nodeB)); + } - @Override - public String toString() { - return "ConnectorInput{" - + "nodeA=" - + nodeA - + ", nodeB=" - + nodeB - + ", noOfParallelDevices=" - + noOfParallelDevices - + '}'; - } + public int getNoOfParallelDevices() { + return noOfParallelDevices; + } + + @Override + public boolean equals(Object o) { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + if(!super.equals(o)) + return false; + ConnectorInput that = (ConnectorInput) o; + return noOfParallelDevices == that.noOfParallelDevices && nodeA.equals(that.nodeA) && nodeB.equals(that.nodeB); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), nodeA, nodeB, noOfParallelDevices); + } + + @Override + public String toString() { + return "ConnectorInput{" + "nodeA=" + nodeA + ", nodeB=" + nodeB + ", noOfParallelDevices=" + + noOfParallelDevices + '}'; + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java index 9caf364b9..c56752b26 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.models.input.connector; import static edu.ie3.util.quantities.PowerSystemUnits.PU; @@ -11,146 +11,150 @@ import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; import edu.ie3.datamodel.models.input.connector.type.Transformer3WTypeInput; -import java.util.Objects; -import java.util.UUID; + +import java.util.*; + import tec.uom.se.quantity.Quantities; + /** * Describes a three winding transformer, that is connected to three {@link * edu.ie3.datamodel.models.input.NodeInput}s */ public class Transformer3WInput extends TransformerInput { - /** Type of this 3W transformer, containing default values for transformers of this kind */ - private final Transformer3WTypeInput type; - /** The lower voltage node */ - private final NodeInput nodeC; - /** Internal node of the transformers T equivalent circuit */ - private final NodeInput nodeInternal; - - /** - * Constructor for an operated three winding transformer - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param nodeA The higher voltage node - * @param nodeB The middle voltage node - * @param nodeC The lower voltage node - * @param parallelDevices Amount of singular transformers - * @param type of 3W transformer - * @param tapPos Tap Position of this transformer - * @param autoTap true, if there is an automated regulation activated for this transformer - */ - public Transformer3WInput( - UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput nodeA, - NodeInput nodeB, - NodeInput nodeC, - int parallelDevices, - Transformer3WTypeInput type, - int tapPos, - boolean autoTap) { - super(uuid, operationTime, operator, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); - this.type = type; - this.nodeC = nodeC; - this.nodeInternal = - new NodeInput( - UUID.randomUUID(), - operationTime, - operator, - "internal_node_" + id, - Quantities.getQuantity(1d, PU), - false, - null, - nodeA.getVoltLvl(), - nodeA.getSubnet()); - } - - /** - * Constructor for a non-operated three winding transformer - * - * @param uuid of the input entity - * @param id of the asset - * @param nodeA The higher voltage node - * @param nodeB The middle voltage node - * @param nodeC The lower voltage node - * @param parallelDevices Amount of singular transformers - * @param type of 3W transformer - * @param tapPos Tap Position of this transformer - * @param autoTap true, if there is an automated regulation activated for this transformer - */ - public Transformer3WInput( - UUID uuid, - String id, - NodeInput nodeA, - NodeInput nodeB, - NodeInput nodeC, - int parallelDevices, - Transformer3WTypeInput type, - int tapPos, - boolean autoTap) { - super(uuid, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); - this.type = type; - this.nodeC = nodeC; - this.nodeInternal = - new NodeInput( - UUID.randomUUID(), - getOperationTime(), - getOperator(), - "internal_node_" + id, - Quantities.getQuantity(1d, PU), - false, - null, - nodeA.getVoltLvl(), - nodeA.getSubnet()); - } - - public Transformer3WTypeInput getType() { - return type; - } - - /** @return the node with the highest voltage level */ - @Override - public NodeInput getNodeA() { - return super.getNodeA(); - } - - /** @return the node with the "medium" voltage level */ - @Override - public NodeInput getNodeB() { - return super.getNodeB(); - } - - /** @return the node with the lowest voltage level */ - public NodeInput getNodeC() { - return nodeC; - } - - /** @return The internal node of the T equivalent circuit */ - public NodeInput getNodeInternal() { - return nodeInternal; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - Transformer3WInput that = (Transformer3WInput) o; - return Objects.equals(type, that.type) && Objects.equals(nodeC, that.nodeC); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), type, nodeC); - } - - @Override - public String toString() { - return "Transformer3WInput{" + "type=" + type + ", nodeC=" + nodeC + '}'; - } + /** + * Type of this 3W transformer, containing default values for transformers of this kind + */ + private final Transformer3WTypeInput type; + /** + * The lower voltage node + */ + private final NodeInput nodeC; + /** + * Internal node of the transformers T equivalent circuit + */ + private final NodeInput nodeInternal; + + /** + * Constructor for an operated three winding transformer + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param nodeA The higher voltage node + * @param nodeB The middle voltage node + * @param nodeC The lower voltage node + * @param parallelDevices Amount of singular transformers + * @param type of 3W transformer + * @param tapPos Tap Position of this transformer + * @param autoTap true, if there is an automated regulation activated for this transformer + */ + public Transformer3WInput(UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput nodeA, + NodeInput nodeB, + NodeInput nodeC, + int parallelDevices, + Transformer3WTypeInput type, + int tapPos, + boolean autoTap) { + super(uuid, operationTime, operator, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); + this.type = type; + this.nodeC = nodeC; + this.nodeInternal = new NodeInput(UUID.randomUUID(), operationTime, operator, "internal_node_" + id, + Quantities.getQuantity(1d, PU), false, null, nodeA.getVoltLvl(), nodeA.getSubnet()); + } + + /** + * Constructor for a non-operated three winding transformer + * + * @param uuid of the input entity + * @param id of the asset + * @param nodeA The higher voltage node + * @param nodeB The middle voltage node + * @param nodeC The lower voltage node + * @param parallelDevices Amount of singular transformers + * @param type of 3W transformer + * @param tapPos Tap Position of this transformer + * @param autoTap true, if there is an automated regulation activated for this transformer + */ + public Transformer3WInput(UUID uuid, + String id, + NodeInput nodeA, + NodeInput nodeB, + NodeInput nodeC, + int parallelDevices, + Transformer3WTypeInput type, + int tapPos, + boolean autoTap) { + super(uuid, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); + this.type = type; + this.nodeC = nodeC; + this.nodeInternal = new NodeInput(UUID.randomUUID(), getOperationTime(), getOperator(), "internal_node_" + id, + Quantities.getQuantity(1d, PU), false, null, nodeA.getVoltLvl(), nodeA.getSubnet()); + } + + public Transformer3WTypeInput getType() { + return type; + } + + @Override + public List getNodes() { + return Collections.unmodifiableList(Arrays.asList(super.getNodeA(), super.getNodeB(), nodeC)); + } + + /** + * @return the node with the highest voltage level + */ + @Override + public NodeInput getNodeA() { + return super.getNodeA(); + } + + /** + * @return the node with the "medium" voltage level + */ + @Override + public NodeInput getNodeB() { + return super.getNodeB(); + } + + /** + * @return the node with the lowest voltage level + */ + public NodeInput getNodeC() { + return nodeC; + } + + /** + * @return The internal node of the T equivalent circuit + */ + public NodeInput getNodeInternal() { + return nodeInternal; + } + + @Override + public boolean equals(Object o) { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + if(!super.equals(o)) + return false; + Transformer3WInput that = (Transformer3WInput) o; + return Objects.equals(type, that.type) && Objects.equals(nodeC, that.nodeC); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), type, nodeC); + } + + @Override + public String toString() { + return "Transformer3WInput{" + "type=" + type + ", nodeC=" + nodeC + '}'; + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java index 23a28a43c..d66145aaa 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java @@ -2,60 +2,76 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.models.input.graphics; +import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.input.NodeInput; -import java.util.Objects; -import java.util.UUID; + +import java.util.*; + import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -/** Describes the graphic data belonging to a {@link NodeInput} */ -public class NodeGraphicInput extends GraphicInput { - /** The NodeInput to this graphic data */ - private final NodeInput node; - /** The geometric point of this node */ - private final Point point; - - /** - * @param uuid of the input entity - * @param graphicLayer Description of the graphic layer, this graphic is located on - * @param path A graphic representation as path - * @param node The NodeInput to this graphic data - * @param point The geometric point of this node - */ - public NodeGraphicInput( - UUID uuid, String graphicLayer, LineString path, NodeInput node, Point point) { - super(uuid, graphicLayer, path); - this.node = node; - this.point = point; - } - - public NodeInput getNode() { - return node; - } - - public Point getPoint() { - return point; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - NodeGraphicInput that = (NodeGraphicInput) o; - return Objects.equals(node, that.node) && Objects.equals(point, that.point); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, point); - } - - @Override - public String toString() { - return "NodeGraphicInput{" + "node=" + node + ", point=" + point + '}'; - } + +/** + * Describes the graphic data belonging to a {@link NodeInput} + */ +public class NodeGraphicInput extends GraphicInput implements Nodes { + /** + * The NodeInput to this graphic data + */ + private final NodeInput node; + /** + * The geometric point of this node + */ + private final Point point; + + /** + * @param uuid of the input entity + * @param graphicLayer Description of the graphic layer, this graphic is located on + * @param path A graphic representation as path + * @param node The NodeInput to this graphic data + * @param point The geometric point of this node + */ + public NodeGraphicInput(UUID uuid, String graphicLayer, LineString path, NodeInput node, Point point) { + super(uuid, graphicLayer, path); + this.node = node; + this.point = point; + } + + public NodeInput getNode() { + return node; + } + + public Point getPoint() { + return point; + } + + @Override + public boolean equals(Object o) { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + if(!super.equals(o)) + return false; + NodeGraphicInput that = (NodeGraphicInput) o; + return Objects.equals(node, that.node) && Objects.equals(point, that.point); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, point); + } + + @Override + public String toString() { + return "NodeGraphicInput{" + "node=" + node + ", point=" + point + '}'; + } + + @Override + public List getNodes() { + return Collections.singletonList(node); + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java index 92bb81651..1a65ac9d0 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java @@ -2,92 +2,100 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.models.input.system; +import com.sun.org.apache.xalan.internal.lib.NodeInfo; +import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; -import java.util.Objects; -import java.util.UUID; -/** Describes a system asset that is connected to a node */ -public abstract class SystemParticipantInput extends AssetInput { +import java.util.*; - /** The node that the asset is connected to */ - private final NodeInput node; - /** Description of a reactive power characteristic. For details see further documentation */ - private final String qCharacteristics; +/** + * Describes a system asset that is connected to a node + */ +public abstract class SystemParticipantInput extends AssetInput implements Nodes { - /** - * Constructor for an operated system participant - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param node that the asset is connected to - * @param qCharacteristics Description of a reactive power characteristic - */ - public SystemParticipantInput( - UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput node, - String qCharacteristics) { - super(uuid, operationTime, operator, id); - this.node = node; - this.qCharacteristics = qCharacteristics; - } + /** + * The node that the asset is connected to + */ + private final NodeInput node; - /** - * Constructor for a non-operated system participant - * - * @param uuid of the input entity - * @param id of the asset - * @param node that the asset is connected to - * @param qCharacteristics Description of a reactive power characteristic - */ - public SystemParticipantInput(UUID uuid, String id, NodeInput node, String qCharacteristics) { - super(uuid, id); - this.node = node; - this.qCharacteristics = qCharacteristics; - } + /** + * Description of a reactive power characteristic. For details see further documentation + */ + private final String qCharacteristics; - public String getqCharacteristics() { - return qCharacteristics; - } + /** + * Constructor for an operated system participant + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param node that the asset is connected to + * @param qCharacteristics Description of a reactive power characteristic + */ + public SystemParticipantInput(UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput node, + String qCharacteristics) { + super(uuid, operationTime, operator, id); + this.node = node; + this.qCharacteristics = qCharacteristics; + } - public NodeInput getNode() { - return node; - } + /** + * Constructor for a non-operated system participant + * + * @param uuid of the input entity + * @param id of the asset + * @param node that the asset is connected to + * @param qCharacteristics Description of a reactive power characteristic + */ + public SystemParticipantInput(UUID uuid, String id, NodeInput node, String qCharacteristics) { + super(uuid, id); + this.node = node; + this.qCharacteristics = qCharacteristics; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - SystemParticipantInput that = (SystemParticipantInput) o; - return Objects.equals(node, that.node) - && Objects.equals(qCharacteristics, that.qCharacteristics); - } + public String getqCharacteristics() { + return qCharacteristics; + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, qCharacteristics); - } + public NodeInput getNode() { + return node; + } - @Override - public String toString() { - return "SystemParticipantInput{" - + "node=" - + node - + ", qCharacteristics='" - + qCharacteristics - + '\'' - + '}'; - } + public List getNodes() { + return Collections.singletonList(node); + } + + @Override + public boolean equals(Object o) { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + if(!super.equals(o)) + return false; + SystemParticipantInput that = (SystemParticipantInput) o; + return Objects.equals(node, that.node) && Objects.equals(qCharacteristics, that.qCharacteristics); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, qCharacteristics); + } + + @Override + public String toString() { + return "SystemParticipantInput{" + "node=" + node + ", qCharacteristics='" + qCharacteristics + '\'' + '}'; + } } From 6bfa59f535e3f5a370461e05dfa416b91a567fa5 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 15:58:59 +0200 Subject: [PATCH 05/21] added Extractor for nested models --- .../edu/ie3/datamodel/models/Extractor.java | 42 +++ .../java/edu/ie3/datamodel/models/Nested.java | 14 + .../java/edu/ie3/datamodel/models/Nodes.java | 15 +- .../java/edu/ie3/datamodel/models/Type.java | 14 +- .../models/input/MeasurementUnitInput.java | 262 ++++++++--------- .../input/connector/ConnectorInput.java | 173 ++++++----- .../input/connector/Transformer3WInput.java | 278 +++++++++--------- .../input/graphics/NodeGraphicInput.java | 101 +++---- .../input/system/SystemParticipantInput.java | 148 +++++----- 9 files changed, 540 insertions(+), 507 deletions(-) create mode 100644 src/main/java/edu/ie3/datamodel/models/Extractor.java create mode 100644 src/main/java/edu/ie3/datamodel/models/Nested.java diff --git a/src/main/java/edu/ie3/datamodel/models/Extractor.java b/src/main/java/edu/ie3/datamodel/models/Extractor.java new file mode 100644 index 000000000..5d0b03166 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/models/Extractor.java @@ -0,0 +1,42 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ +package edu.ie3.datamodel.models; + +import edu.ie3.datamodel.models.input.InputEntity; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * //ToDo: Class Description + * + * @version 0.1 + * @since 31.03.20 + */ +public class Extractor { + + private final List extractedElements; + + public Extractor(Nested nestedEntity) { + this.extractedElements = extractElements(nestedEntity); + } + + private List extractElements(Nested nestedEntity) { + List resultingList = new ArrayList<>(); + if (nestedEntity instanceof Nodes) { + resultingList.addAll(((Nodes) nestedEntity).getNodes()); + } + if (nestedEntity instanceof Type) { + resultingList.add(((Type) nestedEntity).getType()); + } + + return Collections.unmodifiableList(resultingList); + } + + public List getExtractedElements() { + return extractedElements; + } +} diff --git a/src/main/java/edu/ie3/datamodel/models/Nested.java b/src/main/java/edu/ie3/datamodel/models/Nested.java new file mode 100644 index 000000000..a935c1a60 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/models/Nested.java @@ -0,0 +1,14 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ +package edu.ie3.datamodel.models; + +/** + * //ToDo: Class Description + * + * @version 0.1 + * @since 31.03.20 + */ +interface Nested {} diff --git a/src/main/java/edu/ie3/datamodel/models/Nodes.java b/src/main/java/edu/ie3/datamodel/models/Nodes.java index d5de9711c..39735a41f 100644 --- a/src/main/java/edu/ie3/datamodel/models/Nodes.java +++ b/src/main/java/edu/ie3/datamodel/models/Nodes.java @@ -1,19 +1,20 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ package edu.ie3.datamodel.models; import edu.ie3.datamodel.models.input.NodeInput; - import java.util.List; - /** - * //ToDo: Class Description - * // todo: UML + * //ToDo: Class Description // todo: UML * * @version 0.1 * @since 31.03.20 */ -public interface Nodes { - - List getNodes(); +public interface Nodes extends Nested { + List getNodes(); } diff --git a/src/main/java/edu/ie3/datamodel/models/Type.java b/src/main/java/edu/ie3/datamodel/models/Type.java index 9840fcda5..375d2cf86 100644 --- a/src/main/java/edu/ie3/datamodel/models/Type.java +++ b/src/main/java/edu/ie3/datamodel/models/Type.java @@ -1,17 +1,19 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ package edu.ie3.datamodel.models; import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput; - /** - * //ToDo: Class Description - * // todo uml + * //ToDo: Class Description // todo uml * * @version 0.1 * @since 31.03.20 */ -public interface Type { - - SystemParticipantTypeInput getType(); +public interface Type extends Nested { + SystemParticipantTypeInput getType(); } diff --git a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java index 6da254467..e70d8f625 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java @@ -2,146 +2,138 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.models.input; import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.OperationTime; - import java.util.*; - -/** - * Model of a measuring unit attached to a certain {@link NodeInput}. - */ +/** Model of a measuring unit attached to a certain {@link NodeInput}. */ public class MeasurementUnitInput extends AssetInput implements Nodes { - /** - * Grid node, the asset is attached to - */ - private final NodeInput node; - - /** - * True, if the voltage magnitude is measured - */ - private final boolean vMag; - - /** - * True, if the voltage angle is measured - */ - private final boolean vAng; - - /** - * True, if the nodal residual active power is measured - */ - private final boolean p; - - /** - * True, if the reactive power is measured - */ - private final boolean q; - - /** - * Constructor for an operated measurement unit - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param node Grid node, the asset is attached to - * @param vMag True, if the voltage magnitude is measured - * @param vAng True, if the voltage angle is measured - * @param p True, if the nodal residual active power is measured - * @param q True, if the reactive power is measured - */ - public MeasurementUnitInput(UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput node, - boolean vMag, - boolean vAng, - boolean p, - boolean q) { - super(uuid, operationTime, operator, id); - this.node = node; - this.vMag = vMag; - this.vAng = vAng; - this.p = p; - this.q = q; - } - - /** - * Constructor for a non-operated measurement unit - * - * @param uuid of the input entity - * @param id of the asset - * @param node Grid node, the asset is attached to - * @param vMag True, if the voltage magnitude is measured - * @param vAng True, if the voltage angle is measured - * @param p True, if the nodal residual active power is measured - * @param q True, if the reactive power is measured - */ - public MeasurementUnitInput(UUID uuid, - String id, - NodeInput node, - boolean vMag, - boolean vAng, - boolean p, - boolean q) { - super(uuid, id); - this.node = node; - this.vMag = vMag; - this.vAng = vAng; - this.p = p; - this.q = q; - } - - public NodeInput getNode() { - return node; - } - - public boolean getVMag() { - return vMag; - } - - public boolean getVAng() { - return vAng; - } - - public boolean getP() { - return p; - } - - public boolean getQ() { - return q; - } - - @Override - public boolean equals(Object o) { - if(this == o) - return true; - if(o == null || getClass() != o.getClass()) - return false; - if(!super.equals(o)) - return false; - MeasurementUnitInput that = (MeasurementUnitInput) o; - return Objects.equals(node, that.node) && Objects.equals(vMag, that.vMag) && Objects.equals(vAng, that.vAng) && - Objects.equals(p, that.p) && Objects.equals(q, that.q); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, vMag, vAng, p, q); - } - - @Override - public String toString() { - return "MeasurementUnitInput{" + "node=" + node + ", vMag=" + vMag + ", vAng=" + vAng + ", p=" + p + ", q=" + - q + '}'; - } - - @Override - public List getNodes() { - return Collections.unmodifiableList(Collections.singletonList(node)); - } + /** Grid node, the asset is attached to */ + private final NodeInput node; + + /** True, if the voltage magnitude is measured */ + private final boolean vMag; + + /** True, if the voltage angle is measured */ + private final boolean vAng; + + /** True, if the nodal residual active power is measured */ + private final boolean p; + + /** True, if the reactive power is measured */ + private final boolean q; + + /** + * Constructor for an operated measurement unit + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param node Grid node, the asset is attached to + * @param vMag True, if the voltage magnitude is measured + * @param vAng True, if the voltage angle is measured + * @param p True, if the nodal residual active power is measured + * @param q True, if the reactive power is measured + */ + public MeasurementUnitInput( + UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput node, + boolean vMag, + boolean vAng, + boolean p, + boolean q) { + super(uuid, operationTime, operator, id); + this.node = node; + this.vMag = vMag; + this.vAng = vAng; + this.p = p; + this.q = q; + } + + /** + * Constructor for a non-operated measurement unit + * + * @param uuid of the input entity + * @param id of the asset + * @param node Grid node, the asset is attached to + * @param vMag True, if the voltage magnitude is measured + * @param vAng True, if the voltage angle is measured + * @param p True, if the nodal residual active power is measured + * @param q True, if the reactive power is measured + */ + public MeasurementUnitInput( + UUID uuid, String id, NodeInput node, boolean vMag, boolean vAng, boolean p, boolean q) { + super(uuid, id); + this.node = node; + this.vMag = vMag; + this.vAng = vAng; + this.p = p; + this.q = q; + } + + public NodeInput getNode() { + return node; + } + + public boolean getVMag() { + return vMag; + } + + public boolean getVAng() { + return vAng; + } + + public boolean getP() { + return p; + } + + public boolean getQ() { + return q; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + MeasurementUnitInput that = (MeasurementUnitInput) o; + return Objects.equals(node, that.node) + && Objects.equals(vMag, that.vMag) + && Objects.equals(vAng, that.vAng) + && Objects.equals(p, that.p) + && Objects.equals(q, that.q); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, vMag, vAng, p, q); + } + + @Override + public String toString() { + return "MeasurementUnitInput{" + + "node=" + + node + + ", vMag=" + + vMag + + ", vAng=" + + vAng + + ", p=" + + p + + ", q=" + + q + + '}'; + } + + @Override + public List getNodes() { + return Collections.unmodifiableList(Collections.singletonList(node)); + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java index d5ee89960..0e24416e8 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.models.input.connector; import edu.ie3.datamodel.models.Nodes; @@ -10,103 +10,100 @@ import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; - import java.util.*; - -/** - * Describes an asset that connects two {@link NodeInput}s - */ +/** Describes an asset that connects two {@link NodeInput}s */ public abstract class ConnectorInput extends AssetInput implements Nodes { - /** - * Grid node at one side of the connector - */ - private final NodeInput nodeA; - /** - * Grid node at the other side of the connector - */ - private final NodeInput nodeB; - /** - * Amount of parallelDevices - */ - private final int noOfParallelDevices; + /** Grid node at one side of the connector */ + private final NodeInput nodeA; + /** Grid node at the other side of the connector */ + private final NodeInput nodeB; + /** Amount of parallelDevices */ + private final int noOfParallelDevices; - /** - * Constructor for an operated connector - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param nodeA Grid node at one side of the connector - * @param nodeB Grid node at the other side of the connector - * @param noOfParallelDevices Amount of parallel devices - */ - public ConnectorInput(UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput nodeA, - NodeInput nodeB, - int noOfParallelDevices) { - super(uuid, operationTime, operator, id); - this.nodeA = nodeA; - this.nodeB = nodeB; - this.noOfParallelDevices = noOfParallelDevices; - } + /** + * Constructor for an operated connector + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param nodeA Grid node at one side of the connector + * @param nodeB Grid node at the other side of the connector + * @param noOfParallelDevices Amount of parallel devices + */ + public ConnectorInput( + UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput nodeA, + NodeInput nodeB, + int noOfParallelDevices) { + super(uuid, operationTime, operator, id); + this.nodeA = nodeA; + this.nodeB = nodeB; + this.noOfParallelDevices = noOfParallelDevices; + } - /** - * Constructor for a non-operated connector - * - * @param uuid of the input entity - * @param id of the asset - * @param nodeA Grid node at one side of the connector - * @param nodeB Grid node at the other side of the connector - * @param noOfParallelDevices Amount of parallel devices - */ - public ConnectorInput(UUID uuid, String id, NodeInput nodeA, NodeInput nodeB, int noOfParallelDevices) { - super(uuid, id); - this.nodeA = nodeA; - this.nodeB = nodeB; - this.noOfParallelDevices = noOfParallelDevices; - } + /** + * Constructor for a non-operated connector + * + * @param uuid of the input entity + * @param id of the asset + * @param nodeA Grid node at one side of the connector + * @param nodeB Grid node at the other side of the connector + * @param noOfParallelDevices Amount of parallel devices + */ + public ConnectorInput( + UUID uuid, String id, NodeInput nodeA, NodeInput nodeB, int noOfParallelDevices) { + super(uuid, id); + this.nodeA = nodeA; + this.nodeB = nodeB; + this.noOfParallelDevices = noOfParallelDevices; + } - public NodeInput getNodeA() { - return nodeA; - } + public NodeInput getNodeA() { + return nodeA; + } - public NodeInput getNodeB() { - return nodeB; - } + public NodeInput getNodeB() { + return nodeB; + } - public List getNodes() { - return Collections.unmodifiableList(Arrays.asList(nodeA, nodeB)); - } + public List getNodes() { + return Collections.unmodifiableList(Arrays.asList(nodeA, nodeB)); + } - public int getNoOfParallelDevices() { - return noOfParallelDevices; - } + public int getNoOfParallelDevices() { + return noOfParallelDevices; + } - @Override - public boolean equals(Object o) { - if(this == o) - return true; - if(o == null || getClass() != o.getClass()) - return false; - if(!super.equals(o)) - return false; - ConnectorInput that = (ConnectorInput) o; - return noOfParallelDevices == that.noOfParallelDevices && nodeA.equals(that.nodeA) && nodeB.equals(that.nodeB); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + ConnectorInput that = (ConnectorInput) o; + return noOfParallelDevices == that.noOfParallelDevices + && nodeA.equals(that.nodeA) + && nodeB.equals(that.nodeB); + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), nodeA, nodeB, noOfParallelDevices); - } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), nodeA, nodeB, noOfParallelDevices); + } - @Override - public String toString() { - return "ConnectorInput{" + "nodeA=" + nodeA + ", nodeB=" + nodeB + ", noOfParallelDevices=" + - noOfParallelDevices + '}'; - } + @Override + public String toString() { + return "ConnectorInput{" + + "nodeA=" + + nodeA + + ", nodeB=" + + nodeB + + ", noOfParallelDevices=" + + noOfParallelDevices + + '}'; + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java index c56752b26..65cf9a587 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.models.input.connector; import static edu.ie3.util.quantities.PowerSystemUnits.PU; @@ -11,150 +11,150 @@ import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; import edu.ie3.datamodel.models.input.connector.type.Transformer3WTypeInput; - import java.util.*; - import tec.uom.se.quantity.Quantities; - /** * Describes a three winding transformer, that is connected to three {@link * edu.ie3.datamodel.models.input.NodeInput}s */ public class Transformer3WInput extends TransformerInput { - /** - * Type of this 3W transformer, containing default values for transformers of this kind - */ - private final Transformer3WTypeInput type; - /** - * The lower voltage node - */ - private final NodeInput nodeC; - /** - * Internal node of the transformers T equivalent circuit - */ - private final NodeInput nodeInternal; - - /** - * Constructor for an operated three winding transformer - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param nodeA The higher voltage node - * @param nodeB The middle voltage node - * @param nodeC The lower voltage node - * @param parallelDevices Amount of singular transformers - * @param type of 3W transformer - * @param tapPos Tap Position of this transformer - * @param autoTap true, if there is an automated regulation activated for this transformer - */ - public Transformer3WInput(UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput nodeA, - NodeInput nodeB, - NodeInput nodeC, - int parallelDevices, - Transformer3WTypeInput type, - int tapPos, - boolean autoTap) { - super(uuid, operationTime, operator, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); - this.type = type; - this.nodeC = nodeC; - this.nodeInternal = new NodeInput(UUID.randomUUID(), operationTime, operator, "internal_node_" + id, - Quantities.getQuantity(1d, PU), false, null, nodeA.getVoltLvl(), nodeA.getSubnet()); - } - - /** - * Constructor for a non-operated three winding transformer - * - * @param uuid of the input entity - * @param id of the asset - * @param nodeA The higher voltage node - * @param nodeB The middle voltage node - * @param nodeC The lower voltage node - * @param parallelDevices Amount of singular transformers - * @param type of 3W transformer - * @param tapPos Tap Position of this transformer - * @param autoTap true, if there is an automated regulation activated for this transformer - */ - public Transformer3WInput(UUID uuid, - String id, - NodeInput nodeA, - NodeInput nodeB, - NodeInput nodeC, - int parallelDevices, - Transformer3WTypeInput type, - int tapPos, - boolean autoTap) { - super(uuid, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); - this.type = type; - this.nodeC = nodeC; - this.nodeInternal = new NodeInput(UUID.randomUUID(), getOperationTime(), getOperator(), "internal_node_" + id, - Quantities.getQuantity(1d, PU), false, null, nodeA.getVoltLvl(), nodeA.getSubnet()); - } - - public Transformer3WTypeInput getType() { - return type; - } - - @Override - public List getNodes() { - return Collections.unmodifiableList(Arrays.asList(super.getNodeA(), super.getNodeB(), nodeC)); - } - - /** - * @return the node with the highest voltage level - */ - @Override - public NodeInput getNodeA() { - return super.getNodeA(); - } - - /** - * @return the node with the "medium" voltage level - */ - @Override - public NodeInput getNodeB() { - return super.getNodeB(); - } - - /** - * @return the node with the lowest voltage level - */ - public NodeInput getNodeC() { - return nodeC; - } - - /** - * @return The internal node of the T equivalent circuit - */ - public NodeInput getNodeInternal() { - return nodeInternal; - } - - @Override - public boolean equals(Object o) { - if(this == o) - return true; - if(o == null || getClass() != o.getClass()) - return false; - if(!super.equals(o)) - return false; - Transformer3WInput that = (Transformer3WInput) o; - return Objects.equals(type, that.type) && Objects.equals(nodeC, that.nodeC); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), type, nodeC); - } - - @Override - public String toString() { - return "Transformer3WInput{" + "type=" + type + ", nodeC=" + nodeC + '}'; - } + /** Type of this 3W transformer, containing default values for transformers of this kind */ + private final Transformer3WTypeInput type; + /** The lower voltage node */ + private final NodeInput nodeC; + /** Internal node of the transformers T equivalent circuit */ + private final NodeInput nodeInternal; + + /** + * Constructor for an operated three winding transformer + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param nodeA The higher voltage node + * @param nodeB The middle voltage node + * @param nodeC The lower voltage node + * @param parallelDevices Amount of singular transformers + * @param type of 3W transformer + * @param tapPos Tap Position of this transformer + * @param autoTap true, if there is an automated regulation activated for this transformer + */ + public Transformer3WInput( + UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput nodeA, + NodeInput nodeB, + NodeInput nodeC, + int parallelDevices, + Transformer3WTypeInput type, + int tapPos, + boolean autoTap) { + super(uuid, operationTime, operator, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); + this.type = type; + this.nodeC = nodeC; + this.nodeInternal = + new NodeInput( + UUID.randomUUID(), + operationTime, + operator, + "internal_node_" + id, + Quantities.getQuantity(1d, PU), + false, + null, + nodeA.getVoltLvl(), + nodeA.getSubnet()); + } + + /** + * Constructor for a non-operated three winding transformer + * + * @param uuid of the input entity + * @param id of the asset + * @param nodeA The higher voltage node + * @param nodeB The middle voltage node + * @param nodeC The lower voltage node + * @param parallelDevices Amount of singular transformers + * @param type of 3W transformer + * @param tapPos Tap Position of this transformer + * @param autoTap true, if there is an automated regulation activated for this transformer + */ + public Transformer3WInput( + UUID uuid, + String id, + NodeInput nodeA, + NodeInput nodeB, + NodeInput nodeC, + int parallelDevices, + Transformer3WTypeInput type, + int tapPos, + boolean autoTap) { + super(uuid, id, nodeA, nodeB, parallelDevices, tapPos, autoTap); + this.type = type; + this.nodeC = nodeC; + this.nodeInternal = + new NodeInput( + UUID.randomUUID(), + getOperationTime(), + getOperator(), + "internal_node_" + id, + Quantities.getQuantity(1d, PU), + false, + null, + nodeA.getVoltLvl(), + nodeA.getSubnet()); + } + + public Transformer3WTypeInput getType() { + return type; + } + + @Override + public List getNodes() { + return Collections.unmodifiableList(Arrays.asList(super.getNodeA(), super.getNodeB(), nodeC)); + } + + /** @return the node with the highest voltage level */ + @Override + public NodeInput getNodeA() { + return super.getNodeA(); + } + + /** @return the node with the "medium" voltage level */ + @Override + public NodeInput getNodeB() { + return super.getNodeB(); + } + + /** @return the node with the lowest voltage level */ + public NodeInput getNodeC() { + return nodeC; + } + + /** @return The internal node of the T equivalent circuit */ + public NodeInput getNodeInternal() { + return nodeInternal; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Transformer3WInput that = (Transformer3WInput) o; + return Objects.equals(type, that.type) && Objects.equals(nodeC, that.nodeC); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), type, nodeC); + } + + @Override + public String toString() { + return "Transformer3WInput{" + "type=" + type + ", nodeC=" + nodeC + '}'; + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java index d66145aaa..3e9215509 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java @@ -2,76 +2,65 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.models.input.graphics; import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.input.NodeInput; - import java.util.*; - import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; - -/** - * Describes the graphic data belonging to a {@link NodeInput} - */ +/** Describes the graphic data belonging to a {@link NodeInput} */ public class NodeGraphicInput extends GraphicInput implements Nodes { - /** - * The NodeInput to this graphic data - */ - private final NodeInput node; - /** - * The geometric point of this node - */ - private final Point point; + /** The NodeInput to this graphic data */ + private final NodeInput node; + /** The geometric point of this node */ + private final Point point; - /** - * @param uuid of the input entity - * @param graphicLayer Description of the graphic layer, this graphic is located on - * @param path A graphic representation as path - * @param node The NodeInput to this graphic data - * @param point The geometric point of this node - */ - public NodeGraphicInput(UUID uuid, String graphicLayer, LineString path, NodeInput node, Point point) { - super(uuid, graphicLayer, path); - this.node = node; - this.point = point; - } + /** + * @param uuid of the input entity + * @param graphicLayer Description of the graphic layer, this graphic is located on + * @param path A graphic representation as path + * @param node The NodeInput to this graphic data + * @param point The geometric point of this node + */ + public NodeGraphicInput( + UUID uuid, String graphicLayer, LineString path, NodeInput node, Point point) { + super(uuid, graphicLayer, path); + this.node = node; + this.point = point; + } - public NodeInput getNode() { - return node; - } + public NodeInput getNode() { + return node; + } - public Point getPoint() { - return point; - } + public Point getPoint() { + return point; + } - @Override - public boolean equals(Object o) { - if(this == o) - return true; - if(o == null || getClass() != o.getClass()) - return false; - if(!super.equals(o)) - return false; - NodeGraphicInput that = (NodeGraphicInput) o; - return Objects.equals(node, that.node) && Objects.equals(point, that.point); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + NodeGraphicInput that = (NodeGraphicInput) o; + return Objects.equals(node, that.node) && Objects.equals(point, that.point); + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, point); - } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, point); + } - @Override - public String toString() { - return "NodeGraphicInput{" + "node=" + node + ", point=" + point + '}'; - } + @Override + public String toString() { + return "NodeGraphicInput{" + "node=" + node + ", point=" + point + '}'; + } - @Override - public List getNodes() { - return Collections.singletonList(node); - } + @Override + public List getNodes() { + return Collections.singletonList(node); + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java index 1a65ac9d0..db4684a51 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java @@ -2,100 +2,96 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.models.input.system; -import com.sun.org.apache.xalan.internal.lib.NodeInfo; import edu.ie3.datamodel.models.Nodes; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; - import java.util.*; - -/** - * Describes a system asset that is connected to a node - */ +/** Describes a system asset that is connected to a node */ public abstract class SystemParticipantInput extends AssetInput implements Nodes { - /** - * The node that the asset is connected to - */ - private final NodeInput node; + /** The node that the asset is connected to */ + private final NodeInput node; - /** - * Description of a reactive power characteristic. For details see further documentation - */ - private final String qCharacteristics; + /** Description of a reactive power characteristic. For details see further documentation */ + private final String qCharacteristics; - /** - * Constructor for an operated system participant - * - * @param uuid of the input entity - * @param operationTime Time for which the entity is operated - * @param operator of the asset - * @param id of the asset - * @param node that the asset is connected to - * @param qCharacteristics Description of a reactive power characteristic - */ - public SystemParticipantInput(UUID uuid, - OperationTime operationTime, - OperatorInput operator, - String id, - NodeInput node, - String qCharacteristics) { - super(uuid, operationTime, operator, id); - this.node = node; - this.qCharacteristics = qCharacteristics; - } + /** + * Constructor for an operated system participant + * + * @param uuid of the input entity + * @param operationTime Time for which the entity is operated + * @param operator of the asset + * @param id of the asset + * @param node that the asset is connected to + * @param qCharacteristics Description of a reactive power characteristic + */ + public SystemParticipantInput( + UUID uuid, + OperationTime operationTime, + OperatorInput operator, + String id, + NodeInput node, + String qCharacteristics) { + super(uuid, operationTime, operator, id); + this.node = node; + this.qCharacteristics = qCharacteristics; + } - /** - * Constructor for a non-operated system participant - * - * @param uuid of the input entity - * @param id of the asset - * @param node that the asset is connected to - * @param qCharacteristics Description of a reactive power characteristic - */ - public SystemParticipantInput(UUID uuid, String id, NodeInput node, String qCharacteristics) { - super(uuid, id); - this.node = node; - this.qCharacteristics = qCharacteristics; - } + /** + * Constructor for a non-operated system participant + * + * @param uuid of the input entity + * @param id of the asset + * @param node that the asset is connected to + * @param qCharacteristics Description of a reactive power characteristic + */ + public SystemParticipantInput(UUID uuid, String id, NodeInput node, String qCharacteristics) { + super(uuid, id); + this.node = node; + this.qCharacteristics = qCharacteristics; + } - public String getqCharacteristics() { - return qCharacteristics; - } + public String getqCharacteristics() { + return qCharacteristics; + } - public NodeInput getNode() { - return node; - } + public NodeInput getNode() { + return node; + } - public List getNodes() { - return Collections.singletonList(node); - } + public List getNodes() { + return Collections.singletonList(node); + } - @Override - public boolean equals(Object o) { - if(this == o) - return true; - if(o == null || getClass() != o.getClass()) - return false; - if(!super.equals(o)) - return false; - SystemParticipantInput that = (SystemParticipantInput) o; - return Objects.equals(node, that.node) && Objects.equals(qCharacteristics, that.qCharacteristics); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + SystemParticipantInput that = (SystemParticipantInput) o; + return Objects.equals(node, that.node) + && Objects.equals(qCharacteristics, that.qCharacteristics); + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), node, qCharacteristics); - } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), node, qCharacteristics); + } - @Override - public String toString() { - return "SystemParticipantInput{" + "node=" + node + ", qCharacteristics='" + qCharacteristics + '\'' + '}'; - } + @Override + public String toString() { + return "SystemParticipantInput{" + + "node=" + + node + + ", qCharacteristics='" + + qCharacteristics + + '\'' + + '}'; + } } From 8b50db627bb64214995edcfc3f12f56fad926f8c Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 16:00:39 +0200 Subject: [PATCH 06/21] moved extractor and new interfaces to own class --- .../edu/ie3/datamodel/{models => io/extractor}/Extractor.java | 2 +- .../java/edu/ie3/datamodel/{models => io/extractor}/Nested.java | 2 +- .../java/edu/ie3/datamodel/{models => io/extractor}/Nodes.java | 2 +- .../java/edu/ie3/datamodel/{models => io/extractor}/Type.java | 2 +- .../edu/ie3/datamodel/models/input/MeasurementUnitInput.java | 2 +- .../ie3/datamodel/models/input/connector/ConnectorInput.java | 2 +- .../ie3/datamodel/models/input/graphics/NodeGraphicInput.java | 2 +- .../datamodel/models/input/system/SystemParticipantInput.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename src/main/java/edu/ie3/datamodel/{models => io/extractor}/Extractor.java (96%) rename src/main/java/edu/ie3/datamodel/{models => io/extractor}/Nested.java (87%) rename src/main/java/edu/ie3/datamodel/{models => io/extractor}/Nodes.java (91%) rename src/main/java/edu/ie3/datamodel/{models => io/extractor}/Type.java (91%) diff --git a/src/main/java/edu/ie3/datamodel/models/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java similarity index 96% rename from src/main/java/edu/ie3/datamodel/models/Extractor.java rename to src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index 5d0b03166..19654b37d 100644 --- a/src/main/java/edu/ie3/datamodel/models/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -3,7 +3,7 @@ * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ -package edu.ie3.datamodel.models; +package edu.ie3.datamodel.io.extractor; import edu.ie3.datamodel.models.input.InputEntity; import java.util.ArrayList; diff --git a/src/main/java/edu/ie3/datamodel/models/Nested.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java similarity index 87% rename from src/main/java/edu/ie3/datamodel/models/Nested.java rename to src/main/java/edu/ie3/datamodel/io/extractor/Nested.java index a935c1a60..ba5c69ef2 100644 --- a/src/main/java/edu/ie3/datamodel/models/Nested.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java @@ -3,7 +3,7 @@ * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ -package edu.ie3.datamodel.models; +package edu.ie3.datamodel.io.extractor; /** * //ToDo: Class Description diff --git a/src/main/java/edu/ie3/datamodel/models/Nodes.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java similarity index 91% rename from src/main/java/edu/ie3/datamodel/models/Nodes.java rename to src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java index 39735a41f..84db37570 100644 --- a/src/main/java/edu/ie3/datamodel/models/Nodes.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java @@ -3,7 +3,7 @@ * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ -package edu.ie3.datamodel.models; +package edu.ie3.datamodel.io.extractor; import edu.ie3.datamodel.models.input.NodeInput; import java.util.List; diff --git a/src/main/java/edu/ie3/datamodel/models/Type.java b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java similarity index 91% rename from src/main/java/edu/ie3/datamodel/models/Type.java rename to src/main/java/edu/ie3/datamodel/io/extractor/Type.java index 375d2cf86..e6cdabecc 100644 --- a/src/main/java/edu/ie3/datamodel/models/Type.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java @@ -3,7 +3,7 @@ * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation */ -package edu.ie3.datamodel.models; +package edu.ie3.datamodel.io.extractor; import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput; diff --git a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java index e70d8f625..4a5985863 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.models.input; -import edu.ie3.datamodel.models.Nodes; +import edu.ie3.datamodel.io.extractor.Nodes; import edu.ie3.datamodel.models.OperationTime; import java.util.*; diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java index 0e24416e8..8730647ca 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.models.input.connector; -import edu.ie3.datamodel.models.Nodes; +import edu.ie3.datamodel.io.extractor.Nodes; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; diff --git a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java index 3e9215509..dd9d2bfc5 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.models.input.graphics; -import edu.ie3.datamodel.models.Nodes; +import edu.ie3.datamodel.io.extractor.Nodes; import edu.ie3.datamodel.models.input.NodeInput; import java.util.*; import org.locationtech.jts.geom.LineString; diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java index db4684a51..3e195980d 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; -import edu.ie3.datamodel.models.Nodes; +import edu.ie3.datamodel.io.extractor.Nodes; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; From 795fcc3e7f8720dd844f55ea726a0b24c0a464c5 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 16:36:59 +0200 Subject: [PATCH 07/21] - added ExtractorException - adaptions in Extractor processing to throw an exception for unknown elements - integrate Extractor into CsvFileSink - extended DataSink interface with methods for nested and unnested elements for performance purposes --- .../exceptions/ExtractorException.java | 28 ++ .../ie3/datamodel/io/extractor/Extractor.java | 43 +-- .../ie3/datamodel/io/extractor/Nested.java | 4 +- .../ie3/datamodel/io/sink/CsvFileSink.java | 270 ++++++++++-------- .../edu/ie3/datamodel/io/sink/DataSink.java | 5 + 5 files changed, 217 insertions(+), 133 deletions(-) create mode 100644 src/main/java/edu/ie3/datamodel/exceptions/ExtractorException.java diff --git a/src/main/java/edu/ie3/datamodel/exceptions/ExtractorException.java b/src/main/java/edu/ie3/datamodel/exceptions/ExtractorException.java new file mode 100644 index 000000000..e9385ae93 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/exceptions/ExtractorException.java @@ -0,0 +1,28 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ +package edu.ie3.datamodel.exceptions; + +/** + * Exception that should be used whenevery something invalid happens in a implementation of a {@link + * edu.ie3.datamodel.io.connectors.DataConnector} + * + * @version 0.1 + * @since 20.03.20 + */ +public class ExtractorException extends Exception { + + public ExtractorException(final String message, final Throwable cause) { + super(message, cause); + } + + public ExtractorException(final Throwable cause) { + super(cause); + } + + public ExtractorException(final String message) { + super(message); + } +} diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index 19654b37d..9a7a14bc4 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -2,14 +2,17 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.io.extractor; +import edu.ie3.datamodel.exceptions.ExtractorException; import edu.ie3.datamodel.models.input.InputEntity; + import java.util.ArrayList; import java.util.Collections; import java.util.List; + /** * //ToDo: Class Description * @@ -18,25 +21,29 @@ */ public class Extractor { - private final List extractedElements; - - public Extractor(Nested nestedEntity) { - this.extractedElements = extractElements(nestedEntity); - } + private final List extractedEntities; - private List extractElements(Nested nestedEntity) { - List resultingList = new ArrayList<>(); - if (nestedEntity instanceof Nodes) { - resultingList.addAll(((Nodes) nestedEntity).getNodes()); - } - if (nestedEntity instanceof Type) { - resultingList.add(((Type) nestedEntity).getType()); + public Extractor(Nested nestedEntity) throws ExtractorException { + this.extractedEntities = extractElements(nestedEntity); } - return Collections.unmodifiableList(resultingList); - } + private List extractElements(Nested nestedEntity) throws ExtractorException { + List resultingList = new ArrayList<>(); + if(nestedEntity instanceof Nodes) { + resultingList.addAll(((Nodes) nestedEntity).getNodes()); + } + if(nestedEntity instanceof Type) { + resultingList.add(((Type) nestedEntity).getType()); + } else { + throw new ExtractorException( + "The interface 'Nested' is not meant to be extended and cannot be processed by " + + "the extractor! Currently only the interfaces ‘Nodes‘ and ‘Type' are supported!"); + } + + return Collections.unmodifiableList(resultingList); + } - public List getExtractedElements() { - return extractedElements; - } + public List getExtractedEntities() { + return extractedEntities; + } } diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java index ba5c69ef2..828f05f31 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java @@ -8,7 +8,9 @@ /** * //ToDo: Class Description * + * THIS interface is not meant to be extended! + * * @version 0.1 * @since 31.03.20 */ -interface Nested {} +public interface Nested {} diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index dbc72b982..a1d6eb581 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -2,21 +2,30 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.io.sink; +import edu.ie3.datamodel.exceptions.ExtractorException; import edu.ie3.datamodel.exceptions.SinkException; import edu.ie3.datamodel.io.FileNamingStrategy; import edu.ie3.datamodel.io.connectors.CsvFileConnector; import edu.ie3.datamodel.io.connectors.DataConnector; +import edu.ie3.datamodel.io.extractor.Extractor; +import edu.ie3.datamodel.io.extractor.Nested; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.io.processor.ProcessorProvider; import edu.ie3.datamodel.models.UniqueEntity; + import java.io.BufferedWriter; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; + +import edu.ie3.datamodel.models.input.InputEntity; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + /** * Sink that provides all capabilities to write {@link UniqueEntity}s to .csv-files * @@ -25,121 +34,154 @@ */ public class CsvFileSink implements DataSink { - private static final Logger log = LogManager.getLogger(CsvFileSink.class); - - private final CsvFileConnector connector; - private final ProcessorProvider processorProvider; - - private final String csvSep; - - public CsvFileSink(String baseFolderPath) { - this(baseFolderPath, new ProcessorProvider(), new FileNamingStrategy(), false, ","); - } - - /** - * Create an instance of a csv file sink - * - * @param baseFolderPath the base folder path where the files should be put into - * @param processorProvider the processor provided that should be used for entity de-serialization - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink( - String baseFolderPath, - ProcessorProvider processorProvider, - FileNamingStrategy fileNamingStrategy, - boolean initFiles, - String csvSep) { - this.csvSep = csvSep; - this.processorProvider = processorProvider; - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if (initFiles) initFiles(processorProvider, connector); - } - - @Override - public DataConnector getDataConnector() { - return connector; - } - - @Override - public void persistAll(Collection entities) { - for (T entity : entities) { - persist(entity); + private static final Logger log = LogManager.getLogger(CsvFileSink.class); + + private final CsvFileConnector connector; + private final ProcessorProvider processorProvider; + + private final String csvSep; + + public CsvFileSink(String baseFolderPath) { + this(baseFolderPath, new FileNamingStrategy(), false, ","); } - } - - @Override - public void persist(T entity) { - - LinkedHashMap entityFieldData = - processorProvider - .processEntity(entity) - .orElseThrow( - () -> - new SinkException( - "Cannot persist entity of type '" - + entity.getClass().getSimpleName() - + "'. Is this sink properly initialized?")); - - String[] headerElements = - processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); - BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); - write(entityFieldData, headerElements, writer); - } - - /** - * Initialize files, hence create a file for each expected class that will be processed in the - * future. - * - * @param processorProvider the processor provider all files that will be processed is derived - * from - * @param connector the connector to the files - */ - private void initFiles( - final ProcessorProvider processorProvider, final CsvFileConnector connector) { - - processorProvider - .getRegisteredClasses() - .forEach( - clz -> - processorProvider - .getHeaderElements(clz) - .ifPresent( - headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); - } - - /** - * Actually persisting the provided entity field data - * - * @param entityFieldData a mapping of an entity instance fields to their values - * @param headerElements the header elements of the entity, normally all attributes of the entity - * class - * @param writer the corresponding writer for that should be used - */ - private void write( - LinkedHashMap entityFieldData, - String[] headerElements, - BufferedWriter writer) { - - try { - for (int i = 0; i < headerElements.length; i++) { - String attribute = headerElements[i]; - writer.append(entityFieldData.get(attribute)); - if (i + 1 < headerElements.length) { - writer.append(csvSep); + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. + * This implementation processes in sequential order. To parallelize this process one + * might consider starting several sinks and use them for specific entities. + * + * @param baseFolderPath the base folder path where the files should be put into + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink(String baseFolderPath, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep) { + this.csvSep = csvSep; + this.processorProvider = new ProcessorProvider(); + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if(initFiles) + initFiles(processorProvider, connector); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. + * This implementation processes in sequential order. To parallelize this process one + * might consider starting several sinks and use them for specific entities. + * Be careful when providing your own {@link ProcessorProvider} because if you're not 100% sure that + * it knows about all entities you're going to process exceptions might occur. Therefore it is strongly + * advised to either use a constructor without providing the {@link ProcessorProvider} or + * provide a general {@link ProcessorProvider} by calling {@link ProcessorProvider()} + * + * @param baseFolderPath the base folder path where the files should be put into + * @param processorProvider the processor provided that should be used for entity de-serialization + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink(String baseFolderPath, + ProcessorProvider processorProvider, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this.csvSep = csvSep; + this.processorProvider = processorProvider; + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if(initFiles) + initFiles(processorProvider, connector); + } + + @Override + public DataConnector getDataConnector() { + return connector; + } + + @Override + public void persistAll(Collection entities) { + for(T entity : entities) { + persist(entity); + } + } + + @Override + public void persistAllIgnoreNested(C entity) { + LinkedHashMap entityFieldData = processorProvider.processEntity(entity) + .orElseThrow(() -> new SinkException( + "Cannot persist entity of type '" + entity.getClass().getSimpleName() + + "'. This sink can only process the following entities: [" + + processorProvider.getRegisteredClasses().stream().map(Class::getSimpleName) + .collect(Collectors.joining(",")) + "]")); + + String[] headerElements = processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); + BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); + write(entityFieldData, headerElements, writer); + } + + @Override + public void persistAllIgnoreNested(Collection entities) { + entities.parallelStream().forEach(this::persistAllIgnoreNested); + } + + @Override + public void persist(T entity) { + if(entity instanceof Nested) { + try { + Extractor extractor = new Extractor((Type) entity); + for(InputEntity ent : extractor.getExtractedEntities()) { + persistAllIgnoreNested(ent); + } + + } catch(ExtractorException e) { + log.error("An error occurred during extraction of nested entity'" + entity.getClass().getSimpleName() + + "': ", e); + } } else { - writer.append("\n"); + persistAllIgnoreNested(entity); + } + + } + + /** + * Initialize files, hence create a file for each expected class that will be processed in the + * future. + * + * @param processorProvider the processor provider all files that will be processed is derived + * from + * @param connector the connector to the files + */ + private void initFiles(final ProcessorProvider processorProvider, final CsvFileConnector connector) { + + processorProvider.getRegisteredClasses().forEach(clz -> processorProvider.getHeaderElements(clz) + .ifPresent(headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); + } + + /** + * Actually persisting the provided entity field data + * + * @param entityFieldData a mapping of an entity instance fields to their values + * @param headerElements the header elements of the entity, normally all attributes of the entity + * class + * @param writer the corresponding writer for that should be used + */ + private void write(LinkedHashMap entityFieldData, String[] headerElements, BufferedWriter writer) { + + try { + for(int i = 0; i < headerElements.length; i++) { + String attribute = headerElements[i]; + writer.append(entityFieldData.get(attribute)); + if(i + 1 < headerElements.length) { + writer.append(csvSep); + } else { + writer.append("\n"); + } + } + writer.flush(); + } catch(IOException e) { + log.error("Error while writing entity with field data: " + + Arrays.toString(entityFieldData.entrySet().toArray()), e); } - } - writer.flush(); - } catch (IOException e) { - log.error( - "Error while writing entity with field data: " - + Arrays.toString(entityFieldData.entrySet().toArray()), - e); } - } } diff --git a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java index 622790d94..d5b3fbe08 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java @@ -18,4 +18,9 @@ public interface DataSink { void persist(C entity); void persistAll(Collection entities); + + void persistAllIgnoreNested(C entity); + + void persistAllIgnoreNested(Collection entities); + } From 7e1a634d5095cf92771bc123c092c6361eb973db Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 16:43:58 +0200 Subject: [PATCH 08/21] fmt --- .../ie3/datamodel/io/extractor/Extractor.java | 46 ++- .../ie3/datamodel/io/extractor/Nested.java | 2 +- .../ie3/datamodel/io/sink/CsvFileSink.java | 318 ++++++++++-------- .../edu/ie3/datamodel/io/sink/DataSink.java | 1 - 4 files changed, 193 insertions(+), 174 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index 9a7a14bc4..cb0d02304 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -2,17 +2,15 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.io.extractor; import edu.ie3.datamodel.exceptions.ExtractorException; import edu.ie3.datamodel.models.input.InputEntity; - import java.util.ArrayList; import java.util.Collections; import java.util.List; - /** * //ToDo: Class Description * @@ -21,29 +19,29 @@ */ public class Extractor { - private final List extractedEntities; - - public Extractor(Nested nestedEntity) throws ExtractorException { - this.extractedEntities = extractElements(nestedEntity); - } + private final List extractedEntities; - private List extractElements(Nested nestedEntity) throws ExtractorException { - List resultingList = new ArrayList<>(); - if(nestedEntity instanceof Nodes) { - resultingList.addAll(((Nodes) nestedEntity).getNodes()); - } - if(nestedEntity instanceof Type) { - resultingList.add(((Type) nestedEntity).getType()); - } else { - throw new ExtractorException( - "The interface 'Nested' is not meant to be extended and cannot be processed by " + - "the extractor! Currently only the interfaces ‘Nodes‘ and ‘Type' are supported!"); - } + public Extractor(Nested nestedEntity) throws ExtractorException { + this.extractedEntities = extractElements(nestedEntity); + } - return Collections.unmodifiableList(resultingList); + private List extractElements(Nested nestedEntity) throws ExtractorException { + List resultingList = new ArrayList<>(); + if (nestedEntity instanceof Nodes) { + resultingList.addAll(((Nodes) nestedEntity).getNodes()); } - - public List getExtractedEntities() { - return extractedEntities; + if (nestedEntity instanceof Type) { + resultingList.add(((Type) nestedEntity).getType()); + } else { + throw new ExtractorException( + "The interface 'Nested' is not meant to be extended and cannot be processed by " + + "the extractor! Currently only the interfaces ‘Nodes‘ and ‘Type' are supported!"); } + + return Collections.unmodifiableList(resultingList); + } + + public List getExtractedEntities() { + return extractedEntities; + } } diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java index 828f05f31..0b17f1997 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java @@ -8,7 +8,7 @@ /** * //ToDo: Class Description * - * THIS interface is not meant to be extended! + *

THIS interface is not meant to be extended! * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index a1d6eb581..89f3c45b2 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.io.sink; import edu.ie3.datamodel.exceptions.ExtractorException; @@ -15,17 +15,14 @@ import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.io.processor.ProcessorProvider; import edu.ie3.datamodel.models.UniqueEntity; - +import edu.ie3.datamodel.models.input.InputEntity; import java.io.BufferedWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; - -import edu.ie3.datamodel.models.input.InputEntity; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - /** * Sink that provides all capabilities to write {@link UniqueEntity}s to .csv-files * @@ -34,154 +31,179 @@ */ public class CsvFileSink implements DataSink { - private static final Logger log = LogManager.getLogger(CsvFileSink.class); - - private final CsvFileConnector connector; - private final ProcessorProvider processorProvider; - - private final String csvSep; - - public CsvFileSink(String baseFolderPath) { - this(baseFolderPath, new FileNamingStrategy(), false, ","); - } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. - * This implementation processes in sequential order. To parallelize this process one - * might consider starting several sinks and use them for specific entities. - * - * @param baseFolderPath the base folder path where the files should be put into - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink(String baseFolderPath, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep) { - this.csvSep = csvSep; - this.processorProvider = new ProcessorProvider(); - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if(initFiles) - initFiles(processorProvider, connector); - } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. - * This implementation processes in sequential order. To parallelize this process one - * might consider starting several sinks and use them for specific entities. - * Be careful when providing your own {@link ProcessorProvider} because if you're not 100% sure that - * it knows about all entities you're going to process exceptions might occur. Therefore it is strongly - * advised to either use a constructor without providing the {@link ProcessorProvider} or - * provide a general {@link ProcessorProvider} by calling {@link ProcessorProvider()} - * - * @param baseFolderPath the base folder path where the files should be put into - * @param processorProvider the processor provided that should be used for entity de-serialization - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink(String baseFolderPath, - ProcessorProvider processorProvider, - FileNamingStrategy fileNamingStrategy, - boolean initFiles, - String csvSep) { - this.csvSep = csvSep; - this.processorProvider = processorProvider; - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if(initFiles) - initFiles(processorProvider, connector); + private static final Logger log = LogManager.getLogger(CsvFileSink.class); + + private final CsvFileConnector connector; + private final ProcessorProvider processorProvider; + + private final String csvSep; + + public CsvFileSink(String baseFolderPath) { + this(baseFolderPath, new FileNamingStrategy(), false, ","); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. + * + * @param baseFolderPath the base folder path where the files should be put into + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink( + String baseFolderPath, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this.csvSep = csvSep; + this.processorProvider = new ProcessorProvider(); + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if (initFiles) initFiles(processorProvider, connector); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. Be careful when providing your own + * {@link ProcessorProvider} because if you're not 100% sure that it knows about all entities + * you're going to process exceptions might occur. Therefore it is strongly advised to either use + * a constructor without providing the {@link ProcessorProvider} or provide a general {@link + * ProcessorProvider} by calling {@link ProcessorProvider()} + * + * @param baseFolderPath the base folder path where the files should be put into + * @param processorProvider the processor provided that should be used for entity de-serialization + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink( + String baseFolderPath, + ProcessorProvider processorProvider, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this.csvSep = csvSep; + this.processorProvider = processorProvider; + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if (initFiles) initFiles(processorProvider, connector); + } + + @Override + public DataConnector getDataConnector() { + return connector; + } + + @Override + public void persistAll(Collection entities) { + for (T entity : entities) { + persist(entity); } - - @Override - public DataConnector getDataConnector() { - return connector; - } - - @Override - public void persistAll(Collection entities) { - for(T entity : entities) { - persist(entity); + } + + @Override + public void persistAllIgnoreNested(C entity) { + LinkedHashMap entityFieldData = + processorProvider + .processEntity(entity) + .orElseThrow( + () -> + new SinkException( + "Cannot persist entity of type '" + + entity.getClass().getSimpleName() + + "'. This sink can only process the following entities: [" + + processorProvider.getRegisteredClasses().stream() + .map(Class::getSimpleName) + .collect(Collectors.joining(",")) + + "]")); + + String[] headerElements = + processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); + BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); + write(entityFieldData, headerElements, writer); + } + + @Override + public void persistAllIgnoreNested(Collection entities) { + entities.parallelStream().forEach(this::persistAllIgnoreNested); + } + + @Override + public void persist(T entity) { + if (entity instanceof Nested) { + try { + Extractor extractor = new Extractor((Type) entity); + for (InputEntity ent : extractor.getExtractedEntities()) { + persistAllIgnoreNested(ent); } - } - @Override - public void persistAllIgnoreNested(C entity) { - LinkedHashMap entityFieldData = processorProvider.processEntity(entity) - .orElseThrow(() -> new SinkException( - "Cannot persist entity of type '" + entity.getClass().getSimpleName() + - "'. This sink can only process the following entities: [" + - processorProvider.getRegisteredClasses().stream().map(Class::getSimpleName) - .collect(Collectors.joining(",")) + "]")); - - String[] headerElements = processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); - BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); - write(entityFieldData, headerElements, writer); + } catch (ExtractorException e) { + log.error( + "An error occurred during extraction of nested entity'" + + entity.getClass().getSimpleName() + + "': ", + e); + } + } else { + persistAllIgnoreNested(entity); } - - @Override - public void persistAllIgnoreNested(Collection entities) { - entities.parallelStream().forEach(this::persistAllIgnoreNested); - } - - @Override - public void persist(T entity) { - if(entity instanceof Nested) { - try { - Extractor extractor = new Extractor((Type) entity); - for(InputEntity ent : extractor.getExtractedEntities()) { - persistAllIgnoreNested(ent); - } - - } catch(ExtractorException e) { - log.error("An error occurred during extraction of nested entity'" + entity.getClass().getSimpleName() + - "': ", e); - } + } + + /** + * Initialize files, hence create a file for each expected class that will be processed in the + * future. + * + * @param processorProvider the processor provider all files that will be processed is derived + * from + * @param connector the connector to the files + */ + private void initFiles( + final ProcessorProvider processorProvider, final CsvFileConnector connector) { + + processorProvider + .getRegisteredClasses() + .forEach( + clz -> + processorProvider + .getHeaderElements(clz) + .ifPresent( + headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); + } + + /** + * Actually persisting the provided entity field data + * + * @param entityFieldData a mapping of an entity instance fields to their values + * @param headerElements the header elements of the entity, normally all attributes of the entity + * class + * @param writer the corresponding writer for that should be used + */ + private void write( + LinkedHashMap entityFieldData, + String[] headerElements, + BufferedWriter writer) { + + try { + for (int i = 0; i < headerElements.length; i++) { + String attribute = headerElements[i]; + writer.append(entityFieldData.get(attribute)); + if (i + 1 < headerElements.length) { + writer.append(csvSep); } else { - persistAllIgnoreNested(entity); - } - - } - - /** - * Initialize files, hence create a file for each expected class that will be processed in the - * future. - * - * @param processorProvider the processor provider all files that will be processed is derived - * from - * @param connector the connector to the files - */ - private void initFiles(final ProcessorProvider processorProvider, final CsvFileConnector connector) { - - processorProvider.getRegisteredClasses().forEach(clz -> processorProvider.getHeaderElements(clz) - .ifPresent(headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); - } - - /** - * Actually persisting the provided entity field data - * - * @param entityFieldData a mapping of an entity instance fields to their values - * @param headerElements the header elements of the entity, normally all attributes of the entity - * class - * @param writer the corresponding writer for that should be used - */ - private void write(LinkedHashMap entityFieldData, String[] headerElements, BufferedWriter writer) { - - try { - for(int i = 0; i < headerElements.length; i++) { - String attribute = headerElements[i]; - writer.append(entityFieldData.get(attribute)); - if(i + 1 < headerElements.length) { - writer.append(csvSep); - } else { - writer.append("\n"); - } - } - writer.flush(); - } catch(IOException e) { - log.error("Error while writing entity with field data: " + - Arrays.toString(entityFieldData.entrySet().toArray()), e); + writer.append("\n"); } + } + writer.flush(); + } catch (IOException e) { + log.error( + "Error while writing entity with field data: " + + Arrays.toString(entityFieldData.entrySet().toArray()), + e); } + } } diff --git a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java index d5b3fbe08..d343bde4e 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java @@ -22,5 +22,4 @@ public interface DataSink { void persistAllIgnoreNested(C entity); void persistAllIgnoreNested(Collection entities); - } From bddcb0e99883f44c117b9d4a00fc44331b4e00e8 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 16:47:20 +0200 Subject: [PATCH 09/21] disabled passed tests login in tests.gradle --- gradle/scripts/tests.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/scripts/tests.gradle b/gradle/scripts/tests.gradle index 0e4aa5e56..7c366eb49 100644 --- a/gradle/scripts/tests.gradle +++ b/gradle/scripts/tests.gradle @@ -5,7 +5,7 @@ test { } useJUnitPlatform() testLogging { - events "passed", "skipped", "failed" + events "skipped", "failed" } } From 2c07caf1f1cd4b1cc07eeeb2ec412b8ea364db8b Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 17:13:37 +0200 Subject: [PATCH 10/21] disabled passed tests logging for allTests() --- gradle/scripts/tests.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/scripts/tests.gradle b/gradle/scripts/tests.gradle index 7c366eb49..e7332351d 100644 --- a/gradle/scripts/tests.gradle +++ b/gradle/scripts/tests.gradle @@ -24,7 +24,7 @@ task allTests(type: Test) { useJUnitPlatform() testLogging { - events "passed", "skipped", "failed" + events "skipped", "failed" } filter { From 886959442c52b8bcd1af6be4da9b28503bcac3fe Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 17:14:19 +0200 Subject: [PATCH 11/21] introduced new interfaces to avoid model adaptions for Extractor --- .../ie3/datamodel/io/extractor/Extractor.java | 10 +++++++++- .../edu/ie3/datamodel/io/extractor/Node.java | 19 +++++++++++++++++++ .../edu/ie3/datamodel/io/extractor/NodeC.java | 19 +++++++++++++++++++ .../edu/ie3/datamodel/io/extractor/Nodes.java | 5 +++-- .../models/input/MeasurementUnitInput.java | 10 +++------- .../input/connector/ConnectorInput.java | 6 ++---- .../input/connector/Transformer3WInput.java | 9 +++------ .../input/graphics/NodeGraphicInput.java | 10 +++------- .../input/system/SystemParticipantInput.java | 9 +++------ 9 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 src/main/java/edu/ie3/datamodel/io/extractor/Node.java create mode 100644 src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index cb0d02304..5dd36f116 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -8,6 +8,7 @@ import edu.ie3.datamodel.exceptions.ExtractorException; import edu.ie3.datamodel.models.input.InputEntity; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -28,7 +29,14 @@ public Extractor(Nested nestedEntity) throws ExtractorException { private List extractElements(Nested nestedEntity) throws ExtractorException { List resultingList = new ArrayList<>(); if (nestedEntity instanceof Nodes) { - resultingList.addAll(((Nodes) nestedEntity).getNodes()); + resultingList.addAll( + Arrays.asList(((Nodes) nestedEntity).getNodeA(), ((Nodes) nestedEntity).getNodeB())); + } + if (nestedEntity instanceof Node) { + resultingList.add(((Node) nestedEntity).getNode()); + } + if (nestedEntity instanceof NodeC) { + resultingList.add(((NodeC) nestedEntity).getNodeC()); } if (nestedEntity instanceof Type) { resultingList.add(((Type) nestedEntity).getType()); diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Node.java b/src/main/java/edu/ie3/datamodel/io/extractor/Node.java new file mode 100644 index 000000000..d76efe597 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Node.java @@ -0,0 +1,19 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ +package edu.ie3.datamodel.io.extractor; + +import edu.ie3.datamodel.models.input.NodeInput; + +/** + * //ToDo: Class Description + * + * @version 0.1 + * @since 31.03.20 + */ +public interface Node extends Nested { + + NodeInput getNode(); +} diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java b/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java new file mode 100644 index 000000000..897d010d1 --- /dev/null +++ b/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java @@ -0,0 +1,19 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation +*/ +package edu.ie3.datamodel.io.extractor; + +import edu.ie3.datamodel.models.input.NodeInput; + +/** + * //ToDo: Class Description // todo UML + * + * @version 0.1 + * @since 31.03.20 + */ +public interface NodeC extends Nested { + + NodeInput getNodeC(); +} diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java index 84db37570..8cce7e3c7 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java @@ -6,7 +6,6 @@ package edu.ie3.datamodel.io.extractor; import edu.ie3.datamodel.models.input.NodeInput; -import java.util.List; /** * //ToDo: Class Description // todo: UML @@ -16,5 +15,7 @@ */ public interface Nodes extends Nested { - List getNodes(); + NodeInput getNodeA(); + + NodeInput getNodeB(); } diff --git a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java index 4a5985863..66829a941 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/MeasurementUnitInput.java @@ -5,12 +5,12 @@ */ package edu.ie3.datamodel.models.input; -import edu.ie3.datamodel.io.extractor.Nodes; +import edu.ie3.datamodel.io.extractor.Node; import edu.ie3.datamodel.models.OperationTime; import java.util.*; /** Model of a measuring unit attached to a certain {@link NodeInput}. */ -public class MeasurementUnitInput extends AssetInput implements Nodes { +public class MeasurementUnitInput extends AssetInput implements Node { /** Grid node, the asset is attached to */ private final NodeInput node; @@ -78,6 +78,7 @@ public MeasurementUnitInput( this.q = q; } + @Override public NodeInput getNode() { return node; } @@ -131,9 +132,4 @@ public String toString() { + q + '}'; } - - @Override - public List getNodes() { - return Collections.unmodifiableList(Collections.singletonList(node)); - } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java index 8730647ca..2e9f3fcc7 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/ConnectorInput.java @@ -63,18 +63,16 @@ public ConnectorInput( this.noOfParallelDevices = noOfParallelDevices; } + @Override public NodeInput getNodeA() { return nodeA; } + @Override public NodeInput getNodeB() { return nodeB; } - public List getNodes() { - return Collections.unmodifiableList(Arrays.asList(nodeA, nodeB)); - } - public int getNoOfParallelDevices() { return noOfParallelDevices; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java index 65cf9a587..da2fd8f8b 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java @@ -7,6 +7,7 @@ import static edu.ie3.util.quantities.PowerSystemUnits.PU; +import edu.ie3.datamodel.io.extractor.NodeC; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -18,7 +19,7 @@ * Describes a three winding transformer, that is connected to three {@link * edu.ie3.datamodel.models.input.NodeInput}s */ -public class Transformer3WInput extends TransformerInput { +public class Transformer3WInput extends TransformerInput implements NodeC { /** Type of this 3W transformer, containing default values for transformers of this kind */ private final Transformer3WTypeInput type; /** The lower voltage node */ @@ -112,11 +113,6 @@ public Transformer3WTypeInput getType() { return type; } - @Override - public List getNodes() { - return Collections.unmodifiableList(Arrays.asList(super.getNodeA(), super.getNodeB(), nodeC)); - } - /** @return the node with the highest voltage level */ @Override public NodeInput getNodeA() { @@ -130,6 +126,7 @@ public NodeInput getNodeB() { } /** @return the node with the lowest voltage level */ + @Override public NodeInput getNodeC() { return nodeC; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java index dd9d2bfc5..813e2c28f 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/graphics/NodeGraphicInput.java @@ -5,14 +5,14 @@ */ package edu.ie3.datamodel.models.input.graphics; -import edu.ie3.datamodel.io.extractor.Nodes; +import edu.ie3.datamodel.io.extractor.Node; import edu.ie3.datamodel.models.input.NodeInput; import java.util.*; import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; /** Describes the graphic data belonging to a {@link NodeInput} */ -public class NodeGraphicInput extends GraphicInput implements Nodes { +public class NodeGraphicInput extends GraphicInput implements Node { /** The NodeInput to this graphic data */ private final NodeInput node; /** The geometric point of this node */ @@ -32,6 +32,7 @@ public NodeGraphicInput( this.point = point; } + @Override public NodeInput getNode() { return node; } @@ -58,9 +59,4 @@ public int hashCode() { public String toString() { return "NodeGraphicInput{" + "node=" + node + ", point=" + point + '}'; } - - @Override - public List getNodes() { - return Collections.singletonList(node); - } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java index 3e195980d..18ce7827f 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/SystemParticipantInput.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; -import edu.ie3.datamodel.io.extractor.Nodes; +import edu.ie3.datamodel.io.extractor.Node; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.NodeInput; @@ -13,7 +13,7 @@ import java.util.*; /** Describes a system asset that is connected to a node */ -public abstract class SystemParticipantInput extends AssetInput implements Nodes { +public abstract class SystemParticipantInput extends AssetInput implements Node { /** The node that the asset is connected to */ private final NodeInput node; @@ -61,14 +61,11 @@ public String getqCharacteristics() { return qCharacteristics; } + @Override public NodeInput getNode() { return node; } - public List getNodes() { - return Collections.singletonList(node); - } - @Override public boolean equals(Object o) { if (this == o) return true; From 39e83f7f0798af252c8c41677011aaddef7ad2ff Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 17:18:47 +0200 Subject: [PATCH 12/21] added type interface to classes that hold a type --- src/main/java/edu/ie3/datamodel/io/extractor/Type.java | 4 ++-- .../edu/ie3/datamodel/models/input/connector/LineInput.java | 4 +++- .../datamodel/models/input/connector/Transformer2WInput.java | 4 +++- .../datamodel/models/input/connector/Transformer3WInput.java | 4 +++- .../java/edu/ie3/datamodel/models/input/system/BmInput.java | 4 +++- .../java/edu/ie3/datamodel/models/input/system/ChpInput.java | 4 +++- .../java/edu/ie3/datamodel/models/input/system/EvInput.java | 4 +++- .../edu/ie3/datamodel/models/input/system/StorageInput.java | 4 +++- .../java/edu/ie3/datamodel/models/input/system/WecInput.java | 4 +++- 9 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Type.java b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java index e6cdabecc..1d1c09d3a 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Type.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java @@ -5,7 +5,7 @@ */ package edu.ie3.datamodel.io.extractor; -import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput; +import edu.ie3.datamodel.models.input.AssetTypeInput; /** * //ToDo: Class Description // todo uml @@ -15,5 +15,5 @@ */ public interface Type extends Nested { - SystemParticipantTypeInput getType(); + AssetTypeInput getType(); } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/LineInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/LineInput.java index 1b6715150..102bee5f4 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/LineInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/LineInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.connector; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.StandardUnits; import edu.ie3.datamodel.models.input.NodeInput; @@ -21,7 +22,7 @@ * Describes an electrical grid line that connects two {@link * edu.ie3.datamodel.models.input.NodeInput}s */ -public class LineInput extends ConnectorInput { +public class LineInput extends ConnectorInput implements Type { /** Type of this line, containing default values for lines of this kind */ private final LineTypeInput type; @@ -96,6 +97,7 @@ public LineInput( this.olmCharacteristic = olmCharacteristic; } + @Override public LineTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer2WInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer2WInput.java index 91d167e4a..d030eadcd 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer2WInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer2WInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.connector; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -16,7 +17,7 @@ * Describes a two winding transformer, that is connected to two {@link * edu.ie3.datamodel.models.input.NodeInput}s */ -public class Transformer2WInput extends TransformerInput { +public class Transformer2WInput extends TransformerInput implements Type { /** Type of this 2W transformer, containing default values for transformers of this kind */ private final Transformer2WTypeInput type; @@ -74,6 +75,7 @@ public Transformer2WInput( this.type = type; } + @Override public Transformer2WTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java index da2fd8f8b..b95b1b106 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/connector/Transformer3WInput.java @@ -8,6 +8,7 @@ import static edu.ie3.util.quantities.PowerSystemUnits.PU; import edu.ie3.datamodel.io.extractor.NodeC; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -19,7 +20,7 @@ * Describes a three winding transformer, that is connected to three {@link * edu.ie3.datamodel.models.input.NodeInput}s */ -public class Transformer3WInput extends TransformerInput implements NodeC { +public class Transformer3WInput extends TransformerInput implements NodeC, Type { /** Type of this 3W transformer, containing default values for transformers of this kind */ private final Transformer3WTypeInput type; /** The lower voltage node */ @@ -109,6 +110,7 @@ public Transformer3WInput( nodeA.getSubnet()); } + @Override public Transformer3WTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/BmInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/BmInput.java index 0a8163946..5034a4b65 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/BmInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/BmInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.StandardUnits; import edu.ie3.datamodel.models.input.NodeInput; @@ -16,7 +17,7 @@ import javax.measure.Quantity; /** Describes a biomass plant */ -public class BmInput extends SystemParticipantInput { +public class BmInput extends SystemParticipantInput implements Type { /** Type of this BM plant, containing default values for BM plants of this kind */ private final BmTypeInput type; /** Is this asset market oriented? */ @@ -90,6 +91,7 @@ public BmInput( this.feedInTariff = feedInTariff.to(StandardUnits.ENERGY_PRICE); } + @Override public BmTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/ChpInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/ChpInput.java index e54dab409..8635263b4 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/ChpInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/ChpInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -15,7 +16,7 @@ import java.util.UUID; /** Describes a combined heat and power plant */ -public class ChpInput extends SystemParticipantInput { +public class ChpInput extends SystemParticipantInput implements Type { /** The thermal bus, this model is connected to */ private final ThermalBusInput thermalBus; /** Type of this CHP plant, containing default values for CHP plants of this kind */ @@ -91,6 +92,7 @@ public ThermalBusInput getThermalBus() { return thermalBus; } + @Override public ChpTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/EvInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/EvInput.java index cac3c9d83..d84ee65de 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/EvInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/EvInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -13,7 +14,7 @@ import java.util.UUID; /** Describes an electric vehicle */ -public class EvInput extends SystemParticipantInput { +public class EvInput extends SystemParticipantInput implements Type { /** Type of this EV, containing default values for EVs of this kind */ private final EvTypeInput type; /** @@ -53,6 +54,7 @@ public EvInput(UUID uuid, String id, NodeInput node, String qCharacteristics, Ev this.type = type; } + @Override public EvTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/StorageInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/StorageInput.java index 1b753906d..7df05a17c 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/StorageInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/StorageInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -13,7 +14,7 @@ import java.util.UUID; /** Describes a battery storage */ -public class StorageInput extends SystemParticipantInput { +public class StorageInput extends SystemParticipantInput implements Type { /** Type of this storage, containing default values for storages of this kind */ private final StorageTypeInput type; @@ -68,6 +69,7 @@ public StorageInput( this.behaviour = StorageStrategy.get(behaviour); } + @Override public StorageTypeInput getType() { return type; } diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/WecInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/WecInput.java index eeb89f0a9..85f005ae1 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/WecInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/WecInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -13,7 +14,7 @@ import java.util.UUID; /** Describes a Wind Energy Converter */ -public class WecInput extends SystemParticipantInput { +public class WecInput extends SystemParticipantInput implements Type { /** Type of this WEC, containing default values for WEC assets of this kind */ private final WecTypeInput type; @@ -71,6 +72,7 @@ public boolean isMarketReaction() { return marketReaction; } + @Override public WecTypeInput getType() { return type; } From 27cc3bd3188e4147d0fbce2afa3401140de25f97 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 19:32:57 +0200 Subject: [PATCH 13/21] added ExtractorTest + minor adaptions --- .../ie3/datamodel/io/extractor/Extractor.java | 17 ++-- .../ie3/datamodel/io/extractor/Nested.java | 5 +- .../models/input/system/HpInput.java | 4 +- .../io/extractor/ExtractorTest.groovy | 90 +++++++++++++++++++ 4 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 src/test/groovy/edu/ie3/datamodel/io/extractor/ExtractorTest.groovy diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index 5dd36f116..3904b306e 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -28,22 +28,25 @@ public Extractor(Nested nestedEntity) throws ExtractorException { private List extractElements(Nested nestedEntity) throws ExtractorException { List resultingList = new ArrayList<>(); - if (nestedEntity instanceof Nodes) { - resultingList.addAll( - Arrays.asList(((Nodes) nestedEntity).getNodeA(), ((Nodes) nestedEntity).getNodeB())); - } if (nestedEntity instanceof Node) { resultingList.add(((Node) nestedEntity).getNode()); } if (nestedEntity instanceof NodeC) { resultingList.add(((NodeC) nestedEntity).getNodeC()); } + if (nestedEntity instanceof Nodes) { + resultingList.addAll( + Arrays.asList(((Nodes) nestedEntity).getNodeA(), ((Nodes) nestedEntity).getNodeB())); + } if (nestedEntity instanceof Type) { resultingList.add(((Type) nestedEntity).getType()); - } else { + } + if (resultingList.isEmpty()) { throw new ExtractorException( - "The interface 'Nested' is not meant to be extended and cannot be processed by " - + "the extractor! Currently only the interfaces ‘Nodes‘ and ‘Type' are supported!"); + "The interface 'Nested' is not meant to be extended. The provided entity of class '" + + nestedEntity.getClass().getSimpleName() + + "' and cannot be processed by " + + "the extractor! Currently only the interfaces 'Node', 'NodeC', ‘Nodes‘ and ‘Type' are supported!"); } return Collections.unmodifiableList(resultingList); diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java index 0b17f1997..271871bf7 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java @@ -6,9 +6,8 @@ package edu.ie3.datamodel.io.extractor; /** - * //ToDo: Class Description - * - *

THIS interface is not meant to be extended! + * //ToDo: Class Description THIS interface is not meant to be extended or implemented by other + * classes or interfaces other than defined in this package and used by the extractor * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/models/input/system/HpInput.java b/src/main/java/edu/ie3/datamodel/models/input/system/HpInput.java index fc9cbc558..ebed7844a 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/system/HpInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/system/HpInput.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.input.system; +import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.models.OperationTime; import edu.ie3.datamodel.models.input.NodeInput; import edu.ie3.datamodel.models.input.OperatorInput; @@ -14,7 +15,7 @@ import java.util.UUID; /** Describes a heat pump */ -public class HpInput extends SystemParticipantInput { +public class HpInput extends SystemParticipantInput implements Type { /** Type of this heat pump, containing default values for heat pump of this kind */ private final HpTypeInput type; /** The thermal bus, this model is connected to */ @@ -68,6 +69,7 @@ public HpInput( this.type = type; } + @Override public HpTypeInput getType() { return type; } diff --git a/src/test/groovy/edu/ie3/datamodel/io/extractor/ExtractorTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/extractor/ExtractorTest.groovy new file mode 100644 index 000000000..02fba6f64 --- /dev/null +++ b/src/test/groovy/edu/ie3/datamodel/io/extractor/ExtractorTest.groovy @@ -0,0 +1,90 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ +package edu.ie3.datamodel.io.extractor + +import edu.ie3.datamodel.exceptions.ExtractorException +import edu.ie3.test.common.GridTestData as gtd +import edu.ie3.test.common.SystemParticipantTestData as sptd +import edu.ie3.util.TimeTools +import spock.lang.Specification + +import java.time.ZoneId + +class ExtractorTest extends Specification { + + private final class InvalidNestedExtensionClass implements Nested {} + + static { + TimeTools.initialize(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd HH:mm:ss") + } + + def "An Extractor should be able to extract an entity with nested elements correctly"() { + given: + def extractor = new Extractor(nestedEntity) + + expect: + extractor.extractedEntities == expectedExtractedEntities + + where: + nestedEntity || expectedExtractedEntities + gtd.lineCtoD || [ + gtd.lineCtoD.nodeA, + gtd.lineCtoD.nodeB, + gtd.lineCtoD.type + ] + gtd.transformerAtoBtoC || [ + gtd.transformerAtoBtoC.nodeC, + gtd.transformerAtoBtoC.nodeA, + gtd.transformerAtoBtoC.nodeB, + gtd.transformerAtoBtoC.type + ] + gtd.transformerCtoG || [ + gtd.transformerCtoG.nodeA, + gtd.transformerCtoG.nodeB, + gtd.transformerCtoG.type + ] + gtd.switchAtoB || [ + gtd.switchAtoB.nodeA, + gtd.switchAtoB.nodeB + ] + sptd.fixedFeedInInput || [sptd.fixedFeedInInput.node] + sptd.wecInput || [ + sptd.wecInput.node, + sptd.wecInput.type + ] + sptd.chpInput || [ + sptd.chpInput.node, + sptd.chpInput.type + ] + sptd.bmInput || [ + sptd.bmInput.node, + sptd.bmInput.type + ] + sptd.evInput || [ + sptd.evInput.node, + sptd.evInput.type + ] + sptd.storageInput || [ + sptd.storageInput.node, + sptd.storageInput.type + ] + sptd.hpInput || [ + sptd.hpInput.node, + sptd.hpInput.type + ] + } + + def "An Extractor should throw an ExtractorException if the provided Nested entity is unknown and or an invalid extension of the 'Nested' interface took place"() { + when: + new Extractor(new InvalidNestedExtensionClass()) + + then: + ExtractorException ex = thrown() + ex.message == "The interface 'Nested' is not meant to be extended. The provided entity of class " + + "'InvalidNestedExtensionClass' and cannot be processed by the extractor! Currently only the interfaces " + + "'Node', 'NodeC', ‘Nodes‘ and ‘Type' are supported!" + } +} From 137615133606c02c8339fb1da953926ca1e8a54d Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 19:58:53 +0200 Subject: [PATCH 14/21] extended tests for CsvFileSink --- .../ie3/datamodel/io/sink/CsvFileSink.java | 12 +++++----- .../edu/ie3/datamodel/io/sink/DataSink.java | 4 +++- .../datamodel/io/sink/CsvFileSinkTest.groovy | 22 +++++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index 89f3c45b2..946496536 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -107,7 +107,7 @@ public void persistAll(Collection entities) { } @Override - public void persistAllIgnoreNested(C entity) { + public void persistIgnoreNested(C entity) { LinkedHashMap entityFieldData = processorProvider .processEntity(entity) @@ -130,16 +130,16 @@ public void persistAllIgnoreNested(C entity) { @Override public void persistAllIgnoreNested(Collection entities) { - entities.parallelStream().forEach(this::persistAllIgnoreNested); + entities.parallelStream().forEach(this::persistIgnoreNested); } @Override public void persist(T entity) { if (entity instanceof Nested) { try { - Extractor extractor = new Extractor((Type) entity); - for (InputEntity ent : extractor.getExtractedEntities()) { - persistAllIgnoreNested(ent); + persistIgnoreNested(entity); + for (InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { + persistIgnoreNested(ent); } } catch (ExtractorException e) { @@ -150,7 +150,7 @@ public void persist(T entity) { e); } } else { - persistAllIgnoreNested(entity); + persistIgnoreNested(entity); } } diff --git a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java index d343bde4e..eebd91a3b 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java @@ -19,7 +19,9 @@ public interface DataSink { void persistAll(Collection entities); - void persistAllIgnoreNested(C entity); + // todo description + void persistIgnoreNested(C entity); + // todo description void persistAllIgnoreNested(Collection entities); } diff --git a/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy index fa860ad24..1ea1412a8 100644 --- a/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy @@ -7,12 +7,19 @@ package edu.ie3.datamodel.io.sink import edu.ie3.datamodel.exceptions.SinkException import edu.ie3.datamodel.io.FileNamingStrategy +import edu.ie3.datamodel.io.extractor.Nested import edu.ie3.datamodel.io.processor.ProcessorProvider +import edu.ie3.datamodel.io.processor.input.InputEntityProcessor import edu.ie3.datamodel.io.processor.result.ResultEntityProcessor import edu.ie3.datamodel.models.StandardUnits +import edu.ie3.datamodel.models.UniqueEntity +import edu.ie3.datamodel.models.input.NodeInput +import edu.ie3.datamodel.models.input.connector.Transformer2WInput +import edu.ie3.datamodel.models.input.connector.type.Transformer2WTypeInput import edu.ie3.datamodel.models.result.system.EvResult import edu.ie3.datamodel.models.result.system.PvResult import edu.ie3.datamodel.models.result.system.WecResult +import edu.ie3.test.common.GridTestData import edu.ie3.util.TimeTools import edu.ie3.util.io.FileIOUtils import spock.lang.Shared @@ -68,7 +75,10 @@ class CsvFileSinkTest extends Specification { new ProcessorProvider([ new ResultEntityProcessor(PvResult), new ResultEntityProcessor(WecResult), - new ResultEntityProcessor(EvResult) + new ResultEntityProcessor(EvResult), + new InputEntityProcessor(Transformer2WInput), + new InputEntityProcessor(NodeInput), + new InputEntityProcessor(Transformer2WTypeInput) ]), new FileNamingStrategy(), false, @@ -82,13 +92,20 @@ class CsvFileSinkTest extends Specification { WecResult wecResult = new WecResult(uuid, TimeTools.toZonedDateTime("2020-01-30 17:26:44"), inputModel, p, q) when: - csvFileSink.persistAll([pvResult, wecResult]) + csvFileSink.persistAll([ + pvResult, + wecResult, + GridTestData.transformerCtoG + ]) csvFileSink.dataConnector.shutdown() then: new File(testBaseFolderPath).exists() new File(testBaseFolderPath + File.separator + "wec_res.csv").exists() new File(testBaseFolderPath + File.separator + "pv_res.csv").exists() + new File(testBaseFolderPath + File.separator + "transformer2w_type_input.csv").exists() + new File(testBaseFolderPath + File.separator + "node_input.csv").exists() + new File(testBaseFolderPath + File.separator + "transformer2w_input.csv").exists() !new File(testBaseFolderPath + File.separator + "ev_res.csv").exists() } @@ -116,4 +133,5 @@ class CsvFileSinkTest extends Specification { then: thrown(SinkException) } + } From 5547b549c78f3785223b171b2c67f3815ff27949 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 20:06:57 +0200 Subject: [PATCH 15/21] reduced constructor complexity in CsvFileSink --- .../ie3/datamodel/io/sink/CsvFileSink.java | 310 ++++++++---------- 1 file changed, 141 insertions(+), 169 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index 946496536..79027de79 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation -*/ + */ package edu.ie3.datamodel.io.sink; import edu.ie3.datamodel.exceptions.ExtractorException; @@ -16,13 +16,16 @@ import edu.ie3.datamodel.io.processor.ProcessorProvider; import edu.ie3.datamodel.models.UniqueEntity; import edu.ie3.datamodel.models.input.InputEntity; + import java.io.BufferedWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + /** * Sink that provides all capabilities to write {@link UniqueEntity}s to .csv-files * @@ -31,179 +34,148 @@ */ public class CsvFileSink implements DataSink { - private static final Logger log = LogManager.getLogger(CsvFileSink.class); - - private final CsvFileConnector connector; - private final ProcessorProvider processorProvider; - - private final String csvSep; - - public CsvFileSink(String baseFolderPath) { - this(baseFolderPath, new FileNamingStrategy(), false, ","); - } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. This - * implementation processes in sequential order. To parallelize this process one might consider - * starting several sinks and use them for specific entities. - * - * @param baseFolderPath the base folder path where the files should be put into - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink( - String baseFolderPath, - FileNamingStrategy fileNamingStrategy, - boolean initFiles, - String csvSep) { - this.csvSep = csvSep; - this.processorProvider = new ProcessorProvider(); - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if (initFiles) initFiles(processorProvider, connector); - } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. This - * implementation processes in sequential order. To parallelize this process one might consider - * starting several sinks and use them for specific entities. Be careful when providing your own - * {@link ProcessorProvider} because if you're not 100% sure that it knows about all entities - * you're going to process exceptions might occur. Therefore it is strongly advised to either use - * a constructor without providing the {@link ProcessorProvider} or provide a general {@link - * ProcessorProvider} by calling {@link ProcessorProvider()} - * - * @param baseFolderPath the base folder path where the files should be put into - * @param processorProvider the processor provided that should be used for entity de-serialization - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink( - String baseFolderPath, - ProcessorProvider processorProvider, - FileNamingStrategy fileNamingStrategy, - boolean initFiles, - String csvSep) { - this.csvSep = csvSep; - this.processorProvider = processorProvider; - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if (initFiles) initFiles(processorProvider, connector); - } - - @Override - public DataConnector getDataConnector() { - return connector; - } - - @Override - public void persistAll(Collection entities) { - for (T entity : entities) { - persist(entity); + private static final Logger log = LogManager.getLogger(CsvFileSink.class); + + private final CsvFileConnector connector; + private final ProcessorProvider processorProvider; + + private final String csvSep; + + public CsvFileSink(String baseFolderPath) { + this(baseFolderPath, new FileNamingStrategy(), false, ","); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. + * + * @param baseFolderPath the base folder path where the files should be put into + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink(String baseFolderPath, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep) { + this(baseFolderPath, new ProcessorProvider(), fileNamingStrategy, initFiles, csvSep); } - } - - @Override - public void persistIgnoreNested(C entity) { - LinkedHashMap entityFieldData = - processorProvider - .processEntity(entity) - .orElseThrow( - () -> - new SinkException( - "Cannot persist entity of type '" - + entity.getClass().getSimpleName() - + "'. This sink can only process the following entities: [" - + processorProvider.getRegisteredClasses().stream() - .map(Class::getSimpleName) - .collect(Collectors.joining(",")) - + "]")); - - String[] headerElements = - processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); - BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); - write(entityFieldData, headerElements, writer); - } - - @Override - public void persistAllIgnoreNested(Collection entities) { - entities.parallelStream().forEach(this::persistIgnoreNested); - } - - @Override - public void persist(T entity) { - if (entity instanceof Nested) { - try { - persistIgnoreNested(entity); - for (InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { - persistIgnoreNested(ent); + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. Be careful when providing your own + * {@link ProcessorProvider} because if you're not 100% sure that it knows about all entities + * you're going to process exceptions might occur. Therefore it is strongly advised to either use + * a constructor without providing the {@link ProcessorProvider} or provide a general {@link + * ProcessorProvider} by calling {@link ProcessorProvider()} + * + * @param baseFolderPath the base folder path where the files should be put into + * @param processorProvider the processor provided that should be used for entity de-serialization + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink(String baseFolderPath, + ProcessorProvider processorProvider, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this.csvSep = csvSep; + this.processorProvider = processorProvider; + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if(initFiles) + initFiles(processorProvider, connector); + } + + @Override + public DataConnector getDataConnector() { + return connector; + } + + @Override + public void persistAll(Collection entities) { + for(T entity : entities) { + persist(entity); } + } - } catch (ExtractorException e) { - log.error( - "An error occurred during extraction of nested entity'" - + entity.getClass().getSimpleName() - + "': ", - e); - } - } else { - persistIgnoreNested(entity); + @Override + public void persistIgnoreNested(C entity) { + LinkedHashMap entityFieldData = processorProvider.processEntity(entity) + .orElseThrow(() -> new SinkException( + "Cannot persist entity of type '" + entity.getClass().getSimpleName() + + "'. This sink can only process the following entities: [" + + processorProvider.getRegisteredClasses().stream().map(Class::getSimpleName) + .collect(Collectors.joining(",")) + "]")); + + String[] headerElements = processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); + BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); + write(entityFieldData, headerElements, writer); } - } - - /** - * Initialize files, hence create a file for each expected class that will be processed in the - * future. - * - * @param processorProvider the processor provider all files that will be processed is derived - * from - * @param connector the connector to the files - */ - private void initFiles( - final ProcessorProvider processorProvider, final CsvFileConnector connector) { - - processorProvider - .getRegisteredClasses() - .forEach( - clz -> - processorProvider - .getHeaderElements(clz) - .ifPresent( - headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); - } - - /** - * Actually persisting the provided entity field data - * - * @param entityFieldData a mapping of an entity instance fields to their values - * @param headerElements the header elements of the entity, normally all attributes of the entity - * class - * @param writer the corresponding writer for that should be used - */ - private void write( - LinkedHashMap entityFieldData, - String[] headerElements, - BufferedWriter writer) { - - try { - for (int i = 0; i < headerElements.length; i++) { - String attribute = headerElements[i]; - writer.append(entityFieldData.get(attribute)); - if (i + 1 < headerElements.length) { - writer.append(csvSep); + + @Override + public void persistAllIgnoreNested(Collection entities) { + entities.parallelStream().forEach(this::persistIgnoreNested); + } + + @Override + public void persist(T entity) { + if(entity instanceof Nested) { + try { + persistIgnoreNested(entity); + for(InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { + persistIgnoreNested(ent); + } + + } catch(ExtractorException e) { + log.error("An error occurred during extraction of nested entity'" + entity.getClass().getSimpleName() + + "': ", e); + } } else { - writer.append("\n"); + persistIgnoreNested(entity); + } + } + + /** + * Initialize files, hence create a file for each expected class that will be processed in the + * future. + * + * @param processorProvider the processor provider all files that will be processed is derived + * from + * @param connector the connector to the files + */ + private void initFiles(final ProcessorProvider processorProvider, final CsvFileConnector connector) { + + processorProvider.getRegisteredClasses().forEach(clz -> processorProvider.getHeaderElements(clz) + .ifPresent(headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); + } + + /** + * Actually persisting the provided entity field data + * + * @param entityFieldData a mapping of an entity instance fields to their values + * @param headerElements the header elements of the entity, normally all attributes of the entity + * class + * @param writer the corresponding writer for that should be used + */ + private void write(LinkedHashMap entityFieldData, String[] headerElements, BufferedWriter writer) { + + try { + for(int i = 0; i < headerElements.length; i++) { + String attribute = headerElements[i]; + writer.append(entityFieldData.get(attribute)); + if(i + 1 < headerElements.length) { + writer.append(csvSep); + } else { + writer.append("\n"); + } + } + writer.flush(); + } catch(IOException e) { + log.error("Error while writing entity with field data: " + + Arrays.toString(entityFieldData.entrySet().toArray()), e); } - } - writer.flush(); - } catch (IOException e) { - log.error( - "Error while writing entity with field data: " - + Arrays.toString(entityFieldData.entrySet().toArray()), - e); } - } } From c47866f17f3e8ccbcb24b54ac60586202131a0dc Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 20:12:09 +0200 Subject: [PATCH 16/21] fmt --- .../ie3/datamodel/io/sink/CsvFileSink.java | 306 ++++++++++-------- 1 file changed, 165 insertions(+), 141 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index 79027de79..d6d4d5026 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -2,7 +2,7 @@ * © 2020. TU Dortmund University, * Institute of Energy Systems, Energy Efficiency and Energy Economics, * Research group Distribution grid planning and operation - */ +*/ package edu.ie3.datamodel.io.sink; import edu.ie3.datamodel.exceptions.ExtractorException; @@ -16,16 +16,13 @@ import edu.ie3.datamodel.io.processor.ProcessorProvider; import edu.ie3.datamodel.models.UniqueEntity; import edu.ie3.datamodel.models.input.InputEntity; - import java.io.BufferedWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - /** * Sink that provides all capabilities to write {@link UniqueEntity}s to .csv-files * @@ -34,148 +31,175 @@ */ public class CsvFileSink implements DataSink { - private static final Logger log = LogManager.getLogger(CsvFileSink.class); - - private final CsvFileConnector connector; - private final ProcessorProvider processorProvider; - - private final String csvSep; - - public CsvFileSink(String baseFolderPath) { - this(baseFolderPath, new FileNamingStrategy(), false, ","); - } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. This - * implementation processes in sequential order. To parallelize this process one might consider - * starting several sinks and use them for specific entities. - * - * @param baseFolderPath the base folder path where the files should be put into - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink(String baseFolderPath, FileNamingStrategy fileNamingStrategy, boolean initFiles, String csvSep) { - this(baseFolderPath, new ProcessorProvider(), fileNamingStrategy, initFiles, csvSep); + private static final Logger log = LogManager.getLogger(CsvFileSink.class); + + private final CsvFileConnector connector; + private final ProcessorProvider processorProvider; + + private final String csvSep; + + public CsvFileSink(String baseFolderPath) { + this(baseFolderPath, new FileNamingStrategy(), false, ","); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. + * + * @param baseFolderPath the base folder path where the files should be put into + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink( + String baseFolderPath, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this(baseFolderPath, new ProcessorProvider(), fileNamingStrategy, initFiles, csvSep); + } + + /** + * Create an instance of a csv file sink that can be used to persist Unique entities. This + * implementation processes in sequential order. To parallelize this process one might consider + * starting several sinks and use them for specific entities. Be careful when providing your own + * {@link ProcessorProvider} because if you're not 100% sure that it knows about all entities + * you're going to process exceptions might occur. Therefore it is strongly advised to either use + * a constructor without providing the {@link ProcessorProvider} or provide a general {@link + * ProcessorProvider} by calling {@link ProcessorProvider()} + * + * @param baseFolderPath the base folder path where the files should be put into + * @param processorProvider the processor provided that should be used for entity de-serialization + * @param fileNamingStrategy the file naming strategy that should be used + * @param initFiles true if the files should be created during initialization (might create files, + * that only consist of a headline, because no data will be writen into them), false otherwise + * @param csvSep the csv file separator that should be use + */ + public CsvFileSink( + String baseFolderPath, + ProcessorProvider processorProvider, + FileNamingStrategy fileNamingStrategy, + boolean initFiles, + String csvSep) { + this.csvSep = csvSep; + this.processorProvider = processorProvider; + this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); + + if (initFiles) initFiles(processorProvider, connector); + } + + @Override + public DataConnector getDataConnector() { + return connector; + } + + @Override + public void persistAll(Collection entities) { + for (T entity : entities) { + persist(entity); } - - /** - * Create an instance of a csv file sink that can be used to persist Unique entities. This - * implementation processes in sequential order. To parallelize this process one might consider - * starting several sinks and use them for specific entities. Be careful when providing your own - * {@link ProcessorProvider} because if you're not 100% sure that it knows about all entities - * you're going to process exceptions might occur. Therefore it is strongly advised to either use - * a constructor without providing the {@link ProcessorProvider} or provide a general {@link - * ProcessorProvider} by calling {@link ProcessorProvider()} - * - * @param baseFolderPath the base folder path where the files should be put into - * @param processorProvider the processor provided that should be used for entity de-serialization - * @param fileNamingStrategy the file naming strategy that should be used - * @param initFiles true if the files should be created during initialization (might create files, - * that only consist of a headline, because no data will be writen into them), false otherwise - * @param csvSep the csv file separator that should be use - */ - public CsvFileSink(String baseFolderPath, - ProcessorProvider processorProvider, - FileNamingStrategy fileNamingStrategy, - boolean initFiles, - String csvSep) { - this.csvSep = csvSep; - this.processorProvider = processorProvider; - this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy); - - if(initFiles) - initFiles(processorProvider, connector); - } - - @Override - public DataConnector getDataConnector() { - return connector; - } - - @Override - public void persistAll(Collection entities) { - for(T entity : entities) { - persist(entity); + } + + @Override + public void persistIgnoreNested(C entity) { + LinkedHashMap entityFieldData = + processorProvider + .processEntity(entity) + .orElseThrow( + () -> + new SinkException( + "Cannot persist entity of type '" + + entity.getClass().getSimpleName() + + "'. This sink can only process the following entities: [" + + processorProvider.getRegisteredClasses().stream() + .map(Class::getSimpleName) + .collect(Collectors.joining(",")) + + "]")); + + String[] headerElements = + processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); + BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); + write(entityFieldData, headerElements, writer); + } + + @Override + public void persistAllIgnoreNested(Collection entities) { + entities.parallelStream().forEach(this::persistIgnoreNested); + } + + @Override + public void persist(T entity) { + if (entity instanceof Nested) { + try { + persistIgnoreNested(entity); + for (InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { + persistIgnoreNested(ent); } - } - @Override - public void persistIgnoreNested(C entity) { - LinkedHashMap entityFieldData = processorProvider.processEntity(entity) - .orElseThrow(() -> new SinkException( - "Cannot persist entity of type '" + entity.getClass().getSimpleName() + - "'. This sink can only process the following entities: [" + - processorProvider.getRegisteredClasses().stream().map(Class::getSimpleName) - .collect(Collectors.joining(",")) + "]")); - - String[] headerElements = processorProvider.getHeaderElements(entity.getClass()).orElse(new String[0]); - BufferedWriter writer = connector.getOrInitWriter(entity.getClass(), headerElements, csvSep); - write(entityFieldData, headerElements, writer); + } catch (ExtractorException e) { + log.error( + "An error occurred during extraction of nested entity'" + + entity.getClass().getSimpleName() + + "': ", + e); + } + } else { + persistIgnoreNested(entity); } - - @Override - public void persistAllIgnoreNested(Collection entities) { - entities.parallelStream().forEach(this::persistIgnoreNested); - } - - @Override - public void persist(T entity) { - if(entity instanceof Nested) { - try { - persistIgnoreNested(entity); - for(InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { - persistIgnoreNested(ent); - } - - } catch(ExtractorException e) { - log.error("An error occurred during extraction of nested entity'" + entity.getClass().getSimpleName() + - "': ", e); - } + } + + /** + * Initialize files, hence create a file for each expected class that will be processed in the + * future. + * + * @param processorProvider the processor provider all files that will be processed is derived + * from + * @param connector the connector to the files + */ + private void initFiles( + final ProcessorProvider processorProvider, final CsvFileConnector connector) { + + processorProvider + .getRegisteredClasses() + .forEach( + clz -> + processorProvider + .getHeaderElements(clz) + .ifPresent( + headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); + } + + /** + * Actually persisting the provided entity field data + * + * @param entityFieldData a mapping of an entity instance fields to their values + * @param headerElements the header elements of the entity, normally all attributes of the entity + * class + * @param writer the corresponding writer for that should be used + */ + private void write( + LinkedHashMap entityFieldData, + String[] headerElements, + BufferedWriter writer) { + + try { + for (int i = 0; i < headerElements.length; i++) { + String attribute = headerElements[i]; + writer.append(entityFieldData.get(attribute)); + if (i + 1 < headerElements.length) { + writer.append(csvSep); } else { - persistIgnoreNested(entity); - } - } - - /** - * Initialize files, hence create a file for each expected class that will be processed in the - * future. - * - * @param processorProvider the processor provider all files that will be processed is derived - * from - * @param connector the connector to the files - */ - private void initFiles(final ProcessorProvider processorProvider, final CsvFileConnector connector) { - - processorProvider.getRegisteredClasses().forEach(clz -> processorProvider.getHeaderElements(clz) - .ifPresent(headerElements -> connector.getOrInitWriter(clz, headerElements, csvSep))); - } - - /** - * Actually persisting the provided entity field data - * - * @param entityFieldData a mapping of an entity instance fields to their values - * @param headerElements the header elements of the entity, normally all attributes of the entity - * class - * @param writer the corresponding writer for that should be used - */ - private void write(LinkedHashMap entityFieldData, String[] headerElements, BufferedWriter writer) { - - try { - for(int i = 0; i < headerElements.length; i++) { - String attribute = headerElements[i]; - writer.append(entityFieldData.get(attribute)); - if(i + 1 < headerElements.length) { - writer.append(csvSep); - } else { - writer.append("\n"); - } - } - writer.flush(); - } catch(IOException e) { - log.error("Error while writing entity with field data: " + - Arrays.toString(entityFieldData.entrySet().toArray()), e); + writer.append("\n"); } + } + writer.flush(); + } catch (IOException e) { + log.error( + "Error while writing entity with field data: " + + Arrays.toString(entityFieldData.entrySet().toArray()), + e); } + } } From d45c2a92d2066dbe062032177e48dff39fb849a6 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Tue, 31 Mar 2020 20:18:16 +0200 Subject: [PATCH 17/21] addressing codacy issues --- .../groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy b/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy index 1ea1412a8..793b64ac1 100644 --- a/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy @@ -7,12 +7,10 @@ package edu.ie3.datamodel.io.sink import edu.ie3.datamodel.exceptions.SinkException import edu.ie3.datamodel.io.FileNamingStrategy -import edu.ie3.datamodel.io.extractor.Nested import edu.ie3.datamodel.io.processor.ProcessorProvider import edu.ie3.datamodel.io.processor.input.InputEntityProcessor import edu.ie3.datamodel.io.processor.result.ResultEntityProcessor import edu.ie3.datamodel.models.StandardUnits -import edu.ie3.datamodel.models.UniqueEntity import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.connector.Transformer2WInput import edu.ie3.datamodel.models.input.connector.type.Transformer2WTypeInput From 7b484fbb6c8cbaba1b6a418acfe64e1aeb8ef309 Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Wed, 1 Apr 2020 09:03:44 +0200 Subject: [PATCH 18/21] added new interfaces to InputDatamodelConcept.puml --- docs/uml/main/InputDatamodelConcept.puml | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/uml/main/InputDatamodelConcept.puml b/docs/uml/main/InputDatamodelConcept.puml index 79af3962e..267342b24 100644 --- a/docs/uml/main/InputDatamodelConcept.puml +++ b/docs/uml/main/InputDatamodelConcept.puml @@ -1,5 +1,23 @@ @startuml +'extractor interface information + +interface Nested + +interface Node +Node --|> Nested + +interface Nodes +Nodes --|> Nested + +interface NodeC +NodeC --|> Nested + +interface Type +Type --|> Nested + + + abstract Class UniqueEntity { + uuid: UUID } @@ -24,6 +42,7 @@ abstract Class SystemParticipantInput { - qCharacteristics: String } SystemParticipantInput --|> AssetInput +SystemParticipantInput --|> Node Class OperatorInput { + name: String @@ -35,6 +54,7 @@ abstract Class ConnectorInput { + nodeB: NodeInput } ConnectorInput --|> AssetInput +ConnectorInput --|> Nodes abstract Class AssetCharacteristicsInput { - type: T @@ -208,12 +228,14 @@ Class WecInput{ - marketReaction: Boolean } WecInput --|> SystemParticipantInput +WecInput --|> Type Class ChpInput { - type: ChpTypeInput - marketReaction: Boolean } ChpInput --|> SystemParticipantInput +ChpInput --|> Type Class BmInput { - type: BmTypeInput @@ -223,11 +245,13 @@ Class BmInput { - costControlled: Boolean } BmInput --|> SystemParticipantInput +BmInput --|> Type Class EvInput { - type: EvTypeInput } EvInput --|> SystemParticipantInput +EvInput --|> Type Class LoadInput { - scenario: String @@ -242,11 +266,13 @@ Class StorageInput { - behaviour: String } StorageInput --|> SystemParticipantInput +StorageInput --|> Type Class HpInput { - type: HpTypeInput } HpInput --|> SystemParticipantInput +HpInput --|> Type Abstract Class ThermalUnitInput { - uuid: UUID @@ -314,6 +340,7 @@ Class LineInput { + geoPosition: LineString } LineInput --|> ConnectorInput +LineInput --|> Type Class SwitchInput { + closed: Boolean @@ -331,12 +358,15 @@ Class Transformer2WInput { + type: Transformer2WTypeInput } Transformer2WInput --|> TransformerInput +Transformer2WInput --|> Type Class Transformer3WInput { + nodeC: NodeInput + type: Transformer3WTypeInput } Transformer3WInput --|> TransformerInput +Transformer3WInput --|> NodeC +Transformer3WInput --|> Type abstract Class GraphicInput { + graphicLayer: String From 25008b004481371a38f0f9c3ef2e9c7eef5908be Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Wed, 1 Apr 2020 09:41:08 +0200 Subject: [PATCH 19/21] added missing documentation + fmt --- .../ie3/datamodel/io/extractor/Extractor.java | 3 +- .../ie3/datamodel/io/extractor/Nested.java | 6 +- .../edu/ie3/datamodel/io/extractor/Node.java | 3 +- .../edu/ie3/datamodel/io/extractor/NodeC.java | 4 +- .../edu/ie3/datamodel/io/extractor/Nodes.java | 5 +- .../edu/ie3/datamodel/io/extractor/Type.java | 3 +- .../edu/ie3/datamodel/io/sink/DataSink.java | 59 ++++++++++++++++++- 7 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java index 3904b306e..ac8a40722 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java @@ -13,7 +13,8 @@ import java.util.List; /** - * //ToDo: Class Description + * A simple utility class that can be used by sinks to extract nested elements (e.g. nodes, types) + * that should be persisted. * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java index 271871bf7..1d34edccc 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nested.java @@ -6,8 +6,10 @@ package edu.ie3.datamodel.io.extractor; /** - * //ToDo: Class Description THIS interface is not meant to be extended or implemented by other - * classes or interfaces other than defined in this package and used by the extractor + * This interface should be implemented only by other interfaces that should be used by the {@link + * Extractor} It provides the entry point for the extraction method in the {@link Extractor}. If + * this interface is implemented by other interfaces one has to take care about, that the + * corresponding method {@link Extractor.extractElements()} is extended accordingly. * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Node.java b/src/main/java/edu/ie3/datamodel/io/extractor/Node.java index d76efe597..6acc58cee 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Node.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Node.java @@ -8,7 +8,8 @@ import edu.ie3.datamodel.models.input.NodeInput; /** - * //ToDo: Class Description + * Interface that should be implemented by all elements holding a {@link NodeInput} and should be + * processable by the {@link Extractor} * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java b/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java index 897d010d1..163011736 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/NodeC.java @@ -8,7 +8,9 @@ import edu.ie3.datamodel.models.input.NodeInput; /** - * //ToDo: Class Description // todo UML + * Interface that should be implemented by all elements holding a third {@link NodeInput} and should + * be processable by the {@link Extractor}. For now, this only holds true by the {@link + * edu.ie3.datamodel.models.input.connector.Transformer3WInput} * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java index 8cce7e3c7..3c996412c 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Nodes.java @@ -8,7 +8,10 @@ import edu.ie3.datamodel.models.input.NodeInput; /** - * //ToDo: Class Description // todo: UML + * Interface that should be implemented by all elements holding a two {@link NodeInput} elements and + * should be processable by the {@link Extractor}. For now, this only holds true by all {@link + * edu.ie3.datamodel.models.input.connector.ConnectorInput} and {@link + * edu.ie3.datamodel.models.input.connector.TransformerInput} * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/extractor/Type.java b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java index 1d1c09d3a..3ce40e09c 100644 --- a/src/main/java/edu/ie3/datamodel/io/extractor/Type.java +++ b/src/main/java/edu/ie3/datamodel/io/extractor/Type.java @@ -8,7 +8,8 @@ import edu.ie3.datamodel.models.input.AssetTypeInput; /** - * //ToDo: Class Description // todo uml + * Interface that should be implemented by all elements holding a {@link AssetTypeInput} and should + * be processable by the {@link Extractor}. * * @version 0.1 * @since 31.03.20 diff --git a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java index eebd91a3b..980e1a5f3 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/DataSink.java @@ -6,22 +6,75 @@ package edu.ie3.datamodel.io.sink; import edu.ie3.datamodel.io.connectors.DataConnector; +import edu.ie3.datamodel.io.processor.EntityProcessor; import edu.ie3.datamodel.models.UniqueEntity; import java.util.Collection; -/** Describes a class that manages data persistence */ +/** + * Describes a class that manages data persistence. A sample implementation that can be used as a + * blueprint for all method implementation incl. entity handling with processors can be found in + * {@link CsvFileSink} + */ public interface DataSink { /** @return the connector of this sink */ DataConnector getDataConnector(); + /** + * Should implement the entry point of a data sink to persist an entity. By default this method + * should take care about the extraction process of nested entities (if any) and use {@link + * edu.ie3.datamodel.io.extractor.Extractor} accordingly. For an faster method e.g. that neglects + * the nested objects persistence and only persists the uuid of the nested objects (if any), + * instead of the object itself use {@link DataSink.persistIgnoreNested()} + * + * @param entity the entity that should be persisted + * @param bounded to be all unique entities. Handling of specific entities is normally then + * executed by a specific {@link EntityProcessor} + */ void persist(C entity); + /** + * Should implement the entry point of a data sink to persist multiple entities in a collection. + * By default this method should take care about the extraction process of nested entities (if + * any) and use {@link edu.ie3.datamodel.io.extractor.Extractor} accordingly. For an faster method + * e.g. that neglects the nested objects persistence and only persists the uuid of the nested + * objects (if any), instead of the object itself use {@link DataSink.persistAllIgnoreNested()} + * + * @param entities a collection of entities that should be persisted + * @param bounded to be all unique entities. Handling of specific entities is normally then + * executed by a specific {@link EntityProcessor} + */ void persistAll(Collection entities); - // todo description + /** + * Should implement the entry point of a data sink to persist an entity. In contrast to {@link + * DataSink.persist()}, this method should not take care about the extraction process of + * nested entities (if any) but only persist the uuid of the nested entity. This might + * speed up things a little bit because of missing if-/else-clauses but can also lead to missing + * persisted data that should be persisted, but is not e.g. nested types that are not available + * anymore afterwards. It might be useful especially for all entities without nested entities. For + * all doubts about if the provided entity contains needed nested data or not {@link + * DataSink.persist()} is the recommended method to be used. + * + * @param entity the entity that should be persisted + * @param bounded to be all unique entities. Handling of specific entities is normally then + * executed by a specific {@link EntityProcessor} + */ void persistIgnoreNested(C entity); - // todo description + /** + * Should implement the entry point of a data sink to persist multiple entities in a collection. + * In contrast to {@link DataSink.persistAll()}, this method should not take care about the + * extraction process of nested entities (if any) but only persist the uuid of the nested entity. + * This might speed up things a little bit because of missing if-/else-clauses but but can + * also lead to missing persisted data that should be persisted, but is not e.g. nested types that + * are not available anymore afterwards. It might be useful especially for all entities without + * nested entities. For all doubts about if the provided entity contains needed nested data or not + * {@link DataSink.persistAll()} is the recommended method to be used. + * + * @param entities the entities that should be persisted + * @param bounded to be all unique entities. Handling of specific entities is normally then + * executed by a specific {@link EntityProcessor} + */ void persistAllIgnoreNested(Collection entities); } From 17e7438f19ba5fbf99bd4fae80058cc0c285458f Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Wed, 1 Apr 2020 09:45:41 +0200 Subject: [PATCH 20/21] fix a wrong cast in CsvFileSink --- src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index d6d4d5026..2b6c4bdae 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -134,7 +134,7 @@ public void persist(T entity) { if (entity instanceof Nested) { try { persistIgnoreNested(entity); - for (InputEntity ent : new Extractor((Type) entity).getExtractedEntities()) { + for (InputEntity ent : new Extractor((Nested) entity).getExtractedEntities()) { persistIgnoreNested(ent); } From 65040e15b6cde52eb195a7e6d66afa6cf6f79c1e Mon Sep 17 00:00:00 2001 From: Johannes Hiry Date: Wed, 1 Apr 2020 10:08:51 +0200 Subject: [PATCH 21/21] fmt --- src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java index 2b6c4bdae..a82ed5079 100644 --- a/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java +++ b/src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java @@ -12,7 +12,6 @@ import edu.ie3.datamodel.io.connectors.DataConnector; import edu.ie3.datamodel.io.extractor.Extractor; import edu.ie3.datamodel.io.extractor.Nested; -import edu.ie3.datamodel.io.extractor.Type; import edu.ie3.datamodel.io.processor.ProcessorProvider; import edu.ie3.datamodel.models.UniqueEntity; import edu.ie3.datamodel.models.input.InputEntity;