Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3019] Restore support for the discovery of domains and views model
Bug: #3019 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
- Loading branch information
1 parent
2daf28a
commit 86cc3e7
Showing
31 changed files
with
632 additions
and
54 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
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
25 changes: 25 additions & 0 deletions
25
...rc/main/java/org/eclipse/sirius/web/application/editingcontext/services/DocumentData.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,25 @@ | ||
/******************************************************************************* | ||
* 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.sirius.web.domain.boundedcontexts.semanticdata.Document; | ||
|
||
/** | ||
* The data retrieved from the serialization of a document. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record DocumentData(Document document, List<EPackageEntry> ePackageEntries) { | ||
} |
58 changes: 58 additions & 0 deletions
58
...org/eclipse/sirius/web/application/editingcontext/services/DocumentToResourceService.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,58 @@ | ||
/******************************************************************************* | ||
* 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.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; | ||
import org.eclipse.sirius.components.emf.services.JSONResourceFactory; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IDocumentToResourceService; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to load documents as resources. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class DocumentToResourceService implements IDocumentToResourceService { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(DocumentToResourceService.class); | ||
|
||
@Override | ||
public Optional<Resource> toResource(ResourceSet resourceSet, Document document) { | ||
Optional<Resource> optionalResource = Optional.empty(); | ||
|
||
var resource = new JSONResourceFactory().createResourceFromPath(document.getId().toString()); | ||
try (var inputStream = new ByteArrayInputStream(document.getContent().getBytes())) { | ||
resourceSet.getResources().add(resource); | ||
resource.load(inputStream, null); | ||
|
||
resource.eAdapters().add(new ResourceMetadataAdapter(document.getName())); | ||
|
||
optionalResource = Optional.of(resource); | ||
} catch (IOException | IllegalArgumentException exception) { | ||
this.logger.warn("An error occured while loading document {}: {}.", document.getId(), exception.getMessage()); | ||
resourceSet.getResources().remove(resource); | ||
} | ||
|
||
return optionalResource; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...c/main/java/org/eclipse/sirius/web/application/editingcontext/services/EPackageEntry.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,21 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
/** | ||
* Used to store the EPackage used in a JsonResource. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record EPackageEntry(String nsPrefix, String nsURI) { | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
...pse/sirius/web/application/editingcontext/services/JsonResourceSerializationListener.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,51 @@ | ||
/******************************************************************************* | ||
* 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 com.google.gson.JsonElement; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EReference; | ||
import org.eclipse.sirius.emfjson.resource.JsonResource; | ||
|
||
/** | ||
* Used to collect serialization data from JsonResource. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public class JsonResourceSerializationListener implements JsonResource.ISerializationListener { | ||
|
||
private final List<EPackageEntry> ePackageEntries = new ArrayList<>(); | ||
|
||
@Override | ||
public void onNsHeaderEntryAdded(String nsPrefix, String nsURI) { | ||
this.ePackageEntries.add(new EPackageEntry(nsPrefix, nsURI)); | ||
} | ||
|
||
@Override | ||
public void onObjectSerialized(EObject eObject, JsonElement jsonElement) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onCrossReferenceURICreated(EObject eObject, EReference eReference, String s) { | ||
// Do nothing | ||
} | ||
|
||
public List<EPackageEntry> getePackageEntries() { | ||
return this.ePackageEntries; | ||
} | ||
} |
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
...clipse/sirius/web/application/editingcontext/services/api/IDocumentToResourceService.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) 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.api; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document; | ||
|
||
/** | ||
* Used to load documents as EMF resources. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public interface IDocumentToResourceService { | ||
Optional<Resource> toResource(ResourceSet resourceSet, Document document); | ||
} |
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.