From 676b262b86cc20310db872f909b2e1bf36d45fef Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 16:48:31 +0100 Subject: [PATCH 01/21] WIP change project structure --- aspect-model-editor-core/pom.xml | 47 ++ .../esmf/ame/config/ApplicationSettings.java | 0 ...spectModelPrintDocumentationException.java | 3 + .../ame/exceptions/CreateFileException.java | 3 + .../exceptions/FileCannotDeleteException.java | 3 + .../ame/exceptions/FileHandlingException.java | 3 + .../ame/exceptions/FileNotFoundException.java | 3 + .../ame/exceptions/FileReadException.java | 3 + .../ame/exceptions/FileWriteException.java | 3 + .../InvalidAspectModelException.java | 3 + .../ame/exceptions/UrnNotFoundException.java | 2 + .../eclipse/esmf/ame/model/StoragePath.java | 17 +- .../eclipse/esmf/ame/utils/ModelUtils.java | 120 +++++ aspect-model-editor-migrator/pom.xml | 35 ++ .../esmf/ame/model/FileProcessingResult.java | 4 +- .../ame/model/NamespaceFileCollection.java | 7 +- .../ame/model/VersionedNamespaceFiles.java | 10 +- .../eclipse/esmf/ame/utils/MigratorUtils.java | 43 ++ aspect-model-editor-repository/pom.xml | 43 ++ .../repository/ModelResolverRepository.java | 0 .../strategy/LocalFolderResolverStrategy.java | 17 +- .../strategy/ModelResolverStrategy.java | 6 +- .../utils/LocalFolderResolverUtils.java | 24 +- aspect-model-editor-resolver/pom.xml | 32 ++ .../resolver/strategy/FileSystemStrategy.java | 4 +- .../resolver/strategy/InMemoryStrategy.java | 12 +- .../resolver/strategy/ResolutionStrategy.java | 13 +- .../strategy/model}/FolderStructure.java | 2 +- .../strategy/model/NamespaceFileContent.java | 6 +- .../strategy/utils/ResolverUtils.java | 168 ++++++ aspect-model-editor-runtime/pom.xml | 68 +++ .../postman}/ame.postman_collection.json | 7 +- .../postman}/ame.postman_environment.json | 0 .../org/eclipse/esmf/ame/Application.java | 0 .../esmf/ame/config/ApplicationConfig.java | 7 +- .../main/resources/application-dev.properties | 0 .../main/resources/application-mac.properties | 0 .../main/resources/application.properties | 0 .../org/eclipse/esmf/ame/ApplicationTest.java | 28 + aspect-model-editor-service/pom.xml | 83 +++ .../ame/services/FileHandlingService.java | 0 .../esmf/ame/services/GenerateService.java | 11 +- .../esmf/ame/services/ModelService.java | 68 +-- .../esmf/ame/services/PackageService.java | 108 ++-- .../services/model/ElementMissingReport.java | 4 +- .../services/model/FileValidationReport.java | 61 +++ .../model/NamespaceFileCollection.java | 4 +- .../services/model/NamespaceFileReport.java | 8 +- .../esmf/ame/services/utils/UnzipUtils.java | 0 .../esmf/ame/services/utils/ZipUtils.java | 0 .../eclipse/esmf/ame/config/TestConfig.java | 47 ++ .../ame/services/FileHandlingServiceTest.java | 51 ++ .../ame/services/GenerateServiceTest.java | 113 ++++ .../esmf/ame/services/ModelServiceTest.java | 186 +++++++ .../esmf/ame/services/PackageServiceTest.java | 96 ++++ .../test/resources/services/TestArchive.zip | Bin 0 -> 2888 bytes .../1.0.0/AspectModelForService.ttl | 29 + .../AspectModelForStrategyWithExtRef.ttl | 30 ++ .../1.0.0/FileToDelete.ttl | 30 ++ .../1.0.0/OldAspectModel.ttl | 19 + .../1.0.0/TestFileOne.ttl | 29 + .../1.0.0/TestFileThree.ttl | 29 + .../1.0.0/TestFileTwo.ttl | 29 + .../1.0.0/ToBackupOne.ttl | 29 + .../1.0.0/ToBackupTwo.ttl | 29 + .../1.0.0/ToBackupOne.ttl | 29 + .../1.0.0/ToBackupTwo.ttl | 29 + .../1.0.0/ToMigrateOne.ttl | 22 + .../1.0.0/ToMigrateTwo.ttl | 22 + .../1.0.0/ToMigrateOne.ttl | 22 + .../1.0.0/ToMigrateTwo.ttl | 22 + .../1.0.0/AspectModelForStrategy.ttl | 29 + .../AspectModelForStrategyWithExtRef.ttl | 30 ++ aspect-model-editor-validation/pom.xml | 39 ++ .../ame/validation/model}/ViolationError.java | 2 +- .../validation/model}/ViolationReport.java | 2 +- .../services}/ViolationFormatter.java | 10 +- .../ame/validation/utils/ValidationUtils.java | 83 +++ aspect-model-editor-web-core/pom.xml | 35 ++ .../eclipse/esmf/ame}/MediaTypeExtension.java | 6 +- .../esmf/ame/config/SecurityConfig.java | 2 + .../exceptions/ResponseExceptionHandler.java | 4 +- .../esmf/ame}/model/ErrorResponse.java | 2 +- .../resources/multipart-default.properties | 13 + aspect-model-editor-web/pom.xml | 55 ++ .../esmf/ame/api/FileHandlingController.java | 6 +- .../esmf/ame/api/GenerateController.java | 12 +- .../eclipse/esmf/ame/api/ModelController.java | 18 +- .../esmf/ame/api/PackageController.java | 23 +- pom.xml | 496 ++++++++++-------- .../ame/model/packaging/ProcessPackage.java | 61 --- .../esmf/ame/services/utils/ModelUtils.java | 317 ----------- .../strategy/FileSystemStrategyTest.java | 6 +- 93 files changed, 2430 insertions(+), 806 deletions(-) create mode 100644 aspect-model-editor-core/pom.xml rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java (100%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java (96%) rename {src => aspect-model-editor-core/src}/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java (97%) rename src/main/java/org/eclipse/esmf/ame/model/ProcessPath.java => aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/model/StoragePath.java (73%) create mode 100644 aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java create mode 100644 aspect-model-editor-migrator/pom.xml rename src/main/java/org/eclipse/esmf/ame/model/migration/FileInformation.java => aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/FileProcessingResult.java (91%) rename src/main/java/org/eclipse/esmf/ame/model/migration/Namespaces.java => aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/NamespaceFileCollection.java (83%) rename src/main/java/org/eclipse/esmf/ame/model/migration/Namespace.java => aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/VersionedNamespaceFiles.java (78%) create mode 100644 aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/utils/MigratorUtils.java create mode 100644 aspect-model-editor-repository/pom.xml rename {src => aspect-model-editor-repository/src}/main/java/org/eclipse/esmf/ame/repository/ModelResolverRepository.java (100%) rename {src => aspect-model-editor-repository/src}/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java (96%) rename {src => aspect-model-editor-repository/src}/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java (95%) rename {src => aspect-model-editor-repository/src}/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java (69%) create mode 100644 aspect-model-editor-resolver/pom.xml rename {src => aspect-model-editor-resolver/src}/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java (95%) rename {src => aspect-model-editor-resolver/src}/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java (86%) rename {src => aspect-model-editor-resolver/src}/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java (94%) rename {src/main/java/org/eclipse/esmf/ame/model/resolver => aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model}/FolderStructure.java (96%) rename src/main/java/org/eclipse/esmf/ame/model/repository/AspectModelInformation.java => aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/NamespaceFileContent.java (82%) create mode 100644 aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/utils/ResolverUtils.java create mode 100644 aspect-model-editor-runtime/pom.xml rename {postman => aspect-model-editor-runtime/postman}/ame.postman_collection.json (99%) rename {postman => aspect-model-editor-runtime/postman}/ame.postman_environment.json (100%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/Application.java (100%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java (94%) rename {src => aspect-model-editor-runtime/src}/main/resources/application-dev.properties (100%) rename {src => aspect-model-editor-runtime/src}/main/resources/application-mac.properties (100%) rename {src => aspect-model-editor-runtime/src}/main/resources/application.properties (100%) create mode 100644 aspect-model-editor-runtime/src/test/java/org/eclipse/esmf/ame/ApplicationTest.java create mode 100644 aspect-model-editor-service/pom.xml rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/FileHandlingService.java (100%) rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/GenerateService.java (93%) rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/ModelService.java (63%) rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/PackageService.java (62%) rename src/main/java/org/eclipse/esmf/ame/model/packaging/MissingElement.java => aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/ElementMissingReport.java (91%) create mode 100644 aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/FileValidationReport.java rename src/main/java/org/eclipse/esmf/ame/model/packaging/AspectModelFiles.java => aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileCollection.java (91%) rename src/main/java/org/eclipse/esmf/ame/model/packaging/ValidFile.java => aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileReport.java (80%) rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java (100%) rename {src => aspect-model-editor-service/src}/main/java/org/eclipse/esmf/ame/services/utils/ZipUtils.java (100%) create mode 100644 aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java create mode 100644 aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java create mode 100644 aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java create mode 100644 aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java create mode 100644 aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java create mode 100644 aspect-model-editor-service/src/test/resources/services/TestArchive.zip create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl create mode 100644 aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl create mode 100644 aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl create mode 100644 aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl create mode 100644 aspect-model-editor-validation/pom.xml rename {src/main/java/org/eclipse/esmf/ame/model/validation => aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model}/ViolationError.java (96%) rename {src/main/java/org/eclipse/esmf/ame/model/validation => aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model}/ViolationReport.java (95%) rename {src/main/java/org/eclipse/esmf/ame/validation => aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/services}/ViolationFormatter.java (97%) create mode 100644 aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/utils/ValidationUtils.java create mode 100644 aspect-model-editor-web-core/pom.xml rename {src/main/java/org/eclipse/esmf/ame/web/utils => aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame}/MediaTypeExtension.java (97%) rename {src => aspect-model-editor-web-core/src}/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java (93%) rename {src => aspect-model-editor-web-core/src}/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java (98%) rename {src/main/java/org/eclipse/esmf/ame/exceptions => aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame}/model/ErrorResponse.java (97%) create mode 100644 aspect-model-editor-web-core/src/main/resources/multipart-default.properties create mode 100644 aspect-model-editor-web/pom.xml rename src/main/java/org/eclipse/esmf/ame/web/FileHandlingResource.java => aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java (96%) rename src/main/java/org/eclipse/esmf/ame/web/GenerateResource.java => aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/GenerateController.java (95%) rename src/main/java/org/eclipse/esmf/ame/web/ModelResource.java => aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java (92%) rename src/main/java/org/eclipse/esmf/ame/web/PackageResource.java => aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java (83%) delete mode 100644 src/main/java/org/eclipse/esmf/ame/model/packaging/ProcessPackage.java delete mode 100644 src/main/java/org/eclipse/esmf/ame/services/utils/ModelUtils.java diff --git a/aspect-model-editor-core/pom.xml b/aspect-model-editor-core/pom.xml new file mode 100644 index 00000000..2a90629c --- /dev/null +++ b/aspect-model-editor-core/pom.xml @@ -0,0 +1,47 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-core + ESMF Aspect Model Editor Core + jar + + + + org.eclipse.esmf + esmf-aspect-model-starter + + + org.eclipse.esmf + esmf-aspect-model-urn + + + org.eclipse.esmf + esmf-aspect-meta-model-java + + + org.eclipse.esmf + esmf-aspect-model-validator + + + org.springframework.boot + spring-boot-starter-security + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java index e050149b..4c35f39d 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java @@ -13,10 +13,13 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + import lombok.Getter; @Getter public class AspectModelPrintDocumentationException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java index 3058cd3f..7fcbe210 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java @@ -13,10 +13,13 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + import lombok.Getter; @Getter public class CreateFileException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java index 751dfca6..0d4ab0ea 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileCannotDeleteException.java @@ -13,10 +13,13 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + import lombok.Getter; @Getter public class FileCannotDeleteException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java index d6ce8f98..ed4a3880 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileHandlingException.java @@ -13,10 +13,13 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + import lombok.Getter; @Getter public class FileHandlingException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java index 84319cbe..36c8be76 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileNotFoundException.java @@ -13,10 +13,13 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + import lombok.Getter; @Getter public class FileNotFoundException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java index 7eae4013..f12e6ff1 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileReadException.java @@ -13,7 +13,10 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + public class FileReadException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java index ee1755c8..90aaeede 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/FileWriteException.java @@ -13,7 +13,10 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + public class FileWriteException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java index 2a012cd4..62313fb5 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/InvalidAspectModelException.java @@ -13,7 +13,10 @@ package org.eclipse.esmf.ame.exceptions; +import java.io.Serial; + public class InvalidAspectModelException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java similarity index 97% rename from src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java index f39004f6..024ec428 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java @@ -14,6 +14,7 @@ package org.eclipse.esmf.ame.exceptions; import java.io.IOException; +import java.io.Serial; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -21,6 +22,7 @@ @Getter public class UrnNotFoundException extends IOException { + @Serial private static final long serialVersionUID = 1L; private final transient AspectModelUrn urn; diff --git a/src/main/java/org/eclipse/esmf/ame/model/ProcessPath.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/model/StoragePath.java similarity index 73% rename from src/main/java/org/eclipse/esmf/ame/model/ProcessPath.java rename to aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/model/StoragePath.java index cd1e6c19..fdc2166f 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/ProcessPath.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/model/StoragePath.java @@ -18,21 +18,20 @@ import org.eclipse.esmf.ame.config.ApplicationSettings; -public enum ProcessPath { - AspectModelPath( ApplicationSettings.getAspectModelEditorStoragePath() ), - MODELS( ApplicationSettings.getMetaModelStoragePath() ); +import lombok.Getter; + +@Getter +public enum StoragePath { + AspectModel( ApplicationSettings.getAspectModelEditorStoragePath() ), + MetaModel( ApplicationSettings.getMetaModelStoragePath() ); private final Path path; - ProcessPath( final Path path ) { + StoragePath( final Path path ) { this.path = path; } - public Path getPath() { - return path; - } - - public static ProcessPath getEnum( final String value ) { + public static StoragePath getEnum( final String value ) { return Arrays.stream( values() ) .filter( v -> v.getPath().toString().equalsIgnoreCase( value ) ) .findFirst() diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java new file mode 100644 index 00000000..017ecdf0 --- /dev/null +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.utils; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jena.rdf.model.Model; +import org.eclipse.esmf.ame.config.ApplicationSettings; +import org.eclipse.esmf.ame.exceptions.FileReadException; +import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; +import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; +import org.eclipse.esmf.aspectmodel.shacl.violation.Violation; +import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; +import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; +import org.eclipse.esmf.aspectmodel.validation.services.ViolationFormatter; +import org.eclipse.esmf.metamodel.AspectContext; + +import io.vavr.control.Try; + +public class ModelUtils { + + private ModelUtils() { + } + + public static final String TTL = "ttl"; + public static final String TTL_EXTENSION = "." + TTL; + + /** + * Retrieves the AspectContext from the provided Try, handling exceptions if necessary. + * + * @param context The Try representing the context to retrieve the AspectContext from. + * @return The retrieved AspectContext. + * + * @throws FileReadException If there are failures in the generation process due to violations in the model. + */ + public static AspectContext getAspectContext( Try context ) { + return context.recover( throwable -> { + // Another exception, e.g. syntax error. Let the validator handle this + final List violations = new AspectModelValidator().validateModel( + context.map( AspectContext::rdfModel ) ); + + throw new FileReadException( + String.format( "The generation process encountered failures due to the following violations: %s", + new ViolationFormatter().apply( violations ) ) ); + } ).get(); + } + + /** + * Returns the {@link Model} that corresponds to the given model URN + * + * @param aspectModelUrn The model URN + * @return The file that defines the supplied aspectModelUrn. + */ + public static String getAspectModelFile( final String modelsRootPath, final AspectModelUrn aspectModelUrn ) { + if ( aspectModelUrn == null ) { + return StringUtils.EMPTY; + } + + final Path directory = Path.of( modelsRootPath ).resolve( aspectModelUrn.getNamespace() ) + .resolve( aspectModelUrn.getVersion() ); + + final String fileInformation = Arrays.stream( + Optional.ofNullable( directory.toFile().listFiles() ).orElse( new File[] {} ) ).filter( File::isFile ) + .filter( file -> file.getName().endsWith( ".ttl" ) ).map( File::toURI ) + .sorted().filter( + uri -> AspectModelResolver.containsDefinition( loadFromUri( uri ).get(), aspectModelUrn ) ) + .map( URI::getPath ).findFirst().orElse( "NO CORRESPONDING FILE FOUND" ); + + final File filePath = new File( fileInformation ); + + if ( !filePath.exists() ) { + return fileInformation; + } + + return filePath.getPath().replace( ApplicationSettings.getMetaModelStoragePath() + File.separator, "" ); + } + + /** + * Loads an Aspect model from a resolvable URI + * + * @param uri The URI + * @return The model + */ + private static Try loadFromUri( final URI uri ) { + try { + return loadFromUrl( uri.toURL() ); + } catch ( final MalformedURLException exception ) { + return Try.failure( exception ); + } + } + + /** + * Loads an Aspect model from a resolvable URL + * + * @param url The URL + * @return The model + */ + private static Try loadFromUrl( final URL url ) { + return Try.ofSupplier( () -> TurtleLoader.openUrl( url ) ).flatMap( TurtleLoader::loadTurtle ); + } +} diff --git a/aspect-model-editor-migrator/pom.xml b/aspect-model-editor-migrator/pom.xml new file mode 100644 index 00000000..49c74f0b --- /dev/null +++ b/aspect-model-editor-migrator/pom.xml @@ -0,0 +1,35 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-migrator + ESMF Aspect Model Editor Migrator + jar + + + + org.eclipse.esmf + aspect-model-editor-resolver + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/model/migration/FileInformation.java b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/FileProcessingResult.java similarity index 91% rename from src/main/java/org/eclipse/esmf/ame/model/migration/FileInformation.java rename to aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/FileProcessingResult.java index 3319e6b3..6478a27b 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/migration/FileInformation.java +++ b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/FileProcessingResult.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.migration; +package org.eclipse.esmf.ame.model; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -21,7 +21,7 @@ @Data @AllArgsConstructor -public class FileInformation { +public class FileProcessingResult { @JsonInclude( JsonInclude.Include.NON_NULL ) @JsonProperty( "name" ) public String name; diff --git a/src/main/java/org/eclipse/esmf/ame/model/migration/Namespaces.java b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/NamespaceFileCollection.java similarity index 83% rename from src/main/java/org/eclipse/esmf/ame/model/migration/Namespaces.java rename to aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/NamespaceFileCollection.java index 03baaf2d..ee7d56f1 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/migration/Namespaces.java +++ b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/NamespaceFileCollection.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.migration; +package org.eclipse.esmf.ame.model; import java.util.List; @@ -23,9 +23,8 @@ @Data @AllArgsConstructor -public class Namespaces { - +public class NamespaceFileCollection { @JsonInclude( JsonInclude.Include.NON_NULL ) @JsonProperty( "namespaces" ) - public List namespaces; + public List versionedNamespaceFiles; } diff --git a/src/main/java/org/eclipse/esmf/ame/model/migration/Namespace.java b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/VersionedNamespaceFiles.java similarity index 78% rename from src/main/java/org/eclipse/esmf/ame/model/migration/Namespace.java rename to aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/VersionedNamespaceFiles.java index 1f71a6ed..3b4a1df9 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/migration/Namespace.java +++ b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/model/VersionedNamespaceFiles.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.migration; +package org.eclipse.esmf.ame.model; import java.util.ArrayList; import java.util.List; @@ -26,20 +26,20 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class Namespace { +public class VersionedNamespaceFiles { @JsonInclude( JsonInclude.Include.NON_NULL ) @JsonProperty( "namespace" ) public String versionedNamespace; @JsonInclude( JsonInclude.Include.NON_NULL ) @JsonProperty( "files" ) - public List files = new ArrayList<>(); + public List files = new ArrayList<>(); - public Namespace( final String versionedNamespace ) { + public VersionedNamespaceFiles( final String versionedNamespace ) { this.versionedNamespace = versionedNamespace; } - public void addAspectModelFile( final FileInformation file ) { + public void addAspectModelFile( final FileProcessingResult file ) { files.add( file ); } } diff --git a/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/utils/MigratorUtils.java b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/utils/MigratorUtils.java new file mode 100644 index 00000000..fdc19236 --- /dev/null +++ b/aspect-model-editor-migrator/src/main/java/org/eclipse/esmf/ame/utils/MigratorUtils.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.utils; + +import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; +import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; +import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; +import org.eclipse.esmf.aspectmodel.versionupdate.MigratorService; + +import io.vavr.control.Try; + +public class MigratorUtils { + /** + * Migrates a model to its latest version. + * + * @param aspectModel as a string. + * @return migrated Aspect Model as a string. + */ + public static String migrateModel( final String aspectModel ) throws InvalidAspectModelException { + final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); + + final Try migratedFile = new MigratorService().updateMetaModelVersion( + ResolverUtils.loadModelFromStoragePath( fileSystemStrategy ) ); + + final VersionedModel versionedModel = migratedFile.getOrElseThrow( + error -> new InvalidAspectModelException( "Aspect Model cannot be migrated.", error ) ); + + return ResolverUtils.getPrettyPrintedVersionedModel( versionedModel, + fileSystemStrategy.getAspectModelUrn().getUrn() ); + } +} diff --git a/aspect-model-editor-repository/pom.xml b/aspect-model-editor-repository/pom.xml new file mode 100644 index 00000000..d18fef50 --- /dev/null +++ b/aspect-model-editor-repository/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-repository + ESMF Aspect Model Editor Repository + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.eclipse.esmf + aspect-model-editor-resolver + + + org.eclipse.esmf + esmf-aspect-model-validator + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/repository/ModelResolverRepository.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/ModelResolverRepository.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/repository/ModelResolverRepository.java rename to aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/ModelResolverRepository.java diff --git a/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java rename to aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java index 02ab3321..b4ff7063 100644 --- a/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java +++ b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java @@ -42,11 +42,12 @@ import org.eclipse.esmf.ame.exceptions.FileNotFoundException; import org.eclipse.esmf.ame.exceptions.FileReadException; import org.eclipse.esmf.ame.exceptions.FileWriteException; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; -import org.eclipse.esmf.ame.model.resolver.FolderStructure; import org.eclipse.esmf.ame.repository.strategy.utils.LocalFolderResolverUtils; import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; -import org.eclipse.esmf.ame.services.utils.ModelUtils; +import org.eclipse.esmf.ame.resolver.strategy.model.FolderStructure; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; +import org.eclipse.esmf.ame.utils.ModelUtils; import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidNamespaceException; import org.eclipse.esmf.aspectmodel.resolver.services.ExtendedXsdDataType; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -178,7 +179,7 @@ public Map> getAllNamespaces( final boolean shouldRefresh ) } @Override - public List getImportedAspectModelInformation() { + public List getImportedNamespaceFileContent() { Path importStoragePath = importFileSystem.getRootDirectories().iterator().next(); if ( !Files.exists( importStoragePath ) ) { @@ -186,7 +187,7 @@ public List getImportedAspectModelInformation() { } try ( Stream paths = Files.walk( importStoragePath ) ) { - return getListOfAspectModels( paths.filter( Files::isRegularFile ).map( Path::toString ).toList() ); + return listAllAspectModels( paths.filter( Files::isRegularFile ).map( Path::toString ).toList() ); } catch ( IOException e ) { LOG.error( "Cannot find files in the imported package." ); throw new FileNotFoundException( "Cannot find files in the imported package.", e ); @@ -309,15 +310,15 @@ private String excludeStandaloneFiles( final String rootSharedFolder, final Stri return relativePath; } - private List getListOfAspectModels( final List filePath ) { + private List listAllAspectModels( final List filePath ) { return filePath.stream().map( path -> { try { final String[] arg = transformToValidModelDirectory( path ).split( ":" ); final String namespace = arg[0] + ":" + arg[1]; final String fileName = arg[2]; - String aspectModel = LocalFolderResolverUtils.readString( importFileSystem.getPath( path ), + String aspectModel = ResolverUtils.readString( importFileSystem.getPath( path ), StandardCharsets.UTF_8 ); - return new AspectModelInformation( namespace, fileName, aspectModel ); + return new NamespaceFileContent( namespace, fileName, aspectModel ); } catch ( IOException e ) { throw new FileNotFoundException( "Cannot find in-memory file to create package information", e ); } diff --git a/src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java similarity index 95% rename from src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java rename to aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java index b36e5dcd..e4b84da8 100644 --- a/src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java +++ b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/ModelResolverStrategy.java @@ -20,7 +20,7 @@ import javax.annotation.Nonnull; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; import io.vavr.Tuple2; @@ -82,9 +82,9 @@ public interface ModelResolverStrategy { /** * Gets information about all imported Aspect Models. * - * @return A list of {@link AspectModelInformation} containing information about each imported Aspect Model. + * @return A list of {@link NamespaceFileContent} containing information about each imported Aspect Model. */ - List getImportedAspectModelInformation(); + List getImportedNamespaceFileContent(); /** * Converts the provided file to a tuple representing the Aspect Model URN. diff --git a/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java similarity index 69% rename from src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java rename to aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java index 44dae294..d7fec2e1 100644 --- a/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java +++ b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java @@ -13,15 +13,9 @@ package org.eclipse.esmf.ame.repository.strategy.utils; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; - import javax.annotation.Nonnull; -import org.eclipse.esmf.ame.model.resolver.FolderStructure; +import org.eclipse.esmf.ame.resolver.strategy.model.FolderStructure; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,20 +63,4 @@ public static String buildFilePath( final String namespace, final String fileNam folderStructure.setFileName( fileName ); return folderStructure.toString(); } - - /** - * Reads the content of a file located at the specified path using the provided character encoding. - * - * @param path The path to the file to be read. - * @param charset The character encoding to be used for decoding the file content. - * @return The content of the file as a string decoded with the specified character encoding. - * - * @throws IOException If an I/O error occurs while reading the file. - */ - public static String readString( Path path, Charset charset ) throws IOException { - try ( InputStream inputStream = Files.newInputStream( path ) ) { - byte[] bytes = inputStream.readAllBytes(); - return new String( bytes, charset ); - } - } } diff --git a/aspect-model-editor-resolver/pom.xml b/aspect-model-editor-resolver/pom.xml new file mode 100644 index 00000000..62d15f71 --- /dev/null +++ b/aspect-model-editor-resolver/pom.xml @@ -0,0 +1,32 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-resolver + ESMF Aspect Model Editor Resolver + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.projectlombok + lombok + ${lombok-version} + + + diff --git a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java similarity index 95% rename from src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java rename to aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java index bca20610..2e0efe2b 100644 --- a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategy.java @@ -23,7 +23,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.riot.RiotException; -import org.eclipse.esmf.ame.model.ProcessPath; +import org.eclipse.esmf.ame.model.StoragePath; import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -31,7 +31,7 @@ public class FileSystemStrategy extends ResolutionStrategy { public FileSystemStrategy( final String aspectModel ) throws RiotException { - super( aspectModel, ProcessPath.MODELS.getPath() ); + super( aspectModel, StoragePath.MetaModel.getPath() ); } protected Try getModelFromFileSystem( final AspectModelUrn aspectModelUrn, final Path rootPath ) { diff --git a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java similarity index 86% rename from src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java rename to aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java index 058dc959..11afef16 100644 --- a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategy.java @@ -27,8 +27,8 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.riot.RiotException; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; -import org.eclipse.esmf.ame.repository.strategy.utils.LocalFolderResolverUtils; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -39,9 +39,9 @@ public class InMemoryStrategy extends ResolutionStrategy { private final FileSystem fileSystem; - public InMemoryStrategy( final AspectModelInformation aspectModelInformation, final Path processingRootPath, + public InMemoryStrategy( final NamespaceFileContent namespaceFileContent, final Path processingRootPath, final FileSystem fileSystem ) throws RiotException { - super( aspectModelInformation, processingRootPath ); + super( namespaceFileContent, processingRootPath ); this.fileSystem = fileSystem; } @@ -55,7 +55,7 @@ protected Try getModelFromFileSystem( final AspectModelUrn aspectModelUrn if ( Files.exists( file ) ) { return Try.of( - () -> loadTurtleFromString( LocalFolderResolverUtils.readString( file, StandardCharsets.UTF_8 ) ) ); + () -> loadTurtleFromString( ResolverUtils.readString( file, StandardCharsets.UTF_8 ) ) ); } LOG.warn( "Looking for {}, but no {}.ttl was found. Inspecting files in {}", aspectModelUrn.getName(), @@ -66,7 +66,7 @@ protected Try getModelFromFileSystem( final AspectModelUrn aspectModelUrn .map( fileSystem::getPath ) .map( aspectModelPath -> Try.of( () -> loadTurtleFromString( - LocalFolderResolverUtils.readString( + ResolverUtils.readString( aspectModelPath, StandardCharsets.UTF_8 ) ) ) ).filter( tryModel -> tryModel.map( diff --git a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java similarity index 94% rename from src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java rename to aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java index b91030fb..dbb71471 100644 --- a/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java @@ -29,12 +29,11 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.rdf.model.StmtIterator; -import org.apache.jena.riot.RiotException; import org.apache.jena.vocabulary.RDF; import org.eclipse.esmf.ame.exceptions.FileReadException; import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; import org.eclipse.esmf.ame.exceptions.UrnNotFoundException; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; import org.eclipse.esmf.aspectmodel.resolver.AbstractResolutionStrategy; import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -79,13 +78,13 @@ public ResolutionStrategy( final String aspectModel, final Path processingRootPa /** * Constructs a new ResolutionStrategy with the given parameters. * - * @param aspectModelInformation The information about the aspect model. + * @param namespaceFileContent The information about the aspect model. * @param processingRootPath The root path where processing should occur. */ - public ResolutionStrategy( final AspectModelInformation aspectModelInformation, final Path processingRootPath ) { + public ResolutionStrategy( final NamespaceFileContent namespaceFileContent, final Path processingRootPath ) { this.processingRootPath = processingRootPath; - this.currentFileName = aspectModelInformation.getFileName(); - this.currentAspectModel = loadTurtleFromString( aspectModelInformation.getAspectModel() ); + this.currentFileName = namespaceFileContent.getFileName(); + this.currentAspectModel = loadTurtleFromString( namespaceFileContent.getContent() ); } /** @@ -139,7 +138,7 @@ protected Model loadTurtleFromString( final String aspectModel ) { if ( resultTry.isFailure() ) { Throwable cause = resultTry.getCause(); String errorMessage = cause != null ? cause.getMessage() : "Unknown Error"; - throw new RiotException( errorMessage, cause ); + throw new InvalidAspectModelException( errorMessage, cause ); } return resultTry.get(); diff --git a/src/main/java/org/eclipse/esmf/ame/model/resolver/FolderStructure.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/FolderStructure.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/model/resolver/FolderStructure.java rename to aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/FolderStructure.java index 702098e3..a2ac3005 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/resolver/FolderStructure.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/FolderStructure.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.resolver; +package org.eclipse.esmf.ame.resolver.strategy.model; import java.io.File; diff --git a/src/main/java/org/eclipse/esmf/ame/model/repository/AspectModelInformation.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/NamespaceFileContent.java similarity index 82% rename from src/main/java/org/eclipse/esmf/ame/model/repository/AspectModelInformation.java rename to aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/NamespaceFileContent.java index 8ff02792..9958318e 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/repository/AspectModelInformation.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/model/NamespaceFileContent.java @@ -11,15 +11,15 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.repository; +package org.eclipse.esmf.ame.resolver.strategy.model; import lombok.AllArgsConstructor; import lombok.Data; @Data @AllArgsConstructor -public class AspectModelInformation { +public class NamespaceFileContent { private String namespace; private String fileName; - private String aspectModel; + private String content; } diff --git a/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/utils/ResolverUtils.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/utils/ResolverUtils.java new file mode 100644 index 00000000..6cd3425e --- /dev/null +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/utils/ResolverUtils.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.resolver.strategy.utils; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.net.URI; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.jena.rdf.model.Model; +import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; +import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; +import org.eclipse.esmf.ame.resolver.strategy.InMemoryStrategy; +import org.eclipse.esmf.ame.utils.ModelUtils; +import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; +import org.eclipse.esmf.aspectmodel.resolver.services.SammAspectMetaModelResourceResolver; +import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; +import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; +import org.eclipse.esmf.aspectmodel.serializer.PrettyPrinter; +import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; +import org.eclipse.esmf.metamodel.Aspect; +import org.eclipse.esmf.metamodel.AspectContext; +import org.eclipse.esmf.metamodel.loader.AspectModelLoader; + +import io.vavr.control.Try; + +public class ResolverUtils { + /** + * Reads the content of a file located at the specified path using the provided character encoding. + * + * @param path The path to the file to be read. + * @param charset The character encoding to be used for decoding the file content. + * @return The content of the file as a string decoded with the specified character encoding. + * + * @throws IOException If an I/O error occurs while reading the file. + */ + public static String readString( Path path, Charset charset ) throws IOException { + try ( InputStream inputStream = Files.newInputStream( path ) ) { + byte[] bytes = inputStream.readAllBytes(); + return new String( bytes, charset ); + } + } + + /** + * Method to resolve a given AspectModelUrn using a suitable ResolutionStrategy. + * + * @param fileSystemStrategy strategy of the backend. + * @return The resolved model on success. + */ + public static Try fetchVersionModel( final FileSystemStrategy fileSystemStrategy ) { + return new AspectModelResolver().resolveAspectModel( fileSystemStrategy, fileSystemStrategy.getAspectModelUrn() ); + } + + public static Try fetchVersionModel( final InMemoryStrategy inMemoryStrategy ) { + return new AspectModelResolver().resolveAspectModel( inMemoryStrategy, inMemoryStrategy.getAspectModelUrn() ); + } + + /** + * Load Aspect Model from storage path. + * + * @param fileSystemStrategy for the given storage path. + * @return the resulting {@link VersionedModel} that corresponds to the input Aspect model. + */ + public static VersionedModel loadModelFromStoragePath( final FileSystemStrategy fileSystemStrategy ) { + return resolveModel( fileSystemStrategy.getCurrentAspectModel() ).getOrElseThrow( + e -> new InvalidAspectModelException( "Cannot resolve Aspect Model.", e ) ); + } + + /** + * Loading the Aspect Model from input file. + * + * @param file Aspect Model as a file. + * @return the resulting {@link VersionedModel} that corresponds to the input Aspect model. + */ + public static Try loadModelFromFile( final File file ) { + try ( final InputStream inputStream = new FileInputStream( file ) ) { + return TurtleLoader.loadTurtle( inputStream ).flatMap( ResolverUtils::resolveModel ); + } catch ( final IOException exception ) { + return Try.failure( exception ); + } + } + + private static Try resolveModel( final Model model ) { + final SammAspectMetaModelResourceResolver resourceResolver = new SammAspectMetaModelResourceResolver(); + + return resourceResolver.getMetaModelVersion( model ).flatMap( + metaModelVersion -> resourceResolver.mergeMetaModelIntoRawModel( model, metaModelVersion ) ); + } + + /** + * Creates a pretty-printed string representation of the provided versioned model. + * This method formats the versioned model into a more readable and structured text format, + * making it easier to understand and interpret. + * + * @param versionedModel The versioned model to be pretty-printed. + * @param urn The URI of the aspect related to the model. + * @return A string that represents the pretty-printed version of the versioned aspect model. + */ + public static String getPrettyPrintedVersionedModel( final VersionedModel versionedModel, final URI urn ) { + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + final PrintWriter writer = new PrintWriter( buffer ); + new PrettyPrinter( versionedModel, AspectModelUrn.fromUrn( urn ), writer ).print(); + writer.flush(); + return buffer.toString(); + } + + /** + * Generates a pretty-printed string representation of the aspect model. + * This method first resolves the versioned model from the given aspect model string + * using a FileSystemStrategy and then pretty-prints it. + * + * @param aspectModel The string representation of the aspect model. + * @return A pretty-printed string of the resolved and formatted versioned aspect model. + */ + public static String getPrettyPrintedModel( final String aspectModel ) { + final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); + final VersionedModel versionedModel = ResolverUtils.loadModelFromStoragePath( fileSystemStrategy ); + + return getPrettyPrintedVersionedModel( versionedModel, fileSystemStrategy.getAspectModelUrn().getUrn() ); + } + + /** + * Creates an Aspect instance from an Aspect Model. + * + * @param aspectModel as a string. + * @return the Aspect as an object. + */ + public static Aspect resolveAspectFromModel( final String aspectModel ) throws InvalidAspectModelException { + final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); + final Try versionedModels = ResolverUtils.fetchVersionModel( fileSystemStrategy ); + + final Try context = versionedModels.flatMap( + model -> resolveSingleAspect( fileSystemStrategy, model ) ); + + return ModelUtils.getAspectContext( context ).aspect(); + } + + /** + * Retrieves a single AspectContext based on the given FileSystemStrategy and VersionedModel. + * + * @param fileSystemStrategy The file system strategy to retrieve the AspectModel URN. + * @param model The versioned model to search for the aspect. + * @return A Try containing the AspectContext if found, otherwise a failure. + */ + public static Try resolveSingleAspect( final FileSystemStrategy fileSystemStrategy, + final VersionedModel model ) { + return AspectModelLoader.getSingleAspect( model, + aspect -> aspect.getName().equals( fileSystemStrategy.getAspectModelUrn().getName() ) ) + .map( aspect -> new AspectContext( model, aspect ) ); + } +} diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml new file mode 100644 index 00000000..9832c922 --- /dev/null +++ b/aspect-model-editor-runtime/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-runtime + ESMF Aspect Model Editor Runtime + jar + + + org.eclipse.esmf.ame.Application + + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.eclipse.esmf + aspect-model-editor-web-core + + + org.eclipse.esmf + aspect-model-editor-web + + + org.eclipse.esmf + aspect-model-editor-repository + + + org.eclipse.esmf + aspect-model-editor-migrator + + + org.springframework.boot + spring-boot-starter-web + + + jakarta.validation + jakarta.validation-api + + + org.eclipse.esmf + esmf-aspect-model-validator + + + com.github.marschall + memoryfilesystem + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/postman/ame.postman_collection.json b/aspect-model-editor-runtime/postman/ame.postman_collection.json similarity index 99% rename from postman/ame.postman_collection.json rename to aspect-model-editor-runtime/postman/ame.postman_collection.json index 22db86d5..406391e4 100644 --- a/postman/ame.postman_collection.json +++ b/aspect-model-editor-runtime/postman/ame.postman_collection.json @@ -359,9 +359,9 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(200);\r", - " pm.expect(pm.response.json().violationErrors.length).to.eql(1);\r", + "pm.test(\"Status code is 422\", function () {\r", + " pm.response.to.have.status(422);\r", + " pm.expect(pm.response.json().error.message).to.contain(\"[line: 17, col: 1 ] Triples not terminated by DOT\");\r", "});" ], "type": "text/javascript" @@ -961,7 +961,6 @@ " const jsonData = pm.response.text();\r", " pm.expect(jsonData).to.include(\"\");\r", " pm.expect(jsonData).to.include(\"https://admin-shell.io/aas/3/0\");\r", - "\r", "});" ], "type": "text/javascript" diff --git a/postman/ame.postman_environment.json b/aspect-model-editor-runtime/postman/ame.postman_environment.json similarity index 100% rename from postman/ame.postman_environment.json rename to aspect-model-editor-runtime/postman/ame.postman_environment.json diff --git a/src/main/java/org/eclipse/esmf/ame/Application.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/Application.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/Application.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/Application.java diff --git a/src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java similarity index 94% rename from src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java index 5f25f340..5e4aa9fd 100644 --- a/src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/config/ApplicationConfig.java @@ -19,9 +19,10 @@ import java.util.Collections; import java.util.List; +import org.eclipse.esmf.ame.api.ModelController; import org.eclipse.esmf.ame.exceptions.CreateFileException; import org.eclipse.esmf.ame.exceptions.ResponseExceptionHandler; -import org.eclipse.esmf.ame.model.ProcessPath; +import org.eclipse.esmf.ame.model.StoragePath; import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; import org.eclipse.esmf.ame.repository.strategy.ModelResolverStrategy; import org.eclipse.esmf.aspectmodel.shacl.constraint.JsConstraint; @@ -42,7 +43,7 @@ * This class primarily sets up properties, file systems, model paths, and CORS mappings. */ @Configuration -@ComponentScan( basePackageClasses = ResponseExceptionHandler.class ) +@ComponentScan( basePackageClasses = { ResponseExceptionHandler.class, ModelController.class } ) @EnableConfigurationProperties( ApplicationSettings.class ) public class ApplicationConfig implements WebMvcConfigurer { @@ -113,7 +114,7 @@ public String modelPath() { return Path.of( "src", "test", "resources", "services" ).toAbsolutePath().toString(); } - return ProcessPath.MODELS.getPath().toString(); + return StoragePath.MetaModel.getPath().toString(); } /** diff --git a/src/main/resources/application-dev.properties b/aspect-model-editor-runtime/src/main/resources/application-dev.properties similarity index 100% rename from src/main/resources/application-dev.properties rename to aspect-model-editor-runtime/src/main/resources/application-dev.properties diff --git a/src/main/resources/application-mac.properties b/aspect-model-editor-runtime/src/main/resources/application-mac.properties similarity index 100% rename from src/main/resources/application-mac.properties rename to aspect-model-editor-runtime/src/main/resources/application-mac.properties diff --git a/src/main/resources/application.properties b/aspect-model-editor-runtime/src/main/resources/application.properties similarity index 100% rename from src/main/resources/application.properties rename to aspect-model-editor-runtime/src/main/resources/application.properties diff --git a/aspect-model-editor-runtime/src/test/java/org/eclipse/esmf/ame/ApplicationTest.java b/aspect-model-editor-runtime/src/test/java/org/eclipse/esmf/ame/ApplicationTest.java new file mode 100644 index 00000000..758fb761 --- /dev/null +++ b/aspect-model-editor-runtime/src/test/java/org/eclipse/esmf/ame/ApplicationTest.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@ActiveProfiles( "test" ) +public class ApplicationTest { + + @Test + void contextLoads() { + // This test will simply check if the application context loads successfully + } +} diff --git a/aspect-model-editor-service/pom.xml b/aspect-model-editor-service/pom.xml new file mode 100644 index 00000000..86dd7cd5 --- /dev/null +++ b/aspect-model-editor-service/pom.xml @@ -0,0 +1,83 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-service + ESMF Aspect Model Editor Service + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.eclipse.esmf + aspect-model-editor-resolver + + + org.eclipse.esmf + aspect-model-editor-repository + + + org.eclipse.esmf + aspect-model-editor-migrator + + + org.eclipse.esmf + aspect-model-editor-validation + + + org.eclipse.esmf + esmf-aspect-model-validator + + + org.eclipse.esmf + esmf-aspect-model-document-generators + + + org.eclipse.esmf + esmf-aspect-model-aas-generator + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-test + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.github.marschall + memoryfilesystem + test + + + diff --git a/src/main/java/org/eclipse/esmf/ame/services/FileHandlingService.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/FileHandlingService.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/services/FileHandlingService.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/FileHandlingService.java diff --git a/src/main/java/org/eclipse/esmf/ame/services/GenerateService.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/GenerateService.java similarity index 93% rename from src/main/java/org/eclipse/esmf/ame/services/GenerateService.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/GenerateService.java index 4f7f0555..36583aa6 100644 --- a/src/main/java/org/eclipse/esmf/ame/services/GenerateService.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/GenerateService.java @@ -22,7 +22,8 @@ import org.apache.commons.lang3.LocaleUtils; import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; -import org.eclipse.esmf.ame.services.utils.ModelUtils; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; +import org.eclipse.esmf.ame.utils.ModelUtils; import org.eclipse.esmf.aspectmodel.aas.AspectModelAASGenerator; import org.eclipse.esmf.aspectmodel.generator.docu.AspectModelDocumentationGenerator; import org.eclipse.esmf.aspectmodel.generator.json.AspectModelJsonPayloadGenerator; @@ -128,10 +129,10 @@ public String generateAasXmlFile( String aspectModel ) { private AspectContext generateAspectContext( final String aspectModel ) { final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); - final Try versionedModels = ModelUtils.fetchVersionModel( fileSystemStrategy ); + final Try versionedModels = ResolverUtils.fetchVersionModel( fileSystemStrategy ); final Try context = versionedModels.flatMap( - model -> ModelUtils.getSingleAspect( fileSystemStrategy, model ) ); + model -> ResolverUtils.resolveSingleAspect( fileSystemStrategy, model ) ); return ModelUtils.getAspectContext( context ); } @@ -141,7 +142,7 @@ public String generateYamlOpenApiSpec( final String language, final String aspec try { final AspectModelOpenApiGenerator generator = new AspectModelOpenApiGenerator(); - return generator.applyForYaml( ModelUtils.resolveAspectFromModel( aspectModel ), + return generator.applyForYaml( ResolverUtils.resolveAspectFromModel( aspectModel ), useSemanticVersion, baseUrl, Optional.empty(), Optional.empty(), includeQueryApi, pagingOption, Locale.forLanguageTag( language ) ); } catch ( final IOException e ) { @@ -156,7 +157,7 @@ public String generateJsonOpenApiSpec( final String language, final String aspec final AspectModelOpenApiGenerator generator = new AspectModelOpenApiGenerator(); final JsonNode json = generator.applyForJson( - ModelUtils.resolveAspectFromModel( aspectModel ), useSemanticVersion, baseUrl, + ResolverUtils.resolveAspectFromModel( aspectModel ), useSemanticVersion, baseUrl, Optional.empty(), Optional.empty(), includeQueryApi, pagingOption, LocaleUtils.toLocale( language ) ); final ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/src/main/java/org/eclipse/esmf/ame/services/ModelService.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/ModelService.java similarity index 63% rename from src/main/java/org/eclipse/esmf/ame/services/ModelService.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/ModelService.java index 1edb9a5b..498b32c9 100644 --- a/src/main/java/org/eclipse/esmf/ame/services/ModelService.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/ModelService.java @@ -21,16 +21,19 @@ import org.apache.commons.io.FileUtils; import org.apache.jena.rdf.model.StmtIterator; -import org.eclipse.esmf.ame.model.ProcessPath; -import org.eclipse.esmf.ame.model.migration.FileInformation; -import org.eclipse.esmf.ame.model.migration.Namespace; -import org.eclipse.esmf.ame.model.migration.Namespaces; -import org.eclipse.esmf.ame.model.validation.ViolationReport; +import org.eclipse.esmf.ame.model.FileProcessingResult; +import org.eclipse.esmf.ame.model.NamespaceFileCollection; +import org.eclipse.esmf.ame.model.StoragePath; +import org.eclipse.esmf.ame.model.VersionedNamespaceFiles; import org.eclipse.esmf.ame.repository.ModelResolverRepository; import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; import org.eclipse.esmf.ame.repository.strategy.ModelResolverStrategy; import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; -import org.eclipse.esmf.ame.services.utils.ModelUtils; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; +import org.eclipse.esmf.ame.utils.MigratorUtils; +import org.eclipse.esmf.ame.utils.ModelUtils; +import org.eclipse.esmf.ame.validation.model.ViolationReport; +import org.eclipse.esmf.ame.validation.utils.ValidationUtils; import org.eclipse.esmf.aspectmodel.resolver.services.DataType; import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; @@ -64,7 +67,7 @@ public String getModel( final String namespace, final String filename ) { public String saveModel( final Optional namespace, final Optional fileName, final String aspectModel ) { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); - final String prettyPrintedModel = ModelUtils.getPrettyPrintedModel( aspectModel ); + final String prettyPrintedModel = ResolverUtils.getPrettyPrintedModel( aspectModel ); return strategy.saveModel( namespace, fileName, prettyPrintedModel ); } @@ -74,13 +77,10 @@ private void saveVersionedModel( final VersionedModel versionedModel, final Stri final Optional esmfStatements = FileSystemStrategy.getEsmfStatements( versionedModel.getModel() ); - final String uri = esmfStatements.stream().findFirst() - .orElseThrow( - () -> new NotImplementedError( "AspectModelUrn cannot be found." ) ) - .next() - .getSubject().getURI(); + final String uri = esmfStatements.stream().findFirst().orElseThrow( + () -> new NotImplementedError( "AspectModelUrn cannot be found." ) ).next().getSubject().getURI(); - final String prettyPrintedVersionedModel = ModelUtils.getPrettyPrintedVersionedModel( versionedModel, + final String prettyPrintedVersionedModel = ResolverUtils.getPrettyPrintedVersionedModel( versionedModel, AspectModelUrn.fromUrn( uri ).getUrn() ); saveModel( Optional.of( namespace ), Optional.of( fileName ), prettyPrintedVersionedModel ); @@ -98,67 +98,71 @@ public Map> getAllNamespaces( final boolean shouldRefresh ) } public ViolationReport validateModel( final String aspectModel ) { - return ModelUtils.validateModel( aspectModel, aspectModelValidator ); + final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); + final Try versionedModel = ResolverUtils.fetchVersionModel( fileSystemStrategy ); + return ValidationUtils.validateModel( versionedModel, aspectModelValidator ); } public String migrateModel( final String aspectModel ) { - return ModelUtils.migrateModel( aspectModel ); + return MigratorUtils.migrateModel( aspectModel ); } - public Namespaces migrateWorkspace() { + public NamespaceFileCollection migrateWorkspace() { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); - final File storageDirectory = ProcessPath.MODELS.getPath().toFile(); + final File storageDirectory = StoragePath.MetaModel.getPath().toFile(); final String[] extensions = { "ttl" }; - final List namespaces = new ArrayList<>(); + final List versionedNamespaceFiles = new ArrayList<>(); FileUtils.listFiles( storageDirectory, extensions, true ).stream().map( File::getAbsoluteFile ) .forEach( inputFile -> { if ( !inputFile.getName().equals( "latest.ttl" ) ) { final Try versionedModels = updateModelVersion( inputFile ); final Tuple2 fileInfo = strategy.convertFileToTuple( inputFile ); - final Namespace namespace = resolveNamespace( namespaces, fileInfo._2 ); - namespaceFileInfo( namespace, versionedModels, fileInfo._1, fileInfo._2 ); + final VersionedNamespaceFiles namespaces = resolveNamespace( versionedNamespaceFiles, + fileInfo._2 ); + namespaceFileInfo( namespaces, versionedModels, fileInfo._1, fileInfo._2 ); } } ); - return new Namespaces( namespaces ); + return new NamespaceFileCollection( versionedNamespaceFiles ); } private Try updateModelVersion( final File inputFile ) { - return ModelUtils.loadModelFromFile( inputFile ).flatMap( new MigratorService()::updateMetaModelVersion ); + return ResolverUtils.loadModelFromFile( inputFile ).flatMap( new MigratorService()::updateMetaModelVersion ); } - private Namespace resolveNamespace( final List namespaces, final String versionedNamespace ) { - final Optional first = namespaces.stream().filter( + private VersionedNamespaceFiles resolveNamespace( final List namespaces, + final String versionedNamespace ) { + final Optional first = namespaces.stream().filter( namespace -> namespace.versionedNamespace.equals( versionedNamespace ) ).findFirst(); return first.orElseGet( () -> { - final Namespace namespace = new Namespace( versionedNamespace ); + final VersionedNamespaceFiles namespace = new VersionedNamespaceFiles( versionedNamespace ); namespaces.add( namespace ); return namespace; } ); } - private void namespaceFileInfo( final Namespace namespace, final Try model, final String fileName, - final String versionedNamespace ) { + private void namespaceFileInfo( final VersionedNamespaceFiles versionedNamespaceFiles, + final Try model, final String fileName, final String versionedNamespace ) { boolean modelIsSuccess = false; if ( model.isSuccess() ) { saveVersionedModel( model.get(), versionedNamespace, fileName + ModelUtils.TTL_EXTENSION ); - modelIsSuccess = !getModel( namespace.versionedNamespace, fileName + ModelUtils.TTL_EXTENSION ).contains( - "undefined:" ); + modelIsSuccess = !getModel( versionedNamespaceFiles.versionedNamespace, + fileName + ModelUtils.TTL_EXTENSION ).contains( "undefined:" ); } - final FileInformation aspectModelFile = new FileInformation( fileName + ModelUtils.TTL_EXTENSION, + final FileProcessingResult aspectModelFile = new FileProcessingResult( fileName + ModelUtils.TTL_EXTENSION, modelIsSuccess, model.isSuccess() ? "File is valid" : model.getCause().getMessage() ); - namespace.addAspectModelFile( aspectModelFile ); + versionedNamespaceFiles.addAspectModelFile( aspectModelFile ); } public String getFormattedModel( final String aspectModel ) { - return ModelUtils.getPrettyPrintedModel( aspectModel ); + return ResolverUtils.getPrettyPrintedModel( aspectModel ); } } diff --git a/src/main/java/org/eclipse/esmf/ame/services/PackageService.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java similarity index 62% rename from src/main/java/org/eclipse/esmf/ame/services/PackageService.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java index 8db5076e..15fccded 100644 --- a/src/main/java/org/eclipse/esmf/ame/services/PackageService.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java @@ -33,22 +33,27 @@ import org.eclipse.esmf.ame.exceptions.FileCannotDeleteException; import org.eclipse.esmf.ame.exceptions.FileNotFoundException; -import org.eclipse.esmf.ame.model.packaging.AspectModelFiles; -import org.eclipse.esmf.ame.model.packaging.MissingElement; -import org.eclipse.esmf.ame.model.packaging.ProcessPackage; -import org.eclipse.esmf.ame.model.packaging.ValidFile; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; -import org.eclipse.esmf.ame.model.resolver.FolderStructure; -import org.eclipse.esmf.ame.model.validation.ViolationError; -import org.eclipse.esmf.ame.model.validation.ViolationReport; import org.eclipse.esmf.ame.repository.ModelResolverRepository; import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; import org.eclipse.esmf.ame.repository.strategy.ModelResolverStrategy; import org.eclipse.esmf.ame.repository.strategy.utils.LocalFolderResolverUtils; -import org.eclipse.esmf.ame.services.utils.ModelUtils; +import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; +import org.eclipse.esmf.ame.resolver.strategy.InMemoryStrategy; +import org.eclipse.esmf.ame.resolver.strategy.model.FolderStructure; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; +import org.eclipse.esmf.ame.resolver.strategy.utils.ResolverUtils; +import org.eclipse.esmf.ame.services.model.ElementMissingReport; +import org.eclipse.esmf.ame.services.model.FileValidationReport; +import org.eclipse.esmf.ame.services.model.NamespaceFileCollection; +import org.eclipse.esmf.ame.services.model.NamespaceFileReport; import org.eclipse.esmf.ame.services.utils.UnzipUtils; import org.eclipse.esmf.ame.services.utils.ZipUtils; +import org.eclipse.esmf.ame.utils.ModelUtils; +import org.eclipse.esmf.ame.validation.model.ViolationError; +import org.eclipse.esmf.ame.validation.model.ViolationReport; +import org.eclipse.esmf.ame.validation.utils.ValidationUtils; import org.eclipse.esmf.aspectmodel.resolver.services.DataType; +import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; import org.eclipse.esmf.aspectmodel.shacl.violation.ProcessingViolation; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; @@ -57,6 +62,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import io.vavr.control.Try; + @Service public class PackageService { private static final Logger LOG = LoggerFactory.getLogger( PackageService.class ); @@ -77,33 +84,35 @@ public PackageService( final AspectModelValidator aspectModelValidator, final St DataType.setupTypeMapping(); } - public ProcessPackage validateAspectModelsForExport( final List aspectModelFiles ) { + public FileValidationReport validateAspectModelsForExport( final List aspectModelFiles ) { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); - final ProcessPackage processPackage = new ProcessPackage(); + final FileValidationReport fileValidationReport = new FileValidationReport(); AspectModelToExportCache.clear(); - Map validFiles = aspectModelFiles.stream() - .flatMap( data -> data.getFiles().stream().map( fileName -> { - String model = strategy.getModelAsString( - data.getNamespace(), fileName ); - AspectModelToExportCache.put( - data.getNamespace() + ":" + fileName, model ); - ViolationReport report = ModelUtils.validateModel( model, - aspectModelValidator ); - return new ValidFile( data.getNamespace(), fileName, - report ); - } ) ).collect( - Collectors.toMap( validFile -> validFile.getNamespace() + ":" + validFile.getFileName(), - Function.identity() ) ); - - validFiles.values().forEach( processPackage::addValidFile ); + Map validFiles = + aspectModelFiles.stream() + .flatMap( data -> data.getFiles().stream().map( fileName -> { + String aspectModel = strategy.getModelAsString( data.getNamespace(), fileName ); + AspectModelToExportCache.put( data.getNamespace() + ":" + fileName, aspectModel ); + final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); + final Try versionedModel = ResolverUtils.fetchVersionModel( + fileSystemStrategy ); + ViolationReport report = ValidationUtils.validateModel( versionedModel, + aspectModelValidator ); + return new NamespaceFileReport( data.getNamespace(), fileName, report ); + } ) ) + .collect( Collectors.toMap( namespaceFileReport -> namespaceFileReport.getNamespace() + ":" + + namespaceFileReport.getFileName(), Function.identity() ) ); + + validFiles.values().forEach( fileValidationReport::addValidFile ); validFiles.values().stream().flatMap( - validFile -> getMissingAspectModelFiles( validFile.getViolationReport(), validFile.getFileName(), - modelPath ).stream() ).forEach( processPackage::addMissingElement ); + namespaceFileReport -> getMissingAspectModelFiles( namespaceFileReport.getViolationReport(), + namespaceFileReport.getFileName(), + modelPath ).stream() ).forEach( fileValidationReport::addMissingElement ); - return processPackage; + return fileValidationReport; } public byte[] exportAspectModelPackage( final String zipFileName ) { @@ -116,7 +125,7 @@ public byte[] exportAspectModelPackage( final String zipFileName ) { } } - public ProcessPackage validateImportAspectModelPackage( final MultipartFile zipFile ) { + public FileValidationReport validateImportAspectModelPackage( final MultipartFile zipFile ) { try ( final InputStream inputStream = zipFile.getInputStream() ) { deleteInMemoryFileSystem(); @@ -147,33 +156,39 @@ public void deleteInMemoryFileSystem() throws IOException { } } - private ProcessPackage validateValidFiles( final String modelStoragePath ) { + private FileValidationReport validateValidFiles( final String modelStoragePath ) { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); - final List aspectModelInformations = strategy.getImportedAspectModelInformation(); + final List namespaceFileContent = strategy.getImportedNamespaceFileContent(); + + return namespaceFileContent.stream().map( content -> { + final Boolean modelExist = strategy.checkModelExist( content.getNamespace(), content.getFileName() ); + + final Path root = importFileSystem.getRootDirectories().iterator().next(); + + final InMemoryStrategy inMemoryStrategy = new InMemoryStrategy( content, root, importFileSystem ); + final Try versionedModel = ResolverUtils.fetchVersionModel( inMemoryStrategy ); - return aspectModelInformations.stream().map( fileInfo -> { - final Boolean modelExist = strategy.checkModelExist( fileInfo.getNamespace(), fileInfo.getFileName() ); + final ViolationReport violationReport = ValidationUtils.validateModel( versionedModel, + aspectModelValidator ); - final ViolationReport violationReport = ModelUtils.validateModelInMemoryFiles( fileInfo, aspectModelValidator, - importFileSystem ); + final NamespaceFileReport namespaceFileReport = new NamespaceFileReport( content.getNamespace(), + content.getFileName(), violationReport, modelExist ); - final ValidFile validFile = new ValidFile( fileInfo.getNamespace(), fileInfo.getFileName(), violationReport, - modelExist ); - final List missingFiles = getMissingAspectModelFiles( violationReport, fileInfo.getFileName(), - modelStoragePath ); + final List missingFiles = getMissingAspectModelFiles( violationReport, + content.getFileName(), modelStoragePath ); - return new ProcessPackage( validFile, missingFiles ); - } ).reduce( new ProcessPackage(), ProcessPackage::merge ); + return new FileValidationReport( namespaceFileReport, missingFiles ); + } ).reduce( new FileValidationReport(), FileValidationReport::merge ); } - public List importAspectModelPackage( final List aspectModelFiles ) { + public List importAspectModelPackage( final List aspectModelFiles ) { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); return aspectModelFiles.stream().flatMap( data -> data.getFiles().stream().map( fileName -> { try { final FolderStructure folderStructure = LocalFolderResolverUtils.extractFilePath( data.getNamespace() ); folderStructure.setFileName( fileName ); - String aspectModel = LocalFolderResolverUtils.readString( + String aspectModel = ResolverUtils.readString( importFileSystem.getPath( folderStructure.toString() ), StandardCharsets.UTF_8 ); Optional namespaceVersion = Optional.of( folderStructure.getFileRootPath() + File.separator + folderStructure.getVersion() ); @@ -188,7 +203,7 @@ public List importAspectModelPackage( final List aspec } ) ).toList(); } - private List getMissingAspectModelFiles( final ViolationReport violationReport, + private List getMissingAspectModelFiles( final ViolationReport violationReport, final String fileName, final String modelStoragePath ) { final List violationErrors = violationReport.getViolationErrors().stream().filter( violation -> violation.getErrorCode() != null && violation.getErrorCode() @@ -206,7 +221,8 @@ private List getMissingAspectModelFiles( final ViolationReport v final String errorMessage = String.format( "Referenced element: '%s' could not be found in Aspect Model file: '%s'.", focusNode, fileName ); - return new MissingElement( fileName, (focusNode != null ? focusNode.toString() : ""), missingAspectModelFile, + return new ElementMissingReport( fileName, (focusNode != null ? focusNode.toString() : ""), + missingAspectModelFile, errorMessage ); } ).toList(); } diff --git a/src/main/java/org/eclipse/esmf/ame/model/packaging/MissingElement.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/ElementMissingReport.java similarity index 91% rename from src/main/java/org/eclipse/esmf/ame/model/packaging/MissingElement.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/ElementMissingReport.java index fe8117d9..4cb8da7a 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/packaging/MissingElement.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/ElementMissingReport.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.packaging; +package org.eclipse.esmf.ame.services.model; import com.fasterxml.jackson.annotation.JsonProperty; @@ -20,7 +20,7 @@ @Data @AllArgsConstructor -public class MissingElement { +public class ElementMissingReport { @JsonProperty( "analysedFileName" ) private String analysedFileName; diff --git a/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/FileValidationReport.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/FileValidationReport.java new file mode 100644 index 00000000..290ddaa1 --- /dev/null +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/FileValidationReport.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.services.model; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +public class FileValidationReport { + @JsonProperty( "validFiles" ) + private final List namespaceFileReports = new ArrayList<>(); + + @JsonProperty( "missingElements" ) + private final List elementMissingReports = new ArrayList<>(); + + public FileValidationReport() { + } + + public FileValidationReport( NamespaceFileReport namespaceFileReport, List missingFiles ) { + namespaceFileReports.add( namespaceFileReport ); + elementMissingReports.addAll( missingFiles ); + } + + public void addValidFile( final NamespaceFileReport namespaceFileReport ) { + namespaceFileReports.add( namespaceFileReport ); + } + + public void addMissingElement( final ElementMissingReport elementMissingReport ) { + elementMissingReports.add( elementMissingReport ); + } + + public FileValidationReport merge( FileValidationReport other ) { + // Create a new instance of ProcessPackage + FileValidationReport mergedPackage = new FileValidationReport(); + + // Merge the valid files + mergedPackage.getNamespaceFileReports().addAll( this.getNamespaceFileReports() ); + mergedPackage.getNamespaceFileReports().addAll( other.getNamespaceFileReports() ); + + // Merge the missing elements + mergedPackage.getElementMissingReports().addAll( this.getElementMissingReports() ); + mergedPackage.getElementMissingReports().addAll( other.getElementMissingReports() ); + + return mergedPackage; + } +} diff --git a/src/main/java/org/eclipse/esmf/ame/model/packaging/AspectModelFiles.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileCollection.java similarity index 91% rename from src/main/java/org/eclipse/esmf/ame/model/packaging/AspectModelFiles.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileCollection.java index 62cc648d..08407e64 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/packaging/AspectModelFiles.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileCollection.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.packaging; +package org.eclipse.esmf.ame.services.model; import java.util.List; @@ -25,7 +25,7 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class AspectModelFiles { +public class NamespaceFileCollection { @JsonInclude( JsonInclude.Include.NON_NULL ) @JsonProperty( "namespace" ) private String namespace; diff --git a/src/main/java/org/eclipse/esmf/ame/model/packaging/ValidFile.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileReport.java similarity index 80% rename from src/main/java/org/eclipse/esmf/ame/model/packaging/ValidFile.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileReport.java index 9c34ae0d..7cdfecb6 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/packaging/ValidFile.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/model/NamespaceFileReport.java @@ -11,9 +11,9 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.packaging; +package org.eclipse.esmf.ame.services.model; -import org.eclipse.esmf.ame.model.validation.ViolationReport; +import org.eclipse.esmf.ame.validation.model.ViolationReport; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -23,7 +23,7 @@ @Data @AllArgsConstructor -public class ValidFile { +public class NamespaceFileReport { @JsonProperty( "namespace" ) private final String namespace; @@ -37,7 +37,7 @@ public class ValidFile { @JsonProperty( "fileAlreadyDefined" ) private Boolean fileAlreadyDefined; - public ValidFile( final String namespace, final String fileName, final ViolationReport violationReport ) { + public NamespaceFileReport( final String namespace, final String fileName, final ViolationReport violationReport ) { this.namespace = namespace; this.fileName = fileName; this.violationReport = violationReport; diff --git a/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java diff --git a/src/main/java/org/eclipse/esmf/ame/services/utils/ZipUtils.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/ZipUtils.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/services/utils/ZipUtils.java rename to aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/ZipUtils.java diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java new file mode 100644 index 00000000..8a630f7c --- /dev/null +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.config; + +import java.nio.file.FileSystem; +import java.nio.file.Path; +import java.util.List; + +import org.eclipse.esmf.ame.repository.ModelResolverRepository; +import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; + +import lombok.SneakyThrows; + +@TestConfiguration +@Import( ApplicationSettings.class ) +public class TestConfig { + @Autowired + private ApplicationSettings applicationSettings; + + @SneakyThrows + @Bean + public ModelResolverRepository modelResolverRepository() { + FileSystem fileSystem = MemoryFileSystemBuilder.newEmpty().build(); + String rootPath = Path.of( "src", "test", "resources", "services" ).toAbsolutePath().toString(); + + LocalFolderResolverStrategy localFolderResolverStrategy = new LocalFolderResolverStrategy( applicationSettings, + fileSystem, rootPath ); + return new ModelResolverRepository( List.of( localFolderResolverStrategy ) ); + } +} diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java new file mode 100644 index 00000000..92d9fbdc --- /dev/null +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.services; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.esmf.ame.config.TestConfig; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest( classes = FileHandlingService.class ) +@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) +@Import( TestConfig.class ) +@ActiveProfiles( "test" ) +class FileHandlingServiceTest { + + @Autowired + private FileHandlingService fileHandlingService; + + private static final String VERSION = "1.0.0"; + private static final String EXAMPLE_NAMESPACE = "org.eclipse.esmf.example"; + private static final String NAMESPACE_VERSION = EXAMPLE_NAMESPACE + ":" + VERSION; + private static final String TEST_MODEL = "AspectModelForService.ttl"; + + @Test + void testLockAndUnlockFile() { + String lockResult = fileHandlingService.lockFile( NAMESPACE_VERSION, TEST_MODEL ); + assertEquals( lockResult, "File is locked" ); + + String unlockResult = fileHandlingService.unlockFile( NAMESPACE_VERSION, TEST_MODEL ); + assertEquals( unlockResult, "File is unlocked" ); + } +} diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java new file mode 100644 index 00000000..ab5be93f --- /dev/null +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.services; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; + +import org.eclipse.esmf.aspectmodel.generator.openapi.PagingOption; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest( classes = GenerateService.class ) +@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) +class GenerateServiceTest { + + @Autowired + private GenerateService generateService; + + private static final Path resourcesPath = Path.of( "src", "test", "resources", "services" ); + private static final Path eclipseTestPath = Path.of( resourcesPath.toString(), "org.eclipse.esmf.example", "1.0.0" ); + + private static final String model = "AspectModelForService.ttl"; + + @Test + void testAspectModelJsonSample() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.sampleJSONPayload( testModel ); + + assertEquals( "{\"property\":\"eOMtThyhVNLWUZNRcBaQKxI\"}", payload ); + } + + @Test + void testAspectModelJsonSchema() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.jsonSchema( testModel, "en-EN" ); + + assertTrue( payload.contains( "#/components/schemas/urn_samm_org.eclipse.esmf.example_1.0.0_Characteristic" ) ); + } + + @Test + void testAspectModelJsonOpenApiSpec() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.generateJsonOpenApiSpec( "en", testModel, "https://test.com", false, false, + Optional.of( PagingOption.TIME_BASED_PAGING ) ); + + assertTrue( payload.contains( "\"openapi\" : \"3.0.3\"" ) ); + assertTrue( payload.contains( "\"version\" : \"v1\"" ) ); + assertTrue( payload.contains( "\"title\" : \"AspectModelForService\"" ) ); + assertTrue( payload.contains( "\"url\" : \"https://test.com/api/v1\"" ) ); + } + + @Test + void testAspectModelYamlOpenApiSpec() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.generateYamlOpenApiSpec( "en", testModel, "https://test.com", false, false, + Optional.of( PagingOption.TIME_BASED_PAGING ) ); + + assertTrue( payload.contains( "openapi: 3.0.3" ) ); + assertTrue( payload.contains( "title: AspectModel" ) ); + assertTrue( payload.contains( "version: v1" ) ); + assertTrue( payload.contains( "url: https://test.com/api/v1" ) ); + } + + @Test + void testAspectModelAASX() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.generateAASXFile( testModel ); + + assertTrue( payload.contains( "aasx" ) ); + } + + @Test + void testAspectModelAASXML() throws IOException { + final Path storagePath = Path.of( eclipseTestPath.toString(), model ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String payload = generateService.generateAasXmlFile( testModel ); + + assertTrue( payload.contains( "" ) ); + assertTrue( payload.contains( "https://admin-shell.io/aas/3/0" ) ); + } +} diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java new file mode 100644 index 00000000..24a5cfe6 --- /dev/null +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.services; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.io.FileUtils; +import org.eclipse.esmf.ame.exceptions.FileNotFoundException; +import org.eclipse.esmf.ame.model.NamespaceFileCollection; +import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; +import org.eclipse.esmf.ame.validation.model.ViolationReport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest +@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) +@ActiveProfiles( "test" ) +class ModelServiceTest { + + @Autowired + private ModelService modelService; + + private static final String VERSION = "1.0.0"; + private static final String EXAMPLE_NAMESPACE = "org.eclipse.esmf.example"; + private static final String NAMESPACE_VERSION = EXAMPLE_NAMESPACE + ":" + VERSION; + + private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "services" ); + private static final Path TEST_NAMESPACE_PATH = Path.of( RESOURCE_PATH.toString(), EXAMPLE_NAMESPACE, VERSION ); + + private static final Path MIGRATION_WORKSPACE_PATH = Path.of( RESOURCE_PATH.toString(), "workspace-to-migrate" ); + private static final Path TO_MIGRATE_WORKSPACE_ONE = Path.of( MIGRATION_WORKSPACE_PATH.toString(), + "io.migrate-workspace-one", VERSION ); + + private static final Path MIGRATE_WORKSPACE_ONE = Path.of( RESOURCE_PATH.toString(), "io.migrate-workspace-one", + VERSION ); + private static final Path TO_MIGRATE_WORKSPACE_TWO = Path.of( MIGRATION_WORKSPACE_PATH.toString(), + "io.migrate-workspace-two", VERSION ); + + private static final Path MIGRATE_WORKSPACE_TWO = Path.of( RESOURCE_PATH.toString(), "io.migrate-workspace-two", + VERSION ); + + private static final String TEST_MODEL = "AspectModelForService.ttl"; + private static final String TEST_MODEL_TO_DELTE = "FileToDelete.ttl"; + private static final String TEST_MODEL_NOT_FOUND = "NOTFOUND.ttl"; + + @Test + void testGetModel() throws IOException { + final String result = modelService.getModel( NAMESPACE_VERSION, TEST_MODEL ); + + assertEquals( result, Files.readString( TEST_NAMESPACE_PATH.resolve( TEST_MODEL ) ) ); + } + + @Test() + void testGetModelThrowsIOException() { + assertThrows( FileNotFoundException.class, + () -> modelService.getModel( NAMESPACE_VERSION, TEST_MODEL_NOT_FOUND ) ); + } + + @Test + void testValidateNewModel() throws IOException { + final Path storagePath = Path.of( TEST_NAMESPACE_PATH.toString(), TEST_MODEL ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final ViolationReport validateReport = modelService.validateModel( testModel ); + + assertTrue( validateReport.getViolationErrors().isEmpty() ); + } + + @Test + void testSaveModel() throws IOException { + final Path fileToReplace = Path.of( TEST_NAMESPACE_PATH.toString(), TEST_MODEL ); + final String turtleData = Files.readString( fileToReplace, StandardCharsets.UTF_8 ); + + final String result = modelService.saveModel( Optional.of( NAMESPACE_VERSION ), Optional.of( TEST_MODEL ), + turtleData ); + assertEquals( result, Path.of( EXAMPLE_NAMESPACE, VERSION, TEST_MODEL ).toString() ); + } + + @Test() + void testDeleteModel() { + modelService.deleteModel( NAMESPACE_VERSION, TEST_MODEL_TO_DELTE ); + assertThrows( FileNotFoundException.class, + () -> modelService.getModel( NAMESPACE_VERSION, TEST_MODEL_TO_DELTE ) ); + } + + @Test + void testMigrateModel() throws IOException { + final Path storagePath = Path.of( TEST_NAMESPACE_PATH.toString(), "OldAspectModel.ttl" ); + final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); + + final String migratedModel = modelService.migrateModel( testModel ); + + checkMigratedModel( migratedModel ); + } + + @Test + void testMigrateWorkspaceWithoutVersionUpgrade() throws IOException { + try ( final MockedStatic strategyUtilities = Mockito.mockStatic( + LocalFolderResolverStrategy.class ); + final MockedStatic fileUtilities = Mockito.mockStatic( FileUtils.class ) ) { + final Path storagePath = MIGRATION_WORKSPACE_PATH.toAbsolutePath(); + final File OneToMigrateOne = new File( TO_MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateOne.ttl" ); + final File OneToMigrateTwo = new File( TO_MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateTwo.ttl" ); + final File TwoToMigrateOne = new File( TO_MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateOne.ttl" ); + final File TwoToMigrateTwo = new File( TO_MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateTwo.ttl" ); + + fileUtilities.when( () -> FileUtils.listFiles( any( File.class ), any(), anyBoolean() ) ) + .thenReturn( List.of( OneToMigrateOne, OneToMigrateTwo, TwoToMigrateOne, TwoToMigrateTwo ) ); + + strategyUtilities.when( () -> LocalFolderResolverStrategy.transformToValidModelDirectory( any() ) ) + .thenReturn( storagePath.toString() ); + + final NamespaceFileCollection collection = modelService.migrateWorkspace(); + + assertEquals( 2, collection.versionedNamespaceFiles.size() ); + assertEquals( "io.migrate-workspace-one:1.0.0", + collection.versionedNamespaceFiles.get( 0 ).versionedNamespace ); + assertEquals( 2, collection.versionedNamespaceFiles.get( 0 ).files.size() ); + assertEquals( "ToMigrateOne.ttl", collection.versionedNamespaceFiles.get( 0 ).files.get( 0 ).getName() ); + assertEquals( true, collection.versionedNamespaceFiles.get( 0 ).files.get( 0 ).getSuccess() ); + assertEquals( "ToMigrateTwo.ttl", collection.versionedNamespaceFiles.get( 0 ).files.get( 1 ).getName() ); + assertEquals( true, collection.versionedNamespaceFiles.get( 0 ).files.get( 1 ).getSuccess() ); + + assertEquals( "io.migrate-workspace-two:1.0.0", + collection.versionedNamespaceFiles.get( 1 ).versionedNamespace ); + assertEquals( 2, collection.versionedNamespaceFiles.get( 1 ).files.size() ); + assertEquals( "ToMigrateOne.ttl", collection.versionedNamespaceFiles.get( 1 ).files.get( 0 ).getName() ); + assertEquals( true, collection.versionedNamespaceFiles.get( 1 ).files.get( 0 ).getSuccess() ); + assertEquals( "ToMigrateTwo.ttl", collection.versionedNamespaceFiles.get( 1 ).files.get( 1 ).getName() ); + assertEquals( true, collection.versionedNamespaceFiles.get( 1 ).files.get( 1 ).getSuccess() ); + + final String migratedModelOne = Files.readString( + new File( MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateOne.ttl" ).toPath(), + StandardCharsets.UTF_8 ); + final String migratedModelTwo = Files.readString( + new File( MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateTwo.ttl" ).toPath(), + StandardCharsets.UTF_8 ); + final String migratedModelThree = Files.readString( + new File( MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateOne.ttl" ).toPath(), + StandardCharsets.UTF_8 ); + final String migratedModelFour = Files.readString( + new File( MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateTwo.ttl" ).toPath(), + StandardCharsets.UTF_8 ); + + checkMigratedModel( migratedModelOne ); + checkMigratedModel( migratedModelTwo ); + checkMigratedModel( migratedModelThree ); + checkMigratedModel( migratedModelFour ); + } + } + + private void checkMigratedModel( final String migratedModel ) { + assertTrue( migratedModel.contains( "@prefix samm: " ) ); + assertTrue( migratedModel.contains( "@prefix samm-c: " ) ); + assertTrue( migratedModel.contains( "@prefix samm-e: " ) ); + assertTrue( migratedModel.contains( "@prefix unit: " ) ); + } +} diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java new file mode 100644 index 00000000..354f907c --- /dev/null +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.services; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import org.eclipse.esmf.ame.services.model.FileValidationReport; +import org.eclipse.esmf.ame.services.model.NamespaceFileCollection; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest +@ActiveProfiles( "test" ) +class PackageServiceTest { + + @Autowired + private PackageService packageService; + + private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "services" ); + private static final String VERSION = "1.0.0"; + private static final String NAMESPACE = "org.eclipse.esmf.export"; + private static final String NAMESPACE_VERSION = NAMESPACE + ":" + VERSION; + private static final String FILE_ONE = "TestFileOne.ttl"; + private static final String FILE_TWO = "TestFileTwo.ttl"; + private static final String FILE_THREE = "TestFileThree.ttl"; + + @Test + void testValidateImportAspectModelPackage() throws IOException { + final Path zipFilePath = Paths.get( RESOURCE_PATH.toString(), "TestArchive.zip" ); + final byte[] testPackage = Files.readAllBytes( zipFilePath ); + + final MockMultipartFile mockedZipFile = new MockMultipartFile( "TestArchive.zip", testPackage ); + + final FileValidationReport importPackage = packageService.validateImportAspectModelPackage( mockedZipFile ); + + assertEquals( importPackage.getNamespaceFileReports().size(), 2 ); + } + + @Test + void testExportValidateAspectModels() { + final List aspectModelFiles = List.of( + new NamespaceFileCollection( NAMESPACE_VERSION, List.of( FILE_ONE, FILE_TWO ) ) ); + + final FileValidationReport file = packageService.validateAspectModelsForExport( aspectModelFiles ); + + assertEquals( 2, file.getNamespaceFileReports().size() ); + assertEquals( 1, file.getElementMissingReports().size() ); + + assertTrue( file.getElementMissingReports().get( 0 ).getAnalysedFileName().contains( FILE_ONE ) ); + + assertTrue( file.getElementMissingReports().get( 0 ).getMissingFileName().contains( FILE_THREE ) ); + } + + @Test + void testExportAspectModelPackage() { + final List aspectModelFiles = List.of( + new NamespaceFileCollection( NAMESPACE_VERSION, List.of( FILE_ONE, FILE_TWO, FILE_THREE ) ) ); + + packageService.validateAspectModelsForExport( aspectModelFiles ); + + assertTrue( packageService.exportAspectModelPackage( "TestExportArchive.zip" ).length > 0 ); + } + + @Test + void testBackupWorkspace() { + packageService.backupWorkspace( RESOURCE_PATH.toString() ); + + assertTrue( Arrays.stream( Objects.requireNonNull( RESOURCE_PATH.toFile().list() ) ) + .anyMatch( file -> file.contains( "backup-" ) ) ); + } +} diff --git a/aspect-model-editor-service/src/test/resources/services/TestArchive.zip b/aspect-model-editor-service/src/test/resources/services/TestArchive.zip new file mode 100644 index 0000000000000000000000000000000000000000..5d083b9424000b71ca4800ab1b4a1d0dfc080048 GIT binary patch literal 2888 zcmai$3p|r;AIERU#-wo`0*Z=QiCnl}{2%7V0 z3-n^={|{;YI|vuPCz#-e3)6Gr&l8LQK=EMh9&4bm$woXWjVMQ#qQ7`BIvpNmVq?1G$Jo zY)WBbjxOt3XJBzm%1sY$Cv|qee|WWyVzso~b*u8ZvdZ}ng(odA#=JF+rLf%MOZxE+ zsHT10mi|4CI)90!zh=Xl&M0*kqMLV0#%~yYUztY8D``z-%UNdsAy!W7g!h+`V%rF! zoe_+M-PXI048=a^P$d|MgXa%mQetro7Y_s6t+mSZg5J~CR(@Igv_Pg zp8BYO?1L*!^pr7KB8-cVK5hXeF*OfGC|gfgmJ|l9F))02s68sFpnB|GF}xbd_5>^%K}YF?Ja zFsyT~UuJGwWuMqbZ6HcAGqkMF?s|Letm2!TJ6iMXP+eWLcc{X% zr@L!NxR($-@)Gm$E(fU)K79`Ga^4t@oF0+Sf0J-hb?Q) zcSN{*AphhL_b|$1O1bwox+uFPg*4QOhlcF4Gart(Bl%U<&pS*L*JVBC^VQ?z)A1Ku-uRa;(nxuLGUPPekzj12KtykM zZ#fwC+gL2*g_e%4qsd5PoGQ0Wo$3*QoRfq!Pl8laJ@$Ok2#r$&V-+Fo{eeRmQVAgq zWou<5H6H)!xMPjRDes7Mjn*{0!N3KT$yo>#I~a;5P}U!`4bsc%xpl|wDodPlG`r;1 z)q>o82P+dCG+u{aWm_qg`3US z9LCPp4|k|k-g)1{t8MKzpAkWu6I?CWGCLd@37taKOW*1U#1 z*U7xx=rR0=Zv{s#@X}^h#C)KG;nQgd%w>9jRLo5%+7-B zK-e}+oEYL1%6ekP-Yu#@V(840n>@IH#s65%H~##)%O$kY&ue*kyclDn8)Qf zSI_)8bHm=NZAAX~u4p#f{ligfNW-l3HR8M4j>f?cgD=QhI8q3f=z}O(IJ?f=;>Ktk z+RNg`=e0!@*v2xuMqYH>8#P{qsU_a_ZSc@!5w9x$PM97AQ;qy!ON=#0okmUa%0K~s=eA}E=g0KGpKvNBd literal 0 HcmV?d00001 diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl new file mode 100644 index 00000000..adadffd7 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:AspectModelForService a samm:Aspect ; + samm:properties (:property) ; + samm:operations () . + +:property a samm:Property; + samm:characteristic :Characteristic . + +:Characteristic a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl new file mode 100644 index 00000000..6f249130 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl @@ -0,0 +1,30 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . +@prefix ext-ref: . + +:AspectModelForStrategyWithExtRef a samm:Aspect ; + samm:properties (:propertyThis ext-ref:property) ; + samm:operations () . + +:propertyThis a samm:Property; + samm:characteristic :CharacteristicThis . + +:CharacteristicThis a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl new file mode 100644 index 00000000..98006a84 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl @@ -0,0 +1,30 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:FileToDelete a samm:Aspect ; + samm:properties ( :property ) ; + samm:operations ( ) . + +:property a samm:Property ; + samm:characteristic :Characteristic . + +:Characteristic a samm:Characteristic ; + samm:dataType xsd:string . + diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl new file mode 100644 index 00000000..d192428f --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl @@ -0,0 +1,19 @@ +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:OldAspectModel a samm:Aspect ; + samm:properties ( :property ) ; + samm:operations ( ) . + +:property a samm:Property ; + samm:characteristic :Characteristic . + +:Characteristic a samm:Characteristic ; + samm:dataType xsd:string . + diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl new file mode 100644 index 00000000..205b6125 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:TestFileOne a samm:Aspect ; + samm:properties (:property1 :property3) ; + samm:operations () . + +:property1 a samm:Property; + samm:characteristic :Characteristic1 . + +:Characteristic1 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl new file mode 100644 index 00000000..27234a1f --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:TestFileThree a samm:Aspect ; + samm:properties (:property3) ; + samm:operations () . + +:property3 a samm:Property; + samm:characteristic :Characteristic3 . + +:Characteristic3 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl new file mode 100644 index 00000000..2c6871be --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:TestFileTwo a samm:Aspect ; + samm:properties (:property2) ; + samm:operations () . + +:property2 a samm:Property; + samm:characteristic :Characteristic2 . + +:Characteristic2 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl new file mode 100644 index 00000000..b4503431 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToBackupOne a samm:Aspect ; + samm:properties (:property1) ; + samm:operations () . + +:property1 a samm:Property; + samm:characteristic :Characteristic1 . + +:Characteristic1 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl new file mode 100644 index 00000000..bc4b5f7e --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToBackupTwo a samm:Aspect ; + samm:properties (:property2) ; + samm:operations () . + +:property2 a samm:Property; + samm:characteristic :Characteristic2 . + +:Characteristic2 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl new file mode 100644 index 00000000..f91ab7b9 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToBackupOne a samm:Aspect ; + samm:properties (:property1) ; + samm:operations () . + +:property1 a samm:Property; + samm:characteristic :Characteristic1 . + +:Characteristic1 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl new file mode 100644 index 00000000..e0b94afe --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToBackupTwo a samm:Aspect ; + samm:properties (:property2) ; + samm:operations () . + +:property2 a samm:Property; + samm:characteristic :Characteristic2 . + +:Characteristic2 a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl new file mode 100644 index 00000000..d4e41c0e --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl @@ -0,0 +1,22 @@ +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToMigrateOne a samm:Aspect ; + samm:properties ( :property1 ) ; + samm:operations ( ) ; + samm:name "ToMigrateOne" . + +:property1 a samm:Property ; + samm:characteristic :Characteristic1 ; + samm:name "property1" . + +:Characteristic1 a samm:Characteristic ; + samm:dataType xsd:string ; + samm:name "Characteristic1" . + diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl new file mode 100644 index 00000000..96acf649 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl @@ -0,0 +1,22 @@ +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToMigrateTwo a samm:Aspect ; + samm:properties ( :property2 ) ; + samm:operations ( ) ; + samm:name "ToMigrateTwo" . + +:property2 a samm:Property ; + samm:characteristic :Characteristic2 ; + samm:name "property2" . + +:Characteristic2 a samm:Characteristic ; + samm:dataType xsd:string ; + samm:name "Characteristic2" . + diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl new file mode 100644 index 00000000..aeb0b5c1 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl @@ -0,0 +1,22 @@ +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToMigrateOne a samm:Aspect ; + samm:properties ( :property1 ) ; + samm:operations ( ) ; + samm:name "ToMigrateOne" . + +:property1 a samm:Property ; + samm:characteristic :Characteristic1 ; + samm:name "property1" . + +:Characteristic1 a samm:Characteristic ; + samm:dataType xsd:string ; + samm:name "Characteristic1" . + diff --git a/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl new file mode 100644 index 00000000..f89ff0fb --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl @@ -0,0 +1,22 @@ +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:ToMigrateTwo a samm:Aspect ; + samm:properties ( :property2 ) ; + samm:operations ( ) ; + samm:name "ToMigrateTwo" . + +:property2 a samm:Property ; + samm:characteristic :Characteristic2 ; + samm:name "property2" . + +:Characteristic2 a samm:Characteristic ; + samm:dataType xsd:string ; + samm:name "Characteristic2" . + diff --git a/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl b/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl new file mode 100644 index 00000000..979d8671 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . + +:AspectModelForStrategy a samm:Aspect ; + samm:properties (:property) ; + samm:operations () . + +:property a samm:Property; + samm:characteristic :Characteristic . + +:Characteristic a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl b/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl new file mode 100644 index 00000000..6f249130 --- /dev/null +++ b/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl @@ -0,0 +1,30 @@ +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# +# See the AUTHORS file(s) distributed with this work for additional +# information regarding authorship. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# SPDX-License-Identifier: MPL-2.0 + +@prefix samm: . +@prefix samm-c: . +@prefix samm-e: . +@prefix unit: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix : . +@prefix ext-ref: . + +:AspectModelForStrategyWithExtRef a samm:Aspect ; + samm:properties (:propertyThis ext-ref:property) ; + samm:operations () . + +:propertyThis a samm:Property; + samm:characteristic :CharacteristicThis . + +:CharacteristicThis a samm:Characteristic ; + samm:dataType xsd:string . diff --git a/aspect-model-editor-validation/pom.xml b/aspect-model-editor-validation/pom.xml new file mode 100644 index 00000000..106e131f --- /dev/null +++ b/aspect-model-editor-validation/pom.xml @@ -0,0 +1,39 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-validation + ESMF Aspect Model Editor Validation + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.eclipse.esmf + esmf-aspect-model-validator + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/model/validation/ViolationError.java b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationError.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/model/validation/ViolationError.java rename to aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationError.java index 9c8d79c0..e2706b7d 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/validation/ViolationError.java +++ b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationError.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.validation; +package org.eclipse.esmf.ame.validation.model; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/eclipse/esmf/ame/model/validation/ViolationReport.java b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationReport.java similarity index 95% rename from src/main/java/org/eclipse/esmf/ame/model/validation/ViolationReport.java rename to aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationReport.java index 85a2cdd4..294b6dd1 100644 --- a/src/main/java/org/eclipse/esmf/ame/model/validation/ViolationReport.java +++ b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/model/ViolationReport.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.model.validation; +package org.eclipse.esmf.ame.validation.model; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/eclipse/esmf/ame/validation/ViolationFormatter.java b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/services/ViolationFormatter.java similarity index 97% rename from src/main/java/org/eclipse/esmf/ame/validation/ViolationFormatter.java rename to aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/services/ViolationFormatter.java index b8ec48e3..42523dc2 100644 --- a/src/main/java/org/eclipse/esmf/ame/validation/ViolationFormatter.java +++ b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/services/ViolationFormatter.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.validation; +package org.eclipse.esmf.ame.validation.services; import java.util.ArrayList; import java.util.List; @@ -20,8 +20,8 @@ import java.util.stream.Collectors; import org.eclipse.esmf.ame.exceptions.UrnNotFoundException; -import org.eclipse.esmf.ame.model.validation.ViolationError; -import org.eclipse.esmf.ame.services.utils.ModelUtils; +import org.eclipse.esmf.ame.validation.model.ViolationError; +import org.eclipse.esmf.ame.validation.utils.ValidationUtils; import org.eclipse.esmf.aspectmodel.shacl.fix.Fix; import org.eclipse.esmf.aspectmodel.shacl.violation.ClassTypeViolation; import org.eclipse.esmf.aspectmodel.shacl.violation.ClosedViolation; @@ -70,8 +70,8 @@ public List apply( final List violations ) { } private List filterNonSemanticViolations( final List violations ) { - return violations.stream().filter( violation -> ModelUtils.isInvalidSyntaxViolation().test( violation ) - || ModelUtils.isProcessingViolation().test( violation ) ).toList(); + return violations.stream().filter( violation -> ValidationUtils.isInvalidSyntaxViolation().test( violation ) + || ValidationUtils.isProcessingViolation().test( violation ) ).toList(); } protected List processNonSemanticViolation( final List violations, diff --git a/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/utils/ValidationUtils.java b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/utils/ValidationUtils.java new file mode 100644 index 00000000..39206d71 --- /dev/null +++ b/aspect-model-editor-validation/src/main/java/org/eclipse/esmf/ame/validation/utils/ValidationUtils.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.validation.utils; + +import java.util.List; +import java.util.function.Predicate; + +import org.apache.jena.riot.RiotException; +import org.eclipse.esmf.ame.validation.model.ViolationReport; +import org.eclipse.esmf.ame.validation.services.ViolationFormatter; +import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; +import org.eclipse.esmf.aspectmodel.shacl.violation.InvalidSyntaxViolation; +import org.eclipse.esmf.aspectmodel.shacl.violation.ProcessingViolation; +import org.eclipse.esmf.aspectmodel.shacl.violation.Violation; +import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; + +import io.vavr.control.Try; + +public class ValidationUtils { + /** + * Validates a versioned model in memory using a specified aspect model validator. + * This method checks the model for any violations according to the rules defined in the provided validator. + * If violations are found, they are formatted and added to a ViolationReport object. + * In case of a syntax error or other processing issues, an invalid syntax violation is added to the report. + * + * @param versionedModel The versioned model to be validated, wrapped in a Try for safe exception handling. + * @param aspectModelValidator The validator used to check the model for compliance with specific rules. + * @return A ViolationReport object containing all the violations found during validation. + * If no violations are found, this report will be empty. + * + * @throws RiotException If a syntax error is encountered during the validation + * process, a RiotException is thrown and caught within the + * method. The exception's message is then added to the ViolationReport. + */ + public static ViolationReport validateModel( Try versionedModel, + final AspectModelValidator aspectModelValidator ) { + final ViolationReport violationReport = new ViolationReport(); + + try { + final List violations = aspectModelValidator.validateModel( versionedModel ); + + violationReport.setViolationErrors( new ViolationFormatter().apply( violations ) ); + + return violationReport; + } catch ( final RiotException riotException ) { + violationReport.addViolation( + new ViolationFormatter().visitInvalidSyntaxViolation( riotException.getMessage() ) ); + + return violationReport; + } + } + + /** + * Returns a predicate that tests if a given violation is an invalid syntax violation. + * + * @return Predicate that can be used to filter invalid syntax violations. + */ + public static Predicate isInvalidSyntaxViolation() { + return violation -> violation.errorCode() != null && violation.errorCode() + .equals( InvalidSyntaxViolation.ERROR_CODE ); + } + + /** + * Returns a predicate that tests if a given violation is a processing violation. + * + * @return Predicate that can be used to filter processing violations. + */ + public static Predicate isProcessingViolation() { + return violation -> violation.errorCode() != null && violation.errorCode() + .equals( ProcessingViolation.ERROR_CODE ); + } +} diff --git a/aspect-model-editor-web-core/pom.xml b/aspect-model-editor-web-core/pom.xml new file mode 100644 index 00000000..9c49d144 --- /dev/null +++ b/aspect-model-editor-web-core/pom.xml @@ -0,0 +1,35 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-web-core + ESMF Aspect Model Editor Web Core + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/web/utils/MediaTypeExtension.java b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/MediaTypeExtension.java similarity index 97% rename from src/main/java/org/eclipse/esmf/ame/web/utils/MediaTypeExtension.java rename to aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/MediaTypeExtension.java index dc1608a9..ff5135fb 100644 --- a/src/main/java/org/eclipse/esmf/ame/web/utils/MediaTypeExtension.java +++ b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/MediaTypeExtension.java @@ -11,12 +11,14 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.web.utils; +package org.eclipse.esmf.ame; import org.springframework.http.MediaType; public final class MediaTypeExtension { + private static final String APPLICATION = "application"; + /** * Public constant mediat typ for {@code application/schema+json}. */ @@ -44,8 +46,6 @@ public final class MediaTypeExtension { */ public static final MediaType APPLICATION_ZIP; - private static final String APPLICATION = "application"; - static { TEXT_TURTLE = new MediaType( "text", "turtle" ); IMAGE_SVG = new MediaType( "image", "svg+xml" ); diff --git a/src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java similarity index 93% rename from src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java rename to aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java index e812204b..c5de26bf 100644 --- a/src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java +++ b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/config/SecurityConfig.java @@ -15,6 +15,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; @@ -26,6 +27,7 @@ *

Typical usage includes disabling CSRF and permitting all requests to certain paths.

*/ @Configuration +@PropertySource( { "classpath:/multipart-default.properties" } ) public class SecurityConfig { /** * Configures the HTTP security filter chain. This configuration disables CSRF, diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java similarity index 98% rename from src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java rename to aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java index 81b6f3c7..d2ca7766 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java +++ b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java @@ -15,7 +15,7 @@ import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import org.eclipse.esmf.ame.exceptions.model.ErrorResponse; +import org.eclipse.esmf.ame.model.ErrorResponse; import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidNamespaceException; import org.eclipse.esmf.metamodel.loader.AspectLoadingException; import org.slf4j.Logger; @@ -140,7 +140,7 @@ public ResponseEntity handleAspectLoadingException( final WebRequest req @ExceptionHandler( InvalidAspectModelException.class ) public ResponseEntity handleInvalidAspectModelException( final WebRequest request, final InvalidAspectModelException e ) { - return error( HttpStatus.BAD_REQUEST, request, e, e.getMessage() ); + return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); } /** diff --git a/src/main/java/org/eclipse/esmf/ame/exceptions/model/ErrorResponse.java b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/model/ErrorResponse.java similarity index 97% rename from src/main/java/org/eclipse/esmf/ame/exceptions/model/ErrorResponse.java rename to aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/model/ErrorResponse.java index 7f88553b..63cbaa40 100644 --- a/src/main/java/org/eclipse/esmf/ame/exceptions/model/ErrorResponse.java +++ b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/model/ErrorResponse.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.exceptions.model; +package org.eclipse.esmf.ame.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/aspect-model-editor-web-core/src/main/resources/multipart-default.properties b/aspect-model-editor-web-core/src/main/resources/multipart-default.properties new file mode 100644 index 00000000..57d102f8 --- /dev/null +++ b/aspect-model-editor-web-core/src/main/resources/multipart-default.properties @@ -0,0 +1,13 @@ +# +# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved. +# +spring.main.allow-bean-definition-overriding=true +## MULTIPART (MultipartProperties) +# Enable multipart uploads +spring.servlet.multipart.enabled=true +# Threshold after which files are written to disk. +spring.servlet.multipart.file-size-threshold=100MB +# Max file size. +spring.servlet.multipart.max-file-size=100MB +# Max Request Size +spring.servlet.multipart.max-request-size=100MB diff --git a/aspect-model-editor-web/pom.xml b/aspect-model-editor-web/pom.xml new file mode 100644 index 00000000..a30ff936 --- /dev/null +++ b/aspect-model-editor-web/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + + org.eclipse.esmf + aspect-model-editor-parent + DEV-SNAPSHOT + + + aspect-model-editor-web + ESMF Aspect Model Editor Web + jar + + + + org.eclipse.esmf + aspect-model-editor-core + + + org.eclipse.esmf + aspect-model-editor-service + + + org.eclipse.esmf + aspect-model-editor-validation + + + org.eclipse.esmf + aspect-model-editor-web-core + + + org.eclipse.esmf + esmf-aspect-model-document-generators + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + org.projectlombok + lombok + + + diff --git a/src/main/java/org/eclipse/esmf/ame/web/FileHandlingResource.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java similarity index 96% rename from src/main/java/org/eclipse/esmf/ame/web/FileHandlingResource.java rename to aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java index a54ceeb1..ba85405d 100644 --- a/src/main/java/org/eclipse/esmf/ame/web/FileHandlingResource.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.web; +package org.eclipse.esmf.ame.api; import java.util.Map; import java.util.Optional; @@ -30,13 +30,13 @@ */ @RestController @RequestMapping( "file-handling" ) -public class FileHandlingResource { +public class FileHandlingController { public static final String FILE_NAME = "file-name"; public static final String NAMESPACE = "namespace"; private final FileHandlingService fileHandlingService; - public FileHandlingResource( final FileHandlingService fileHandlingService ) { + public FileHandlingController( final FileHandlingService fileHandlingService ) { this.fileHandlingService = fileHandlingService; } diff --git a/src/main/java/org/eclipse/esmf/ame/web/GenerateResource.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/GenerateController.java similarity index 95% rename from src/main/java/org/eclipse/esmf/ame/web/GenerateResource.java rename to aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/GenerateController.java index 2416216f..dbb3758a 100644 --- a/src/main/java/org/eclipse/esmf/ame/web/GenerateResource.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/GenerateController.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.web; +package org.eclipse.esmf.ame.api; import java.io.IOException; import java.util.Optional; @@ -30,11 +30,11 @@ */ @RestController @RequestMapping( "generate" ) -public class GenerateResource { +public class GenerateController { private final GenerateService generateService; - public GenerateResource( final GenerateService generateService ) { + public GenerateController( final GenerateService generateService ) { this.generateService = generateService; } @@ -124,11 +124,9 @@ public ResponseEntity openApiSpec( @RequestBody final String aspectModel final String openApiOutput = output.equals( "json" ) ? generateService.generateJsonOpenApiSpec( language, aspectModel, baseUrl, includeQueryApi, - useSemanticVersion, - pagingOption ) : + useSemanticVersion, pagingOption ) : generateService.generateYamlOpenApiSpec( language, aspectModel, baseUrl, includeQueryApi, - useSemanticVersion, - pagingOption ); + useSemanticVersion, pagingOption ); return ResponseEntity.ok( openApiOutput ); } diff --git a/src/main/java/org/eclipse/esmf/ame/web/ModelResource.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java similarity index 92% rename from src/main/java/org/eclipse/esmf/ame/web/ModelResource.java rename to aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java index 5f05e6da..91bc4ff9 100644 --- a/src/main/java/org/eclipse/esmf/ame/web/ModelResource.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java @@ -11,18 +11,18 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.web; +package org.eclipse.esmf.ame.api; import java.util.List; import java.util.Map; import java.util.Optional; +import org.eclipse.esmf.ame.MediaTypeExtension; import org.eclipse.esmf.ame.exceptions.FileNotFoundException; -import org.eclipse.esmf.ame.model.migration.Namespaces; -import org.eclipse.esmf.ame.model.validation.ViolationReport; +import org.eclipse.esmf.ame.model.NamespaceFileCollection; import org.eclipse.esmf.ame.services.ModelService; -import org.eclipse.esmf.ame.services.utils.ModelUtils; -import org.eclipse.esmf.ame.web.utils.MediaTypeExtension; +import org.eclipse.esmf.ame.utils.MigratorUtils; +import org.eclipse.esmf.ame.validation.model.ViolationReport; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -41,13 +41,13 @@ */ @RestController @RequestMapping( "models" ) -public class ModelResource { +public class ModelController { public static final String FILE_NAME = "file-name"; public static final String NAMESPACE = "namespace"; private final ModelService modelService; - public ModelResource( final ModelService modelService ) { + public ModelController( final ModelService modelService ) { this.modelService = modelService; } @@ -101,7 +101,7 @@ public ResponseEntity validateModel( @RequestBody final String */ @PostMapping( path = "migrate", consumes = { MediaType.TEXT_PLAIN_VALUE, MediaTypeExtension.TEXT_TURTLE_VALUE } ) public ResponseEntity migrateModel( @RequestBody final String aspectModel ) { - return ResponseEntity.ok( ModelUtils.migrateModel( aspectModel ) ); + return ResponseEntity.ok( MigratorUtils.migrateModel( aspectModel ) ); } /** @@ -121,7 +121,7 @@ public ResponseEntity getFormattedModel( @RequestBody final String aspec * @return A list of Aspect Models that are migrated or not. */ @GetMapping( path = "migrate-workspace" ) - public ResponseEntity migrateWorkspace() { + public ResponseEntity migrateWorkspace() { return ResponseEntity.ok( modelService.migrateWorkspace() ); } diff --git a/src/main/java/org/eclipse/esmf/ame/web/PackageResource.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java similarity index 83% rename from src/main/java/org/eclipse/esmf/ame/web/PackageResource.java rename to aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java index 37c445d5..3bddde3f 100644 --- a/src/main/java/org/eclipse/esmf/ame/web/PackageResource.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java @@ -11,18 +11,18 @@ * SPDX-License-Identifier: MPL-2.0 */ -package org.eclipse.esmf.ame.web; +package org.eclipse.esmf.ame.api; import java.util.List; import java.util.Objects; import org.apache.commons.io.FilenameUtils; +import org.eclipse.esmf.ame.MediaTypeExtension; import org.eclipse.esmf.ame.exceptions.FileReadException; -import org.eclipse.esmf.ame.model.ProcessPath; -import org.eclipse.esmf.ame.model.packaging.AspectModelFiles; -import org.eclipse.esmf.ame.model.packaging.ProcessPackage; +import org.eclipse.esmf.ame.model.StoragePath; import org.eclipse.esmf.ame.services.PackageService; -import org.eclipse.esmf.ame.web.utils.MediaTypeExtension; +import org.eclipse.esmf.ame.services.model.FileValidationReport; +import org.eclipse.esmf.ame.services.model.NamespaceFileCollection; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,10 +39,10 @@ */ @RestController @RequestMapping( "package" ) -public class PackageResource { +public class PackageController { private final PackageService packageService; - public PackageResource( final PackageService packageService ) { + public PackageController( final PackageService packageService ) { this.packageService = packageService; } @@ -53,7 +53,8 @@ public PackageResource( final PackageService packageService ) { * @return information which Aspect Models are valid/invalid or missing. */ @PostMapping( "/validate-models-for-export" ) - public ProcessPackage validateAspectModelsForExport( @RequestBody final List aspectModelFiles ) { + public FileValidationReport validateAspectModelsForExport( + @RequestBody final List aspectModelFiles ) { return packageService.validateAspectModelsForExport( aspectModelFiles ); } @@ -65,7 +66,7 @@ public ProcessPackage validateAspectModelsForExport( @RequestBody final List validateImportAspectModelPackage( + public ResponseEntity validateImportAspectModelPackage( @RequestParam( "zipFile" ) final MultipartFile zipFile ) { final String extension = FilenameUtils.getExtension( zipFile.getOriginalFilename() ); @@ -84,7 +85,7 @@ public ResponseEntity validateImportAspectModelPackage( */ @PostMapping( "/import" ) public ResponseEntity> importAspectModelPackage( - @RequestBody final List aspectModelFiles ) { + @RequestBody final List aspectModelFiles ) { return ResponseEntity.ok( packageService.importAspectModelPackage( aspectModelFiles ) ); } @@ -109,7 +110,7 @@ public ResponseEntity exportAspectModelPackage() { */ @GetMapping( path = "/backup-workspace" ) public ResponseEntity backupWorkspace() { - String aspectModelPath = ProcessPath.AspectModelPath.getPath().toString(); + String aspectModelPath = StoragePath.AspectModel.getPath().toString(); packageService.backupWorkspace( aspectModelPath ); return new ResponseEntity<>( HttpStatus.CREATED ); } diff --git a/pom.xml b/pom.xml index bc17f06d..a83e50fa 100644 --- a/pom.xml +++ b/pom.xml @@ -17,22 +17,46 @@ 4.0.0 org.eclipse.esmf - esmf-aspect-model-editor-backend - ESMF Aspect Model Editor - Backend + aspect-model-editor-parent + ESMF Aspect Model Editor Parent DEV-SNAPSHOT - jar - ESMF Aspect Model Editor Backend + pom + + ESMF Aspect Model Editor Parent MPL-2.0 https://www.mozilla.org/en-US/MPL/2.0/ + + + Eclipse Semantic Modeling Framework Team + esmf-dev@eclipse.org + Eclipse Semantic Modeling Framework + https://projects.eclipse.org/projects/dt.esmf + + https://github.com/eclipse-esmf/esmf-aspect-model-editor-backend + scm:git:git://github.com:eclipse-esmf/esmf-aspect-model-editor-backend.git + scm:git:ssh://git@github.com:eclipse-esmf/esmf-aspect-model-editor-backend.git + + + aspect-model-editor-core + aspect-model-editor-service + aspect-model-editor-validation + aspect-model-editor-web-core + aspect-model-editor-web + aspect-model-editor-resolver + aspect-model-editor-repository + aspect-model-editor-migrator + aspect-model-editor-runtime + + org.eclipse.esmf.ame.Application @@ -53,6 +77,7 @@ 1.1 22.3.0 2.0.5 + 3.0.2 6.0.0 0.9.19 1.3 @@ -102,215 +127,264 @@ - - - - org.eclipse.esmf - esmf-aspect-model-urn - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-meta-model-interface - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-meta-model-version-migrator - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-meta-model-resolver - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-resolver - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-meta-model-types - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-meta-model-java - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-aas-generator - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-document-generators - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-validator - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-java-generator - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-starter - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-static-meta-model-java - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-java-core - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-serializer - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-aspect-model-jackson - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-test-aspect-models - ${esmf-sdk-version} - - - org.eclipse.esmf - esmf-test-resources - ${esmf-sdk-version} - - - org.graalvm.nativeimage - svm - ${graal-svm-version} - provided - + + + + + org.eclipse.esmf + aspect-model-editor-core + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-service + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-validation + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-web-core + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-web + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-resolver + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-repository + ${project.version} + + + org.eclipse.esmf + aspect-model-editor-migrator + ${project.version} + + + + + org.eclipse.esmf + esmf-aspect-model-urn + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-meta-model-interface + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-meta-model-version-migrator + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-meta-model-resolver + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-resolver + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-meta-model-types + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-meta-model-java + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-aas-generator + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-document-generators + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-validator + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-java-generator + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-starter + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-static-meta-model-java + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-java-core + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-serializer + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-aspect-model-jackson + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-test-aspect-models + ${esmf-sdk-version} + + + org.eclipse.esmf + esmf-test-resources + ${esmf-sdk-version} + + + org.graalvm.nativeimage + svm + ${graal-svm-version} + provided + - - - org.springframework.boot - spring-boot-properties-migrator - ${spring-boot-version} - runtime - - - org.springframework.boot - spring-boot-starter-web - ${spring-boot-version} - - - org.springframework.boot - spring-boot-starter-security - ${spring-boot-version} - - - org.projectlombok - lombok - ${lombok-version} - provided - - - org.slf4j - slf4j-api - ${slf4j-api-version} - - - commons-io - commons-io - ${commons-io-version} - - - jakarta.servlet - jakarta.servlet-api - ${jakarta-version} - provided - - - org.graalvm.buildtools - native-maven-plugin - ${native-maven-plugin-version} - - - org.apache.commons - commons-exec - ${commons-exec-version} - - - com.github.marschall - memoryfilesystem - ${memoryfilesystem-version} - - - commons-codec - commons-codec - ${commons-code-version} - + + + org.springframework.boot + spring-boot-properties-migrator + ${spring-boot-version} + runtime + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-security + ${spring-boot-version} + + + org.projectlombok + lombok + ${lombok-version} + provided + + + org.slf4j + slf4j-api + ${slf4j-api-version} + + + commons-io + commons-io + ${commons-io-version} + + + jakarta.validation + jakarta.validation-api + ${jakarta-validation-api-version} + + + jakarta.servlet + jakarta.servlet-api + ${jakarta-version} + provided + + + org.graalvm.buildtools + native-maven-plugin + ${native-maven-plugin-version} + + + org.apache.commons + commons-exec + ${commons-exec-version} + + + com.github.marschall + memoryfilesystem + ${memoryfilesystem-version} + + + commons-codec + commons-codec + ${commons-code-version} + - - - org.springframework.boot - spring-boot-starter-test - ${spring-boot-version} - test - - - org.springframework.boot - spring-boot-test - ${spring-boot-version} - test - - - org.sonatype.plugins - port-allocator-maven-plugin - ${port-allocator-version} - - - classworlds - classworlds - - - test - - - com.bazaarvoice.maven.plugins - process-exec-maven-plugin - ${process-exec-version} - test - - - org.mockito - mockito-inline - ${mockito-inline-version} - test - - - cglib - cglib - ${cglib-version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit-version} - test - - + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot-version} + test + + + org.springframework.boot + spring-boot-test + ${spring-boot-version} + test + + + org.sonatype.plugins + port-allocator-maven-plugin + ${port-allocator-version} + + + classworlds + classworlds + + + test + + + com.bazaarvoice.maven.plugins + process-exec-maven-plugin + ${process-exec-version} + test + + + org.mockito + mockito-inline + ${mockito-inline-version} + test + + + cglib + cglib + ${cglib-version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit-version} + test + + + diff --git a/src/main/java/org/eclipse/esmf/ame/model/packaging/ProcessPackage.java b/src/main/java/org/eclipse/esmf/ame/model/packaging/ProcessPackage.java deleted file mode 100644 index 27c9c39d..00000000 --- a/src/main/java/org/eclipse/esmf/ame/model/packaging/ProcessPackage.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.model.packaging; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.Data; - -@Data -public class ProcessPackage { - @JsonProperty( "validFiles" ) - private final List validFiles = new ArrayList<>(); - - @JsonProperty( "missingElements" ) - private final List missingElements = new ArrayList<>(); - - public ProcessPackage() { - } - - public ProcessPackage( ValidFile validFile, List missingFiles ) { - validFiles.add( validFile ); - missingElements.addAll( missingFiles ); - } - - public void addValidFile( final ValidFile validFile ) { - validFiles.add( validFile ); - } - - public void addMissingElement( final MissingElement missingElement ) { - missingElements.add( missingElement ); - } - - public ProcessPackage merge( ProcessPackage other ) { - // Create a new instance of ProcessPackage - ProcessPackage mergedPackage = new ProcessPackage(); - - // Merge the valid files - mergedPackage.getValidFiles().addAll( this.getValidFiles() ); - mergedPackage.getValidFiles().addAll( other.getValidFiles() ); - - // Merge the missing elements - mergedPackage.getMissingElements().addAll( this.getMissingElements() ); - mergedPackage.getMissingElements().addAll( other.getMissingElements() ); - - return mergedPackage; - } -} diff --git a/src/main/java/org/eclipse/esmf/ame/services/utils/ModelUtils.java b/src/main/java/org/eclipse/esmf/ame/services/utils/ModelUtils.java deleted file mode 100644 index 8c52f492..00000000 --- a/src/main/java/org/eclipse/esmf/ame/services/utils/ModelUtils.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.services.utils; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; - -import org.apache.commons.lang3.StringUtils; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.riot.RiotException; -import org.eclipse.esmf.ame.config.ApplicationSettings; -import org.eclipse.esmf.ame.exceptions.FileReadException; -import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; -import org.eclipse.esmf.ame.model.validation.ViolationReport; -import org.eclipse.esmf.ame.resolver.strategy.FileSystemStrategy; -import org.eclipse.esmf.ame.resolver.strategy.InMemoryStrategy; -import org.eclipse.esmf.ame.validation.ViolationFormatter; -import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; -import org.eclipse.esmf.aspectmodel.resolver.services.SammAspectMetaModelResourceResolver; -import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; -import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; -import org.eclipse.esmf.aspectmodel.serializer.PrettyPrinter; -import org.eclipse.esmf.aspectmodel.shacl.violation.InvalidSyntaxViolation; -import org.eclipse.esmf.aspectmodel.shacl.violation.ProcessingViolation; -import org.eclipse.esmf.aspectmodel.shacl.violation.Violation; -import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; -import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; -import org.eclipse.esmf.aspectmodel.versionupdate.MigratorService; -import org.eclipse.esmf.metamodel.Aspect; -import org.eclipse.esmf.metamodel.AspectContext; -import org.eclipse.esmf.metamodel.loader.AspectModelLoader; - -import io.vavr.control.Try; - -public class ModelUtils { - - private ModelUtils() { - } - - public static final String TTL = "ttl"; - public static final String TTL_EXTENSION = "." + TTL; - - /** - * This Method is used to create a pretty printed string of the versioned model - * - * @param versionedModel The Versioned Model - * @param urn The urn of the Aspect - * @return Pretty printed string of the Versioned Aspect Model. - */ - public static String getPrettyPrintedVersionedModel( final VersionedModel versionedModel, final URI urn ) { - final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - final PrintWriter writer = new PrintWriter( buffer ); - new PrettyPrinter( versionedModel, AspectModelUrn.fromUrn( urn ), writer ).print(); - writer.flush(); - return buffer.toString(); - } - - public static String getPrettyPrintedModel( final String aspectModel ) { - final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); - final VersionedModel versionedModel = ModelUtils.loadModelFromStoragePath( fileSystemStrategy ); - - return getPrettyPrintedVersionedModel( versionedModel, fileSystemStrategy.getAspectModelUrn().getUrn() ); - } - - /** - * Method to resolve a given AspectModelUrn using a suitable ResolutionStrategy. - * - * @param fileSystemStrategy strategy of the backend. - * @return The resolved model on success. - */ - public static Try fetchVersionModel( final FileSystemStrategy fileSystemStrategy ) { - return new AspectModelResolver().resolveAspectModel( fileSystemStrategy, fileSystemStrategy.getAspectModelUrn() ); - } - - public static Try fetchVersionModel( final InMemoryStrategy inMemoryStrategy ) { - return new AspectModelResolver().resolveAspectModel( inMemoryStrategy, inMemoryStrategy.getAspectModelUrn() ); - } - - /** - * Migrates a model to its latest version. - * - * @param aspectModel as a string. - * @return migrated Aspect Model as a string. - */ - public static String migrateModel( final String aspectModel ) throws InvalidAspectModelException { - final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); - - final Try migratedFile = new MigratorService().updateMetaModelVersion( - loadModelFromStoragePath( fileSystemStrategy ) ); - - final VersionedModel versionedModel = migratedFile.getOrElseThrow( - error -> new InvalidAspectModelException( "Aspect Model cannot be migrated.", error ) ); - - return getPrettyPrintedVersionedModel( versionedModel, fileSystemStrategy.getAspectModelUrn().getUrn() ); - } - - /** - * Creates an Aspect instance from an Aspect Model. - * - * @param aspectModel as a string. - * @return the Aspect as an object. - */ - public static Aspect resolveAspectFromModel( final String aspectModel ) throws InvalidAspectModelException { - final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); - final Try versionedModels = ModelUtils.fetchVersionModel( fileSystemStrategy ); - - final Try context = versionedModels.flatMap( - model -> getSingleAspect( fileSystemStrategy, model ) ); - - return getAspectContext( context ).aspect(); - } - - /** - * Retrieves a single AspectContext based on the given FileSystemStrategy and VersionedModel. - * - * @param fileSystemStrategy The file system strategy to retrieve the AspectModel URN. - * @param model The versioned model to search for the aspect. - * @return A Try containing the AspectContext if found, otherwise a failure. - */ - public static Try getSingleAspect( final FileSystemStrategy fileSystemStrategy, - final VersionedModel model ) { - return AspectModelLoader.getSingleAspect( model, - aspect -> aspect.getName().equals( fileSystemStrategy.getAspectModelUrn().getName() ) ) - .map( aspect -> new AspectContext( model, aspect ) ); - } - - /** - * Retrieves the AspectContext from the provided Try, handling exceptions if necessary. - * - * @param context The Try representing the context to retrieve the AspectContext from. - * @return The retrieved AspectContext. - * - * @throws FileReadException If there are failures in the generation process due to violations in the model. - */ - public static AspectContext getAspectContext( Try context ) { - return context.recover( throwable -> { - // Another exception, e.g. syntax error. Let the validator handle this - final List violations = new AspectModelValidator().validateModel( - context.map( AspectContext::rdfModel ) ); - - throw new FileReadException( - String.format( "The generation process encountered failures due to the following violations: %s", - new ViolationFormatter().apply( violations ) ) ); - } ).get(); - } - - /** - * Load Aspect Model from storage path. - * - * @param fileSystemStrategy for the given storage path. - * @return the resulting {@link VersionedModel} that corresponds to the input Aspect model. - */ - public static VersionedModel loadModelFromStoragePath( final FileSystemStrategy fileSystemStrategy ) { - return resolveModel( fileSystemStrategy.getCurrentAspectModel() ).getOrElseThrow( - e -> new InvalidAspectModelException( "Cannot resolve Aspect Model.", e ) ); - } - - /** - * Loading the Aspect Model from input file. - * - * @param file Aspect Model as a file. - * @return the resulting {@link VersionedModel} that corresponds to the input Aspect model. - */ - public static Try loadModelFromFile( final File file ) { - try ( final InputStream inputStream = new FileInputStream( file ) ) { - return TurtleLoader.loadTurtle( inputStream ).flatMap( ModelUtils::resolveModel ); - } catch ( final IOException exception ) { - return Try.failure( exception ); - } - } - - private static Try resolveModel( final Model model ) { - final SammAspectMetaModelResourceResolver resourceResolver = new SammAspectMetaModelResourceResolver(); - - return resourceResolver.getMetaModelVersion( model ).flatMap( - metaModelVersion -> resourceResolver.mergeMetaModelIntoRawModel( model, metaModelVersion ) ); - } - - /** - * Validates an Aspect Model that is provided as a Try of a VersionedModel that can contain either a syntactically - * valid (but semantically invalid) Aspect model, or a RiotException if a parser error occured. - * - * @param aspectModel as a string. - * @param aspectModelValidator Aspect Model Validator from esmf-sdk - * @return Either a ValidationReport.ValidReport if the model is syntactically correct and conforms to the Aspect - * Meta Model semantics or a ValidationReport.InvalidReport that provides a number of ValidationErrors that - * describe all validation violations. - */ - public static ViolationReport validateModel( final String aspectModel, - final AspectModelValidator aspectModelValidator ) { - final ViolationReport violationReport = new ViolationReport(); - - try { - final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); - final Try versionedModel = ModelUtils.fetchVersionModel( fileSystemStrategy ); - final List violations = aspectModelValidator.validateModel( versionedModel ); - - violationReport.setViolationErrors( new ViolationFormatter().apply( violations ) ); - - return violationReport; - } catch ( final RiotException riotException ) { - violationReport.addViolation( - new ViolationFormatter().visitInvalidSyntaxViolation( riotException.getMessage() ) ); - - return violationReport; - } - } - - public static ViolationReport validateModelInMemoryFiles( final AspectModelInformation aspectModelInformation, - final AspectModelValidator aspectModelValidator, final java.nio.file.FileSystem fileSystem ) { - final Path root = fileSystem.getRootDirectories().iterator().next(); - final ViolationReport violationReport = new ViolationReport(); - - try { - final InMemoryStrategy inMemoryStrategy = new InMemoryStrategy( aspectModelInformation, root, fileSystem ); - final Try versionedModel = ModelUtils.fetchVersionModel( inMemoryStrategy ); - final List violations = aspectModelValidator.validateModel( versionedModel ); - - violationReport.setViolationErrors( new ViolationFormatter().apply( violations ) ); - - return violationReport; - } catch ( final RiotException riotException ) { - violationReport.addViolation( - new ViolationFormatter().visitInvalidSyntaxViolation( riotException.getMessage() ) ); - - return violationReport; - } - } - - public static Predicate isInvalidSyntaxViolation() { - return violation -> violation.errorCode() != null && violation.errorCode() - .equals( InvalidSyntaxViolation.ERROR_CODE ); - } - - public static Predicate isProcessingViolation() { - return violation -> violation.errorCode() != null && violation.errorCode() - .equals( ProcessingViolation.ERROR_CODE ); - } - - /** - * Returns the {@link Model} that corresponds to the given model URN - * - * @param aspectModelUrn The model URN - * @return The file that defines the supplied aspectModelUrn. - */ - public static String getAspectModelFile( final String modelsRootPath, final AspectModelUrn aspectModelUrn ) { - if ( aspectModelUrn == null ) { - return StringUtils.EMPTY; - } - - final Path directory = Path.of( modelsRootPath ).resolve( aspectModelUrn.getNamespace() ) - .resolve( aspectModelUrn.getVersion() ); - - final String fileInformation = Arrays.stream( - Optional.ofNullable( directory.toFile().listFiles() ).orElse( new File[] {} ) ).filter( File::isFile ) - .filter( file -> file.getName().endsWith( ".ttl" ) ).map( File::toURI ) - .sorted().filter( - uri -> AspectModelResolver.containsDefinition( loadFromUri( uri ).get(), aspectModelUrn ) ) - .map( URI::getPath ).findFirst().orElse( "NO CORRESPONDING FILE FOUND" ); - - final File filePath = new File( fileInformation ); - - if ( !filePath.exists() ) { - return fileInformation; - } - - return filePath.getPath().replace( ApplicationSettings.getMetaModelStoragePath() + File.separator, "" ); - } - - /** - * Loads an Aspect model from a resolvable URI - * - * @param uri The URI - * @return The model - */ - private static Try loadFromUri( final URI uri ) { - try { - return loadFromUrl( uri.toURL() ); - } catch ( final MalformedURLException exception ) { - return Try.failure( exception ); - } - } - - /** - * Loads an Aspect model from a resolvable URL - * - * @param url The URL - * @return The model - */ - private static Try loadFromUrl( final URL url ) { - return Try.ofSupplier( () -> TurtleLoader.openUrl( url ) ).flatMap( TurtleLoader::loadTurtle ); - } -} diff --git a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java b/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java index b4d816c2..74617411 100644 --- a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java +++ b/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java @@ -21,7 +21,7 @@ import java.nio.file.Path; import org.apache.jena.rdf.model.Model; -import org.eclipse.esmf.ame.model.ProcessPath; +import org.eclipse.esmf.ame.model.StoragePaths; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,8 +44,8 @@ class FileSystemStrategyTest { @BeforeEach void setUp() { - ProcessPath processPath = Mockito.mock( ProcessPath.class ); - Mockito.when( processPath.getPath() ).thenReturn( resourcesPath ); + StoragePaths StoragePaths = Mockito.mock( StoragePaths.class ); + Mockito.when( StoragePaths.getPath() ).thenReturn( resourcesPath ); } @Test From 54881bcba93c5a04b3dc5caedb2234d0ea84d046 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 16:49:31 +0100 Subject: [PATCH 02/21] Update GenerateServiceTest.java --- .../org/eclipse/esmf/ame/services/GenerateServiceTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java index ab5be93f..f243214b 100644 --- a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java @@ -21,17 +21,22 @@ import java.nio.file.Path; import java.util.Optional; +import org.eclipse.esmf.ame.config.TestConfig; import org.eclipse.esmf.aspectmodel.generator.openapi.PagingOption; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith( SpringExtension.class ) @SpringBootTest( classes = GenerateService.class ) @DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) +@Import( TestConfig.class ) +@ActiveProfiles( "test" ) class GenerateServiceTest { @Autowired From 679a247a969f27cc819c434538190e543f0b8495 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 17:08:31 +0100 Subject: [PATCH 03/21] Adjust tests --- .../org/eclipse/esmf/ame/config/ApplicationSettings.java | 2 +- aspect-model-editor-service/pom.xml | 5 +++++ .../test/java/org/eclipse/esmf/ame/config/TestConfig.java | 8 ++++++++ .../org/eclipse/esmf/ame/services/ModelServiceTest.java | 6 ++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java index 5b2a6740..8d0197c9 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/config/ApplicationSettings.java @@ -34,7 +34,7 @@ public class ApplicationSettings { private static final String MIGRATION_PATH = ASPECT_MODEL_PATH + File.separator + MIGRATION_END_PATH; - private String fileType; + private String fileType = ".ttl"; public static Path getAspectModelEditorStoragePath() { return Path.of( ASPECT_MODEL_PATH ); diff --git a/aspect-model-editor-service/pom.xml b/aspect-model-editor-service/pom.xml index 86dd7cd5..ff0e8a07 100644 --- a/aspect-model-editor-service/pom.xml +++ b/aspect-model-editor-service/pom.xml @@ -79,5 +79,10 @@ memoryfilesystem test + + org.mockito + mockito-inline + test + diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java index 8a630f7c..5c9c8e8f 100644 --- a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java @@ -19,6 +19,8 @@ import org.eclipse.esmf.ame.repository.ModelResolverRepository; import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; +import org.eclipse.esmf.aspectmodel.shacl.constraint.JsConstraint; +import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; @@ -44,4 +46,10 @@ public ModelResolverRepository modelResolverRepository() { fileSystem, rootPath ); return new ModelResolverRepository( List.of( localFolderResolverStrategy ) ); } + + @Bean + public AspectModelValidator getAspectModelValidator() { + JsConstraint.setEvaluateJavaScript( false ); + return new AspectModelValidator(); + } } diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java index 24a5cfe6..d9c398d1 100644 --- a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java @@ -25,6 +25,7 @@ import java.util.Optional; import org.apache.commons.io.FileUtils; +import org.eclipse.esmf.ame.config.TestConfig; import org.eclipse.esmf.ame.exceptions.FileNotFoundException; import org.eclipse.esmf.ame.model.NamespaceFileCollection; import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; @@ -35,16 +36,17 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith( SpringExtension.class ) -@SpringBootTest +@SpringBootTest( classes = ModelService.class ) @DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) +@Import( TestConfig.class ) @ActiveProfiles( "test" ) class ModelServiceTest { - @Autowired private ModelService modelService; From 7f6cb5f3b4b592d3fcb80c310e56690e6a927af5 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 17:12:27 +0100 Subject: [PATCH 04/21] Update package service test --- .../org/eclipse/esmf/ame/config/TestConfig.java | 17 ++++++++++++----- .../esmf/ame/services/PackageServiceTest.java | 6 ++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java index 5c9c8e8f..913803b8 100644 --- a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/config/TestConfig.java @@ -36,14 +36,10 @@ public class TestConfig { @Autowired private ApplicationSettings applicationSettings; - @SneakyThrows @Bean public ModelResolverRepository modelResolverRepository() { - FileSystem fileSystem = MemoryFileSystemBuilder.newEmpty().build(); - String rootPath = Path.of( "src", "test", "resources", "services" ).toAbsolutePath().toString(); - LocalFolderResolverStrategy localFolderResolverStrategy = new LocalFolderResolverStrategy( applicationSettings, - fileSystem, rootPath ); + importFileSystem(), modelPath() ); return new ModelResolverRepository( List.of( localFolderResolverStrategy ) ); } @@ -52,4 +48,15 @@ public AspectModelValidator getAspectModelValidator() { JsConstraint.setEvaluateJavaScript( false ); return new AspectModelValidator(); } + + @SneakyThrows + @Bean + public FileSystem importFileSystem() { + return MemoryFileSystemBuilder.newEmpty().build(); + } + + @Bean + public String modelPath() { + return Path.of( "src", "test", "resources", "services" ).toAbsolutePath().toString(); + } } diff --git a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java index 354f907c..c20bd1af 100644 --- a/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java +++ b/aspect-model-editor-service/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java @@ -23,21 +23,23 @@ import java.util.List; import java.util.Objects; +import org.eclipse.esmf.ame.config.TestConfig; import org.eclipse.esmf.ame.services.model.FileValidationReport; import org.eclipse.esmf.ame.services.model.NamespaceFileCollection; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith( SpringExtension.class ) -@SpringBootTest +@SpringBootTest( classes = PackageService.class ) +@Import( TestConfig.class ) @ActiveProfiles( "test" ) class PackageServiceTest { - @Autowired private PackageService packageService; From 97c8766f6d36616d98362aa9629e47be961a17d7 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 17:31:19 +0100 Subject: [PATCH 05/21] Update tests for repository --- aspect-model-editor-repository/pom.xml | 25 +++ .../ModelResolverRepositoryTest.java | 53 +++++ .../ame/repository/config/TestConfig.java | 51 +++++ .../LocalFolderResolverStrategyTest.java | 111 +++++++++++ .../ame/services/FileHandlingServiceTest.java | 48 ----- .../ame/services/GenerateServiceTest.java | 113 ----------- .../esmf/ame/services/ModelServiceTest.java | 184 ------------------ .../esmf/ame/services/PackageServiceTest.java | 96 --------- 8 files changed, 240 insertions(+), 441 deletions(-) create mode 100644 aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java create mode 100644 aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/config/TestConfig.java create mode 100644 aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java delete mode 100644 src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java delete mode 100644 src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java delete mode 100644 src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java delete mode 100644 src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java diff --git a/aspect-model-editor-repository/pom.xml b/aspect-model-editor-repository/pom.xml index d18fef50..324fc05f 100644 --- a/aspect-model-editor-repository/pom.xml +++ b/aspect-model-editor-repository/pom.xml @@ -39,5 +39,30 @@ org.projectlombok lombok + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-test + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.github.marschall + memoryfilesystem + test + + + org.mockito + mockito-inline + test + diff --git a/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java new file mode 100644 index 00000000..bd9d1aa6 --- /dev/null +++ b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.repository; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Collections; + +import org.eclipse.esmf.ame.repository.config.TestConfig; +import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; +import org.eclipse.esmf.ame.repository.strategy.ModelResolverStrategy; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest( classes = ModelResolverRepository.class ) +@Import( TestConfig.class ) +@ActiveProfiles( "test" ) +class ModelResolverRepositoryTest { + + @Autowired + private ModelResolverRepository repository; + + @Test + void testGetStrategy() { + final ModelResolverStrategy result = repository.getStrategy( LocalFolderResolverStrategy.class ); + + assertInstanceOf( LocalFolderResolverStrategy.class, result ); + } + + @Test() + void testGetStrategyHasEmptyStrategyList() { + repository = new ModelResolverRepository( Collections.emptyList() ); + + assertThrows( RuntimeException.class, () -> repository.getStrategy( LocalFolderResolverStrategy.class ) ); + } +} diff --git a/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/config/TestConfig.java b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/config/TestConfig.java new file mode 100644 index 00000000..a9f63d1c --- /dev/null +++ b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/config/TestConfig.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.repository.config; + +import java.nio.file.FileSystem; +import java.nio.file.Path; + +import org.eclipse.esmf.ame.config.ApplicationSettings; +import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; + +import lombok.SneakyThrows; + +@TestConfiguration +@Import( ApplicationSettings.class ) +public class TestConfig { + @Autowired + private ApplicationSettings applicationSettings; + + @Bean + public LocalFolderResolverStrategy localFolderResolverStrategy() { + return new LocalFolderResolverStrategy( applicationSettings, importFileSystem(), modelPath() ); + } + + @SneakyThrows + @Bean + public FileSystem importFileSystem() { + return MemoryFileSystemBuilder.newEmpty().build(); + } + + @Bean + public String modelPath() { + return Path.of( "src", "test", "resources", "strategy" ).toAbsolutePath().toString(); + } +} diff --git a/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java new file mode 100644 index 00000000..045368be --- /dev/null +++ b/aspect-model-editor-repository/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for + * additional information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.repository.strategy; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; + +import org.eclipse.esmf.ame.exceptions.FileNotFoundException; +import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException; +import org.eclipse.esmf.ame.repository.config.TestConfig; +import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import io.vavr.Tuple2; + +@ExtendWith( SpringExtension.class ) +@SpringBootTest( classes = LocalFolderResolverStrategy.class ) +@Import( TestConfig.class ) +@TestPropertySource( properties = { "spring.main.allow-bean-definition-overriding=true" } ) +@ActiveProfiles( "test" ) +class LocalFolderResolverStrategyTest { + @Autowired + private LocalFolderResolverStrategy localFolderResolverStrategy; + + private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "strategy" ); + + private static final String NAMESPACE_VERSION = "org.eclipse.esmf.example:1.0.0"; + + private static final String MODEL = "AspectModelForStrategy.ttl"; + private static final String MODEL_WITH_EXT_REF = "AspectModelForStrategyWithExtRef.ttl"; + private static final String MODEL_NOT_EXIST = "AspectModelNotExist.ttl"; + + private static final String ASPECT_MODEL_URN_WITH_EXT_REF_AS_STRING = + "urn:samm:" + NAMESPACE_VERSION + "#" + MODEL_WITH_EXT_REF.replace( ".ttl", "" ); + + private static final String TTL_FILE_CONTENT = "new result ttl file"; + private static final String TTL_FILE_WITH_EXT_REF = + NAMESPACE_VERSION.replace( ":", File.separator ) + File.separator + MODEL_WITH_EXT_REF; + + @Test + void testCheckModelExists() { + assertTrue( localFolderResolverStrategy.checkModelExist( NAMESPACE_VERSION, MODEL ) ); + } + + @Test + void testCheckModelNotExists() { + assertFalse( localFolderResolverStrategy.checkModelExist( NAMESPACE_VERSION, MODEL_NOT_EXIST ) ); + } + + @Test + void testGetModelFileNotFound() { + assertThrows( FileNotFoundException.class, + () -> localFolderResolverStrategy.getModelAsString( NAMESPACE_VERSION, MODEL_NOT_EXIST ) ); + } + + @Test + void testGetModel() { + final String result = localFolderResolverStrategy.getModelAsString( NAMESPACE_VERSION, MODEL ); + + assertTrue( result.contains( "" ) ); + } + + @Test + void testGetFilePathBasedOnTurtleData() throws IOException { + final Path extRefAspectModel = Path.of( RESOURCE_PATH.toAbsolutePath().toString(), TTL_FILE_WITH_EXT_REF ); + final AspectModelUrn aspectModelUrn = localFolderResolverStrategy.getAspectModelUrn( + Files.readString( extRefAspectModel ) ); + + assertEquals( ASPECT_MODEL_URN_WITH_EXT_REF_AS_STRING, aspectModelUrn.toString() ); + } + + @Test() + void testSaveModelCanNotWriteToFile() { + assertThrows( InvalidAspectModelException.class, + () -> localFolderResolverStrategy.saveModel( Optional.empty(), Optional.empty(), TTL_FILE_CONTENT ) ); + } + + @Test + void convertFileToTuple() { + final Path eclipseTestPath = RESOURCE_PATH.resolve( NAMESPACE_VERSION.replace( ":", File.separator ) ); + final File testFile = new File( eclipseTestPath + File.separator + MODEL ); + + final Tuple2 fileInfo = localFolderResolverStrategy.convertFileToTuple( testFile ); + + assertEquals( MODEL.replace( ".ttl", "" ), fileInfo._1 ); + assertEquals( NAMESPACE_VERSION, fileInfo._2 ); + } +} diff --git a/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java b/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java deleted file mode 100644 index fea2cb56..00000000 --- a/src/test/java/org/eclipse/esmf/ame/services/FileHandlingServiceTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.services; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) -@ActiveProfiles( "test" ) -class FileHandlingServiceTest { - - @Autowired - private FileHandlingService fileHandlingService; - - private static final String VERSION = "1.0.0"; - private static final String EXAMPLE_NAMESPACE = "org.eclipse.esmf.example"; - private static final String NAMESPACE_VERSION = EXAMPLE_NAMESPACE + ":" + VERSION; - private static final String TEST_MODEL = "AspectModelForService.ttl"; - - @Test - void testLockAndUnlockFile() { - String lockResult = fileHandlingService.lockFile( NAMESPACE_VERSION, TEST_MODEL ); - assertEquals( lockResult, "File is locked" ); - - String unlockResult = fileHandlingService.unlockFile( NAMESPACE_VERSION, TEST_MODEL ); - assertEquals( unlockResult, "File is unlocked" ); - } -} diff --git a/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java b/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java deleted file mode 100644 index 5569a71b..00000000 --- a/src/test/java/org/eclipse/esmf/ame/services/GenerateServiceTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.services; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; - -import org.eclipse.esmf.aspectmodel.generator.openapi.PagingOption; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) -class GenerateServiceTest { - - @Autowired - private GenerateService generateService; - - private static final Path resourcesPath = Path.of( "src", "test", "resources", "services" ); - private static final Path eclipseTestPath = Path.of( resourcesPath.toString(), "org.eclipse.esmf.example", "1.0.0" ); - - private static final String model = "AspectModelForService.ttl"; - - @Test - void testAspectModelJsonSample() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.sampleJSONPayload( testModel ); - - assertEquals( "{\"property\":\"eOMtThyhVNLWUZNRcBaQKxI\"}", payload ); - } - - @Test - void testAspectModelJsonSchema() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.jsonSchema( testModel, "en-EN" ); - - assertTrue( payload.contains( "#/components/schemas/urn_samm_org.eclipse.esmf.example_1.0.0_Characteristic" ) ); - } - - @Test - void testAspectModelJsonOpenApiSpec() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.generateJsonOpenApiSpec( "en", testModel, "https://test.com", false, false, - Optional.of( PagingOption.TIME_BASED_PAGING ) ); - - assertTrue( payload.contains( "\"openapi\" : \"3.0.3\"" ) ); - assertTrue( payload.contains( "\"version\" : \"v1\"" ) ); - assertTrue( payload.contains( "\"title\" : \"AspectModelForService\"" ) ); - assertTrue( payload.contains( "\"url\" : \"https://test.com/api/v1\"" ) ); - } - - @Test - void testAspectModelYamlOpenApiSpec() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.generateYamlOpenApiSpec( "en", testModel, "https://test.com", false, false, - Optional.of( PagingOption.TIME_BASED_PAGING ) ); - - assertTrue( payload.contains( "openapi: 3.0.3" ) ); - assertTrue( payload.contains( "title: AspectModel" ) ); - assertTrue( payload.contains( "version: v1" ) ); - assertTrue( payload.contains( "url: https://test.com/api/v1" ) ); - } - - @Test - void testAspectModelAASX() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.generateAASXFile( testModel ); - - assertTrue( payload.contains( "aasx" ) ); - } - - @Test - void testAspectModelAASXML() throws IOException { - final Path storagePath = Path.of( eclipseTestPath.toString(), model ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String payload = generateService.generateAasXmlFile( testModel ); - - assertTrue( payload.contains( "" ) ); - assertTrue( payload.contains( "https://admin-shell.io/aas/3/0" ) ); - } -} diff --git a/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java b/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java deleted file mode 100644 index 584db86e..00000000 --- a/src/test/java/org/eclipse/esmf/ame/services/ModelServiceTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.services; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; - -import org.apache.commons.io.FileUtils; -import org.eclipse.esmf.ame.exceptions.FileNotFoundException; -import org.eclipse.esmf.ame.model.migration.Namespaces; -import org.eclipse.esmf.ame.model.validation.ViolationReport; -import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) -@ActiveProfiles( "test" ) -class ModelServiceTest { - - @Autowired - private ModelService modelService; - - private static final String VERSION = "1.0.0"; - private static final String EXAMPLE_NAMESPACE = "org.eclipse.esmf.example"; - private static final String NAMESPACE_VERSION = EXAMPLE_NAMESPACE + ":" + VERSION; - - private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "services" ); - private static final Path TEST_NAMESPACE_PATH = Path.of( RESOURCE_PATH.toString(), EXAMPLE_NAMESPACE, VERSION ); - - private static final Path MIGRATION_WORKSPACE_PATH = Path.of( RESOURCE_PATH.toString(), "workspace-to-migrate" ); - private static final Path TO_MIGRATE_WORKSPACE_ONE = Path.of( MIGRATION_WORKSPACE_PATH.toString(), - "io.migrate-workspace-one", VERSION ); - - private static final Path MIGRATE_WORKSPACE_ONE = Path.of( RESOURCE_PATH.toString(), "io.migrate-workspace-one", - VERSION ); - private static final Path TO_MIGRATE_WORKSPACE_TWO = Path.of( MIGRATION_WORKSPACE_PATH.toString(), - "io.migrate-workspace-two", VERSION ); - - private static final Path MIGRATE_WORKSPACE_TWO = Path.of( RESOURCE_PATH.toString(), "io.migrate-workspace-two", - VERSION ); - - private static final String TEST_MODEL = "AspectModelForService.ttl"; - private static final String TEST_MODEL_TO_DELTE = "FileToDelete.ttl"; - private static final String TEST_MODEL_NOT_FOUND = "NOTFOUND.ttl"; - - @Test - void testGetModel() throws IOException { - final String result = modelService.getModel( NAMESPACE_VERSION, TEST_MODEL ); - - assertEquals( result, Files.readString( TEST_NAMESPACE_PATH.resolve( TEST_MODEL ) ) ); - } - - @Test() - void testGetModelThrowsIOException() { - assertThrows( FileNotFoundException.class, - () -> modelService.getModel( NAMESPACE_VERSION, TEST_MODEL_NOT_FOUND ) ); - } - - @Test - void testValidateNewModel() throws IOException { - final Path storagePath = Path.of( TEST_NAMESPACE_PATH.toString(), TEST_MODEL ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final ViolationReport validateReport = modelService.validateModel( testModel ); - - assertTrue( validateReport.getViolationErrors().isEmpty() ); - } - - @Test - void testSaveModel() throws IOException { - final Path fileToReplace = Path.of( TEST_NAMESPACE_PATH.toString(), TEST_MODEL ); - final String turtleData = Files.readString( fileToReplace, StandardCharsets.UTF_8 ); - - final String result = modelService.saveModel( Optional.of( NAMESPACE_VERSION ), Optional.of( TEST_MODEL ), - turtleData ); - assertEquals( result, Path.of( EXAMPLE_NAMESPACE, VERSION, TEST_MODEL ).toString() ); - } - - @Test() - void testDeleteModel() { - modelService.deleteModel( NAMESPACE_VERSION, TEST_MODEL_TO_DELTE ); - assertThrows( FileNotFoundException.class, - () -> modelService.getModel( NAMESPACE_VERSION, TEST_MODEL_TO_DELTE ) ); - } - - @Test - void testMigrateModel() throws IOException { - final Path storagePath = Path.of( TEST_NAMESPACE_PATH.toString(), "OldAspectModel.ttl" ); - final String testModel = Files.readString( storagePath, StandardCharsets.UTF_8 ); - - final String migratedModel = modelService.migrateModel( testModel ); - - checkMigratedModel( migratedModel ); - } - - @Test - void testMigrateWorkspaceWithoutVersionUpgrade() throws IOException { - try ( final MockedStatic strategyUtilities = Mockito.mockStatic( - LocalFolderResolverStrategy.class ); - final MockedStatic fileUtilities = Mockito.mockStatic( FileUtils.class ) ) { - final Path storagePath = MIGRATION_WORKSPACE_PATH.toAbsolutePath(); - final File OneToMigrateOne = new File( TO_MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateOne.ttl" ); - final File OneToMigrateTwo = new File( TO_MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateTwo.ttl" ); - final File TwoToMigrateOne = new File( TO_MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateOne.ttl" ); - final File TwoToMigrateTwo = new File( TO_MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateTwo.ttl" ); - - fileUtilities.when( () -> FileUtils.listFiles( any( File.class ), any(), anyBoolean() ) ) - .thenReturn( List.of( OneToMigrateOne, OneToMigrateTwo, TwoToMigrateOne, TwoToMigrateTwo ) ); - - strategyUtilities.when( () -> LocalFolderResolverStrategy.transformToValidModelDirectory( any() ) ) - .thenReturn( storagePath.toString() ); - - final Namespaces namespaces = modelService.migrateWorkspace(); - - assertEquals( 2, namespaces.namespaces.size() ); - assertEquals( "io.migrate-workspace-one:1.0.0", namespaces.namespaces.get( 0 ).versionedNamespace ); - assertEquals( 2, namespaces.namespaces.get( 0 ).files.size() ); - assertEquals( "ToMigrateOne.ttl", namespaces.namespaces.get( 0 ).files.get( 0 ).getName() ); - assertEquals( true, namespaces.namespaces.get( 0 ).files.get( 0 ).getSuccess() ); - assertEquals( "ToMigrateTwo.ttl", namespaces.namespaces.get( 0 ).files.get( 1 ).getName() ); - assertEquals( true, namespaces.namespaces.get( 0 ).files.get( 1 ).getSuccess() ); - - assertEquals( "io.migrate-workspace-two:1.0.0", namespaces.namespaces.get( 1 ).versionedNamespace ); - assertEquals( 2, namespaces.namespaces.get( 1 ).files.size() ); - assertEquals( "ToMigrateOne.ttl", namespaces.namespaces.get( 1 ).files.get( 0 ).getName() ); - assertEquals( true, namespaces.namespaces.get( 1 ).files.get( 0 ).getSuccess() ); - assertEquals( "ToMigrateTwo.ttl", namespaces.namespaces.get( 1 ).files.get( 1 ).getName() ); - assertEquals( true, namespaces.namespaces.get( 1 ).files.get( 1 ).getSuccess() ); - - final String migratedModelOne = Files.readString( - new File( MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateOne.ttl" ).toPath(), - StandardCharsets.UTF_8 ); - final String migratedModelTwo = Files.readString( - new File( MIGRATE_WORKSPACE_ONE + File.separator + "ToMigrateTwo.ttl" ).toPath(), - StandardCharsets.UTF_8 ); - final String migratedModelThree = Files.readString( - new File( MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateOne.ttl" ).toPath(), - StandardCharsets.UTF_8 ); - final String migratedModelFour = Files.readString( - new File( MIGRATE_WORKSPACE_TWO + File.separator + "ToMigrateTwo.ttl" ).toPath(), - StandardCharsets.UTF_8 ); - - checkMigratedModel( migratedModelOne ); - checkMigratedModel( migratedModelTwo ); - checkMigratedModel( migratedModelThree ); - checkMigratedModel( migratedModelFour ); - } - } - - private void checkMigratedModel( final String migratedModel ) { - assertTrue( migratedModel.contains( "@prefix samm: " ) ); - assertTrue( migratedModel.contains( "@prefix samm-c: " ) ); - assertTrue( migratedModel.contains( "@prefix samm-e: " ) ); - assertTrue( migratedModel.contains( "@prefix unit: " ) ); - } -} diff --git a/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java b/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java deleted file mode 100644 index 3f5bcf43..00000000 --- a/src/test/java/org/eclipse/esmf/ame/services/PackageServiceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.services; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -import org.eclipse.esmf.ame.model.packaging.AspectModelFiles; -import org.eclipse.esmf.ame.model.packaging.ProcessPackage; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -@ActiveProfiles( "test" ) -class PackageServiceTest { - - @Autowired - private PackageService packageService; - - private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "services" ); - private static final String VERSION = "1.0.0"; - private static final String NAMESPACE = "org.eclipse.esmf.export"; - private static final String NAMESPACE_VERSION = NAMESPACE + ":" + VERSION; - private static final String FILE_ONE = "TestFileOne.ttl"; - private static final String FILE_TWO = "TestFileTwo.ttl"; - private static final String FILE_THREE = "TestFileThree.ttl"; - - @Test - void testValidateImportAspectModelPackage() throws IOException { - final Path zipFilePath = Paths.get( RESOURCE_PATH.toString(), "TestArchive.zip" ); - final byte[] testPackage = Files.readAllBytes( zipFilePath ); - - final MockMultipartFile mockedZipFile = new MockMultipartFile( "TestArchive.zip", testPackage ); - - final ProcessPackage importPackage = packageService.validateImportAspectModelPackage( mockedZipFile ); - - assertEquals( importPackage.getValidFiles().size(), 2 ); - } - - @Test - void testExportValidateAspectModels() { - final List aspectModelFiles = List.of( - new AspectModelFiles( NAMESPACE_VERSION, List.of( FILE_ONE, FILE_TWO ) ) ); - - final ProcessPackage processedExportedPackage = packageService.validateAspectModelsForExport( aspectModelFiles ); - - assertEquals( 2, processedExportedPackage.getValidFiles().size() ); - assertEquals( 1, processedExportedPackage.getMissingElements().size() ); - - assertTrue( processedExportedPackage.getMissingElements().get( 0 ).getAnalysedFileName().contains( FILE_ONE ) ); - - assertTrue( processedExportedPackage.getMissingElements().get( 0 ).getMissingFileName().contains( FILE_THREE ) ); - } - - @Test - void testExportAspectModelPackage() { - final List aspectModelFiles = List.of( - new AspectModelFiles( NAMESPACE_VERSION, List.of( FILE_ONE, FILE_TWO, FILE_THREE ) ) ); - - packageService.validateAspectModelsForExport( aspectModelFiles ); - - assertTrue( packageService.exportAspectModelPackage( "TestExportArchive.zip" ).length > 0 ); - } - - @Test - void testBackupWorkspace() { - packageService.backupWorkspace( RESOURCE_PATH.toString() ); - - assertTrue( Arrays.stream( Objects.requireNonNull( RESOURCE_PATH.toFile().list() ) ) - .anyMatch( file -> file.contains( "backup-" ) ) ); - } -} From 0b064422460ea445ed4bec2a613e7b144b507baa Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 17:31:50 +0100 Subject: [PATCH 06/21] Move .ttl file to new testing folder --- .../org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl | 0 .../1.0.0/AspectModelForStrategyWithExtRef.ttl | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {aspect-model-editor-service => aspect-model-editor-repository}/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl (100%) rename {aspect-model-editor-service => aspect-model-editor-repository}/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl (100%) diff --git a/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl b/aspect-model-editor-repository/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl similarity index 100% rename from aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl rename to aspect-model-editor-repository/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl diff --git a/aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl b/aspect-model-editor-repository/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl similarity index 100% rename from aspect-model-editor-service/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl rename to aspect-model-editor-repository/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl From 278376bed06b26d2699f9138b201cfd1385f3b6c Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Mon, 11 Dec 2023 17:37:43 +0100 Subject: [PATCH 07/21] Remove old test structure and add last resolver one --- aspect-model-editor-resolver/pom.xml | 25 ++++ .../strategy/FileSystemStrategyTest.java | 12 +- .../strategy/InMemoryStrategyTest.java | 17 +-- .../1.0.0/AspectModelForResolver.ttl | 2 +- .../ModelResolverRepositoryTest.java | 48 ------- .../LocalFolderResolverStrategyTest.java | 118 ------------------ src/test/resources/services/TestArchive.zip | Bin 2888 -> 0 bytes .../1.0.0/AspectModelForService.ttl | 29 ----- .../AspectModelForStrategyWithExtRef.ttl | 30 ----- .../1.0.0/FileToDelete.ttl | 30 ----- .../1.0.0/OldAspectModel.ttl | 19 --- .../1.0.0/TestFileOne.ttl | 29 ----- .../1.0.0/TestFileThree.ttl | 29 ----- .../1.0.0/TestFileTwo.ttl | 29 ----- .../1.0.0/ToBackupOne.ttl | 29 ----- .../1.0.0/ToBackupTwo.ttl | 29 ----- .../1.0.0/ToBackupOne.ttl | 29 ----- .../1.0.0/ToBackupTwo.ttl | 29 ----- .../1.0.0/ToMigrateOne.ttl | 22 ---- .../1.0.0/ToMigrateTwo.ttl | 22 ---- .../1.0.0/ToMigrateOne.ttl | 22 ---- .../1.0.0/ToMigrateTwo.ttl | 22 ---- .../AspectModelForStrategyWithExtRef.ttl | 30 ----- 23 files changed, 41 insertions(+), 610 deletions(-) rename {src => aspect-model-editor-resolver/src}/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java (89%) rename {src => aspect-model-editor-resolver/src}/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java (84%) rename src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl => aspect-model-editor-resolver/src/test/resources/resolver/org.eclipse.esmf.example/1.0.0/AspectModelForResolver.ttl (96%) delete mode 100644 src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java delete mode 100644 src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java delete mode 100644 src/test/resources/services/TestArchive.zip delete mode 100644 src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl delete mode 100644 src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl delete mode 100644 src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl delete mode 100644 src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl delete mode 100644 src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl delete mode 100644 src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl delete mode 100644 src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl delete mode 100644 src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl delete mode 100644 src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl delete mode 100644 src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl delete mode 100644 src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl diff --git a/aspect-model-editor-resolver/pom.xml b/aspect-model-editor-resolver/pom.xml index 62d15f71..10b7cf49 100644 --- a/aspect-model-editor-resolver/pom.xml +++ b/aspect-model-editor-resolver/pom.xml @@ -28,5 +28,30 @@ lombok ${lombok-version} + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-test + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.github.marschall + memoryfilesystem + test + + + org.mockito + mockito-inline + test + diff --git a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java b/aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java similarity index 89% rename from src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java rename to aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java index 74617411..005db1d3 100644 --- a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java +++ b/aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/FileSystemStrategyTest.java @@ -21,7 +21,7 @@ import java.nio.file.Path; import org.apache.jena.rdf.model.Model; -import org.eclipse.esmf.ame.model.StoragePaths; +import org.eclipse.esmf.ame.model.StoragePath; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,17 +34,17 @@ @ExtendWith( SpringExtension.class ) class FileSystemStrategyTest { - private static final Path resourcesPath = Path.of( "src", "test", "resources", "strategy" ); + private static final Path resourcesPath = Path.of( "src", "test", "resources", "resolver" ); private static final Path eclipseTestPath = Path.of( resourcesPath.toString(), "org.eclipse.esmf.example", "1.0.0" ); - private static final String aspectModelFile = "AspectModelForStrategy.ttl"; - private static final String aspectModelurn = "urn:samm:org.eclipse.esmf.example:1.0.0#AspectModelForStrategy"; + private static final String aspectModelFile = "AspectModelForResolver.ttl"; + private static final String aspectModelurn = "urn:samm:org.eclipse.esmf.example:1.0.0#AspectModelForResolver"; private static final String causeMessage = "AspectModelUrn is not set"; @BeforeEach void setUp() { - StoragePaths StoragePaths = Mockito.mock( StoragePaths.class ); + StoragePath StoragePaths = Mockito.mock( StoragePath.class ); Mockito.when( StoragePaths.getPath() ).thenReturn( resourcesPath ); } @@ -68,7 +68,7 @@ void testApplyFailureNullAndFailureAspectModelUrn() throws IOException { final Try result = fileSystemStrategy.apply( null ); assertTrue( result.isFailure() ); - assertTrue( result.getCause() instanceof NotImplementedError ); + assertInstanceOf( NotImplementedError.class, result.getCause() ); assertEquals( causeMessage, result.getCause().getMessage() ); } } diff --git a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java b/aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java similarity index 84% rename from src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java rename to aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java index dd0065d8..eb6c871a 100644 --- a/src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java +++ b/aspect-model-editor-resolver/src/test/java/org/eclipse/esmf/ame/resolver/strategy/InMemoryStrategyTest.java @@ -22,11 +22,12 @@ import java.nio.file.Path; import org.apache.jena.rdf.model.Model; -import org.eclipse.esmf.ame.model.repository.AspectModelInformation; +import org.eclipse.esmf.ame.resolver.strategy.model.NamespaceFileContent; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; @@ -35,14 +36,14 @@ import io.vavr.control.Try; @ExtendWith( SpringExtension.class ) +@ActiveProfiles( "test" ) class InMemoryStrategyTest { - - private static final Path resourcesPath = Path.of( "src", "test", "resources", "strategy" ); + private static final Path resourcesPath = Path.of( "src", "test", "resources", "resolver" ); private static final String version = "1.0.0"; private static final String versionedNamespace = "org.eclipse.esmf.example" + ":" + version; private static final Path eclipseTestPath = Path.of( resourcesPath.toString(), "org.eclipse.esmf.example", version ); - private static final String aspectModelFile = "AspectModelForStrategy.ttl"; - private static final String aspectModelurn = "urn:samm:org.eclipse.esmf.example:1.0.0#AspectModelForStrategy"; + private static final String aspectModelFile = "AspectModelForResolver.ttl"; + private static final String aspectModelurn = "urn:samm:org.eclipse.esmf.example:1.0.0#AspectModelForResolver"; private static final String causeMessage = "AspectModelUrn is not set"; private static Path rootPath; @@ -57,7 +58,7 @@ void setUp() throws IOException { @Test void testApplySuccess() throws IOException { final String fileToTest = Files.readString( eclipseTestPath.resolve( aspectModelFile ), StandardCharsets.UTF_8 ); - AspectModelInformation aspectModelInformation = new AspectModelInformation( versionedNamespace, aspectModelFile, + NamespaceFileContent aspectModelInformation = new NamespaceFileContent( versionedNamespace, aspectModelFile, fileToTest ); final InMemoryStrategy inMemoryStrategy = new InMemoryStrategy( aspectModelInformation, rootPath, fileSystem ); @@ -69,14 +70,14 @@ void testApplySuccess() throws IOException { @Test void testApplyFailureNullAndFailureAspectModelUrn() throws IOException { final String fileToTest = Files.readString( eclipseTestPath.resolve( aspectModelFile ), StandardCharsets.UTF_8 ); - AspectModelInformation aspectModelInformation = new AspectModelInformation( versionedNamespace, aspectModelFile, + NamespaceFileContent aspectModelInformation = new NamespaceFileContent( versionedNamespace, aspectModelFile, fileToTest ); final InMemoryStrategy inMemoryStrategy = new InMemoryStrategy( aspectModelInformation, rootPath, fileSystem ); final Try result = inMemoryStrategy.apply( null ); assertTrue( result.isFailure() ); - assertTrue( result.getCause() instanceof NotImplementedError ); + assertInstanceOf( NotImplementedError.class, result.getCause() ); assertEquals( causeMessage, result.getCause().getMessage() ); } } diff --git a/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl b/aspect-model-editor-resolver/src/test/resources/resolver/org.eclipse.esmf.example/1.0.0/AspectModelForResolver.ttl similarity index 96% rename from src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl rename to aspect-model-editor-resolver/src/test/resources/resolver/org.eclipse.esmf.example/1.0.0/AspectModelForResolver.ttl index 979d8671..71f5a157 100644 --- a/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategy.ttl +++ b/aspect-model-editor-resolver/src/test/resources/resolver/org.eclipse.esmf.example/1.0.0/AspectModelForResolver.ttl @@ -18,7 +18,7 @@ @prefix xsd: . @prefix : . -:AspectModelForStrategy a samm:Aspect ; +:AspectModelForResolver a samm:Aspect ; samm:properties (:property) ; samm:operations () . diff --git a/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java b/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java deleted file mode 100644 index c44ec918..00000000 --- a/src/test/java/org/eclipse/esmf/ame/repository/ModelResolverRepositoryTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.repository; - -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Collections; - -import org.eclipse.esmf.ame.repository.strategy.LocalFolderResolverStrategy; -import org.eclipse.esmf.ame.repository.strategy.ModelResolverStrategy; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -class ModelResolverRepositoryTest { - - @Autowired - private ModelResolverRepository repository; - - @Test - void testGetStrategy() { - final ModelResolverStrategy result = repository.getStrategy( LocalFolderResolverStrategy.class ); - - assertTrue( result instanceof LocalFolderResolverStrategy ); - } - - @Test() - void testGetStrategyHasEmptyStrategyList() { - repository = new ModelResolverRepository( Collections.emptyList() ); - - assertThrows( RuntimeException.class, () -> repository.getStrategy( LocalFolderResolverStrategy.class ) ); - } -} diff --git a/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java b/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java deleted file mode 100644 index 42534d32..00000000 --- a/src/test/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategyTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.repository.strategy; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.File; -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; - -import org.apache.jena.riot.RiotException; -import org.eclipse.esmf.ame.config.ApplicationSettings; -import org.eclipse.esmf.ame.exceptions.FileNotFoundException; -import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import io.vavr.Tuple2; - -@ExtendWith( SpringExtension.class ) -@SpringBootTest -class LocalFolderResolverStrategyTest { - @Autowired - private ApplicationSettings applicationSettingsMock; - - @Autowired - private FileSystem importFileSystemMock; - - private LocalFolderResolverStrategy localFolderResolverStrategy; - - private static final Path RESOURCE_PATH = Path.of( "src", "test", "resources", "strategy" ); - - private static final String NAMESPACE_VERSION = "org.eclipse.esmf.example:1.0.0"; - - private static final String MODEL = "AspectModelForStrategy.ttl"; - private static final String MODEL_WITH_EXT_REF = "AspectModelForStrategyWithExtRef.ttl"; - private static final String MODEL_NOT_EXIST = "AspectModelNotExist.ttl"; - - private static final String ASPECT_MODEL_URN_WITH_EXT_REF_AS_STRING = - "urn:samm:" + NAMESPACE_VERSION + "#" + MODEL_WITH_EXT_REF.replace( ".ttl", "" ); - - private static final String TTL_FILE_CONTENT = "new result ttl file"; - private static final String TTL_FILE_WITH_EXT_REF = - NAMESPACE_VERSION.replace( ":", File.separator ) + File.separator + MODEL_WITH_EXT_REF; - - @BeforeEach - void setUp() { - localFolderResolverStrategy = new LocalFolderResolverStrategy( applicationSettingsMock, importFileSystemMock, - RESOURCE_PATH.toString() ); - } - - @Test - void testCheckModelExists() { - assertTrue( localFolderResolverStrategy.checkModelExist( NAMESPACE_VERSION, MODEL ) ); - } - - @Test - void testCheckModelNotExists() { - assertFalse( localFolderResolverStrategy.checkModelExist( NAMESPACE_VERSION, MODEL_NOT_EXIST ) ); - } - - @Test - void testGetModelFileNotFound() { - assertThrows( FileNotFoundException.class, - () -> localFolderResolverStrategy.getModelAsString( NAMESPACE_VERSION, MODEL_NOT_EXIST ) ); - } - - @Test - void testGetModel() { - final String result = localFolderResolverStrategy.getModelAsString( NAMESPACE_VERSION, MODEL ); - - assertTrue( result.contains( "" ) ); - } - - @Test - void testGetFilePathBasedOnTurtleData() throws IOException { - final Path extRefAspectModel = Path.of( RESOURCE_PATH.toAbsolutePath().toString(), TTL_FILE_WITH_EXT_REF ); - final AspectModelUrn aspectModelUrn = localFolderResolverStrategy.getAspectModelUrn( - Files.readString( extRefAspectModel ) ); - - assertEquals( ASPECT_MODEL_URN_WITH_EXT_REF_AS_STRING, aspectModelUrn.toString() ); - } - - @Test() - void testSaveModelCanNotWriteToFile() { - assertThrows( RiotException.class, - () -> localFolderResolverStrategy.saveModel( Optional.empty(), Optional.empty(), TTL_FILE_CONTENT ) ); - } - - @Test - void convertFileToTuple() { - final Path eclipseTestPath = RESOURCE_PATH.resolve( NAMESPACE_VERSION.replace( ":", File.separator ) ); - final File testFile = new File( eclipseTestPath + File.separator + MODEL ); - - final Tuple2 fileInfo = localFolderResolverStrategy.convertFileToTuple( testFile ); - - assertEquals( MODEL.replace( ".ttl", "" ), fileInfo._1 ); - assertEquals( NAMESPACE_VERSION, fileInfo._2 ); - } -} diff --git a/src/test/resources/services/TestArchive.zip b/src/test/resources/services/TestArchive.zip deleted file mode 100644 index 5d083b9424000b71ca4800ab1b4a1d0dfc080048..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2888 zcmai$3p|r;AIERU#-wo`0*Z=QiCnl}{2%7V0 z3-n^={|{;YI|vuPCz#-e3)6Gr&l8LQK=EMh9&4bm$woXWjVMQ#qQ7`BIvpNmVq?1G$Jo zY)WBbjxOt3XJBzm%1sY$Cv|qee|WWyVzso~b*u8ZvdZ}ng(odA#=JF+rLf%MOZxE+ zsHT10mi|4CI)90!zh=Xl&M0*kqMLV0#%~yYUztY8D``z-%UNdsAy!W7g!h+`V%rF! zoe_+M-PXI048=a^P$d|MgXa%mQetro7Y_s6t+mSZg5J~CR(@Igv_Pg zp8BYO?1L*!^pr7KB8-cVK5hXeF*OfGC|gfgmJ|l9F))02s68sFpnB|GF}xbd_5>^%K}YF?Ja zFsyT~UuJGwWuMqbZ6HcAGqkMF?s|Letm2!TJ6iMXP+eWLcc{X% zr@L!NxR($-@)Gm$E(fU)K79`Ga^4t@oF0+Sf0J-hb?Q) zcSN{*AphhL_b|$1O1bwox+uFPg*4QOhlcF4Gart(Bl%U<&pS*L*JVBC^VQ?z)A1Ku-uRa;(nxuLGUPPekzj12KtykM zZ#fwC+gL2*g_e%4qsd5PoGQ0Wo$3*QoRfq!Pl8laJ@$Ok2#r$&V-+Fo{eeRmQVAgq zWou<5H6H)!xMPjRDes7Mjn*{0!N3KT$yo>#I~a;5P}U!`4bsc%xpl|wDodPlG`r;1 z)q>o82P+dCG+u{aWm_qg`3US z9LCPp4|k|k-g)1{t8MKzpAkWu6I?CWGCLd@37taKOW*1U#1 z*U7xx=rR0=Zv{s#@X}^h#C)KG;nQgd%w>9jRLo5%+7-B zK-e}+oEYL1%6ekP-Yu#@V(840n>@IH#s65%H~##)%O$kY&ue*kyclDn8)Qf zSI_)8bHm=NZAAX~u4p#f{ligfNW-l3HR8M4j>f?cgD=QhI8q3f=z}O(IJ?f=;>Ktk z+RNg`=e0!@*v2xuMqYH>8#P{qsU_a_ZSc@!5w9x$PM97AQ;qy!ON=#0okmUa%0K~s=eA}E=g0KGpKvNBd diff --git a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl b/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl deleted file mode 100644 index adadffd7..00000000 --- a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForService.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:AspectModelForService a samm:Aspect ; - samm:properties (:property) ; - samm:operations () . - -:property a samm:Property; - samm:characteristic :Characteristic . - -:Characteristic a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl b/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl deleted file mode 100644 index 6f249130..00000000 --- a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . -@prefix ext-ref: . - -:AspectModelForStrategyWithExtRef a samm:Aspect ; - samm:properties (:propertyThis ext-ref:property) ; - samm:operations () . - -:propertyThis a samm:Property; - samm:characteristic :CharacteristicThis . - -:CharacteristicThis a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl b/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl deleted file mode 100644 index 98006a84..00000000 --- a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/FileToDelete.ttl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:FileToDelete a samm:Aspect ; - samm:properties ( :property ) ; - samm:operations ( ) . - -:property a samm:Property ; - samm:characteristic :Characteristic . - -:Characteristic a samm:Characteristic ; - samm:dataType xsd:string . - diff --git a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl b/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl deleted file mode 100644 index d192428f..00000000 --- a/src/test/resources/services/org.eclipse.esmf.example/1.0.0/OldAspectModel.ttl +++ /dev/null @@ -1,19 +0,0 @@ -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:OldAspectModel a samm:Aspect ; - samm:properties ( :property ) ; - samm:operations ( ) . - -:property a samm:Property ; - samm:characteristic :Characteristic . - -:Characteristic a samm:Characteristic ; - samm:dataType xsd:string . - diff --git a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl b/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl deleted file mode 100644 index 205b6125..00000000 --- a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileOne.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:TestFileOne a samm:Aspect ; - samm:properties (:property1 :property3) ; - samm:operations () . - -:property1 a samm:Property; - samm:characteristic :Characteristic1 . - -:Characteristic1 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl b/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl deleted file mode 100644 index 27234a1f..00000000 --- a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileThree.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:TestFileThree a samm:Aspect ; - samm:properties (:property3) ; - samm:operations () . - -:property3 a samm:Property; - samm:characteristic :Characteristic3 . - -:Characteristic3 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl b/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl deleted file mode 100644 index 2c6871be..00000000 --- a/src/test/resources/services/org.eclipse.esmf.export/1.0.0/TestFileTwo.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:TestFileTwo a samm:Aspect ; - samm:properties (:property2) ; - samm:operations () . - -:property2 a samm:Property; - samm:characteristic :Characteristic2 . - -:Characteristic2 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl b/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl deleted file mode 100644 index b4503431..00000000 --- a/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupOne.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToBackupOne a samm:Aspect ; - samm:properties (:property1) ; - samm:operations () . - -:property1 a samm:Property; - samm:characteristic :Characteristic1 . - -:Characteristic1 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl b/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl deleted file mode 100644 index bc4b5f7e..00000000 --- a/src/test/resources/services/workspace-to-backup/io.backup-workspace-one/1.0.0/ToBackupTwo.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToBackupTwo a samm:Aspect ; - samm:properties (:property2) ; - samm:operations () . - -:property2 a samm:Property; - samm:characteristic :Characteristic2 . - -:Characteristic2 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl b/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl deleted file mode 100644 index f91ab7b9..00000000 --- a/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupOne.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToBackupOne a samm:Aspect ; - samm:properties (:property1) ; - samm:operations () . - -:property1 a samm:Property; - samm:characteristic :Characteristic1 . - -:Characteristic1 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl b/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl deleted file mode 100644 index e0b94afe..00000000 --- a/src/test/resources/services/workspace-to-backup/io.backup-workspace-two/1.0.0/ToBackupTwo.ttl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToBackupTwo a samm:Aspect ; - samm:properties (:property2) ; - samm:operations () . - -:property2 a samm:Property; - samm:characteristic :Characteristic2 . - -:Characteristic2 a samm:Characteristic ; - samm:dataType xsd:string . diff --git a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl b/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl deleted file mode 100644 index d4e41c0e..00000000 --- a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateOne.ttl +++ /dev/null @@ -1,22 +0,0 @@ -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToMigrateOne a samm:Aspect ; - samm:properties ( :property1 ) ; - samm:operations ( ) ; - samm:name "ToMigrateOne" . - -:property1 a samm:Property ; - samm:characteristic :Characteristic1 ; - samm:name "property1" . - -:Characteristic1 a samm:Characteristic ; - samm:dataType xsd:string ; - samm:name "Characteristic1" . - diff --git a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl b/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl deleted file mode 100644 index 96acf649..00000000 --- a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-one/1.0.0/ToMigrateTwo.ttl +++ /dev/null @@ -1,22 +0,0 @@ -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToMigrateTwo a samm:Aspect ; - samm:properties ( :property2 ) ; - samm:operations ( ) ; - samm:name "ToMigrateTwo" . - -:property2 a samm:Property ; - samm:characteristic :Characteristic2 ; - samm:name "property2" . - -:Characteristic2 a samm:Characteristic ; - samm:dataType xsd:string ; - samm:name "Characteristic2" . - diff --git a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl b/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl deleted file mode 100644 index aeb0b5c1..00000000 --- a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateOne.ttl +++ /dev/null @@ -1,22 +0,0 @@ -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToMigrateOne a samm:Aspect ; - samm:properties ( :property1 ) ; - samm:operations ( ) ; - samm:name "ToMigrateOne" . - -:property1 a samm:Property ; - samm:characteristic :Characteristic1 ; - samm:name "property1" . - -:Characteristic1 a samm:Characteristic ; - samm:dataType xsd:string ; - samm:name "Characteristic1" . - diff --git a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl b/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl deleted file mode 100644 index f89ff0fb..00000000 --- a/src/test/resources/services/workspace-to-migrate/io.migrate-workspace-two/1.0.0/ToMigrateTwo.ttl +++ /dev/null @@ -1,22 +0,0 @@ -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . - -:ToMigrateTwo a samm:Aspect ; - samm:properties ( :property2 ) ; - samm:operations ( ) ; - samm:name "ToMigrateTwo" . - -:property2 a samm:Property ; - samm:characteristic :Characteristic2 ; - samm:name "property2" . - -:Characteristic2 a samm:Characteristic ; - samm:dataType xsd:string ; - samm:name "Characteristic2" . - diff --git a/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl b/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl deleted file mode 100644 index 6f249130..00000000 --- a/src/test/resources/strategy/org.eclipse.esmf.example/1.0.0/AspectModelForStrategyWithExtRef.ttl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH -# -# See the AUTHORS file(s) distributed with this work for additional -# information regarding authorship. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. -# -# SPDX-License-Identifier: MPL-2.0 - -@prefix samm: . -@prefix samm-c: . -@prefix samm-e: . -@prefix unit: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . -@prefix : . -@prefix ext-ref: . - -:AspectModelForStrategyWithExtRef a samm:Aspect ; - samm:properties (:propertyThis ext-ref:property) ; - samm:operations () . - -:propertyThis a samm:Property; - samm:characteristic :CharacteristicThis . - -:CharacteristicThis a samm:Characteristic ; - samm:dataType xsd:string . From 408b7fca91689cd296e271c16e06ec0d26cdbb61 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Tue, 12 Dec 2023 11:39:34 +0100 Subject: [PATCH 08/21] Move graalvm files into new structure --- .../java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java | 4 ++-- .../org/eclipse/esmf/ame/substitution/AdminShellConfig.java | 0 .../org/eclipse/esmf/ame/substitution/ImplementationInfo.java | 0 ...altwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java | 0 ..._esmf_aspectmodel_versionupdate_MigratorServiceLoader.java | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java (98%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/substitution/AdminShellConfig.java (100%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/substitution/ImplementationInfo.java (100%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java (100%) rename {src => aspect-model-editor-runtime/src}/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java (100%) diff --git a/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java similarity index 98% rename from src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java index cdf86309..7de3bb4c 100644 --- a/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java @@ -30,7 +30,6 @@ import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; import org.eclipse.esmf.ame.substitution.AdminShellConfig; -import org.eclipse.esmf.ame.substitution.ImplementationInfo; import org.eclipse.esmf.ame.substitution.Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper; import io.github.classgraph.ClassGraph; @@ -162,7 +161,8 @@ private List scanDefaultImplementations( fi interfaceName ) ); if ( !interfaceClassInfos.isEmpty() ) { final Class implementedClass = interfaceClassInfos.get( 0 ).loadClass(); - defaultImplementations.add( new ImplementationInfo( implementedClass, x ) ); + defaultImplementations.add( + new ReflectionHelper.ImplementationInfo( implementedClass, x ) ); } } ); return defaultImplementations; diff --git a/src/main/java/org/eclipse/esmf/ame/substitution/AdminShellConfig.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/AdminShellConfig.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/substitution/AdminShellConfig.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/AdminShellConfig.java diff --git a/src/main/java/org/eclipse/esmf/ame/substitution/ImplementationInfo.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/ImplementationInfo.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/substitution/ImplementationInfo.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/ImplementationInfo.java diff --git a/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java diff --git a/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java similarity index 100% rename from src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java rename to aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java From f8fdc32968e7384674c0c9921368bed02a1a95fc Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Tue, 12 Dec 2023 14:29:32 +0100 Subject: [PATCH 09/21] Update pom description --- aspect-model-editor-core/pom.xml | 3 +++ aspect-model-editor-migrator/pom.xml | 3 +++ aspect-model-editor-repository/pom.xml | 7 +++++++ aspect-model-editor-resolver/pom.xml | 5 +++++ aspect-model-editor-runtime/pom.xml | 5 +++++ aspect-model-editor-service/pom.xml | 7 +++++++ aspect-model-editor-validation/pom.xml | 3 +++ aspect-model-editor-web-core/pom.xml | 3 +++ aspect-model-editor-web/pom.xml | 5 +++++ pom.xml | 9 +++++---- 10 files changed, 46 insertions(+), 4 deletions(-) diff --git a/aspect-model-editor-core/pom.xml b/aspect-model-editor-core/pom.xml index 2a90629c..b20309fb 100644 --- a/aspect-model-editor-core/pom.xml +++ b/aspect-model-editor-core/pom.xml @@ -19,6 +19,7 @@ jar + org.eclipse.esmf esmf-aspect-model-starter @@ -35,6 +36,8 @@ org.eclipse.esmf esmf-aspect-model-validator + + org.springframework.boot spring-boot-starter-security diff --git a/aspect-model-editor-migrator/pom.xml b/aspect-model-editor-migrator/pom.xml index 49c74f0b..d8bd1ed8 100644 --- a/aspect-model-editor-migrator/pom.xml +++ b/aspect-model-editor-migrator/pom.xml @@ -19,10 +19,13 @@ jar + org.eclipse.esmf aspect-model-editor-resolver + + org.springframework.boot spring-boot-starter-web diff --git a/aspect-model-editor-repository/pom.xml b/aspect-model-editor-repository/pom.xml index 324fc05f..303c9666 100644 --- a/aspect-model-editor-repository/pom.xml +++ b/aspect-model-editor-repository/pom.xml @@ -19,6 +19,7 @@ jar + org.eclipse.esmf aspect-model-editor-core @@ -27,10 +28,14 @@ org.eclipse.esmf aspect-model-editor-resolver + + org.eclipse.esmf esmf-aspect-model-validator + + org.springframework.boot spring-boot-starter-web @@ -39,6 +44,8 @@ org.projectlombok lombok + + org.springframework.boot spring-boot-starter-test diff --git a/aspect-model-editor-resolver/pom.xml b/aspect-model-editor-resolver/pom.xml index 10b7cf49..f8d3d2b2 100644 --- a/aspect-model-editor-resolver/pom.xml +++ b/aspect-model-editor-resolver/pom.xml @@ -19,15 +19,20 @@ jar + org.eclipse.esmf aspect-model-editor-core + + org.projectlombok lombok ${lombok-version} + + org.springframework.boot spring-boot-starter-test diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml index 9832c922..ad718dcd 100644 --- a/aspect-model-editor-runtime/pom.xml +++ b/aspect-model-editor-runtime/pom.xml @@ -23,6 +23,7 @@ + org.eclipse.esmf aspect-model-editor-core @@ -43,6 +44,8 @@ org.eclipse.esmf aspect-model-editor-migrator + + org.springframework.boot spring-boot-starter-web @@ -59,6 +62,8 @@ com.github.marschall memoryfilesystem + + org.springframework.boot spring-boot-starter-test diff --git a/aspect-model-editor-service/pom.xml b/aspect-model-editor-service/pom.xml index ff0e8a07..0fd6aa6b 100644 --- a/aspect-model-editor-service/pom.xml +++ b/aspect-model-editor-service/pom.xml @@ -19,6 +19,7 @@ jar + org.eclipse.esmf aspect-model-editor-core @@ -39,6 +40,8 @@ org.eclipse.esmf aspect-model-editor-validation + + org.eclipse.esmf esmf-aspect-model-validator @@ -51,6 +54,8 @@ org.eclipse.esmf esmf-aspect-model-aas-generator + + org.springframework.boot spring-boot-starter-web @@ -59,6 +64,8 @@ org.projectlombok lombok + + org.springframework.boot spring-boot-starter-test diff --git a/aspect-model-editor-validation/pom.xml b/aspect-model-editor-validation/pom.xml index 106e131f..26b64605 100644 --- a/aspect-model-editor-validation/pom.xml +++ b/aspect-model-editor-validation/pom.xml @@ -19,6 +19,7 @@ jar + org.eclipse.esmf aspect-model-editor-core @@ -27,6 +28,8 @@ org.eclipse.esmf esmf-aspect-model-validator + + org.springframework.boot spring-boot-starter-web diff --git a/aspect-model-editor-web-core/pom.xml b/aspect-model-editor-web-core/pom.xml index 9c49d144..508739db 100644 --- a/aspect-model-editor-web-core/pom.xml +++ b/aspect-model-editor-web-core/pom.xml @@ -19,10 +19,13 @@ jar + org.eclipse.esmf aspect-model-editor-core + + org.springframework.boot spring-boot-starter-web diff --git a/aspect-model-editor-web/pom.xml b/aspect-model-editor-web/pom.xml index a30ff936..530a8342 100644 --- a/aspect-model-editor-web/pom.xml +++ b/aspect-model-editor-web/pom.xml @@ -19,6 +19,7 @@ jar + org.eclipse.esmf aspect-model-editor-core @@ -35,10 +36,14 @@ org.eclipse.esmf aspect-model-editor-web-core + + org.eclipse.esmf esmf-aspect-model-document-generators + + org.springframework.boot spring-boot-starter-web diff --git a/pom.xml b/pom.xml index a83e50fa..f97681d4 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ - + org.eclipse.esmf aspect-model-editor-core @@ -171,7 +171,7 @@ ${project.version} - + org.eclipse.esmf esmf-aspect-model-urn @@ -269,7 +269,7 @@ provided - + org.springframework.boot spring-boot-properties-migrator @@ -334,7 +334,7 @@ ${commons-code-version} - + org.springframework.boot spring-boot-starter-test @@ -563,6 +563,7 @@ org.codehaus.mojo exec-maven-plugin + ${exec-maven-plugin-version} From df5f5083ccce7600904a07fd8d3a159bb5627cd4 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Tue, 12 Dec 2023 14:42:01 +0100 Subject: [PATCH 10/21] Update pom --- aspect-model-editor-runtime/pom.xml | 371 ++++++++++++++++++++++++++++ pom.xml | 371 ---------------------------- 2 files changed, 371 insertions(+), 371 deletions(-) diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml index ad718dcd..bda6043a 100644 --- a/aspect-model-editor-runtime/pom.xml +++ b/aspect-model-editor-runtime/pom.xml @@ -70,4 +70,375 @@ test + + + + native-image + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + + + generate-admin-shell-reflection-config + process-classes + + java + + + + org.eclipse.esmf.ame.buildtime.Aas4jClassSetup + + ${project.build.outputDirectory}/adminshell.properties + + false + + + + + + org.graalvm.buildtools + native-maven-plugin + ${native-maven-plugin-version} + true + + + add-reachability-metadata + + add-reachability-metadata + + + + build-native + + compile-no-fork + + package + + + + ${main.class} + ame-backend-${project.version}-${os.platform} + true + + -Dspring.graal.remove-unused-autoconfig=true + -Dspring.graal.remove-yaml-support=true + --no-fallback + --report-unsupported-elements-at-runtime + + --initialize-at-build-time=org.slf4j.LoggerFactory,ch.qos.logback,guru.nidi.graphviz.attribute.,org.apache.velocity.,org.apache.poi.util.LocaleUtil + + -J-Xmx8G + -H:+ReportExceptionStackTraces + + -H:ReflectionConfigurationFiles=${project.basedir}/.graalvm/reflect-config.json + + + -H:ResourceConfigurationFiles=${project.basedir}/.graalvm/resource-config.json + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + process-test-aot + + process-test-aot + + + + process-aot + + process-aot + + + + + repackage + build-info + + + + + ${main.class} + + + + + + + dependencies-for-integration-tests + + + + + com.github.eirslett + frontend-maven-plugin + ${frontend-maven-plugin-version} + + + install-node-and-npm + pre-integration-test + + install-node-and-npm + + + v${node-version} + ${npm-version} + ${project.build.directory} + + + + install-newman + pre-integration-test + + npm + + + ${project.build.directory} + install . newman@${newman-version} + + + + install-newman-reports + pre-integration-test + + npm + + + ${project.build.directory} + install newman-reporter-htmlextra + + + + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin-version} + + + copy-resources + process-test-resources + + copy-resources + + + ${project.build.outputDirectory}/${postman.directory} + + + + ${postman.directory} + + + + + + + + org.sonatype.plugins + port-allocator-maven-plugin + ${port-allocator-version} + + + classworlds + classworlds + ${classworlds-version} + + + + + pre-integration-test + + allocate-ports + + + + + integration-test-port + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + ${maven-antrun-plugin-version} + + + + adjust-postman-target-url + pre-integration-test + + + + + + + run + + + + + + + + + + start-windows-native-image-for-integration-tests + + + + com.bazaarvoice.maven.plugins + process-exec-maven-plugin + ${process-exec-version} + + + + start-native-image-process + pre-integration-test + + start + + + ${project.build.directory} + + cmd + /C + ame-backend-${project.version}-${os.platform} + -Dserver.port=${integration-test-port} + + + + + + stop-native-image-process + post-integration-test + + stop-all + + + + + + + + + + start-unix-native-image-for-integration-tests + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + + Add execution right´s on native-image + pre-integration-test + + exec + + + chmod + + 755 + + ${project.build.directory}/ame-backend-${project.version}-${os.platform} + + + + + + + + com.bazaarvoice.maven.plugins + process-exec-maven-plugin + ${process-exec-version} + + + + start-native-image-process + pre-integration-test + + start + + + ${project.build.directory} + + ./ame-backend-${project.version}-${os.platform} + -Dserver.port=${integration-test-port} + + + + + + stop-native-image-process + post-integration-test + + stop-all + + + + + + + + + + run-postman-integration-tests + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + false + + + run-postman-integration-tests + integration-test + + exec + + + ${node.path} + + ${project.build.directory}/node_modules/newman/bin/newman.js + run + ${project.build.outputDirectory}/${postman.directory}/${postman.test.collection} + -e + ${project.build.outputDirectory}/${postman.directory}/${postman.test.environment} + -n 1 + --timeout-request 60000 + --delay-request 1000 + --insecure + -r cli,htmlextra + --reporter-htmlextra-title "${project.name} ${project.version}" + --reporter-htmlextra-export + ${project.build.directory}/${testreports.directory}/${testreports.newman} + + + + + + + + + diff --git a/pom.xml b/pom.xml index f97681d4..31d78e2d 100644 --- a/pom.xml +++ b/pom.xml @@ -555,377 +555,6 @@ - - - native-image - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin-version} - - - - generate-admin-shell-reflection-config - process-classes - - java - - - - org.eclipse.esmf.ame.buildtime.Aas4jClassSetup - - ${project.build.outputDirectory}/adminshell.properties - - false - - - - - - org.graalvm.buildtools - native-maven-plugin - ${native-maven-plugin-version} - true - - - add-reachability-metadata - - add-reachability-metadata - - - - build-native - - compile-no-fork - - package - - - - ${main.class} - ame-backend-${project.version}-${os.platform} - true - - -Dspring.graal.remove-unused-autoconfig=true - -Dspring.graal.remove-yaml-support=true - --no-fallback - --report-unsupported-elements-at-runtime - - --initialize-at-build-time=org.slf4j.LoggerFactory,ch.qos.logback,guru.nidi.graphviz.attribute.,org.apache.velocity.,org.apache.poi.util.LocaleUtil - - -J-Xmx8G - -H:+ReportExceptionStackTraces - - -H:ReflectionConfigurationFiles=${project.basedir}/.graalvm/reflect-config.json - - - -H:ResourceConfigurationFiles=${project.basedir}/.graalvm/resource-config.json - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-version} - - - process-test-aot - - process-test-aot - - - - process-aot - - process-aot - - - - - repackage - build-info - - - - - ${main.class} - - - - - - - dependencies-for-integration-tests - - - - - com.github.eirslett - frontend-maven-plugin - ${frontend-maven-plugin-version} - - - install-node-and-npm - pre-integration-test - - install-node-and-npm - - - v${node-version} - ${npm-version} - ${project.build.directory} - - - - install-newman - pre-integration-test - - npm - - - ${project.build.directory} - install . newman@${newman-version} - - - - install-newman-reports - pre-integration-test - - npm - - - ${project.build.directory} - install newman-reporter-htmlextra - - - - - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin-version} - - - copy-resources - process-test-resources - - copy-resources - - - ${project.build.outputDirectory}/${postman.directory} - - - - ${postman.directory} - - - - - - - - org.sonatype.plugins - port-allocator-maven-plugin - ${port-allocator-version} - - - classworlds - classworlds - ${classworlds-version} - - - - - pre-integration-test - - allocate-ports - - - - - integration-test-port - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - ${maven-antrun-plugin-version} - - - - adjust-postman-target-url - pre-integration-test - - - - - - - run - - - - - - - - - - start-windows-native-image-for-integration-tests - - - - com.bazaarvoice.maven.plugins - process-exec-maven-plugin - ${process-exec-version} - - - - start-native-image-process - pre-integration-test - - start - - - ${project.build.directory} - - cmd - /C - ame-backend-${project.version}-${os.platform} - -Dserver.port=${integration-test-port} - - - - - - stop-native-image-process - post-integration-test - - stop-all - - - - - - - - - - start-unix-native-image-for-integration-tests - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin-version} - - - Add execution right´s on native-image - pre-integration-test - - exec - - - chmod - - 755 - - ${project.build.directory}/ame-backend-${project.version}-${os.platform} - - - - - - - - com.bazaarvoice.maven.plugins - process-exec-maven-plugin - ${process-exec-version} - - - - start-native-image-process - pre-integration-test - - start - - - ${project.build.directory} - - ./ame-backend-${project.version}-${os.platform} - -Dserver.port=${integration-test-port} - - - - - - stop-native-image-process - post-integration-test - - stop-all - - - - - - - - - - run-postman-integration-tests - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin-version} - false - - - run-postman-integration-tests - integration-test - - exec - - - ${node.path} - - ${project.build.directory}/node_modules/newman/bin/newman.js - run - ${project.build.outputDirectory}/${postman.directory}/${postman.test.collection} - -e - ${project.build.outputDirectory}/${postman.directory}/${postman.test.environment} - -n 1 - --timeout-request 60000 - --delay-request 1000 - --insecure - -r cli,htmlextra - --reporter-htmlextra-title "${project.name} ${project.version}" - --reporter-htmlextra-export - ${project.build.directory}/${testreports.directory}/${testreports.newman} - - - - - - - - - - esmf-sdk-release From 1a03931058c71795ead9db3a4b1853794022a034 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Wed, 13 Dec 2023 13:39:04 +0100 Subject: [PATCH 11/21] Adjust log messages --- aspect-model-editor-core/pom.xml | 1 - ...spectModelPrintDocumentationException.java | 34 ------- .../ame/exceptions/CreateFileException.java | 9 -- .../ame/exceptions/UrnNotFoundException.java | 16 ---- .../eclipse/esmf/ame/utils/ModelUtils.java | 12 +-- aspect-model-editor-migrator/pom.xml | 1 - aspect-model-editor-repository/pom.xml | 1 - .../strategy/LocalFolderResolverStrategy.java | 6 +- aspect-model-editor-resolver/pom.xml | 1 - .../resolver/strategy/ResolutionStrategy.java | 2 +- aspect-model-editor-runtime/pom.xml | 23 ++++- .../postman/ame.postman_collection.json | 22 +++-- .../esmf/ame/buildtime/Aas4jClassSetup.java | 4 +- aspect-model-editor-service/pom.xml | 1 - .../esmf/ame/services/utils/UnzipUtils.java | 4 +- aspect-model-editor-validation/pom.xml | 1 - aspect-model-editor-web-core/pom.xml | 1 - .../exceptions/ResponseExceptionHandler.java | 94 ++++++++++++------- aspect-model-editor-web/pom.xml | 1 - .../esmf/ame/api/PackageController.java | 2 +- pom.xml | 14 +-- 21 files changed, 109 insertions(+), 141 deletions(-) delete mode 100644 aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java diff --git a/aspect-model-editor-core/pom.xml b/aspect-model-editor-core/pom.xml index b20309fb..7c1bd541 100644 --- a/aspect-model-editor-core/pom.xml +++ b/aspect-model-editor-core/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-core ESMF Aspect Model Editor Core - jar diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java deleted file mode 100644 index 4c35f39d..00000000 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/AspectModelPrintDocumentationException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH - * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * SPDX-License-Identifier: MPL-2.0 - */ - -package org.eclipse.esmf.ame.exceptions; - -import java.io.Serial; - -import lombok.Getter; - -@Getter -public class AspectModelPrintDocumentationException extends RuntimeException { - @Serial - private static final long serialVersionUID = 1L; - - /** - * Constructs a AspectModelValidationException with message and cause. - * - * @param message the message of the exception - * @param cause of the exception - */ - public AspectModelPrintDocumentationException( final String message, final Throwable cause ) { - super( message, cause ); - } -} diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java index 7fcbe210..6a71fdbd 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/CreateFileException.java @@ -22,15 +22,6 @@ public class CreateFileException extends RuntimeException { @Serial private static final long serialVersionUID = 1L; - /** - * Constructs a CreateFileException with message. - * - * @param message the message of the exception - */ - public CreateFileException( final String message ) { - super( message ); - } - /** * Constructs a CreateFileException with message and cause. * diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java index 024ec428..50135b6c 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/exceptions/UrnNotFoundException.java @@ -36,20 +36,4 @@ public UrnNotFoundException( final String message, final AspectModelUrn urn ) { super( message ); this.urn = urn; } - - /** - * Constructs a UrnFoundException with message, cause and value. - * - * @param message the message of the exception - * @param cause of the exception - * @param urn Not found AspectModelUrn - */ - public UrnNotFoundException( final String message, final Throwable cause, final AspectModelUrn urn ) { - super( message, cause ); - this.urn = urn; - } - - public AspectModelUrn getUrn() { - return urn; - } } diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java index 017ecdf0..dd45d68b 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java @@ -19,7 +19,6 @@ import java.net.URL; import java.nio.file.Path; import java.util.Arrays; -import java.util.List; import java.util.Optional; import org.apache.commons.lang3.StringUtils; @@ -28,10 +27,7 @@ import org.eclipse.esmf.ame.exceptions.FileReadException; import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; -import org.eclipse.esmf.aspectmodel.shacl.violation.Violation; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; -import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator; -import org.eclipse.esmf.aspectmodel.validation.services.ViolationFormatter; import org.eclipse.esmf.metamodel.AspectContext; import io.vavr.control.Try; @@ -54,13 +50,7 @@ private ModelUtils() { */ public static AspectContext getAspectContext( Try context ) { return context.recover( throwable -> { - // Another exception, e.g. syntax error. Let the validator handle this - final List violations = new AspectModelValidator().validateModel( - context.map( AspectContext::rdfModel ) ); - - throw new FileReadException( - String.format( "The generation process encountered failures due to the following violations: %s", - new ViolationFormatter().apply( violations ) ) ); + throw new FileReadException( throwable.getMessage() ); } ).get(); } diff --git a/aspect-model-editor-migrator/pom.xml b/aspect-model-editor-migrator/pom.xml index d8bd1ed8..69ae17d3 100644 --- a/aspect-model-editor-migrator/pom.xml +++ b/aspect-model-editor-migrator/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-migrator ESMF Aspect Model Editor Migrator - jar diff --git a/aspect-model-editor-repository/pom.xml b/aspect-model-editor-repository/pom.xml index 303c9666..09dca288 100644 --- a/aspect-model-editor-repository/pom.xml +++ b/aspect-model-editor-repository/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-repository ESMF Aspect Model Editor Repository - jar diff --git a/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java index b4ff7063..55e7049b 100644 --- a/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java +++ b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/LocalFolderResolverStrategy.java @@ -219,7 +219,7 @@ public boolean lockFile( @NonNull String namespace, @NonNull String fileName ) { return true; } catch ( IOException e ) { throw new FileHandlingException( - "Cannot lock file: " + fileName + " in namespace: " + namespace + ". Reason: " + e.getMessage() ); + "Cannot lock file: " + fileName + " in namespace: " + namespace + ". Reason: " + e.getMessage(), e.getCause() ); } } @@ -235,7 +235,7 @@ public boolean unlockFile( @NonNull String namespace, @NonNull String fileName ) } } catch ( IOException e ) { throw new FileHandlingException( - "Cannot unlock file: " + fileName + " in namespace: " + namespace + ". Reason: " + e.getMessage() ); + "Cannot unlock file: " + fileName + " in namespace: " + namespace + ". Reason: " + e.getMessage(), e.getCause() ); } return false; @@ -287,7 +287,7 @@ private List getEndFilePaths( @Nonnull final String rootSharedFolder, @N .filter( StringUtils::isNotBlank ) .toList(); } catch ( final IOException e ) { - throw new FileReadException( "Can not read shared folder file structure", e ); + throw new FileReadException("An error occurred while attempting to access the shared folder's file structure. Please check your permissions or network connection and try again.", e); } } diff --git a/aspect-model-editor-resolver/pom.xml b/aspect-model-editor-resolver/pom.xml index f8d3d2b2..a9958aa8 100644 --- a/aspect-model-editor-resolver/pom.xml +++ b/aspect-model-editor-resolver/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-resolver ESMF Aspect Model Editor Resolver - jar diff --git a/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java index dbb71471..1d77e4ad 100644 --- a/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java +++ b/aspect-model-editor-resolver/src/main/java/org/eclipse/esmf/ame/resolver/strategy/ResolutionStrategy.java @@ -144,7 +144,7 @@ protected Model loadTurtleFromString( final String aspectModel ) { return resultTry.get(); } catch ( IOException e ) { LOG.error( "Cannot read file." ); - throw new FileReadException( "Error reading the Aspect Model file.", e ); + throw new FileReadException("Failed to read the Aspect Model file. Please check if the file exists and is accessible.", e); } } diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml index bda6043a..e17d0e6c 100644 --- a/aspect-model-editor-runtime/pom.xml +++ b/aspect-model-editor-runtime/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-runtime ESMF Aspect Model Editor Runtime - jar org.eclipse.esmf.ame.Application @@ -71,6 +70,24 @@ + + + + src/main/resources + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + ${main.class} + + + + + native-image @@ -134,10 +151,10 @@ -J-Xmx8G -H:+ReportExceptionStackTraces - -H:ReflectionConfigurationFiles=${project.basedir}/.graalvm/reflect-config.json + -H:ReflectionConfigurationFiles=${maven.multiModuleProjectDirectory}/.graalvm/reflect-config.json - -H:ResourceConfigurationFiles=${project.basedir}/.graalvm/resource-config.json + -H:ResourceConfigurationFiles=${maven.multiModuleProjectDirectory}/.graalvm/resource-config.json diff --git a/aspect-model-editor-runtime/postman/ame.postman_collection.json b/aspect-model-editor-runtime/postman/ame.postman_collection.json index 406391e4..0d7885c7 100644 --- a/aspect-model-editor-runtime/postman/ame.postman_collection.json +++ b/aspect-model-editor-runtime/postman/ame.postman_collection.json @@ -359,8 +359,8 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 422\", function () {\r", - " pm.response.to.have.status(422);\r", + "pm.test(\"Status code is 409\", function () {\r", + " pm.response.to.have.status(409);\r", " pm.expect(pm.response.json().error.message).to.contain(\"[line: 17, col: 1 ] Triples not terminated by DOT\");\r", "});" ], @@ -489,6 +489,7 @@ "pm.test(\"Status code is 200\", function () {\r", " pm.response.to.have.status(200);\r", "});\r", + "\r", "pm.test(\"Response body is valid\", function () {\r", " pm.expect(pm.response.json()['property1']).to.exist\r", "});" @@ -571,8 +572,8 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 400\", function () {\r", - " pm.response.to.have.status(422);\r", + "pm.test(\"Status code is 409\", function () {\r", + " pm.response.to.have.status(409);\r", "});\r", "" ], @@ -611,8 +612,8 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 400\", function () {\r", - " pm.response.to.have.status(422);\r", + "pm.test(\"Status code is 409\", function () {\r", + " pm.response.to.have.status(409);\r", "});\r", "" ], @@ -789,8 +790,9 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(422);\r", + "pm.test(\"Status code is 409\", function () {\r", + " pm.response.to.have.status(409);\r", + " pm.expect(pm.response.json().error.message).to.contain(\"Could not load Aspect model, please make sure the model is valid\")\r", "});" ], "type": "text/javascript" @@ -850,8 +852,8 @@ "listen": "test", "script": { "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(422);\r", + "pm.test(\"Status code is 409\", function () {\r", + " pm.response.to.have.status(409);\r", "});" ], "type": "text/javascript" diff --git a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java index 7de3bb4c..cdf86309 100644 --- a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/buildtime/Aas4jClassSetup.java @@ -30,6 +30,7 @@ import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; import org.eclipse.esmf.ame.substitution.AdminShellConfig; +import org.eclipse.esmf.ame.substitution.ImplementationInfo; import org.eclipse.esmf.ame.substitution.Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper; import io.github.classgraph.ClassGraph; @@ -161,8 +162,7 @@ private List scanDefaultImplementations( fi interfaceName ) ); if ( !interfaceClassInfos.isEmpty() ) { final Class implementedClass = interfaceClassInfos.get( 0 ).loadClass(); - defaultImplementations.add( - new ReflectionHelper.ImplementationInfo( implementedClass, x ) ); + defaultImplementations.add( new ImplementationInfo( implementedClass, x ) ); } } ); return defaultImplementations; diff --git a/aspect-model-editor-service/pom.xml b/aspect-model-editor-service/pom.xml index 0fd6aa6b..804310a5 100644 --- a/aspect-model-editor-service/pom.xml +++ b/aspect-model-editor-service/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-service ESMF Aspect Model Editor Service - jar diff --git a/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java index f0ebf277..96285acb 100644 --- a/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/utils/UnzipUtils.java @@ -66,7 +66,7 @@ public static void extractFilesFromPackage( final InputStream zipFile, final Fil } } catch ( IOException e ) { LOG.error( "Package cannot be imported." ); - throw new FileReadException( "Package cannot be imported.", e ); + throw new FileReadException("An error occurred while importing the package.", e); } } @@ -147,7 +147,7 @@ private static String readZipInput( ZipInputStream zipInputStream ) { return stringBuilder.toString(); } catch ( IOException e ) { - throw new FileReadException( "Cannot read file in package.", e ); + throw new FileReadException("An error occurred while reading the file in the package. Please check if the file exists or is accessible.", e); } } } diff --git a/aspect-model-editor-validation/pom.xml b/aspect-model-editor-validation/pom.xml index 26b64605..edfbe9ee 100644 --- a/aspect-model-editor-validation/pom.xml +++ b/aspect-model-editor-validation/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-validation ESMF Aspect Model Editor Validation - jar diff --git a/aspect-model-editor-web-core/pom.xml b/aspect-model-editor-web-core/pom.xml index 508739db..4dc2a48a 100644 --- a/aspect-model-editor-web-core/pom.xml +++ b/aspect-model-editor-web-core/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-web-core ESMF Aspect Model Editor Web Core - jar diff --git a/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java index d2ca7766..08b745e7 100644 --- a/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java +++ b/aspect-model-editor-web-core/src/main/java/org/eclipse/esmf/ame/exceptions/ResponseExceptionHandler.java @@ -15,22 +15,29 @@ import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import java.util.Objects; + import org.eclipse.esmf.ame.model.ErrorResponse; import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidNamespaceException; import org.eclipse.esmf.metamodel.loader.AspectLoadingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.MessageSource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; +import org.springframework.web.util.WebUtils; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * Provides custom exception handling for the REST API. @@ -39,6 +46,8 @@ public class ResponseExceptionHandler extends ResponseEntityExceptionHandler { private static final Logger LOG = LoggerFactory.getLogger( ResponseExceptionHandler.class ); + private MessageSource messageSource; + /** * Method for handling exception to type {@link FileNotFoundException} * @@ -47,7 +56,7 @@ public class ResponseExceptionHandler extends ResponseEntityExceptionHandler { * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( FileNotFoundException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, + public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, final FileNotFoundException e ) { return error( HttpStatus.NOT_FOUND, request, e, e.getMessage() ); } @@ -60,7 +69,7 @@ public ResponseEntity handleInvalidStateTransitionException( final WebRe * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( FileWriteException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, + public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, final FileWriteException e ) { return error( HttpStatus.BAD_REQUEST, request, e, e.getMessage() ); } @@ -73,9 +82,9 @@ public ResponseEntity handleInvalidStateTransitionException( final WebRe * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( FileReadException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, + public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, final FileReadException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -86,9 +95,9 @@ public ResponseEntity handleInvalidStateTransitionException( final WebRe * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( CreateFileException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, + public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, final CreateFileException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -99,22 +108,9 @@ public ResponseEntity handleInvalidStateTransitionException( final WebRe * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( IllegalArgumentException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, + public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, final IllegalArgumentException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); - } - - /** - * Method for handling exception to type {@link AspectModelPrintDocumentationException} - * - * @param request the Http request - * @param e the exception which occurred - * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception - */ - @ExceptionHandler( AspectModelPrintDocumentationException.class ) - public ResponseEntity handleInvalidStateTransitionException( final WebRequest request, - final AspectModelPrintDocumentationException e ) { - return error( HttpStatus.BAD_REQUEST, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -125,9 +121,9 @@ public ResponseEntity handleInvalidStateTransitionException( final WebRe * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( AspectLoadingException.class ) - public ResponseEntity handleAspectLoadingException( final WebRequest request, + public ResponseEntity handleAspectLoadingException( final WebRequest request, final AspectLoadingException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -138,9 +134,9 @@ public ResponseEntity handleAspectLoadingException( final WebRequest req * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( InvalidAspectModelException.class ) - public ResponseEntity handleInvalidAspectModelException( final WebRequest request, + public ResponseEntity handleInvalidAspectModelException( final WebRequest request, final InvalidAspectModelException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -151,9 +147,9 @@ public ResponseEntity handleInvalidAspectModelException( final WebReques * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( InvalidNamespaceException.class ) - public ResponseEntity handleInvalidAspectModelException( final WebRequest request, + public ResponseEntity handleInvalidAspectModelException( final WebRequest request, final InvalidNamespaceException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -164,9 +160,9 @@ public ResponseEntity handleInvalidAspectModelException( final WebReques * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( FileCannotDeleteException.class ) - public ResponseEntity handleInvalidAspectModelException( final WebRequest request, + public ResponseEntity handleInvalidAspectModelException( final WebRequest request, final FileCannotDeleteException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } /** @@ -177,12 +173,12 @@ public ResponseEntity handleInvalidAspectModelException( final WebReques * @return the custom {@link ErrorResponse} as {@link ResponseEntity} for the exception */ @ExceptionHandler( FileHandlingException.class ) - public ResponseEntity handleInvalidAspectModelException( final WebRequest request, + public ResponseEntity handleInvalidAspectModelException( final WebRequest request, final FileHandlingException e ) { - return error( HttpStatus.UNPROCESSABLE_ENTITY, request, e, e.getMessage() ); + return error( HttpStatus.CONFLICT, request, e, e.getMessage() ); } - private ResponseEntity error( final HttpStatus responseCode, final WebRequest request, + private ResponseEntity error( final HttpStatus responseCode, final WebRequest request, final RuntimeException e, final String message ) { logRequest( request, e, responseCode ); @@ -218,4 +214,38 @@ private static String getLogRequestMessage( final String requestURL, final Throw return String.format( "Handling exception %s with response code %s of request %s", ex.getClass().getName(), httpStatus.value(), requestURL ); } + + private ResponseEntity handleExceptionInternal(Exception ex, @Nullable ErrorResponse body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) { + + if (isResponseCommitted(request)) { + logger.warn("Response already committed. Ignoring: " + ex); + return null; + } + + if (statusCode.equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, ex, WebRequest.SCOPE_REQUEST); + } + + if (body == null && ex instanceof org.springframework.web.ErrorResponse) { + return handleErrorResponse(ex, headers, statusCode, request); + } + + return new ResponseEntity<>(body, headers, statusCode); + } + + private boolean isResponseCommitted(WebRequest request) { + if (request instanceof ServletWebRequest) { + HttpServletResponse response = ((ServletWebRequest) request).getResponse(); + return response != null && response.isCommitted(); + } + return false; + } + + private ResponseEntity handleErrorResponse(Exception ex, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) { + ResponseEntity entity = super.handleExceptionInternal(ex, null, headers, statusCode, request); + Object responseBody = Objects.requireNonNull( entity ).getBody(); + ErrorResponse errorResponse = (responseBody instanceof ErrorResponse) ? (ErrorResponse) responseBody : null; + + return new ResponseEntity<>(errorResponse, entity.getHeaders(), entity.getStatusCode()); + } } diff --git a/aspect-model-editor-web/pom.xml b/aspect-model-editor-web/pom.xml index 530a8342..1b880f14 100644 --- a/aspect-model-editor-web/pom.xml +++ b/aspect-model-editor-web/pom.xml @@ -16,7 +16,6 @@ aspect-model-editor-web ESMF Aspect Model Editor Web - jar diff --git a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java index 3bddde3f..42fa4032 100644 --- a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/PackageController.java @@ -71,7 +71,7 @@ public ResponseEntity validateImportAspectModelPackage( final String extension = FilenameUtils.getExtension( zipFile.getOriginalFilename() ); if ( !Objects.requireNonNull( extension ).equals( "zip" ) ) { - throw new FileReadException( "Selected file is not a ZIP file." ); + throw new FileReadException("The file you selected is not in ZIP format."); } return ResponseEntity.ok( packageService.validateImportAspectModelPackage( zipFile ) ); diff --git a/pom.xml b/pom.xml index 31d78e2d..e9dce01f 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,6 @@ - org.eclipse.esmf.ame.Application 2.4.2 @@ -387,15 +386,12 @@ + + + src/main/resources + + - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin-version} - - ${main.class} - - org.apache.maven.plugins maven-scm-plugin From c0b7dec32e716733598c7ffaf765092374238454 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Thu, 14 Dec 2023 14:28:07 +0100 Subject: [PATCH 12/21] Change file structure for native-image --- .../.graalvm}/reflect-config.json | 0 .../.graalvm}/resource-config.json | 0 aspect-model-editor-runtime/pom.xml | 18 +---- ...dataformat_core_util_ReflectionHelper.java | 7 +- ...l_versionupdate_MigratorServiceLoader.java | 4 +- .../Target_org_slf4j_LoggerFactory.java | 35 ++++++++++ pom.xml | 66 ++++++++++++++++++- 7 files changed, 106 insertions(+), 24 deletions(-) rename {.graalvm => aspect-model-editor-runtime/.graalvm}/reflect-config.json (100%) rename {.graalvm => aspect-model-editor-runtime/.graalvm}/resource-config.json (100%) create mode 100644 aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_slf4j_LoggerFactory.java diff --git a/.graalvm/reflect-config.json b/aspect-model-editor-runtime/.graalvm/reflect-config.json similarity index 100% rename from .graalvm/reflect-config.json rename to aspect-model-editor-runtime/.graalvm/reflect-config.json diff --git a/.graalvm/resource-config.json b/aspect-model-editor-runtime/.graalvm/resource-config.json similarity index 100% rename from .graalvm/resource-config.json rename to aspect-model-editor-runtime/.graalvm/resource-config.json diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml index e17d0e6c..30a8a2aa 100644 --- a/aspect-model-editor-runtime/pom.xml +++ b/aspect-model-editor-runtime/pom.xml @@ -18,6 +18,7 @@ ESMF Aspect Model Editor Runtime + org.eclipse.esmf.ame.Application @@ -80,7 +81,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin-version} ${main.class} @@ -96,7 +96,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin-version} @@ -119,7 +118,6 @@ org.graalvm.buildtools native-maven-plugin - ${native-maven-plugin-version} true @@ -151,10 +149,10 @@ -J-Xmx8G -H:+ReportExceptionStackTraces - -H:ReflectionConfigurationFiles=${maven.multiModuleProjectDirectory}/.graalvm/reflect-config.json + -H:ReflectionConfigurationFiles=${project.basedir}/.graalvm/reflect-config.json - -H:ResourceConfigurationFiles=${maven.multiModuleProjectDirectory}/.graalvm/resource-config.json + -H:ResourceConfigurationFiles=${project.basedir}/.graalvm/resource-config.json @@ -162,7 +160,6 @@ org.springframework.boot spring-boot-maven-plugin - ${spring-boot-version} process-test-aot @@ -198,7 +195,6 @@ com.github.eirslett frontend-maven-plugin - ${frontend-maven-plugin-version} install-node-and-npm @@ -242,7 +238,6 @@ org.apache.maven.plugins maven-resources-plugin - ${maven-resources-plugin-version} copy-resources @@ -265,12 +260,10 @@ org.sonatype.plugins port-allocator-maven-plugin - ${port-allocator-version} classworlds classworlds - ${classworlds-version} @@ -292,7 +285,6 @@ org.apache.maven.plugins maven-antrun-plugin - ${maven-antrun-plugin-version} @@ -322,7 +314,6 @@ com.bazaarvoice.maven.plugins process-exec-maven-plugin - ${process-exec-version} @@ -362,7 +353,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin-version} Add execution right´s on native-image @@ -385,7 +375,6 @@ com.bazaarvoice.maven.plugins process-exec-maven-plugin - ${process-exec-version} @@ -424,7 +413,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin-version} false diff --git a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java index 09c8db7a..9dda00b1 100644 --- a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.java @@ -32,11 +32,8 @@ /** * This is a GraalVM substitution class * for {@link ReflectionHelper}, the central point of reflection information of the io.admin-shell.aas library. The - * original ReflectionHelper - * has a static constructor that initializes several maps and collections (using ClassGraph scans) that hold - * information - * about implementations - * of interfaces etc.. For the build of the native image, this logic is replaced by the following logic: + * original ReflectionHelper has a static constructor that initializes several maps and collections (using ClassGraph scans) that hold information + * about implementations of interfaces etc.. For the build of the native image, this logic is replaced by the following logic: *
    *
  1. At build time, the {@link Aas4jClassSetup} is ran (as a standalone program). * This creates an instance of {@link AdminShellConfig} which contains all the information extracted from the ClassGraph scans.
  2. diff --git a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java index 6af844ee..7377a88e 100644 --- a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_eclipse_esmf_aspectmodel_versionupdate_MigratorServiceLoader.java @@ -1,8 +1,8 @@ /* * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH * - * See the AUTHORS file(s) distributed with this work for - * additional information regarding authorship. + * See the AUTHORS file(s) distributed with this work for additional + * information regarding authorship. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_slf4j_LoggerFactory.java b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_slf4j_LoggerFactory.java new file mode 100644 index 00000000..097e9ac6 --- /dev/null +++ b/aspect-model-editor-runtime/src/main/java/org/eclipse/esmf/ame/substitution/Target_org_slf4j_LoggerFactory.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * + * See the AUTHORS file(s) distributed with this work for additional + * information regarding authorship. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package org.eclipse.esmf.ame.substitution; + +import java.util.List; + +import org.slf4j.LoggerFactory; +import org.slf4j.spi.SLF4JServiceProvider; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +@TargetClass( LoggerFactory.class ) +public final class Target_org_slf4j_LoggerFactory { + @Substitute + private static void reportMultipleBindingAmbiguity( final List providerList ) { + // Do nothing + } + + @Substitute + private static void reportActualBinding( final List providerList ) { + // Do nothing + } +} diff --git a/pom.xml b/pom.xml index e9dce01f..9e5a4082 100644 --- a/pom.xml +++ b/pom.xml @@ -74,13 +74,13 @@ 5.1.1 3.3.0 1.1 - 22.3.0 + 23.0.1 2.0.5 3.0.2 6.0.0 0.9.19 1.3 - 2.6.0 + 2.7.0 5.9.2 @@ -103,6 +103,7 @@ postman test-reports + failsafe-report surefire-report newman-report.html false @@ -376,6 +377,11 @@ ${cglib-version} test + + classworlds + classworlds + ${classworlds-version} + org.junit.jupiter junit-jupiter-engine @@ -391,6 +397,62 @@ src/main/resources + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + + org.graalvm.buildtools + native-maven-plugin + ${native-maven-plugin-version} + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + com.github.eirslett + frontend-maven-plugin + ${frontend-maven-plugin-version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin-version} + + + org.sonatype.plugins + port-allocator-maven-plugin + ${port-allocator-version} + + + org.apache.maven.plugins + maven-antrun-plugin + ${maven-antrun-plugin-version} + + + com.bazaarvoice.maven.plugins + process-exec-maven-plugin + ${process-exec-version} + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin-version} + + + + org.apache.maven.plugins From 342f2ed90fea0ccaf368928eeaabd216b5b20e57 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Thu, 14 Dec 2023 15:11:17 +0100 Subject: [PATCH 13/21] Update lombok version --- aspect-model-editor-resolver/pom.xml | 1 - pom.xml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/aspect-model-editor-resolver/pom.xml b/aspect-model-editor-resolver/pom.xml index a9958aa8..87978d34 100644 --- a/aspect-model-editor-resolver/pom.xml +++ b/aspect-model-editor-resolver/pom.xml @@ -28,7 +28,6 @@ org.projectlombok lombok - ${lombok-version} diff --git a/pom.xml b/pom.xml index 9e5a4082..66bb8748 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ 3.0.0 - 1.18.24 + 1.18.26 2.13.0 1.7 1.15 From c4bd46afa2d21009627f4521439470181bc0fde9 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Thu, 14 Dec 2023 15:55:46 +0100 Subject: [PATCH 14/21] Fix newman port problem --- aspect-model-editor-runtime/pom.xml | 2 +- pom.xml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/aspect-model-editor-runtime/pom.xml b/aspect-model-editor-runtime/pom.xml index 30a8a2aa..93570d59 100644 --- a/aspect-model-editor-runtime/pom.xml +++ b/aspect-model-editor-runtime/pom.xml @@ -18,7 +18,6 @@ ESMF Aspect Model Editor Runtime - org.eclipse.esmf.ame.Application @@ -264,6 +263,7 @@ classworlds classworlds + ${classworlds-version} diff --git a/pom.xml b/pom.xml index 66bb8748..f2b4d23a 100644 --- a/pom.xml +++ b/pom.xml @@ -377,11 +377,6 @@ ${cglib-version} test - - classworlds - classworlds - ${classworlds-version} - org.junit.jupiter junit-jupiter-engine From 3870212e2a248f953868659781debcea4e289e4c Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 10:17:33 +0100 Subject: [PATCH 15/21] FIx CodeQl issue --- .../eclipse/esmf/ame/utils/ModelUtils.java | 13 ++++++ .../utils/LocalFolderResolverUtils.java | 2 + .../esmf/ame/services/PackageService.java | 42 +++++++++++-------- .../esmf/ame/api/FileHandlingController.java | 38 +++++++++++------ 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java index dd45d68b..a7b01609 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java @@ -107,4 +107,17 @@ private static Try loadFromUri( final URI uri ) { private static Try loadFromUrl( final URL url ) { return Try.ofSupplier( () -> TurtleLoader.openUrl( url ) ).flatMap( TurtleLoader::loadTurtle ); } + + /** + * Sanitizes the file name to remove any path information and retain only the base file name. + * This method is used to ensure that the file name does not contain any directory path components, + * which helps prevent path traversal attacks. It extracts only the file name portion from a given + * string that may represent a path. + * + * @param fileName The file name string potentially including path information. + * @return The sanitized base file name without any path components. + */ + public static String sanitizeFileInformation( String fileName ) { + return new File( fileName ).getName(); + } } diff --git a/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java index d7fec2e1..d75142a0 100644 --- a/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java +++ b/aspect-model-editor-repository/src/main/java/org/eclipse/esmf/ame/repository/strategy/utils/LocalFolderResolverUtils.java @@ -13,6 +13,8 @@ package org.eclipse.esmf.ame.repository.strategy.utils; +import java.io.File; + import javax.annotation.Nonnull; import org.eclipse.esmf.ame.resolver.strategy.model.FolderStructure; diff --git a/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java index 15fccded..db76361a 100644 --- a/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java +++ b/aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/PackageService.java @@ -92,7 +92,7 @@ public FileValidationReport validateAspectModelsForExport( final List validFiles = aspectModelFiles.stream() - .flatMap( data -> data.getFiles().stream().map( fileName -> { + .flatMap( data -> sanitizeIncomingFiles( data.getFiles() ).stream().map( fileName -> { String aspectModel = strategy.getModelAsString( data.getNamespace(), fileName ); AspectModelToExportCache.put( data.getNamespace() + ":" + fileName, aspectModel ); final FileSystemStrategy fileSystemStrategy = new FileSystemStrategy( aspectModel ); @@ -184,23 +184,29 @@ private FileValidationReport validateValidFiles( final String modelStoragePath ) public List importAspectModelPackage( final List aspectModelFiles ) { final ModelResolverStrategy strategy = modelResolverRepository.getStrategy( LocalFolderResolverStrategy.class ); - return aspectModelFiles.stream().flatMap( data -> data.getFiles().stream().map( fileName -> { - try { - final FolderStructure folderStructure = LocalFolderResolverUtils.extractFilePath( data.getNamespace() ); - folderStructure.setFileName( fileName ); - String aspectModel = ResolverUtils.readString( - importFileSystem.getPath( folderStructure.toString() ), StandardCharsets.UTF_8 ); - Optional namespaceVersion = Optional.of( - folderStructure.getFileRootPath() + File.separator + folderStructure.getVersion() ); - - strategy.saveModel( namespaceVersion, Optional.of( fileName ), aspectModel ); - - return folderStructure.toString(); - } catch ( final IOException e ) { - throw new FileNotFoundException( - String.format( "Cannot import Aspect Model with name %s to workspace", fileName ) ); - } - } ) ).toList(); + return aspectModelFiles.stream().flatMap( + data -> sanitizeIncomingFiles( data.getFiles() ).stream().map( fileName -> { + try { + final FolderStructure folderStructure = LocalFolderResolverUtils.extractFilePath( + data.getNamespace() ); + folderStructure.setFileName( fileName ); + String aspectModel = ResolverUtils.readString( + importFileSystem.getPath( folderStructure.toString() ), StandardCharsets.UTF_8 ); + Optional namespaceVersion = Optional.of( + folderStructure.getFileRootPath() + File.separator + folderStructure.getVersion() ); + + strategy.saveModel( namespaceVersion, Optional.of( fileName ), aspectModel ); + + return folderStructure.toString(); + } catch ( final IOException e ) { + throw new FileNotFoundException( + String.format( "Cannot import Aspect Model with name %s to workspace", fileName ) ); + } + } ) ).toList(); + } + + private List sanitizeIncomingFiles( List incomingFiles ) { + return incomingFiles.stream().map( ModelUtils::sanitizeFileInformation ).toList(); } private List getMissingAspectModelFiles( final ViolationReport violationReport, diff --git a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java index ba85405d..d291c0fc 100644 --- a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/FileHandlingController.java @@ -18,6 +18,7 @@ import org.eclipse.esmf.ame.exceptions.FileNotFoundException; import org.eclipse.esmf.ame.services.FileHandlingService; +import org.eclipse.esmf.ame.utils.ModelUtils; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; @@ -51,7 +52,10 @@ public FileHandlingController( final FileHandlingService fileHandlingService ) { @GetMapping( "lock" ) public ResponseEntity lockFile( @RequestHeader final Map headers ) throws FileNotFoundException { - return processFileOperation( headers, true ); + String sanitizedNamespace = ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ); + String sanitizedFileName = ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ); + + return processFileOperation( sanitizedNamespace, sanitizedFileName, true ); } /** @@ -65,30 +69,38 @@ public ResponseEntity lockFile( @RequestHeader final Map @GetMapping( "unlock" ) public ResponseEntity unlockFile( @RequestHeader final Map headers ) throws FileNotFoundException { - return processFileOperation( headers, false ); + String sanitizedNamespace = ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ); + String sanitizedFileName = ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ); + + return processFileOperation( sanitizedNamespace, sanitizedFileName, false ); } /** - * Processes file operations (lock/unlock) based on the provided namespace and filename. + * Processes file operations (lock/unlock) based on the provided file namespace and filename. + * This method uses the namespace and filename obtained from HTTP headers to determine + * the specific file for the lock/unlock operation. * - * @param headers HTTP headers that contain the namespace and filename. - * @param isLocking Boolean flag to determine the operation type (lock/unlock). - * @return ResponseEntity with operation result. + * @param sanitizedNamespace The namespace associated with the file, extracted from HTTP headers. + * @param sanitizedFileName The name of the file, extracted from HTTP headers. + * @param isLocking Boolean flag to determine the operation type (true for lock, false for unlock). + * @return ResponseEntity with the result of the lock/unlock operation. * - * @throws FileNotFoundException if the filename is not provided. + * @throws FileNotFoundException if the filename is not provided in the headers. + * @throws IllegalArgumentException if either the namespace or filename parameters are invalid. */ - private ResponseEntity processFileOperation( Map headers, boolean isLocking ) + private ResponseEntity processFileOperation( String sanitizedNamespace, String sanitizedFileName, + boolean isLocking ) throws FileNotFoundException { - final String namespace = Optional.ofNullable( headers.get( NAMESPACE ) ).orElse( "" ); - final String filename = Optional.ofNullable( headers.get( FILE_NAME ) ) + final String namespace = Optional.ofNullable( sanitizedNamespace ).orElse( "" ); + final String fileName = Optional.ofNullable( sanitizedFileName ) .orElseThrow( () -> new FileNotFoundException( "Please specify a file name" ) ); - if ( isValidParam( namespace ) && isValidParam( filename ) ) { + if ( isValidParam( namespace ) && isValidParam( fileName ) ) { throw new IllegalArgumentException( "Invalid headers parameter" ); } - return ResponseEntity.ok( isLocking ? fileHandlingService.lockFile( namespace, filename ) - : fileHandlingService.unlockFile( namespace, filename ) ); + return ResponseEntity.ok( isLocking ? fileHandlingService.lockFile( namespace, fileName ) + : fileHandlingService.unlockFile( namespace, fileName ) ); } private boolean isValidParam( String fileName ) { From 513bddc967f50c7e62aee3073bd741d154315ec3 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 10:40:50 +0100 Subject: [PATCH 16/21] Update codeql-scanning.yml --- .github/workflows/codeql-scanning.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/codeql-scanning.yml b/.github/workflows/codeql-scanning.yml index 259e9883..0ec9ef0a 100644 --- a/.github/workflows/codeql-scanning.yml +++ b/.github/workflows/codeql-scanning.yml @@ -4,8 +4,7 @@ on: push: branches: [ "main" ] pull_request: - # The branches below must be a subset of the branches above - branches: [ "main" ] + branches: [ '**' ] schedule: - cron: '30 0 * * *' From d5536c96aa83142965fb0d1604d83ca9c6998b59 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 10:58:32 +0100 Subject: [PATCH 17/21] Update ModelController.java --- .../eclipse/esmf/ame/api/ModelController.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java index 91bc4ff9..b2c778c6 100644 --- a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java @@ -22,6 +22,7 @@ import org.eclipse.esmf.ame.model.NamespaceFileCollection; import org.eclipse.esmf.ame.services.ModelService; import org.eclipse.esmf.ame.utils.MigratorUtils; +import org.eclipse.esmf.ame.utils.ModelUtils; import org.eclipse.esmf.ame.validation.model.ViolationReport; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -57,8 +58,10 @@ public ModelController( final ModelService modelService ) { */ @GetMapping() public ResponseEntity getModel( @RequestHeader final Map headers ) { - final Optional optionalNameSpace = Optional.ofNullable( headers.get( NAMESPACE ) ); - final Optional optionalFilename = Optional.ofNullable( headers.get( FILE_NAME ) ); + final Optional optionalNameSpace = Optional.of( + ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ); + final Optional optionalFilename = Optional.of( + ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); final String filename = optionalFilename.orElseThrow( () -> new FileNotFoundException( "Please specify a file name" ) ); @@ -74,8 +77,8 @@ public ResponseEntity getModel( @RequestHeader final Map @PostMapping( consumes = { MediaType.TEXT_PLAIN_VALUE, MediaTypeExtension.TEXT_TURTLE_VALUE } ) public ResponseEntity createModel( @RequestHeader final Map headers, @RequestBody final String turtleData ) { - final Optional namespace = Optional.ofNullable( headers.get( NAMESPACE ) ); - final Optional fileName = Optional.ofNullable( headers.get( FILE_NAME ) ); + final Optional namespace = Optional.of( ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ); + final Optional fileName = Optional.of( ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); modelService.saveModel( namespace, fileName, turtleData ); return new ResponseEntity<>( HttpStatus.CREATED ); @@ -144,8 +147,10 @@ public ResponseEntity>> getAllNamespaces( */ @DeleteMapping() public void deleteModel( @RequestHeader final Map headers ) { - final Optional optionalNameSpace = Optional.ofNullable( headers.get( NAMESPACE ) ); - final Optional optionalFilename = Optional.ofNullable( headers.get( FILE_NAME ) ); + final Optional optionalNameSpace = Optional.of( + ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ); + final Optional optionalFilename = Optional.of( + ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); final String namespace = optionalNameSpace.orElseThrow( () -> new FileNotFoundException( "Please specify a namespace" ) ); From 835e74a484aeb38723ac3a614d2696718f1ec854 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 11:36:42 +0100 Subject: [PATCH 18/21] Update ModelUtils.java --- .../java/org/eclipse/esmf/ame/utils/ModelUtils.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java index a7b01609..e6cb862b 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java @@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.jena.rdf.model.Model; import org.eclipse.esmf.ame.config.ApplicationSettings; +import org.eclipse.esmf.ame.exceptions.FileHandlingException; import org.eclipse.esmf.ame.exceptions.FileReadException; import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver; import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; @@ -114,10 +115,15 @@ private static Try loadFromUrl( final URL url ) { * which helps prevent path traversal attacks. It extracts only the file name portion from a given * string that may represent a path. * - * @param fileName The file name string potentially including path information. + * @param fileInformation The file name string potentially including path information. * @return The sanitized base file name without any path components. */ - public static String sanitizeFileInformation( String fileName ) { - return new File( fileName ).getName(); + public static String sanitizeFileInformation( String fileInformation ) { + if ( fileInformation.contains( File.separator ) || fileInformation.contains( ".." ) ) { + throw new FileHandlingException( + "Invalid file information: The provided string must not contain directory separators or relative path components." ); + } + + return new File( fileInformation ).getName(); } } From 220c62f607112f7f2deba3d626306d40990fbb90 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 11:38:36 +0100 Subject: [PATCH 19/21] Update ModelUtils.java --- .../src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java index e6cb862b..aa88e299 100644 --- a/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java +++ b/aspect-model-editor-core/src/main/java/org/eclipse/esmf/ame/utils/ModelUtils.java @@ -117,6 +117,8 @@ private static Try loadFromUrl( final URL url ) { * * @param fileInformation The file name string potentially including path information. * @return The sanitized base file name without any path components. + * + * @throws FileHandlingException If the file contains path information´s. */ public static String sanitizeFileInformation( String fileInformation ) { if ( fileInformation.contains( File.separator ) || fileInformation.contains( ".." ) ) { From f16df54bdb517dbbc5d5cf1ea41c846dc5810cda Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 11:55:36 +0100 Subject: [PATCH 20/21] Update ModelController.java --- .../java/org/eclipse/esmf/ame/api/ModelController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java index b2c778c6..60391163 100644 --- a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java @@ -58,8 +58,11 @@ public ModelController( final ModelService modelService ) { */ @GetMapping() public ResponseEntity getModel( @RequestHeader final Map headers ) { - final Optional optionalNameSpace = Optional.of( - ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ); + final Optional optionalNameSpace = + headers.get( NAMESPACE ) != null ? + Optional.of( ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ) : + Optional.empty(); + final Optional optionalFilename = Optional.of( ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); From 5401ac237c9c724eb0e734beb8132c491b3f8588 Mon Sep 17 00:00:00 2001 From: Michele Santoro Date: Fri, 15 Dec 2023 12:18:34 +0100 Subject: [PATCH 21/21] Update ModelController.java --- .../org/eclipse/esmf/ame/api/ModelController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java index 60391163..d600d623 100644 --- a/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java +++ b/aspect-model-editor-web/src/main/java/org/eclipse/esmf/ame/api/ModelController.java @@ -80,9 +80,15 @@ public ResponseEntity getModel( @RequestHeader final Map @PostMapping( consumes = { MediaType.TEXT_PLAIN_VALUE, MediaTypeExtension.TEXT_TURTLE_VALUE } ) public ResponseEntity createModel( @RequestHeader final Map headers, @RequestBody final String turtleData ) { - final Optional namespace = Optional.of( ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ); - final Optional fileName = Optional.of( ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); - modelService.saveModel( namespace, fileName, turtleData ); + final Optional optionalNameSpace = + headers.get( NAMESPACE ) != null ? + Optional.of( ModelUtils.sanitizeFileInformation( headers.get( NAMESPACE ) ) ) : + Optional.empty(); + + final Optional optionalFilename = Optional.of( + ModelUtils.sanitizeFileInformation( headers.get( FILE_NAME ) ) ); + + modelService.saveModel( optionalNameSpace, optionalFilename, turtleData ); return new ResponseEntity<>( HttpStatus.CREATED ); }