Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 7ef3d9d9 authored by Dominique Marcadet's avatar Dominique Marcadet

clean code

parent b33baf7e
......@@ -53,7 +53,7 @@ public class AnyLNValidator {
for( DataObject dObj : lnClass.getDataObject() ) {
this.doMap.put( dObj.getName(), dObj );
if( dObj.getRefersToCDC() != null ) {
if( !cdcMap.containsKey( dObj.getRefersToCDC().getName() ) ) {
if( ! cdcMap.containsKey( dObj.getRefersToCDC().getName() )) {
this.cdcMap.put( dObj.getRefersToCDC().getName(), new DOIValidator( dObj.getRefersToCDC() ));
}
}
......@@ -64,7 +64,7 @@ public class AnyLNValidator {
HashSet< String > checkedDO = new HashSet<>();
for( DOI doi : ln.getDOI() ) {
AbstractRiseClipseConsole.getConsole().info( "validateDOI( " + doi.getName() + " )" );
AbstractRiseClipseConsole.getConsole().verbose( "validateDOI( " + doi.getName() + " )" );
// Test if DOI is a possible DOI in this LN
if( !this.doMap.containsKey( doi.getName() ) ) {
......@@ -78,7 +78,7 @@ public class AnyLNValidator {
this.updateCompulsory( doi.getName(), presCond, checkedDO );
// Validation of DOI content
if( !validateDOI( doi ) ) {
if( ! validateDOI( doi ) ) {
return false;
}
......@@ -98,7 +98,7 @@ public class AnyLNValidator {
public boolean checkCompulsory( String name, String presCond, HashSet< String > checked ) {
switch( presCond ) {
case "M":
if( !checked.contains( name ) ) {
if( ! checked.contains( name ) ) {
AbstractRiseClipseConsole.getConsole().error( "DO " + name + " is missing" );
return false;
}
......@@ -127,15 +127,11 @@ public class AnyLNValidator {
public boolean validateDOI( DOI doi ) {
AbstractRiseClipseConsole.getConsole().info( "found DO " + doi.getName() + " in LNClass " + this.lnClass );
AbstractRiseClipseConsole.getConsole().verbose( "found DO " + doi.getName() + " in LNClass " + this.lnClass );
// DOIValidator validates DOI content
String cdc = this.doMap.get( doi.getName() ).getRefersToCDC().getName();
return cdcMap.get( cdc ).validateDOI( doi );
}
public void log( String message ) {
AbstractRiseClipseConsole.getConsole().info( message );
}
}
......@@ -31,7 +31,6 @@ public class DOIValidator {
private String cdc;
private HashMap< String, DataAttribute > daMap;
//private static Boolean test = false;
public DOIValidator( CDC cdc ) {
this.cdc = cdc.getName();
......@@ -39,20 +38,16 @@ public class DOIValidator {
for( DataAttribute da : cdc.getDataAttribute() ) {
this.daMap.put( da.getName(), da );
}
/*if(!test) {
testValidateVal();
}
test = true;*/
}
public boolean validateDOI( DOI doi ) {
HashSet< String > checkedDA = new HashSet<>();
for( DAI dai : doi.getDAI() ) {
AbstractRiseClipseConsole.getConsole().info( "validateDAI( " + dai.getName() + " )" );
AbstractRiseClipseConsole.getConsole().verbose( "validateDAI( " + dai.getName() + " )" );
// Test if DAI is a possible DAI in this DOI
if( !this.daMap.containsKey( dai.getName() ) ) {
if( ! this.daMap.containsKey( dai.getName() ) ) {
AbstractRiseClipseConsole.getConsole().error( "DA " + dai.getName() + " not found in CDC " + this.cdc );
return false;
}
......@@ -62,14 +57,14 @@ public class DOIValidator {
this.updateCompulsory( dai.getName(), presCond, checkedDA );
// Validation of DAI content
if( !validateDAI( dai ) ) {
if( ! validateDAI( dai ) ) {
return false;
}
}
// Verify all necessary DAI were present
if( !this.daMap.entrySet().stream()
if( ! this.daMap.entrySet().stream()
.map( x -> checkCompulsory( x.getKey(), x.getValue().getPresCond(), checkedDA ) )
.reduce( ( a, b ) -> a && b ).get() ) {
AbstractRiseClipseConsole.getConsole().error( "DO does not contain all mandatory DA from CDC " + this.cdc );
......@@ -110,19 +105,18 @@ public class DOIValidator {
public boolean validateDAI( DAI dai ) {
AbstractRiseClipseConsole.getConsole().info( "found DA " + dai.getName() + " in CDC " + this.cdc );
AbstractRiseClipseConsole.getConsole().verbose( "found DA " + dai.getName() + " in CDC " + this.cdc );
// DataAttributes that are BASIC have a BasicType which describes allowed Val of DA
DataAttribute da = this.daMap.get( dai.getName() );
if( da.getTypeKind().getName().equals( "BASIC" ) ) {
for( Val val : dai.getVal() ) {
if( !validateVal( val.getValue(), da.getType() ) ) {
if( ! validateVal( val.getValue(), da.getType() ) ) {
AbstractRiseClipseConsole.getConsole().error( "Val " + val.getValue() + " of DA " + dai.getName() +
" is not of type " + da.getType() );
;
return false;
}
AbstractRiseClipseConsole.getConsole().info( "Val " + val.getValue() + " of DA " + dai.getName() +
AbstractRiseClipseConsole.getConsole().verbose( "Val " + val.getValue() + " of DA " + dai.getName() +
" is of type " + da.getType() );
}
}
......@@ -217,7 +211,7 @@ public class DOIValidator {
}
}
public void testValidateVal() {
private void testValidateVal() {
log( "\n--\tSTART TEST\t--\n" );
assertTrue( validateVal( "0", "BOOLEAN" ) );
assertTrue( validateVal( "1", "BOOLEAN" ) );
......@@ -302,7 +296,7 @@ public class DOIValidator {
+ "1234567890123456789012345678901234567890123456789012345678901234", "VisString255" ) );
}
public void assertTrue( Boolean b ) {
private void assertTrue( Boolean b ) {
if( b ) {
log( "Check" );
}
......@@ -311,7 +305,7 @@ public class DOIValidator {
}
}
public void log( String message ) {
private void log( String message ) {
AbstractRiseClipseConsole.getConsole().info( message );
}
}
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