Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3021] Improve the new architecture with representation and semantic …
…data related code Bug: #3021 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
- Loading branch information
1 parent
76cfa9d
commit 361aa01
Showing
51 changed files
with
2,316 additions
and
7 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
64 changes: 64 additions & 0 deletions
64
...ation/src/main/java/org/eclipse/sirius/web/application/editingcontext/EditingContext.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,64 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019, 2024 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; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.eclipse.sirius.components.representations.IRepresentationDescription; | ||
import org.eclipse.sirius.components.view.View; | ||
|
||
/** | ||
* Implementation of the editing context. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public class EditingContext implements IEMFEditingContext { | ||
|
||
private final String id; | ||
|
||
private final AdapterFactoryEditingDomain editingDomain; | ||
|
||
private final Map<String, IRepresentationDescription> representationDescriptions; | ||
|
||
private final List<View> views; | ||
|
||
public EditingContext(String id, AdapterFactoryEditingDomain editingDomain, Map<String, IRepresentationDescription> representationDescriptions, List<View> views) { | ||
this.id = Objects.requireNonNull(id); | ||
this.editingDomain = Objects.requireNonNull(editingDomain); | ||
this.representationDescriptions = Objects.requireNonNull(representationDescriptions); | ||
this.views = Objects.requireNonNull(views); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public AdapterFactoryEditingDomain getDomain() { | ||
return this.editingDomain; | ||
} | ||
|
||
public Map<String, IRepresentationDescription> getRepresentationDescriptions() { | ||
return this.representationDescriptions; | ||
} | ||
|
||
public List<View> getViews() { | ||
return this.views; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
.../java/org/eclipse/sirius/web/application/editingcontext/services/DomainSearchService.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,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.Optional; | ||
|
||
import org.eclipse.emf.ecore.EPackage; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.emf.edit.domain.EditingDomain; | ||
import org.eclipse.sirius.components.core.api.Domain; | ||
import org.eclipse.sirius.components.core.api.IDomainSearchService; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service used to search the domains available. | ||
* | ||
* @author frouene | ||
*/ | ||
@Service | ||
public class DomainSearchService implements IDomainSearchService { | ||
@Override | ||
public List<Domain> findAllByEditingContext(IEditingContext editingContext) { | ||
return Optional.of(editingContext) | ||
.filter(IEMFEditingContext.class::isInstance) | ||
.map(IEMFEditingContext.class::cast) | ||
.map(IEMFEditingContext::getDomain) | ||
.map(EditingDomain::getResourceSet) | ||
.map(ResourceSet::getPackageRegistry) | ||
.map(EPackage.Registry::values) | ||
.orElse(List.of()) | ||
.stream() | ||
.filter(EPackage.class::isInstance) | ||
.map(EPackage.class::cast) | ||
.map(ePackage -> new Domain(ePackage.getNsURI(), ePackage.getNsURI())) | ||
.sorted() | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public List<Domain> findRootDomainsByEditingContext(IEditingContext editingContext) { | ||
return Optional.of(editingContext) | ||
.filter(IEMFEditingContext.class::isInstance) | ||
.map(IEMFEditingContext.class::cast) | ||
.map(IEMFEditingContext::getDomain) | ||
.map(EditingDomain::getResourceSet) | ||
.map(ResourceSet::getPackageRegistry) | ||
.map(EPackage.Registry::values) | ||
.orElse(List.of()) | ||
.stream() | ||
.filter(EPackage.class::isInstance) | ||
.map(EPackage.class::cast) | ||
.map(ePackage -> new Domain(ePackage.getNsURI(), ePackage.getNsURI())) | ||
.sorted() | ||
.toList(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...eclipse/sirius/web/application/editingcontext/services/EditingContextEPackageService.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,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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 org.eclipse.emf.ecore.EPackage; | ||
import org.eclipse.sirius.components.emf.services.IEditingContextEPackageService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* A service used to retrieve all the EPackages accessible for a given editing context. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class EditingContextEPackageService implements IEditingContextEPackageService { | ||
@Override | ||
public List<EPackage> getEPackages(String editingContextId) { | ||
return List.of(); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...ipse/sirius/web/application/editingcontext/services/EditingContextPersistenceService.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,120 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IEditingContextPersistenceService; | ||
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; | ||
import org.eclipse.sirius.components.emf.services.EObjectIDManager; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.eclipse.sirius.emfjson.resource.JsonResource; | ||
import org.eclipse.sirius.web.application.UUIDParser; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataUpdateService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.data.jdbc.core.mapping.AggregateReference; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Timer; | ||
|
||
/** | ||
* Used to save the editing context. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class EditingContextPersistenceService implements IEditingContextPersistenceService { | ||
|
||
private static final String TIMER_NAME = "siriusweb_editingcontext_save"; | ||
|
||
private final ISemanticDataUpdateService semanticDataUpdateService; | ||
|
||
private final Timer timer; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(EditingContextPersistenceService.class); | ||
|
||
public EditingContextPersistenceService(ISemanticDataUpdateService semanticDataUpdateService, MeterRegistry meterRegistry) { | ||
this.semanticDataUpdateService = Objects.requireNonNull(semanticDataUpdateService); | ||
this.timer = Timer.builder(TIMER_NAME).register(meterRegistry); | ||
} | ||
|
||
@Override | ||
public void persist(IEditingContext editingContext) { | ||
long start = System.currentTimeMillis(); | ||
|
||
if (editingContext instanceof IEMFEditingContext emfEditingContext) { | ||
new UUIDParser().parse(editingContext.getId()) | ||
.map(AggregateReference::<Project, UUID>to) | ||
.ifPresent(project -> { | ||
var documents = emfEditingContext.getDomain().getResourceSet().getResources().stream() | ||
.map(this::toDocument) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.toSet()); | ||
this.semanticDataUpdateService.updateDocuments(project, documents); | ||
}); | ||
} | ||
|
||
long end = System.currentTimeMillis(); | ||
this.timer.record(end - start, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
private Optional<Document> toDocument(Resource resource) { | ||
HashMap<Object, Object> options = new HashMap<>(); | ||
options.put(JsonResource.OPTION_ID_MANAGER, new EObjectIDManager()); | ||
options.put(JsonResource.OPTION_SCHEMA_LOCATION, true); | ||
|
||
Optional<Document> optionalDocument = Optional.empty(); | ||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { | ||
resource.save(outputStream, options); | ||
|
||
for (Resource.Diagnostic warning : resource.getWarnings()) { | ||
this.logger.warn(warning.getMessage()); | ||
} | ||
for (Resource.Diagnostic error : resource.getErrors()) { | ||
this.logger.warn(error.getMessage()); | ||
} | ||
|
||
var name = resource.eAdapters().stream() | ||
.filter(ResourceMetadataAdapter.class::isInstance) | ||
.map(ResourceMetadataAdapter.class::cast) | ||
.findFirst().map(ResourceMetadataAdapter::getName) | ||
.orElse(""); | ||
var content = outputStream.toString(); | ||
|
||
var resourceId = resource.getURI().path().substring(1); | ||
var documentId = new UUIDParser().parse(resourceId).orElse(UUID.randomUUID()); | ||
|
||
var document = Document.newDocument(documentId) | ||
.name(name) | ||
.content(content) | ||
.build(); | ||
optionalDocument = Optional.of(document); | ||
} catch (IllegalArgumentException | IOException exception) { | ||
this.logger.warn(exception.getMessage(), exception); | ||
} | ||
return optionalDocument; | ||
} | ||
} |
Oops, something went wrong.