Skip to content

Commit

Permalink
Implements sct-data for postgres (using spring-data)
Browse files Browse the repository at this point in the history
Implements sct-service package
These services were implemented (in sct-service and sct-common)
	- add History
	- add IED with DataTypeTemplate
		- get ExtRef information
		- get ExtRef potential binders
		- update ExtRef binder
	- add/get subnetworks

Signed-off-by: Mohamed Sylla <mohamed.sylla@rte-france.com>
  • Loading branch information
syllamoh committed Nov 17, 2021
1 parent 6b30ae2 commit 32d3249
Show file tree
Hide file tree
Showing 96 changed files with 5,272 additions and 161 deletions.
27 changes: 26 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,40 @@
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl2007b4</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>
<!--<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.32</version>
<scope>test</scope>
</dependency>-->
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl2007b4</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<modules>
<module>sct-commons</module>
<module>sct-coverage</module>
<module>sct-data</module>
<module>sct-data-pg</module>
<module>sct-service</module>
</modules>

<build>
Expand All @@ -76,6 +96,11 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down
13 changes: 12 additions & 1 deletion sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down Expand Up @@ -67,6 +72,12 @@
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
Expand Down Expand Up @@ -98,7 +109,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>

<plugin>
Expand All @@ -111,6 +121,7 @@
<goals>
<goal>unpack</goal>
</goals>

