Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/change to multi module structure #57

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions aspect-model-editor-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.esmf</groupId>
<artifactId>aspect-model-editor-parent</artifactId>
<version>DEV-SNAPSHOT</version>
</parent>

<artifactId>aspect-model-editor-core</artifactId>
<name>ESMF Aspect Model Editor Core</name>

<dependencies>
<!-- ESMF dependencies -->
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-aspect-model-starter</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-aspect-model-urn</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-aspect-meta-model-java</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-aspect-model-validator</artifactId>
</dependency>

<!-- Third party dependencies for developing-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@

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;

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
package org.eclipse.esmf.ame.exceptions;

import java.io.IOException;
import java.io.Serial;

import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;

import lombok.Getter;

@Getter
public class UrnNotFoundException extends IOException {
@Serial
private static final long serialVersionUID = 1L;
private final transient AspectModelUrn urn;

Expand All @@ -34,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.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.urn.AspectModelUrn;
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<AspectContext>, handling exceptions if necessary.
*
* @param context The Try<AspectContext> 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<AspectContext> context ) {
return context.recover( throwable -> {
throw new FileReadException( throwable.getMessage() );
} ).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<Model> 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<Model> loadFromUrl( final URL url ) {
return Try.ofSupplier( () -> TurtleLoader.openUrl( url ) ).flatMap( TurtleLoader::loadTurtle );
}
}
37 changes: 37 additions & 0 deletions aspect-model-editor-migrator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.esmf</groupId>
<artifactId>aspect-model-editor-parent</artifactId>
<version>DEV-SNAPSHOT</version>
</parent>

<artifactId>aspect-model-editor-migrator</artifactId>
<name>ESMF Aspect Model Editor Migrator</name>

<dependencies>
<!-- ESMF dependencies -->
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>aspect-model-editor-resolver</artifactId>
</dependency>

<!-- Third party dependencies for developing-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +21,7 @@

@Data
@AllArgsConstructor
public class FileInformation {
public class FileProcessingResult {
@JsonInclude( JsonInclude.Include.NON_NULL )
@JsonProperty( "name" )
public String name;
Expand Down
Loading
Loading