Skip to content

Commit 9e2dfed

Browse files
committed
ST6RI-682 Made some editorial corrections and added issue aggregation
for EMF transformation
1 parent 1cc766e commit 9e2dfed

4 files changed

Lines changed: 46 additions & 26 deletions

File tree

org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ private String load(RepositoryProject repositoryProject) {
489489

490490
System.out.println("Downloading model...");
491491
ProjectDelta delta = fetcher.fetch();
492+
fetcher.getIssues().forEach(System.out::println);
492493

493494
System.out.println("Adding model to index");
494495
delta.getProjectRoots().forEach((eObject, dto) -> {

org.omg.sysml.xtext/src/org/omg/sysml/xtext/util/SysMLRepositoryLoadUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.omg.sysml.util.repository.ProjectDelta;
4141
import org.omg.sysml.util.repository.ProjectRepository;
4242
import org.omg.sysml.util.repository.ProjectRepository.RepositoryProject;
43+
import org.omg.sysml.util.traversal.facade.impl.ApiElementProcessingFacade;
4344
import org.omg.sysml.util.repository.RepositoryContentFetcher;
4445
import org.omg.sysml.xmi.SysMLxStandaloneSetup;
4546
import org.omg.sysml.xtext.SysMLStandaloneSetup;
@@ -60,7 +61,7 @@ public static SysMLRepositoryLoadUtil createUsingArgs(String... args) throws Par
6061
var localLibrary = new Option("l", "library", true, "Path to local library");
6162
localLibrary.setRequired(true);
6263

63-
var repositoryOption = new Option("b", "base", true, "Repository url. E.g: http://localhost:9000");
64+
var repositoryOption = new Option("b", "base", true, "Repository url. E.g: " + ApiElementProcessingFacade.DEFAULT_BASE_PATH);
6465
repositoryOption.setRequired(false);
6566

6667
OptionGroup projectOption = new OptionGroup();
@@ -82,7 +83,7 @@ public static SysMLRepositoryLoadUtil createUsingArgs(String... args) throws Par
8283
CommandLine cli = parser.parse(options, args);
8384

8485
return new SysMLRepositoryLoadUtil(
85-
cli.hasOption(repositoryOption)? cli.getOptionValue(repositoryOption) : "http://localhost:9000",
86+
cli.hasOption(repositoryOption)? cli.getOptionValue(repositoryOption) : ApiElementProcessingFacade.DEFAULT_BASE_PATH,
8687
cli.hasOption(projectNameOption)? cli.getOptionValue(projectNameOption) : cli.getOptionValue(projectIdOption),
8788
cli.getOptionValue(targetOption),
8889
new File(cli.getOptionValue(localLibrary))
@@ -129,6 +130,9 @@ public void load() {
129130
RepositoryContentFetcher repositoryFetcher = new RepositoryContentFetcher(repositoryProject, tracker);
130131
System.out.println("Fetching project...");
131132
ProjectDelta delta = repositoryFetcher.fetch();
133+
134+
repositoryFetcher.getIssues().forEach(System.out::println);
135+
132136
ResourceSet resourceSet = getResourceSet();
133137

134138
try {

org.omg.sysml/src/org/omg/sysml/util/repository/RepositoryContentFetcher.java

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
import java.util.Collection;
2626
import java.util.HashMap;
27+
import java.util.LinkedList;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Objects;
31+
import java.util.Optional;
3032
import java.util.Set;
3133
import java.util.UUID;
3234
import java.util.stream.Collectors;
@@ -60,6 +62,8 @@ public class RepositoryContentFetcher {
6062

6163
private static Set<String> disabledStructuralFeatures = Set.of("importedMembership");
6264

65+
private final List<Issue> issues = new LinkedList<>();
66+
6367
/**
6468
* @param repositoryProject as the input
6569
* @param tracker index based on element UUIDs
@@ -76,6 +80,7 @@ public RepositoryContentFetcher(RepositoryProject repositoryProject, EObjectUUID
7680
* @return project diff. (currently just a container for the entire model downloaded from the project)
7781
*/
7882
public ProjectDelta fetch() {
83+
issues.clear();
7984
boolean success = repositoryProject.loadRemote();
8085

8186
if (!success) throw new RuntimeException("Couldn't download project: " + repositoryProject.getProjectName());
@@ -94,8 +99,8 @@ public ProjectDelta fetch() {
9499
tracker.forEachTrackedUserElement((id, langElement) -> {
95100
Element element = repositoryProject.getElement(id);
96101
if (element != null && isNotStandardLibraryElement(langElement)) {
97-
tranformCrossreferences(langElement, element);
98-
tranformAttributes(langElement, element);
102+
tranformCrossReferences(langElement, element);
103+
transformAttributes(langElement, element);
99104
//set importedMemberships for MembershipImports
100105
setImportedMembership(langElement, element);
101106
}
@@ -130,10 +135,9 @@ private void setImportedMembership(EObject langElement, Element dto) {
130135
//this is a workaround to address library element proxies where UUIDs of referenced Memberships aren't stable,
131136
//so the importedElement UUID is used instead.
132137
Object importedMembers = dto.get("importedElement");
133-
EObject resolvedReference = resolveReference(importedMembers, false);
134-
if (resolvedReference != null) {
138+
resolveReference(importedMembers, false).ifPresent(resolvedReference -> {
135139
membershipImport.setImportedMembership(((org.omg.sysml.lang.sysml.Element) resolvedReference).getOwningMembership());
136-
}
140+
});
137141
}
138142
}
139143

@@ -153,7 +157,7 @@ private boolean isNotStandardLibraryElement(EObject langElement) {
153157
}
154158

155159
private void transformContainmentReferences(EObject langElement, Element remoteElement) {
156-
for (EStructuralFeature feature: getStructuralFeatuers(langElement))
160+
for (EStructuralFeature feature: getStructuralFeatures(langElement))
157161
{
158162
if (!feature.isDerived() && remoteElement.get(feature.getName()) != null) {
159163
if (feature instanceof EReference reference && reference.isContainment()) {
@@ -163,8 +167,8 @@ private void transformContainmentReferences(EObject langElement, Element remoteE
163167
}
164168
}
165169

166-
private void tranformCrossreferences(EObject langElement, Element remoteElement) {
167-
for (EStructuralFeature feature: getStructuralFeatuers(langElement))
170+
private void tranformCrossReferences(EObject langElement, Element remoteElement) {
171+
for (EStructuralFeature feature: getStructuralFeatures(langElement))
168172
{
169173
if (!feature.isDerived() && remoteElement.containsKey(feature.getName())) {
170174
if (feature instanceof EReference reference) {
@@ -178,8 +182,8 @@ private void tranformCrossreferences(EObject langElement, Element remoteElement)
178182
}
179183
}
180184

181-
private void tranformAttributes(EObject langElement, Element remoteElement) {
182-
for (EStructuralFeature feature: getStructuralFeatuers(langElement))
185+
private void transformAttributes(EObject langElement, Element remoteElement) {
186+
for (EStructuralFeature feature: getStructuralFeatures(langElement))
183187
{
184188
if (!feature.isDerived() && remoteElement.containsKey(feature.getName())) {
185189
if (feature instanceof EAttribute reference) {
@@ -189,7 +193,7 @@ private void tranformAttributes(EObject langElement, Element remoteElement) {
189193
}
190194
}
191195

192-
private static Collection<EStructuralFeature> getStructuralFeatuers(EObject langElement){
196+
private static Collection<EStructuralFeature> getStructuralFeatures(EObject langElement){
193197
EClass eClass = langElement.eClass();
194198

195199
Set<EObject> allRedefined = eClass.getEAllStructuralFeatures().stream()
@@ -208,33 +212,31 @@ private void transformStructuralFeature(EObject langElement, Element remoteElem
208212
Object value = remoteElement.get(feature.getName());
209213
if (value instanceof Collection valueCollection) {
210214
for (Object referenceValue: valueCollection) {
211-
EObject referencedLangElement = resolveReference(referenceValue, isContainment);
212-
if (referencedLangElement != null) {
213-
referenceList.add(referencedLangElement);
214-
}
215+
resolveReference(referenceValue, isContainment).ifPresent(referenceList::add);
215216
}
216217
}
217218
} else {
218219
Object value = remoteElement.get(feature.getName());
219220
if (value != null) {
220-
langElement.eSet(feature, isReference? resolveReference(value, isContainment) : transformAttributeValue(value, feature));
221+
langElement.eSet(feature, isReference? resolveReference(value, isContainment).orElse(null) : transformAttributeValue(value, feature));
221222
}
222223
}
223224
}
224-
catch (Exception e) {
225-
System.out.printf("Unable to set structural feature %s::%s %n", feature.getEContainingClass().getName(), feature.getName());
225+
catch (IllegalArgumentException e) {
226+
//handle EObject.eGet, eSet errors
227+
issues.add(new Issue(String.format("Unable to set structural feature %s because %s ha no such feature.", feature.getName(), feature.getEType().getName())));
226228
}
227229
}
228230
}
229231

230-
private EObject resolveReference(Object referenceValue, boolean isContainment) {
232+
private Optional<EObject> resolveReference(Object referenceValue, boolean isContainment) {
231233
if (referenceValue instanceof Map referenceObjectMap) {
232234
Object refUUID = referenceObjectMap.get("@id");
233235
Element referencedElement = repositoryProject.getElement(UUID.fromString(refUUID.toString()));
234236
EObject referencedLangElement = isContainment? transform(referencedElement) : tracker.get(UUID.fromString(refUUID.toString()));
235-
return referencedLangElement;
237+
return Optional.ofNullable(referencedLangElement);
236238
}
237-
return null;
239+
return Optional.empty();
238240
}
239241

240242

@@ -257,4 +259,20 @@ private Object transformAttributeValue(Object attributeValue, EStructuralFeature
257259

258260
return null;
259261
}
262+
263+
public List<Issue> getIssues() {
264+
return issues;
265+
}
266+
267+
public static class Issue {
268+
private final String message;
269+
270+
public Issue(String message) {
271+
this.message = message;
272+
}
273+
274+
public String getMessage() {
275+
return message;
276+
}
277+
}
260278
}

org.omg.sysml/src/org/omg/sysml/util/traversal/facade/impl/ApiElementProcessingFacade.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ public Object process(Element element) {
122122
public boolean commit() {
123123
try {
124124
this.project = projectApi.postProject(this.project);
125-
126125
List<DataVersion> changes = this.getVersions();
127126
Commit commit = new Commit().change(changes);
128-
// System.out.println(new org.omg.sysml.JSON().serialize(commit));
129-
130127
int n = changes.size();
131128
System.out.print("\nPosting Commit (" + n + " element" + (n == 1? ")...": "s)..."));
132129
commit = this.commitApi.postCommitByProject(this.project.getAtId(), commit, null);

0 commit comments

Comments
 (0)