Skip to content

Commit

Permalink
Merge pull request #74 from com-pas/dependabot/maven/io.github.risecl…
Browse files Browse the repository at this point in the history
…ipse-fr.centralesupelec.edf.riseclipse.iec61850.scl-1.2.4

Bump fr.centralesupelec.edf.riseclipse.iec61850.scl from 1.2.3 to 1.2.4
  • Loading branch information
Flurb authored Jun 22, 2022
2 parents 6503eb1 + 2aaeb24 commit 92b9af6
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 80 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@ Image there is a volume `/data/ocl` which can be used to add these files, see ou
example how to.

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

For instance,

```
data
└── ocl
├── FileSpecifics
│ └── CID
│ └── Busbar.ocl
│ └── DOType.ocl
└── SemanticConstraints
└── Busbar.ocl
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
class CompasOclFileCollectorFromJarTest extends AbstractCompasOclFileCollectorTest {
@Test
void getDefaultOclFiles_WhenCalledWithoutCustomDirectory_ThenListReturned() {
assertValidateOclFileCollector(new CompasOclFileCollector(null), 230);
assertValidateOclFileCollector(new CompasOclFileCollector(null), 212);
}

@Test
void getDefaultOclFiles_WhenCalledWithCustomDirectory_ThenListReturned() {
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 231);
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 213);
}
}
2 changes: 1 addition & 1 deletion riseclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SPDX-License-Identifier: Apache-2.0
<eclipse.ocl.version>1.17.0</eclipse.ocl.version>
<antlr.runtime.version>3.2.0</antlr.runtime.version>

<riseclipse.scl.version>1.2.3</riseclipse.scl.version>
<riseclipse.scl.version>1.2.4</riseclipse.scl.version>
<riseclipse.main.version>1.2.5</riseclipse.main.version>

<riseclipse.p2.root>${project.basedir}/riseclipse-p2-to-m2</riseclipse.p2.root>
Expand Down
2 changes: 1 addition & 1 deletion riseclipse/riseclipse-ocl-constraints-scl2003
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import org.eclipse.ocl.pivot.utilities.OCL;
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
import org.eclipse.ocl.xtext.completeocl.validation.CompleteOCLEObjectValidator;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.scl.validator.util.OclUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,9 +53,8 @@ public OclFileLoader(Path tempDirectoryPath, List<URI> oclFiles) {
}
}

public void loadOCLDocuments(SclFileType type) {
public void loadOCLDocuments() {
oclFiles.stream()
.filter(uri -> OclUtil.includeOnType(uri, type))
.forEach(this::addOCLDocument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,11 +34,12 @@ public SclModelLoader() {
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new SclResourceFactoryImpl());
}

public Resource load(String sclData) {
public Resource load(String sclData, SclFileType type) {
LOGGER.debug("Loading SCL Data in RiseClipse.");
try {
UUID uuid = UUID.randomUUID();
Resource resource = resourceSet.createResource(URI.createURI(uuid.toString()));
// Make a fake filename, but the extension is used by the OCL Rules to determine the Type of SCL File.
var filename = UUID.randomUUID().toString() + "." + type.name();
var resource = resourceSet.createResource(URI.createURI(filename));
resource.load(new ByteArrayInputStream(sclData.getBytes(StandardCharsets.UTF_8)), new HashMap<>());
return resource;
} catch (Exception exp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.lfenergy.compas.scl.validator.util.OclUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -53,14 +54,14 @@ public List<ValidationError> validate(SclFileType type, String sclData) {
OclFileLoader oclFileLoader = new OclFileLoader(tempDirectory, oclFiles);
try {
// Load all the OCL Files, adding them to the OCL Instance.
LOGGER.info("Loading OCL Files for type '{}'.", type);
oclFileLoader.loadOCLDocuments(type);
LOGGER.info("Loading OCL Files.");
oclFileLoader.loadOCLDocuments();
oclFileLoader.prepareValidator(validator);

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

LOGGER.info("Validating SCL Data for type '{}'.", type);
var diagnostician = new CompasDiagnostician(validatorRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
package org.lfenergy.compas.scl.validator.util;

import fr.centralesupelec.edf.riseclipse.iec61850.scl.SclPackage;
import org.eclipse.emf.common.util.URI;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class OclUtil {
Expand All @@ -35,16 +32,4 @@ public static void setupOcl() {
throw new SclValidatorException(OCL_MODEL_PACKAGE_NOT_FOUND, "SCL package not found");
}
}

public static boolean includeOnType(URI uri, SclFileType type) {
var fullPath = uri.path();
// OCL Files that are not in the directory 'FileSpecifics' will always be included.
// In the directory 'FileSpecifics' only the OCL Files that are in the directory 'Common' and
// from the directory for the requested SCL File, for instance 'CID', will be included.
var include = fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator + type + separator)
|| fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator + COMMON_DIR_NAME + separator)
|| !fullPath.contains(separator + FILE_SPECIFICS_DIR_NAME + separator);
LOGGER.debug("Full Path '{}' will be included: {}", fullPath, include);
return include;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
class CompasOclFileCollectorTest extends AbstractCompasOclFileCollectorTest {
@Test
void getDefaultOclFiles_WhenCalledWithoutCustomDirectory_ThenListReturned() {
assertValidateOclFileCollector(new CompasOclFileCollector(null), 230);
assertValidateOclFileCollector(new CompasOclFileCollector(null), 212);
}

@Test
void getDefaultOclFiles_WhenCalledWithCustomDirectory_ThenListReturned() {
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 231);
assertValidateOclFileCollector(new CompasOclFileCollector("./src/test/data/ocl"), 213);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.scl.validator.util.OclUtil;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -49,7 +48,7 @@ void setup() throws IOException {

@Test
void loadOCLDocuments_WhenCalled_ThenFilesFromListAreLoaded() throws IOException {
loader.loadOCLDocuments(SclFileType.CID);
loader.loadOCLDocuments();

assertEquals(1, Files.lines(tempFile).count());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
import org.lfenergy.compas.scl.validator.util.OclUtil;

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

var result = loader.load(sclData);
var result = loader.load(sclData, SclFileType.SCD);

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

var exception = assertThrows(SclValidatorException.class,
() -> loader.load(sclData));
() -> loader.load(sclData, SclFileType.SCD));

assertEquals(LOADING_SCL_FILE_ERROR_CODE, exception.getErrorCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,13 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.util;

import org.eclipse.emf.common.util.URI;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.validator.collector.CompasOclFileCollector;
import org.lfenergy.compas.scl.validator.collector.OclFileCollector;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

class OclUtilTest {
private OclFileCollector collector = new CompasOclFileCollector(null);

@Test
void constructor_WhenConstructorCalled_ThenShouldThrowExceptionCauseForbidden() {
assertThrows(UnsupportedOperationException.class, OclUtil::new);
}

@Test
void includeOnType_WhenCalledWithExpectedSclFileTypeUri_ThenReturnTrue() {
assertTrue(executeTest("/ocl/FileSpecifics/CID/ExtRef.ocl"));
}

@Test
void includeOnType_WhenCalledWithUnexpectedSclFileTypeUri_ThenReturnFalse() {
assertFalse(executeTest("/ocl/FileSpecifics/ICD/DOType.ocl"));
}

@Test
void includeOnType_WhenCalledWithCommonUri_ThenReturnTrue() {
assertTrue(executeTest("/ocl/FileSpecifics/Common/ReportControl.ocl"));
}

@Test
void includeOnType_WhenCalledWithNoFileSpecificUri_ThenReturnTrue() {
assertTrue(executeTest("/ocl/SemanticConstraints/Server.ocl"));
}

private boolean executeTest(String oclFileName) {
var uri = getResource(oclFileName);
return OclUtil.includeOnType(uri, SclFileType.CID);
}

private URI getResource(String oclFileName) {
return collector.getOclFiles()
.stream()
.filter(uri -> uri.toFileString().endsWith(oclFileName))
.findFirst()
.orElseThrow();
}
}

0 comments on commit 92b9af6

Please sign in to comment.