forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4652] Add support for loading editing contexts with dependencies
Bug: eclipse-sirius#4652 Signed-off-by: Gwendal Daniel <[email protected]>
- Loading branch information
Showing
19 changed files
with
539 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...clipse/sirius/web/application/editingcontext/services/EditingContextDependencyLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.editingcontext.services; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.web.application.UUIDParser; | ||
import org.eclipse.sirius.web.application.editingcontext.EditingContext; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextDependencyLoader; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextMigrationParticipantPredicate; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IResourceLoader; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Loads dependencies into the editing context. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class EditingContextDependencyLoader implements IEditingContextDependencyLoader { | ||
|
||
private final ISemanticDataSearchService semanticDataSearchService; | ||
|
||
private final IResourceLoader resourceLoader; | ||
|
||
private final List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates; | ||
|
||
public EditingContextDependencyLoader(ISemanticDataSearchService semanticDataSearchService, IResourceLoader resourceLoader, List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates) { | ||
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService); | ||
this.resourceLoader = Objects.requireNonNull(resourceLoader); | ||
this.migrationParticipantPredicates = Objects.requireNonNull(migrationParticipantPredicates); | ||
} | ||
|
||
@Override | ||
public void loadDependencies(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
Set<SemanticData> dependenciesSemanticData = new UUIDParser().parse(siriusWebEditingContext.getId()) | ||
.map(this.semanticDataSearchService::findAllTransitiveSemanticDataById) | ||
.orElse(Set.of()); | ||
for (SemanticData semanticData : dependenciesSemanticData) { | ||
semanticData.getDocuments().forEach(document -> { | ||
URI dependencyResourceURI = URI.createURI(DEPENDENCY_SCHEME + ":///" + document.getId().toString()); | ||
if (siriusWebEditingContext.getDomain().getResourceSet().getResource(dependencyResourceURI, false) == null) { | ||
Optional<Resource> resource = this.resourceLoader.toResource(siriusWebEditingContext.getDomain().getResourceSet(), document.getId().toString(), document.getName(), document.getContent(), | ||
this.migrationParticipantPredicates.stream().anyMatch(predicate -> predicate.test(editingContext.getId()))); | ||
resource.ifPresent(r -> { | ||
siriusWebEditingContext.getDomain().getResourceSet().getURIConverter().getURIMap().put(r.getURI(), dependencyResourceURI); | ||
r.setURI(dependencyResourceURI); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...e/sirius/web/application/editingcontext/services/api/IEditingContextDependencyLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.editingcontext.services.api; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
|
||
/** | ||
* Loads dependencies into the editing context. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IEditingContextDependencyLoader { | ||
|
||
String DEPENDENCY_SCHEME = "dependency"; | ||
|
||
void loadDependencies(IEditingContext editingContext); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...a/org/eclipse/sirius/web/application/object/services/ComposedReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.web.application.object.services.api.IDefaultReadOnlyObjectPredicate; | ||
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicate; | ||
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicateDelegate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Implementation of {@link IReadOnlyObjectPredicate} which delegates to {@link IReadOnlyObjectPredicateDelegate} or fallback to | ||
* {@link IDefaultReadOnlyObjectPredicate}. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class ComposedReadOnlyObjectPredicate implements IReadOnlyObjectPredicate { | ||
|
||
private final List<IReadOnlyObjectPredicateDelegate> readOnlyObjectPredicateDelegate; | ||
|
||
private final IDefaultReadOnlyObjectPredicate defaultReadOnlyObjectPredicate; | ||
|
||
public ComposedReadOnlyObjectPredicate(List<IReadOnlyObjectPredicateDelegate> readOnlyObjectPredicateDelegate, IDefaultReadOnlyObjectPredicate defaultReadOnlyObjectPredicate) { | ||
this.readOnlyObjectPredicateDelegate = Objects.requireNonNull(readOnlyObjectPredicateDelegate); | ||
this.defaultReadOnlyObjectPredicate = Objects.requireNonNull(defaultReadOnlyObjectPredicate); | ||
} | ||
|
||
@Override | ||
public boolean test(Object object) { | ||
var optionalDelegate = this.readOnlyObjectPredicateDelegate.stream() | ||
.filter(delegate -> delegate.canHandle(object)) | ||
.findFirst(); | ||
if (optionalDelegate.isPresent()) { | ||
return optionalDelegate.get().test(object); | ||
} | ||
return this.defaultReadOnlyObjectPredicate.test(object); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...va/org/eclipse/sirius/web/application/object/services/DefaultReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextDependencyLoader; | ||
import org.eclipse.sirius.web.application.object.services.api.IDefaultReadOnlyObjectPredicate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* The default service used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class DefaultReadOnlyObjectPredicate implements IDefaultReadOnlyObjectPredicate { | ||
|
||
@Override | ||
public boolean test(Object object) { | ||
boolean result = false; | ||
if (object instanceof EObject eObject) { | ||
result = Optional.ofNullable(eObject.eResource()) | ||
.map(Resource::getURI) | ||
.map(URI::scheme) | ||
.filter(scheme -> Objects.equals(scheme, IEditingContextDependencyLoader.DEPENDENCY_SCHEME)) | ||
.isPresent(); | ||
} else if (object instanceof Resource resource) { | ||
result = Objects.equals(resource.getURI().scheme(), IEditingContextDependencyLoader.DEPENDENCY_SCHEME); | ||
} | ||
return result; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...g/eclipse/sirius/web/application/object/services/api/IDefaultReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* The default service used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IDefaultReadOnlyObjectPredicate extends Predicate<Object> { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...java/org/eclipse/sirius/web/application/object/services/api/IReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IReadOnlyObjectPredicate extends Predicate<Object> { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../eclipse/sirius/web/application/object/services/api/IReadOnlyObjectPredicateDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IReadOnlyObjectPredicateDelegate extends Predicate<Object> { | ||
|
||
boolean canHandle(Object object); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.