Skip to content

Commit b544213

Browse files
committed
ST6RI-682 Changed magic command names and command arguments
- changed %publications to %projects - changed %download to %load - added optional arguments to %load --id=<ID> --name=<NAME> - changed SysMLRepositoryLoad util arguments -n, -name to reference project by name -id to reference project by id
1 parent 89209a3 commit b544213

6 files changed

Lines changed: 88 additions & 41 deletions

File tree

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Date;
3636
import java.util.List;
3737
import java.util.Scanner;
38+
import java.util.UUID;
3839
import java.util.stream.Collectors;
3940

4041
import org.eclipse.emf.common.util.BasicEList;
@@ -433,21 +434,42 @@ protected String publish(String name) {
433434
publish(name, Collections.emptyList());
434435
}
435436

436-
public String download(String publication, List<String> help) {
437-
if (Strings.isNullOrEmpty(publication)) {
438-
return help.isEmpty()? "": SysMLInteractiveHelp.getDownloadHelp();
437+
public String loadByName(String projectName, List<String> help) {
438+
if (Strings.isNullOrEmpty(projectName)) {
439+
return help.isEmpty()? "": SysMLInteractiveHelp.getLoadHelp();
439440
}
440441

441442
ProjectRepository repository = new ProjectRepository(apiBasePath);
442443

443444
System.out.println("Locating model");
444-
RepositoryProject project = repository.getProjectByName(publication);
445+
RepositoryProject repositoryProject = repository.getProjectByName(projectName);
445446

446-
if (project == null) {
447+
if (repositoryProject == null) {
447448
return "ERROR:Publication doesn't exist.";
448449
}
449450

450-
boolean success = project.loadRemote();
451+
return load(repositoryProject);
452+
}
453+
454+
public String loadById(String projectId, List<String> help) {
455+
if (Strings.isNullOrEmpty(projectId)) {
456+
return help.isEmpty()? "": SysMLInteractiveHelp.getLoadHelp();
457+
}
458+
459+
ProjectRepository repository = new ProjectRepository(apiBasePath);
460+
461+
System.out.println("Locating model");
462+
RepositoryProject repositoryProject = repository.getPRojectById(UUID.fromString(projectId));
463+
464+
if (repositoryProject == null) {
465+
return "ERROR:Publication doesn't exist.";
466+
}
467+
468+
return load(repositoryProject);
469+
}
470+
471+
private String load(RepositoryProject repositoryProject) {
472+
boolean success = repositoryProject.loadRemote();
451473

452474
if (!success) {
453475
return "ERROR:Could not download the publication.";
@@ -463,7 +485,7 @@ public String download(String publication, List<String> help) {
463485
//UUIDS coming from resources that were added later in time will shadow previous ones
464486
tracker.trackUserUUIDs(inputResources);
465487

466-
RepositoryContentFetcher fetcher = new RepositoryContentFetcher(project, tracker);
488+
RepositoryContentFetcher fetcher = new RepositoryContentFetcher(repositoryProject, tracker);
467489

468490
System.out.println("Downloading model...");
469491
ProjectDelta delta = fetcher.fetch();
@@ -482,18 +504,18 @@ public String download(String publication, List<String> help) {
482504
addResourceToIndex(xmiResource);
483505
});
484506

485-
return "Project loaded: " + project.getProjectName() + ", " + project.getProjectId().toString();
507+
return "Project loaded: " + repositoryProject.getProjectName() + ", " + repositoryProject.getProjectId().toString();
486508
}
487509

488510
protected String download(String name) {
489511
return "-h".equals(name)?
490-
download(null, Collections.singletonList("true")):
491-
download(name, Collections.emptyList());
512+
loadByName(null, Collections.singletonList("true")):
513+
loadByName(name, Collections.emptyList());
492514
}
493515

494516
public String listPublications(List<String> help) {
495517
if (help != null && !help.isEmpty()) {
496-
return SysMLInteractiveHelp.getPublicationsHelp();
518+
return SysMLInteractiveHelp.getProjectsHelp();
497519
}
498520
ProjectRepository projectRepository = new ProjectRepository(apiBasePath);
499521
List<RepositoryProject> repositoryProjects = projectRepository.getProjects();

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public class SysMLInteractiveHelp {
3838
private static final String GENERAL_HELP_STRING =
3939
"The following SysML v2 magic commands are available.\n"
4040
+ "For help on a specific command, use \"%help <COMMAND>\" or \"%<cmd> -h\".\n\n"
41-
+ "%download\tDownloads a publication from the repository and adds them to the Xtext index\n"
4241
+ "%eval\t\tEvaluate a given expression.\n"
4342
+ "%export\t\tSave a file of the JSON representation of the abstract syntax tree rooted in the named element.\n"
4443
+ "%help\t\tGet a list of available commands or help on a specific command\n"
4544
+ "%list\t\tList loaded library packages or the results of a given query\n"
45+
+ "%load\tLoads a model from the repository and adds it to the Xtext index\n"
4646
+ "%show\t\tPrint the abstract syntax tree rooted in a named element\n"
47-
+ "%publications\tList publications in the repository\n"
47+
+ "%projects\tList projects in the repository\n"
4848
+ "%publish\tPublish to the repository the modele elements rooted in a named element\n"
4949
+ "%view\t\tRender the view specified by the named view usage\n"
5050
+ "%viz\t\tVisualize the name model elements\n"
@@ -119,13 +119,14 @@ public class SysMLInteractiveHelp {
119119
+ "Save a file containing the complete JSON representation of the abstract syntax tree rooted in <NAME>.\n"
120120
+ "<NAME> must be fully qualified.\n";
121121

122-
private static final String DOWNLOAD_HELP_STRING =
123-
"Usage: %download <NAME>\n\n"
124-
+ "Downloads previously published models from the repository. <NAME> must be the full name of the publication.\n"
125-
+ "Use %publications to view repository contents.\n";
122+
private static final String LOAD_HELP_STRING =
123+
"Usage: %load [--id=<PROJECT ID] [--name=<NAME>] [<NAME>]\n\n"
124+
+ "Downloads previously published models from the repository. <NAME> must be the full name of the project.\n"
125+
+ "Use --id=<PROJECT ID> to load projects by id.\n"
126+
+ "Use %projects to view repository contents.\n";
126127

127-
private static final String PUBLICATIONS_HELP_STRING =
128-
"Usage: %publications\n\n"
128+
private static final String PROJECTS_HELP_STRING =
129+
"Usage: %projects\n\n"
129130
+ "Returns the name and identifier from the repository for all publications\n";
130131

131132
public static String getGeneralHelp() {
@@ -164,12 +165,12 @@ public static String getExportHelp() {
164165
return EXPORT_HELP_STRING;
165166
}
166167

167-
public static String getPublicationsHelp() {
168-
return PUBLICATIONS_HELP_STRING;
168+
public static String getProjectsHelp() {
169+
return PROJECTS_HELP_STRING;
169170
}
170171

171-
public static String getDownloadHelp() {
172-
return DOWNLOAD_HELP_STRING;
172+
public static String getLoadHelp() {
173+
return LOAD_HELP_STRING;
173174
}
174175

175176
private static Map<String, String> commandHelpMap = createCommandHelpMap();
@@ -184,8 +185,8 @@ private static Map<String, String> createCommandHelpMap() {
184185
map.put("%viz", VIZ_HELP_STRING);
185186
map.put("%view", VIEW_HELP_STRING);
186187
map.put("%export", EXPORT_HELP_STRING);
187-
map.put("%download", DOWNLOAD_HELP_STRING);
188-
map.put("%publications", PUBLICATIONS_HELP_STRING);
188+
map.put("%load", LOAD_HELP_STRING);
189+
map.put("%projects", PROJECTS_HELP_STRING);
189190

190191
return map;
191192
}

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public SysMLKernel() {
8080
this.magics.registerMagics(Viz.class);
8181
this.magics.registerMagics(View.class);
8282
this.magics.registerMagics(Export.class);
83-
this.magics.registerMagics(Publications.class);
84-
this.magics.registerMagics(Download.class);
83+
this.magics.registerMagics(Projects.class);
84+
this.magics.registerMagics(Load.class);
8585

8686
this.magicParser = new MyMagicParser();
8787
}

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Download.java renamed to org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Load.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@
3030
import io.github.spencerpark.jupyter.kernel.magic.registry.LineMagic;
3131
import io.github.spencerpark.jupyter.kernel.magic.registry.MagicsArgs;
3232

33-
public class Download {
33+
public class Load {
3434
private static final MagicsArgs SHOW_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags()
35+
.keyword("id")
36+
.keyword("name")
3537
.optional("name")
3638
.flag("help", 'h', "true")
3739
.build();
3840

3941
@LineMagic
40-
public static String download(List<String> args) {
42+
public static String load(List<String> args) {
4143
Map<String, List<String>> vals = SHOW_ARGS.parse(args);
4244
List<String> help = vals.get("help");
4345
List<String> name = vals.get("name");
44-
String publication = name.isEmpty()? null: name.get(0);
45-
return ISysML.getKernelInstance().getInteractive().download(publication, help);
46+
List<String> id = vals.get("id");
47+
48+
if (!name.isEmpty()) {
49+
return ISysML.getKernelInstance().getInteractive().loadByName(name.get(0), help);
50+
} else if (!id.isEmpty()) {
51+
return ISysML.getKernelInstance().getInteractive().loadById(id.get(0), help);
52+
} else {
53+
return ISysML.getKernelInstance().getInteractive().help("%load");
54+
}
4655
}
4756
}

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Publications.java renamed to org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Projects.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import io.github.spencerpark.jupyter.kernel.magic.registry.LineMagic;
3131
import io.github.spencerpark.jupyter.kernel.magic.registry.MagicsArgs;
3232

33-
public class Publications {
33+
public class Projects {
3434

3535
private static final MagicsArgs SHOW_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags().flag("help", 'h', "true").build();
3636

3737
@LineMagic
38-
public static String publications(List<String> args) {
38+
public static String projects(List<String> args) {
3939
Map<String, List<String>> vals = SHOW_ARGS.parse(args);
4040
List<String> help = vals.get("help");
4141
return ISysML.getKernelInstance().getInteractive().listPublications(help);

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.cli.CommandLineParser;
3030
import org.apache.commons.cli.DefaultParser;
3131
import org.apache.commons.cli.Option;
32+
import org.apache.commons.cli.OptionGroup;
3233
import org.apache.commons.cli.Options;
3334
import org.apache.commons.cli.ParseException;
3435
import org.eclipse.emf.common.util.URI;
@@ -62,34 +63,42 @@ public static SysMLRepositoryLoadUtil createUsingArgs(String... args) throws Par
6263
var repositoryOption = new Option("b", "base", true, "Repository url. E.g: http://localhost:9000");
6364
repositoryOption.setRequired(false);
6465

65-
var projectOption = new Option("p", "project", true, "Project name in the repository.");
66+
OptionGroup projectOption = new OptionGroup();
6667
projectOption.setRequired(true);
68+
var projectNameOption = new Option("n", "name", true, "Project's name in the repository.");
69+
var projectIdOption = new Option("id", "id", true, "Project's id in the repository.");
70+
71+
projectOption.addOption(projectNameOption);
72+
projectOption.addOption(projectIdOption);
6773

6874
var targetOption = new Option("t", "target", true, "Location where the project is loaded");
6975
targetOption.setRequired(true);
7076

71-
Options options = new Options().addOption(repositoryOption).addOption(projectOption).addOption(targetOption).addOption(localLibrary);
77+
Options options = new Options().addOption(repositoryOption).addOptionGroup(projectOption).addOption(targetOption).addOption(localLibrary);
78+
7279

7380
CommandLineParser parser = new DefaultParser();
81+
7482
CommandLine cli = parser.parse(options, args);
7583

7684
return new SysMLRepositoryLoadUtil(
7785
cli.hasOption(repositoryOption)? cli.getOptionValue(repositoryOption) : "http://localhost:9000",
78-
cli.getOptionValue(projectOption),
86+
cli.hasOption(projectNameOption)? cli.getOptionValue(projectNameOption) : cli.getOptionValue(projectIdOption),
7987
cli.getOptionValue(targetOption),
8088
new File(cli.getOptionValue(localLibrary))
81-
);
89+
).setIsReferencedById(cli.hasOption(projectIdOption));
8290
}
8391

8492
private final String repositoryURL;
85-
private final String projectName;
93+
private final String project;
8694
private final String targetLocation;
8795
private final File localLibraryPath;
96+
private boolean isReferencedById;
8897

89-
public SysMLRepositoryLoadUtil(String repositoryURL, String projectName, String targetLocation, File localLibraryPath) {
98+
public SysMLRepositoryLoadUtil(String repositoryURL, String project, String targetLocation, File localLibraryPath) {
9099
super();
91100
this.repositoryURL = repositoryURL;
92-
this.projectName = projectName;
101+
this.project = project;
93102
this.targetLocation = targetLocation;
94103
this.localLibraryPath = localLibraryPath;
95104

@@ -99,7 +108,8 @@ public SysMLRepositoryLoadUtil(String repositoryURL, String projectName, String
99108

100109
public void load() {
101110
ProjectRepository projectRepository = new ProjectRepository(repositoryURL);
102-
RepositoryProject repositoryProject = projectRepository.getProjectByName(projectName);
111+
RepositoryProject repositoryProject = isReferencedById? projectRepository.getProjectById(project):
112+
projectRepository.getProjectByName(project);
103113

104114
if (repositoryProject == null) {
105115
System.err.println("Project does not exist.");
@@ -129,4 +139,9 @@ public void load() {
129139
e.printStackTrace();
130140
}
131141
}
142+
143+
public SysMLRepositoryLoadUtil setIsReferencedById(boolean referencedById) {
144+
this.isReferencedById = referencedById;
145+
return this;
146+
}
132147
}

0 commit comments

Comments
 (0)