Skip to content

Commit 2aaeb24

Browse files
author
Dennis Labordus
committed
Updated OCL Rules and changed way FileSpecific Rules are handled.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 5047e3a commit 2aaeb24

File tree

11 files changed

+23
-79
lines changed

11 files changed

+23
-79
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ Image there is a volume `/data/ocl` which can be used to add these files, see ou
4949
example how to.
5050

5151
In this directory, you can use subdirectories like `SemanticConstraints` as RiseClipse is doing. And there is a special
52-
filter that when you create a directory `FileSpecifics`. In this directory you can create for instance a directory `CID`
53-
to put constraints specific for an SCL File Type. Known types are `SSD`, `IID`, `ICD`, `SCD`, `CID`, `SED`, `ISD`,
54-
`STD`.
52+
directory `FileSpecifics`. In this directory mostly file specific rules are added. There are functions that can be used
53+
in the OCL Rules to determine the type of file, like `isInICDFile()`.
5554

5655
For instance,
5756

5857
```
5958
data
6059
└── ocl
6160
├── FileSpecifics
62-
│ └── CID
63-
│ └── Busbar.ocl
61+
│ └── DOType.ocl
6462
└── SemanticConstraints
6563
└── Busbar.ocl
6664
```

app/src/test/java/org/lfenergy/compas/scl/validator/rest/CompasOclFileCollectorFromJarTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
class CompasOclFileCollectorFromJarTest extends AbstractCompasOclFileCollectorTest {
1515
@Test
1616
void getDefaultOclFiles_WhenCalledWithoutCustomDirectory_ThenListReturned() {
17-
assertValidateOclFileCollector(new CompasOclFileCollector(null), 230);
17+
assertValidateOclFileCollector(new CompasOclFileCollector(null), 212);
1818
}
1919

2020
@Test
2121
void getDefaultOclFiles_WhenCalledWithCustomDirectory_ThenListReturned() {
22-
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 231);
22+
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 213);
2323
}
2424
}

riseclipse/validator-riseclipse/src/main/java/org/lfenergy/compas/scl/validator/impl/OclFileLoader.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import org.eclipse.ocl.pivot.utilities.OCL;
1212
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
1313
import org.eclipse.ocl.xtext.completeocl.validation.CompleteOCLEObjectValidator;
14-
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1514
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
16-
import org.lfenergy.compas.scl.validator.util.OclUtil;
1715
import org.slf4j.Logger;
1816
import org.slf4j.LoggerFactory;
1917

@@ -55,9 +53,8 @@ public OclFileLoader(Path tempDirectoryPath, List<URI> oclFiles) {
5553
}
5654
}
5755

58-
public void loadOCLDocuments(SclFileType type) {
56+
public void loadOCLDocuments() {
5957
oclFiles.stream()
60-
.filter(uri -> OclUtil.includeOnType(uri, type))
6158
.forEach(this::addOCLDocument);
6259
}
6360

riseclipse/validator-riseclipse/src/main/java/org/lfenergy/compas/scl/validator/impl/SclModelLoader.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.eclipse.emf.common.util.URI;
99
import org.eclipse.emf.ecore.resource.Resource;
1010
import org.eclipse.emf.ecore.resource.ResourceSet;
11+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1112
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
@@ -33,11 +34,12 @@ public SclModelLoader() {
3334
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new SclResourceFactoryImpl());
3435
}
3536

