Commit 3c487bea authored by Dominique Marcadet's avatar Dominique Marcadet

add validation by ConstructedAttribute

parent 2dca1b4f
......@@ -101,10 +101,11 @@ public class CDCValidator {
for( DA da : doType.getDA() ) {
TypeValidator validator = dataAttributeValidatorMap.get( da.getName() );
if( validator != null ) {
validator.validateDA( da, diagnostics );
validator.validateAbstractDataAttribute( da, diagnostics );
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD validation] while validating DOType (line " + doType.getLineNumber() + "): validator for DA " + da.getName() + " not found" );
// DA not allowed, error will be reported by PresenceConditionValidator
//AbstractRiseClipseConsole.getConsole().warning( "[NSD validation] while validating DOType (line " + doType.getLineNumber() + "): validator for DA " + da.getName() + " not found" );
}
}
......@@ -112,7 +113,6 @@ public class CDCValidator {
CDCValidator validator = subDataObjectValidatorMap.get( sdo.getName() );
if( validator != null ) {
if( sdo.getRefersToDOType() != null ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validateDOType( " + doType.getId() + " ) on sdo " + sdo.getName() );
res = validator.validateDOType( sdo.getRefersToDOType(), diagnostics ) && res;
}
else {
......
/**
* Copyright (c) 2019 CentraleSupélec & EDF.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec
* EDF R&D
* Contacts:
* dominique.marcadet@centralesupelec.fr
* aurelie.dehouck-neveu@edf.fr
* Web site:
* http://wdi.supelec.fr/software/RiseClipse/
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd;
import java.util.HashMap;
import java.util.HashSet;
import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.ConstructedAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.SubDataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.BDA;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DAType;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class ConstructedAttributeValidator extends TypeValidator {
private SubDataAttributePresenceConditionValidator subDataAttributePresenceConditionValidator;
private HashMap< String, TypeValidator > subDataAttributeValidatorMap = new HashMap<>();
private HashSet< DAType > validatedDAType = new HashSet<>();
public ConstructedAttributeValidator( ConstructedAttribute contructedAttribute ) {
subDataAttributePresenceConditionValidator = SubDataAttributePresenceConditionValidator.get( contructedAttribute );
for( SubDataAttribute sda : contructedAttribute.getSubDataAttribute() ) {
TypeValidator validator = TypeValidator.get( sda.getType() );
if( validator != null ) {
subDataAttributeValidatorMap.put( sda.getName(), validator );
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD setup] Type not found for DataAttribute " + sda.getName() );
}
}
}
@Override
public boolean validateAbstractDataAttribute( AbstractDataAttribute da, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] ConstructedAttributeValidator.validateBDA( " + da.getName() + " ) at line " + da.getLineNumber() );
boolean res = true;
if( da.getRefersToDAType() != null ) {
res = validateDAType( da.getRefersToDAType(), diagnostics ) && res;
}
return res;
}
private boolean validateDAType( DAType daType, DiagnosticChain diagnostics ) {
if( validatedDAType.contains( daType )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] ConstructedAttributeValidator.validateDAType( " + daType.getId() + " ) at line " + daType.getLineNumber() );
validatedDAType.add( daType );
subDataAttributePresenceConditionValidator.reset();
daType
.getBDA()
.stream()
.forEach( bda -> subDataAttributePresenceConditionValidator.addBDA( bda, diagnostics ));
boolean res = subDataAttributePresenceConditionValidator.validate( daType, diagnostics );
for( BDA bda : daType.getBDA() ) {
TypeValidator validator = subDataAttributeValidatorMap.get( bda.getName() );
if( validator != null ) {
validator.validateAbstractDataAttribute( bda, diagnostics );
}
else {
// BDA not allowed, error will be reported by PresenceConditionValidator
//AbstractRiseClipseConsole.getConsole().warning( "[NSD validation] while validating DAType (line " + daType.getLineNumber() + "): validator for BDA " + bda.getName() + " not found" );
}
}
return res;
}
}
......@@ -496,42 +496,42 @@ public class DataAttributePresenceConditionValidator {
if( mandatoryIfSiblingPresentElseForbidden != null ) {
for( Entry< String, String > e : mandatoryIfSiblingPresentElseForbidden.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
if( mandatoryIfSiblingPresentElseOptional != null ) {
for( Entry< String, String > e : mandatoryIfSiblingPresentElseOptional.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
if( optionalIfSiblingPresentElseMandatory != null ) {
for( Entry< String, String > e : optionalIfSiblingPresentElseMandatory.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
if( forbiddenIfSiblingPresentElseMandatory != null ) {
for( Entry< String, String > e : forbiddenIfSiblingPresentElseMandatory.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
if( oneOrMoreIfSiblingPresentElseForbidden != null ) {
for( Entry< String, String > e : oneOrMoreIfSiblingPresentElseForbidden.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
if( optionalIfSiblingPresentElseForbidden != null ) {
for( Entry< String, String > e : optionalIfSiblingPresentElseForbidden.entrySet() ) {
if( ! presentDA.containsKey( e.getValue() )) {
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" );
console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" );
}
}
}
......
......@@ -26,7 +26,7 @@ import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumeration;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DA;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumType;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumVal;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.Val;
......@@ -56,8 +56,8 @@ public class EnumerationValidator extends TypeValidator {
}
@Override
public boolean validateDA( DA da, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] EnumerationValidator.validateDA( " + da.getName() + " ) at line " + da.getLineNumber() );
public boolean validateAbstractDataAttribute( AbstractDataAttribute ada, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] EnumerationValidator.validateAbstractDataAttribute( " + ada.getName() + " ) at line " + ada.getLineNumber() );
if(( inheritedFromName != null ) && ( inheritedFrom == null )) {
TypeValidator inheritedValidator = TypeValidator.get( inheritedFromName );
......@@ -70,59 +70,56 @@ public class EnumerationValidator extends TypeValidator {
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] validator for inherited enumeration " + inheritedFromName + " not found",
new Object[] { da } ));
new Object[] { ada } ));
// Avoid checking again
inheritedFromName = null;
}
}
boolean res = true;
if( ! "Enum".equals( da.getBType() )) {
if( ! "Enum".equals( ada.getBType() )) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] bType of DA " + da.getName() + " in DOType (id = " + da.getParentDOType().getId()
+ ", line = " + da.getParentDOType().getLineNumber() + ") is not Enum",
new Object[] { da } ));
"[NSD validation] bType of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not Enum",
new Object[] { ada } ));
res = false;
}
if( ! getName().equals( da.getType() )) {
if( ! getName().equals( ada.getType() )) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] type of DA " + da.getName() + " in DOType (id = " + da.getParentDOType().getId()
+ ", line = " + da.getParentDOType().getLineNumber() + ") is not " + getName(),
new Object[] { da } ));
"[NSD validation] type of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not " + getName(),
new Object[] { ada } ));
res = false;
}
for( Val val : da.getVal() ) {
res = validateValue( da, val.getValue(), diagnostics ) && res;
for( Val val : ada.getVal() ) {
res = validateValue( ada, val.getValue(), diagnostics ) && res;
}
if( da.getRefersToEnumType() != null ) {
res = validateEnumType( da.getRefersToEnumType(), diagnostics ) && res;
if( ada.getRefersToEnumType() != null ) {
res = validateEnumType( ada.getRefersToEnumType(), diagnostics ) && res;
}
return res;
}
protected boolean validateValue( DA da, String value, DiagnosticChain diagnostics ) {
protected boolean validateValue( AbstractDataAttribute ada, String value, DiagnosticChain diagnostics ) {
boolean res = true;
if( ! literals.containsKey( value )) {
if( inheritedFrom != null ) {
res = inheritedFrom.validateValue( da, value, diagnostics ) && res;
res = inheritedFrom.validateValue( ada, value, diagnostics ) && res;
}
else {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] value of DA " + da.getName() + " in DOType (id = " + da.getParentDOType().getId()
+ ", line = " + da.getParentDOType().getLineNumber() + ") is not valid",
new Object[] { da } ));
"[NSD validation] value of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not valid",
new Object[] { ada } ));
res = false;
}
}
......@@ -150,21 +147,36 @@ public class EnumerationValidator extends TypeValidator {
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId()
+ " at line " + enumVal.getLineNumber() + " is unknown",
+ ") at line " + enumVal.getLineNumber() + " is unknown",
new Object[] { enumVal } ));
res = false;
}
}
else if( literals.get( enumVal.getValue() ).equals( enumVal.getOrd() )) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId()
+ " at line " + enumVal.getLineNumber() + " has incorrect ord (" + enumVal.getOrd()
+ " instead of " + literals.get( enumVal.getValue() ),
new Object[] { enumVal } ));
res = false;
else {
try {
Integer val = new Integer( literals.get( enumVal.getValue() ));
if( ! val.equals( enumVal.getOrd() )) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId()
+ ") at line " + enumVal.getLineNumber() + " has incorrect ord (" + enumVal.getOrd()
+ " instead of " + literals.get( enumVal.getValue() ) + ")",
new Object[] { enumVal } ));
res = false;
}
}
catch( NumberFormatException e ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId()
+ ") at line " + enumVal.getLineNumber() + " is not an integer",
new Object[] { enumVal } ));
res = false;
}
}
}
......
......@@ -26,7 +26,7 @@ import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.BasicType;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.ConstructedAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumeration;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DA;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute;
public abstract class TypeValidator {
......@@ -39,9 +39,13 @@ public abstract class TypeValidator {
public static void buildValidators( Stream< BasicType > basicTypeStream, Stream< Enumeration > enumerationStream, Stream< ConstructedAttribute > constructedAttributeStream ) {
basicTypeStream
.forEach( basicType -> validators.put( basicType.getName(), BasicTypeValidator.get( basicType )));
enumerationStream
.forEach( enumeration -> validators.put( enumeration.getName(), new EnumerationValidator( enumeration )));
constructedAttributeStream
.forEach( contructedAttribute -> validators.put( contructedAttribute.getName(), new ConstructedAttributeValidator( contructedAttribute )));
}
public abstract boolean validateDA( DA da, DiagnosticChain diagnostics );
public abstract boolean validateAbstractDataAttribute( AbstractDataAttribute ada, DiagnosticChain diagnostics );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment