Skip to content

Commit

Permalink
Merge branch 'master' into improve_two_print_online_wf_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Jan 10, 2017
2 parents 818aa70 + a2db412 commit 11f0311
Show file tree
Hide file tree
Showing 11 changed files with 647 additions and 430 deletions.
120 changes: 65 additions & 55 deletions iidm-actions-contingencies-xml-client/pom.xml
Expand Up @@ -3,66 +3,76 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.itesla_project</groupId>
<artifactId>itesla-parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.itesla_project</groupId>
<artifactId>itesla-parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>


<artifactId>iidm-actions-contingencies-xml-client</artifactId>
<version>0.1-SNAPSHOT</version>
<name>actions contingencies xml client</name>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>modules</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>iidm-actions-contingencies-xml-client</artifactId>
<version>0.1-SNAPSHOT</version>
<name>actions contingencies xml client</name>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>modules</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>iidm-network-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>iidm-network-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>

<configuration>
<packageName>eu.itesla_project.iidm.actions_contingencies.xml.mapping</packageName>
<locale>en_US</locale>
<sources>
<source>src/main/resources/xsd/actions.xsd</source>
</sources>
</configuration>

</plugin>

</plugins>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>

<configuration>
<packageName>eu.itesla_project.iidm.actions_contingencies.xml.mapping</packageName>
<locale>en_US</locale>
<sources>
<source>src/main/resources/xsd/actions.xsd</source>
</sources>
</configuration>

</plugin>

</plugins>

</build>
</build>
</project>
Expand Up @@ -7,8 +7,11 @@
*/
package eu.itesla_project.iidm.actions_contingencies.xml;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -30,6 +33,7 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import eu.itesla_project.iidm.actions_contingencies.xml.mapping.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
Expand All @@ -38,28 +42,6 @@
import eu.itesla_project.contingency.ContingencyImpl;
import eu.itesla_project.contingency.GeneratorContingency;
import eu.itesla_project.contingency.LineContingency;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Action;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionCtgAssociations;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionPlan;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionsContingencies;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.And;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Association;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Constraint;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Contingency;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ElementaryAction;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Equipment;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.GenerationOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LineOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LogicalExpression;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Operand;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Or;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.PstOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Redispatching;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.SwitchOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Then;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.VoltageLevel;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zone;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zones;
import eu.itesla_project.iidm.network.Line;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.iidm.network.TieLine;
Expand Down Expand Up @@ -101,22 +83,31 @@ public class XmlFileContingenciesAndActionsDatabaseClient implements Contingenci
private ActionsContingencies actionContingencies;
private Map<Number, String> zonesMapping = new HashMap<Number, String>();

public XmlFileContingenciesAndActionsDatabaseClient(Path file)
throws JAXBException, SAXException {
public XmlFileContingenciesAndActionsDatabaseClient(Path file) throws JAXBException, SAXException, IOException {
try (InputStream stream = Files.newInputStream(file)) {
load(stream);
}
}

public XmlFileContingenciesAndActionsDatabaseClient(URL url) throws JAXBException, SAXException, IOException {
try (InputStream stream = url.openStream()) {
load(stream);
}
}

JAXBContext jaxbContext = JAXBContext
.newInstance(ActionsContingencies.class);
private void load(InputStream stream) throws JAXBException, SAXException, IOException {
JAXBContext jaxbContext = JAXBContext.newInstance(ActionsContingencies.class);
Unmarshaller jaxbMarshaller = jaxbContext.createUnmarshaller();

SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL res=XmlFileContingenciesAndActionsDatabaseClient.class.getClassLoader().getResource("xsd/actions.xsd");
Schema schema = sf.newSchema(res);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL res = XmlFileContingenciesAndActionsDatabaseClient.class.getClassLoader().getResource("xsd/actions.xsd");
if (res == null) {
throw new IOException("Unable to find schema");
}
Schema schema = sf.newSchema(res);
jaxbMarshaller.setSchema(schema);

actionContingencies = (ActionsContingencies) jaxbMarshaller
.unmarshal(file.toFile());


actionContingencies = (ActionsContingencies) jaxbMarshaller.unmarshal(stream);
}

@Override
Expand Down Expand Up @@ -921,10 +912,17 @@ else if (sw.getAction().equals("closing"))
if ( network.getTwoWindingsTransformer(transformerId) != null ) {
if (pst.getAction().equals("shunt"))
elements.add(new ShuntAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex()));
else if (pst.getAction().equals("tapChange"))
elements.add(new TapChangeAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex()));
else if (pst.getAction().equals("tapChange")) {
Parameter tapPositionParameter = getParameter(pst.getParameter(), "tapPosition");
if (tapPositionParameter != null) {
int tapPosition = Integer.parseInt(tapPositionParameter.getValue());
elements.add(new TapChangeAction(pst.getId(), tapPosition, pst.getImplementationTime(), pst.getAchievmentIndex()));
}
}
else if (pst.getAction().equals("opening")) {
elements.add(new TransformerOpeningAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex()));
Parameter substationParameter = getParameter(pst.getParameter(), "substation");
String substation = (substationParameter == null) ? null : substationParameter.getValue();
elements.add(new TransformerOpeningAction(pst.getId(), substation, pst.getImplementationTime(), pst.getAchievmentIndex()));
}
else
LOGGER.warn("pst operation not supported : " + pst.getAction());
Expand Down Expand Up @@ -1001,4 +999,10 @@ private boolean constraintOnEquipment(List<Constraint> constraints, String equip
return false;
}

private static Parameter getParameter(List<Parameter> parameters, String name) {
Objects.requireNonNull(parameters);
Objects.requireNonNull(name);

return parameters.stream().filter(p -> p.getName().equals(name)).findFirst().get();
}
}
Expand Up @@ -6,6 +6,7 @@
*/
package eu.itesla_project.iidm.actions_contingencies.xml;

import java.io.IOException;
import java.nio.file.Path;

import javax.xml.bind.JAXBException;
Expand All @@ -21,30 +22,25 @@


/**
*
* @author Quinary <itesla@quinary.com>
*/
public class XmlFileContingenciesAndActionsDatabaseClientFactory implements
ContingenciesAndActionsDatabaseClientFactory {

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

@Override
public ContingenciesAndActionsDatabaseClient create() {
XmlFileContingenciesAndActionsDatabaseClient client=null;
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("xmlcontingencydb");
Path xmlFile = config.getPathProperty("xmlFile");

try {
client= new XmlFileContingenciesAndActionsDatabaseClient(xmlFile);
} catch (JAXBException e) {
LOGGER.error("Error loading input file "+xmlFile,e);
} catch (SAXException e) {
LOGGER.error("Error loading input file "+xmlFile,e);
}
return client;


}
ContingenciesAndActionsDatabaseClientFactory {

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

@Override
public ContingenciesAndActionsDatabaseClient create() {
XmlFileContingenciesAndActionsDatabaseClient client = null;
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("xmlcontingencydb");
Path xmlFile = config.getPathProperty("xmlFile");

try {
client = new XmlFileContingenciesAndActionsDatabaseClient(xmlFile);
} catch (JAXBException | SAXException | IOException e) {
LOGGER.error("Error loading input file " + xmlFile, e);
}

return client;
}
}

0 comments on commit 11f0311

Please sign in to comment.