<configuration>
<artifactItems>
<artifactItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public <T> String marshall(final T obj) {

return sw.toString();
} catch (JAXBException exp) {
String message = "Error marshalling the Class";
log.error(message, exp);
String message = String.format("Error marshalling the Class: %s", exp);
log.error(message);
throw new CompasException(CompasErrorCode.MARSHAL_ERROR_CODE, message);
}
}
Expand All @@ -58,8 +58,8 @@ public <T> T unmarshall(final InputStream xml, Class<T> cls) {
}
return cls.cast(result);
} catch (JAXBException exp) {
String message = "Error unmarshalling to the Class.";
log.error(message, exp);
String message = String.format("Error unmarshalling to the Class: %s", exp.getLocalizedMessage());
log.error(message);
throw new CompasException(CompasErrorCode.UNMARSHAL_ERROR_CODE, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2021 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.dto;


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;

import java.util.Objects;

@Setter
@Getter
@NoArgsConstructor
public class ConnectedApDTO {
private String iedName;
private String apName;

public ConnectedApDTO(ConnectedAPAdapter connectedAPAdapter) {
this.iedName = connectedAPAdapter.getIedName();
this.apName = connectedAPAdapter.getApName();
}

public static ConnectedApDTO from(ConnectedAPAdapter connectedAPAdapter) {
ConnectedApDTO connectedApDTO = new ConnectedApDTO();
connectedApDTO.iedName = connectedAPAdapter.getIedName();
connectedApDTO.apName = connectedAPAdapter.getApName();

return connectedApDTO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package org.lfenergy.compas.sct.commons.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.lfenergy.compas.scl2007b4.model.TClientLN;
import org.lfenergy.compas.scl2007b4.model.TControl;
import org.lfenergy.compas.scl2007b4.model.TControlWithIEDName;
import org.lfenergy.compas.scl2007b4.model.TPredefinedTypeOfSecurityEnum;
import org.lfenergy.compas.scl2007b4.model.TServiceSettingsNoDynEnum;
import org.lfenergy.compas.scl2007b4.model.TServiceType;
import org.lfenergy.compas.scl2007b4.model.TServices;
import org.lfenergy.compas.sct.commons.Utils;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Getter
@Setter
@NoArgsConstructor
public abstract class ControlBlock<T extends ControlBlock> {
protected String id; /// appID or smvID
protected String name;
protected String dataSetRef;
protected String desc;
protected long confRev;
protected List<TControlWithIEDName.IEDName> iedNames = new ArrayList<>();
protected TPredefinedTypeOfSecurityEnum securityEnable = TPredefinedTypeOfSecurityEnum.NONE;

protected abstract Class<T> getClassType();
public abstract TServiceType getServiceType();

public abstract <U extends TControl> U createControlBlock();

public T cast(Object obj){
if (!obj.getClass().isAssignableFrom(getClassType())) {
throw new UnsupportedOperationException("Cannot cast object to " + getClassType());
}
return (T) obj;
}

public void validateCB() throws ScdException {

if(id == null || id.isBlank()){
throw new ScdException("Control block ID is missing");
}

if(name == null || name.isBlank()){
throw new ScdException("Control block Name is missing");
}

if(dataSetRef != null && dataSetRef.isBlank()){
throw new ScdException("Control block datSet is missing");
}

if(iedNames.stream().anyMatch( iedName -> iedName == null ||
iedName.getValue() == null || iedName.getValue().isBlank() ||
iedName.getLdInst() == null || iedName.getLdInst().isBlank())) {
throw new ScdException("Control block destination IEDs are not well defined");
}
}

public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdException {
for(TControlWithIEDName.IEDName iedName : iedNames){
IEDAdapter iedAdapter =sclRootAdapter.getIEDAdapter(iedName.getValue());
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(iedName.getLdInst())
.orElseThrow(
() -> new ScdException(
String.format(
"Unknown LDevice [%s] in IED [%s]", iedName.getLdInst(),iedName.getValue()
)
)
);
if(!iedName.getLnClass().isEmpty()) {
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0),iedName.getLnInst(), iedName.getPrefix());
} else {
Utils.setField(iedName,"lnClass",null);
}
}
}

public final void validateSecurityEnabledValue(IEDAdapter iedAdapter) throws ScdException {
TServices tServices = iedAdapter.getServices();
validateSecurityEnabledValue(tServices);
}

protected Long getConfRev() {
if(dataSetRef == null || dataSetRef.isBlank()){
return 0L;
}
return 10000L ;
}

protected abstract void validateSecurityEnabledValue(TServices tServices) throws ScdException;

public static TControlWithIEDName.IEDName toIEDName(TClientLN clientLN){

TControlWithIEDName.IEDName iedName = new TControlWithIEDName.IEDName();
iedName.setValue(clientLN.getIedName());
iedName.setApRef(clientLN.getApRef());
iedName.setLdInst(clientLN.getLdInst());
iedName.setPrefix(clientLN.getPrefix());
iedName.setLnInst(clientLN.getLnInst());
iedName.getLnClass().addAll(clientLN.getLnClass());

return iedName;
}

public TServiceSettingsNoDynEnum getControlBlockServiceSetting(TServices tServices){
if(tServices == null) {
return TServiceSettingsNoDynEnum.FIX;
}

if (getServiceType() == TServiceType.GOOSE && tServices.getGSESettings() != null){
return tServices.getGSESettings().getCbName();
}
if(getServiceType() == TServiceType.SMV && tServices.getSMVSettings() != null){
return tServices.getSMVSettings().getCbName();
}
if(getServiceType() == TServiceType.REPORT && tServices.getReportSettings() != null){
return tServices.getReportSettings().getCbName();
}
return TServiceSettingsNoDynEnum.FIX;
}

@Override
public String toString() {
String values = iedNames.stream().map(TControlWithIEDName.IEDName::getValue)
.collect(Collectors.joining(","));
return "ControlBlock{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", dataSetRef='" + dataSetRef + '\'' +
", desc='" + desc + '\'' +
", confRev=" + confRev +
", iedNames=" + values +
", securityEnable=" + securityEnable +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2021 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.dto;

import lombok.Getter;
import lombok.Setter;
import org.lfenergy.compas.scl2007b4.model.TFCEnum;

import java.util.Objects;

@Getter
@Setter
public class DaTypeName extends DataTypeName{
public static final String VALIDATION_REGEX
= "[a-zA-Z][a-zA-Z0-9]*(\\([0-9]+\\))?(\\.[a-zA-Z][a-zA-Z0-9]*(\\([0-9]+\\))?)*";
private TFCEnum fc;
private String type;
private String bType;

public DaTypeName(String dataName) {
super(dataName);
validationPattern = VALIDATION_REGEX;
}

public DaTypeName(String name, String names) {
super(name, names);
validationPattern = VALIDATION_REGEX;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || o.getClass() != getClass()) return false;
if (!super.equals(o)) return false;
DaTypeName that = (DaTypeName) o;
return fc == that.fc &&
Objects.equals(bType, that.bType) &&
Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fc, bType, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.lfenergy.compas.sct.commons.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Getter
@NoArgsConstructor
public class DataSetInfo {
private String name;
private List<FCDAInfo> fcdaInfos = new ArrayList<>();

public DataSetInfo(String name){
this.name = name;
}

public void addFCDAInfo(FCDAInfo fcdaInfo){
fcdaInfos.add(fcdaInfo);
}

public List<FCDAInfo> getFcdaInfos(){
return Collections.unmodifiableList(fcdaInfos);
}

public void setName(String name){
this.name = name;
}
}
Loading

0 comments on commit 32d3249

Please sign in to comment.