Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu BAGUE committed Aug 21, 2017
1 parent 7da8a1d commit cccd1c2
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,22 @@ public ContingenciesAndActionsDatabaseClient create() {
@Override
public ContingenciesAndActionsDatabaseClient create(Path xmlFile) {
Objects.requireNonNull(xmlFile);
XmlFileContingenciesAndActionsDatabaseClient client = null;
try {
client = new XmlFileContingenciesAndActionsDatabaseClient(xmlFile);
return new XmlFileContingenciesAndActionsDatabaseClient(xmlFile);
} catch (JAXBException | SAXException | IOException e) {
LOGGER.error("Error loading input file " + xmlFile, e);
throw new ConfigurationException(e);
}
return client;
}

@Override
public ContingenciesAndActionsDatabaseClient create(InputStream data) {
Objects.requireNonNull(data);
XmlFileContingenciesAndActionsDatabaseClient client = null;
try {
client = new XmlFileContingenciesAndActionsDatabaseClient(data);
return new XmlFileContingenciesAndActionsDatabaseClient(data);
} catch (JAXBException | SAXException | IOException e) {
LOGGER.error("Error loading input data ", e);
throw new ConfigurationException(e);
}
return client;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,27 @@
public class ACXmlClientTest {

@Test
public void test() throws JAXBException, SAXException, IOException, URISyntaxException {
public void testPath() throws URISyntaxException {

URL testActionsUrl = getClass().getResource("/test-ac.xml");
ContingenciesAndActionsDatabaseClient cadbClient = new XmlFileContingenciesAndActionsDatabaseClientFactory().create(Paths.get(testActionsUrl.toURI()));

test(cadbClient);
}

@Test
public void testStream() {
ContingenciesAndActionsDatabaseClient cadbClient = new XmlFileContingenciesAndActionsDatabaseClientFactory()
.create(getClass().getResourceAsStream("/test-ac.xml"));

test(cadbClient);
}

protected void test(ContingenciesAndActionsDatabaseClient cadbClient) {
Network network = ACXmlClientTestUtils.getNetwork();

assertNotNull(cadbClient);

// Collection<Zone> getZones();
Collection<Zone> zones = cadbClient.getZones();
assertEquals(1, zones.size());
Expand Down
138 changes: 70 additions & 68 deletions iidm-actions-contingencies-xml-client/src/test/resources/test-ac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,75 @@
-->
<actionsContingencies>

<zones>
<zone name="ZONE1" number="1" description="zone one" >
<voltageLevels>
<voltageLevel ID="VL1" name="VL1" level="380" />
<voltageLevel ID="VL2" name="VL2" level="380" />
</voltageLevels>
</zone>
</zones>
<zones>
<zone name="ZONE1" number="1" description="zone one">
<voltageLevels>
<voltageLevel ID="VL1" name="VL1" level="380"/>
<voltageLevel ID="VL2" name="VL2" level="380"/>
</voltageLevels>
</zone>
</zones>

<contingencies>
<contingency>
<name>N-1_Contingency</name>
<zones>
<num>1</num>
</zones>
<equipments>
<equipment id="LINE1_ACLS"/>
</equipments>
</contingency>
</contingencies>

<elementaryActions>
<elementaryAction name="Action1" curativeType="true" preventiveType="true" startTime="120">
<description info="action 1"/>
<zones>
<num>1</num>
</zones>
<lineOperation id="LINE1_ACLS" substation="S1" action="opening" implementationTime="150"
achievmentIndex="100"/>
</elementaryAction>
<elementaryAction name="Action2" curativeType="true" preventiveType="true" startTime="120">
<description info="action 2"/>
<zones>
<num>1</num>
</zones>
<lineOperation id="LINE2_ACLS" substation="S2" action="opening" implementationTime="150"
achievmentIndex="100"/>
</elementaryAction>
</elementaryActions>

<actionPlans>
<actionPlan name="Plan1">
<description info="plan 1"/>
<zones>
<num>1</num>
</zones>
<option priority="1">
<logicalExpression>
<and>
<operand>1</operand>
<operand>2</operand>
</and>
</logicalExpression>
<action id="Action1" num="1" achievmentIndex="100"/>
<action id="Action2" num="2" achievmentIndex="100"/>
</option>
</actionPlan>
</actionPlans>

<actionCtgAssociations>
<association>
<contingency id="N-1_Contingency"/>
<constraint equipment="LINE1_ACLS" type="overload" value="1200"/>
<action id="Action2"/>
</association>
<association>
<constraint equipment="LINE2_ACLS" type="overload" value="1200"/>
<action id="Action1"/>
</association>
</actionCtgAssociations>

<contingencies>
<contingency>
<name>N-1_Contingency</name>
<zones>
<num>1</num>
</zones>
<equipments>
<equipment id="LINE1_ACLS"/>
</equipments>
</contingency>
</contingencies>

<elementaryActions>
<elementaryAction name="Action1" curativeType="true" preventiveType="true" startTime="120" >
<description info="action 1"/>
<zones>
<num>1</num>
</zones>
<lineOperation id="LINE1_ACLS" substation="S1" action="opening" implementationTime="150" achievmentIndex="100"/>
</elementaryAction>
<elementaryAction name="Action2" curativeType="true" preventiveType="true" startTime="120" >
<description info="action 2"/>
<zones>
<num>1</num>
</zones>
<lineOperation id="LINE2_ACLS" substation="S2" action="opening" implementationTime="150" achievmentIndex="100"/>
</elementaryAction>
</elementaryActions>

<actionPlans>
<actionPlan name="Plan1" >
<description info="plan 1"/>
<zones>
<num>1</num>
</zones>
<option priority="1" >
<logicalExpression>
<and>
<operand>1</operand>
<operand>2</operand>
</and>
</logicalExpression>
<action id="Action1" num="1" achievmentIndex="100" />
<action id="Action2" num="2" achievmentIndex="100" />
</option>
</actionPlan>
</actionPlans>

<actionCtgAssociations>
<association>
<contingency id="N-1_Contingency" />
<constraint equipment="LINE1_ACLS" type="overload" value="1200" />
<action id="Action2" />
</association>
<association>
<constraint equipment="LINE2_ACLS" type="overload" value="1200" />
<action id="Action1" />
</association>
</actionCtgAssociations>

</actionsContingencies>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -60,15 +61,26 @@ public class CsvFileContingenciesAndActionsDatabaseClient implements Contingenci

private static final Logger LOGGER = LoggerFactory.getLogger(CsvFileContingenciesAndActionsDatabaseClient.class);

private final List<ContingencyData> condingency_data = new ArrayList();
private final List<ContingencyData> contingency_data = new ArrayList<>();

public CsvFileContingenciesAndActionsDatabaseClient(Path file) throws IOException {
this(new FileInputStream(file.toFile()));
public CsvFileContingenciesAndActionsDatabaseClient(Path file) {
Objects.requireNonNull(file);
try (InputStream stream = Files.newInputStream(file)) {
load(stream);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

}

public CsvFileContingenciesAndActionsDatabaseClient(InputStream stream) {
load(stream);
}

public CsvFileContingenciesAndActionsDatabaseClient(InputStream input) {
private void load(InputStream stream) {
Objects.requireNonNull(stream);
try {
Reader ir = new InputStreamReader(input, Charset.defaultCharset());
Reader ir = new InputStreamReader(stream, Charset.defaultCharset());
try (BufferedReader r = new BufferedReader(ir)) {

String txt;
Expand All @@ -93,7 +105,7 @@ public CsvFileContingenciesAndActionsDatabaseClient(InputStream input) {
String id = tokens[i];
cd.addElementId(id);
}
condingency_data.add(cd);
contingency_data.add(cd);
}
}
} catch (IOException e) {
Expand All @@ -114,7 +126,7 @@ public List<Contingency> getContingencies(Network network) {
}

List<Contingency> contingencies = new ArrayList<>();
condingency_data.forEach(cd -> {
contingency_data.forEach(cd -> {
List<ContingencyElement> elements = cd.getElementsIds().stream()
.map(id -> getElement(network, tieLines, id))
.filter(Objects::nonNull)
Expand Down Expand Up @@ -219,20 +231,21 @@ public Collection<ActionsContingenciesAssociation> getActionsCtgAssociationsByCo
throw new UnsupportedOperationException();
}

private class ContingencyData {
private static class ContingencyData {
private final String id;
private final List<String> elementIds;

ContingencyData(String id) {
this.id = id;
elementIds = new ArrayList();
this.id = Objects.requireNonNull(id);
elementIds = new ArrayList<>();
}

String getId() {
return this.id;
return id;
}

void addElementId(String id) {
Objects.requireNonNull(id);
elementIds.add(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package eu.itesla_project.modules.test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Objects;
Expand All @@ -27,21 +26,16 @@ public class CsvFileContingenciesAndActionsDatabaseClientFactory implements Cont
public ContingenciesAndActionsDatabaseClient create() {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("csvcontingencydb");
Path csvFile = config.getPathProperty("csvFile");
try {
return new CsvFileContingenciesAndActionsDatabaseClient(csvFile);
} catch (IOException e) {
throw new RuntimeException(e);
}

return new CsvFileContingenciesAndActionsDatabaseClient(csvFile);
}

@Override
public ContingenciesAndActionsDatabaseClient create(Path csvFile) {
Objects.requireNonNull(csvFile);
try {
return new CsvFileContingenciesAndActionsDatabaseClient(csvFile);
} catch (IOException e) {
throw new RuntimeException(e);
}


return new CsvFileContingenciesAndActionsDatabaseClient(csvFile);
}

@Override
Expand Down

0 comments on commit cccd1c2

Please sign in to comment.