GSN
Get GSN facet model
All GSN models and presentations exist in the GSN facet Model which can be accessed by calling getFacet(String symbolicName)of ProjectAccessor.
public IFacet getGSNFacet(ProjectAccessor projectAccessor) throws ProjectNotFoundException {
return projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
}
Get Models and Presentations
Get Models
Relationship between ArgumentAssets
Let’s get an InContextOf from Goal to Context in the sample GSN diagram below.
This is the instance diagram.
Goal, Context, InContextOf, etc. generalize ArgumentAsset.
public IArgumentAsset getInContextOfTarget(IArgumentAsset argumentAsset) throws ClassNotFoundException {
= AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IModule.class);
IModule rootElement for (IArgumentationElement argumentationElement : rootElement.getArgumentationElements()) {
if (argumentationElement instanceof IInContextOf
&& ((IInContextOf) argumentationElement).getSource() == argumentAsset) {
return ((IInContextOf) argumentationElement).getTarget();
}
}
return null;
}
ID and Content of IArgumentAsset
This is the class diagram for Goal and Strategy, etc.
You can see ArgumentAsset is super class of Goal and Strategy.
public String getIdentifier(IArgumentAsset argumentAsset){
return argumentAsset.getIdentifier();
}
public String getContent(IArgumentAsset argumentAsset) {
return argumentAsset.getContent();
}
Get Diagrams and Presentations
Get GSN Diagram
public List<IGsnDiagram> getDiagrams() throws ClassNotFoundException {
= AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IModule.class);
IModule rootElement return getGSNDiagrams(rootElement, new ArrayList<IGsnDiagram>());
}
public List<IGsnDiagram> getGSNDiagrams(IModule module, List<IGsnDiagram> gsnDiagrams) {
for (IDiagram diagram : module.getDiagrams()) {
if (diagram instanceof IGsnDiagram) {
.add((IGsnDiagram) diagram);
gsnDiagrams}
}
for (IArgumentationElement argumentationElement : module.getArgumentationElements()) {
if (argumentationElement instanceof IModule) {
getGSNDiagrams((IModule) argumentationElement, gsnDiagrams);
}
}
return gsnDiagrams;
}
Get Solution presentation in Module presentation
Sample GSN Diagram:
We can use INodePresentation.getChildren to get Strategy presentation in Module presentation.
public INodePresentation[] getChildrenStrategiesPresentation(IGsnDiagram gsnDiagram) throws InvalidUsingException {
for (IPresentation presentation : gsnDiagram.getPresentations()) {
= presentation.getModel();
IElement model if (presentation instanceof INodePresentation && model instanceof IModule
&& "parent module".equals(((IModule) model).getName())) {
return Stream.of(((INodePresentation) presentation).getChildren())
.filter(child -> child.getModel() instanceof IStrategy)
.toArray(INodePresentation[]::new);
}
}
return new INodePresentation[0];
}
Edit Models and Presentations
In order to edit models or presentations using API, you need the transaction process. Also an exception will happen if:
The project is not registered in the project accessor or
The edition for the API is not correct or
target models/presentations you are trying to edit are non-editable
Edit model
Model Editor
The GsnModelEditor is to used when you edit GSN model with API.
For example, A SupportedBy can be created from GsnModelEditor.
If you edit a model that can have multiple presentations, you can create/edit from each Model Editor.
Model Editors | Model elements you can create in the Model Editor |
---|---|
GsnModelEditor | Goal,Strategy,Solution,Context,Justification,Assumption,Module,SupportedBy,InContextOf |
Create a Goal
// Transaction processing is required
public IGoal createGoal() throws InvalidEditingException {
= projectAccessor.getModelEditorFactory();
IModelEditorFactory modelEditorFactory = modelEditorFactory.getModelEditor(GsnModelEditor.class);
GsnModelEditor modelEditor = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IModule.class);
IModule module return modelEditor.createGoal(module, "Goal1");
}
Create a SupportedBy
// Transaction processing is required
public ISupportedBy createSupportedBy(IFacet facet) throws InvalidEditingException {
= projectAccessor.getModelEditorFactory();
IModelEditorFactory modelEditorFactory = modelEditorFactory.getModelEditor(GsnModelEditor.class);
GsnModelEditor modelEditor = facet.getRootElement(IModule.class);
IModule module = modelEditor.createGoal(module, "Source");
IArgumentAsset source = modelEditor.createStrategy(module, "Target");
IArgumentAsset target return modelEditor.createSupportedBy(source, target);
}
Edit Presentations
Diagram Editor
You will use GsnDiagramEditor to create, edit and delete presentations.
You can get GsnDiagramEditor by the way below.
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class); GsnDiagramEditor diagramEditor
Create a GSN Diagrams
// Transaction processing is required
public IGsnDiagram createGsnDiagram() throws InvalidUsingException, InvalidEditingException {
= projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
GsnDiagramEditor diagramEditor = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
IFacet facet = facet.getRootElement(IModule.class);
IModule module return diagramEditor.createGsnDiagram(module, "test");
}
Create a Justification presentation in Module presentation
// Transaction processing is required
public INodePresentation createNestNodePresentation(GsnDiagramEditor editor, IModule module, IJustification justification, Point2D location) throws InvalidEditingException {
= createNodePresentation(editor, module, location);
INodePresentation parentNodePresentation return editor.createNodePresentation(justification, parentNodePresentation, location);
}
// Transaction processing is required
public INodePresentation createNodePresentation(GsnDiagramEditor editor, IModule module,
Point2D location) throws InvalidEditingException {
return editor.createNodePresentation(module, location);
}
Delete GSN Diagram
// Transaction processing is required
public void deleteGSNDiagram(IGsnDiagram gsnDiagram)
throws InvalidUsingException, ClassNotFoundException, InvalidEditingException {
= AstahAPI.getAstahAPI().getProjectAccessor();
ProjectAccessor projectAccessor = projectAccessor.getDiagramEditorFactory();
IDiagramEditorFactory diagramEditorFactory = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
GsnDiagramEditor diagramEditor .delete(gsnDiagram);
diagramEditor}
Supported model / Presentation list
See Astah GSN API Structure details: GSN Overview in Javadoc
Supported Models
Model | Class | Get | Edit | Create Method |
---|---|---|---|---|
GSN / D-Case Diagram | IGsnDiagram | ✓ | ✓ | createGsnDiagram(IModule, String) |
Goal | IGoal | ✓ | ✓ | createGoal(IModule, String) |
Strategy | IStrategy | ✓ | ✓ | createStrategy(IModule, String) |
Solution | ISolution | ✓ | ✓ | createSolution(IModule, String) |
Context | IContext | ✓ | ✓ | createContext(IModule, String) |
Justification | IJustification | ✓ | ✓ | createJustification(IModule, String) |
Assumption | IAssumption | ✓ | ✓ | createAssumption(IModule, String) |
Module | IModule | ✓ | ✓ | createModule(IModule, String) |
SupportedBy | ISupportedBy | ✓ | ✓ | createSupportedBy(IArgumentAsset, IArgumentAsset) |
InContextOf | IInContextOf | ✓ | ✓ | createInContextOf (IArgumentAsset, IArgumentAsset) |
Presentation list
This is a list of Presentation in Astah. To find out which presentation is editable or not, please refer to the Astah API page.
GSN / D-Case Diagram
Type | Model | Presentation Type | Model:Presentation |
---|---|---|---|
Goal | IGoal | INodePresentation | 1:n |
Strategy | IStrategy | INodePresentation | 1:n |
Solution | ISolution | INodePresentation | 1:n |
Context | IContext | INodePresentation | 1:n |
Solution | ISolution | INodePresentation | 1:n |
Justification | IJustification | INodePresentation | 1:n |
Assumption | IAssumption | INodePresentation | 1:n |
Module | IModule | INodePresentation | 1:n |
SupportedBy | ISupportedBy | ILinkPresentation | 1:n |
InContextOf | IInContextOf | ILinkPresentation | 1:n |