36-
public Resource load(String sclData) {
37+
public Resource load(String sclData, SclFileType type) {
3738
LOGGER.debug("Loading SCL Data in RiseClipse.");
3839
try {
39-
UUID uuid = UUID.randomUUID();
40-
Resource resource = resourceSet.createResource(URI.createURI(uuid.toString()));
40+
// Make a fake filename, but the extension is used by the OCL Rules to determine the Type of SCL File.
41+
var filename = UUID.randomUUID().toString() + "." + type.name();
42+
var resource = resourceSet.createResource(URI.createURI(filename));
4143
resource.load(new ByteArrayInputStream(sclData.getBytes(StandardCharsets.UTF_8)), new HashMap<>());
4244
return resource;
4345
} catch (Exception exp) {

riseclipse/validator-riseclipse/src/main/java/org/lfenergy/compas/scl/validator/impl/SclRiseClipseValidator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.lfenergy.compas.scl.validator.util.OclUtil;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
23+
2324
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.List;
@@ -53,14 +54,14 @@ public List<ValidationError> validate(SclFileType type, String sclData) {
5354
OclFileLoader oclFileLoader = new OclFileLoader(tempDirectory, oclFiles);
5455
try {
5556
// Load all the OCL Files, adding them to the OCL Instance.
56-
LOGGER.info("Loading OCL Files for type '{}'.", type);
57-
oclFileLoader.loadOCLDocuments(type);
57+
LOGGER.info("Loading OCL Files.");
58+
oclFileLoader.loadOCLDocuments();
5859
oclFileLoader.prepareValidator(validator);
5960

6061
// Load the SCL File as Resource ready to be processed.
6162
LOGGER.info("Loading SCL Data for type '{}'.", type);
6263
var sclLoader = new SclModelLoader();
63-
var resource = sclLoader.load(sclData);
64+
var resource = sclLoader.load(sclData, type);
6465

6566
LOGGER.info("Validating SCL Data for type '{}'.", type);
6667
var diagnostician = new CompasDiagnostician(validatorRegistry);

riseclipse/validator-riseclipse/src/main/java/org/lfenergy/compas/scl/validator/util/OclUtil.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
package org.lfenergy.compas.scl.validator.util;
55

66
import fr.centralesupelec.edf.riseclipse.iec61850.scl.SclPackage;
7-
import org.eclipse.emf.common.util.URI;
8-
import org.lfenergy.compas.scl.extensions.model.SclFileType;
97
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
108
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
1210

13-
import static java.io.File.separator;
1411
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.OCL_MODEL_PACKAGE_NOT_FOUND;
1512

1613
public class OclUtil {
@@ -35,16 +32,4 @@ public static void setupOcl() {
3532
throw new SclValidatorException(OCL_MODEL_PACKAGE_NOT_FOUND, "SCL package not found");
3633
}
3734
}
38-
39-
public static boolean includeOnType(URI uri, SclFileType type) {
40-
var fullPath = uri.path();
41-
// OCL Files that are not in the directory 'FileSpecifics' will always be included.
42-
// In the directory 'FileSpecifics' only the OCL Files that are in the directory 'Common' and
43-
// from the directory for the requested SCL File, for instance 'CID', will be included.
44-
var include = fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator + type + separator)
45-
|| fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator + COMMON_DIR_NAME + separator)
46-
|| !fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator);
47-
LOGGER.debug("Full Path '{}' will be included: {}", fullPath, include);
48-
return include;
49-
}
5035
}

riseclipse/validator-riseclipse/src/test/java/org/lfenergy/compas/scl/validator/collector/CompasOclFileCollectorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
class CompasOclFileCollectorTest extends AbstractCompasOclFileCollectorTest {
99
@Test
1010
void getDefaultOclFiles_WhenCalledWithoutCustomDirectory_ThenListReturned() {
11-
assertValidateOclFileCollector(new CompasOclFileCollector(null), 230);
11+
assertValidateOclFileCollector(new CompasOclFileCollector(null), 212);
1212
}
1313

1414
@Test
1515
void getDefaultOclFiles_WhenCalledWithCustomDirectory_ThenListReturned() {
16-
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 231);
16+
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 213);
1717
}
1818
}

riseclipse/validator-riseclipse/src/test/java/org/lfenergy/compas/scl/validator/impl/OclFileLoaderTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.junit.jupiter.api.BeforeEach;
1111
import org.junit.jupiter.api.Test;
1212
import org.junit.jupiter.api.extension.ExtendWith;
13-
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1413
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
1514
import org.lfenergy.compas.scl.validator.util.OclUtil;
1615
import org.mockito.junit.jupiter.MockitoExtension;
@@ -49,7 +48,7 @@ void setup() throws IOException {
4948

5049
@Test
5150
void loadOCLDocuments_WhenCalled_ThenFilesFromListAreLoaded() throws IOException {
52-
loader.loadOCLDocuments(SclFileType.CID);
51+
loader.loadOCLDocuments();
5352

5453
assertEquals(1, Files.lines(tempFile).count());
5554
}

riseclipse/validator-riseclipse/src/test/java/org/lfenergy/compas/scl/validator/impl/SclModelLoaderTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.junit.jupiter.api.BeforeEach;
77
import org.junit.jupiter.api.Test;
8+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
89
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
910
import org.lfenergy.compas.scl.validator.util.OclUtil;
1011

@@ -29,7 +30,7 @@ void setup() {
2930
void load_WhenCalledWithValidSCXML_ThenResourceLoaded() throws IOException {
3031
var sclData = readSCL("example.scd");
3132

32-
var result = loader.load(sclData);
33+
var result = loader.load(sclData, SclFileType.SCD);
3334

3435
assertNotNull(result);
3536
}
@@ -39,7 +40,7 @@ void load_WhenCalledWithInvalidSCXML_ThenExceptionThrown() throws IOException {
3940
var sclData = readSCL("invalid.scd");
4041

4142
var exception = assertThrows(SclValidatorException.class,
42-
() -> loader.load(sclData));
43+
() -> loader.load(sclData, SclFileType.SCD));
4344

4445
assertEquals(LOADING_SCL_FILE_ERROR_CODE, exception.getErrorCode());
4546
}

0 commit comments

Comments
 (0)