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.

gsn_incontextof_sample

This is the instance diagram.

gsn_incontextof_instance

Goal, Context, InContextOf, etc. generalize ArgumentAsset.

gsn_incontextof_class

public IArgumentAsset getInContextOfTarget(IArgumentAsset argumentAsset) throws ClassNotFoundException {
    IFacet facet = AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
    IModule rootElement = facet.getRootElement(IModule.class);
    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.

gsn_argumentAsset_class

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 {
    IFacet facet = AstahAPI.getAstahAPI().getProjectAccessor().getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
    IModule rootElement = facet.getRootElement(IModule.class);
    return getGSNDiagrams(rootElement, new ArrayList<IGsnDiagram>());
}

public List<IGsnDiagram> getGSNDiagrams(IModule module, List<IGsnDiagram> gsnDiagrams) {
    for (IDiagram diagram : module.getDiagrams()) {
        if (diagram instanceof IGsnDiagram) {
            gsnDiagrams.add((IGsnDiagram) diagram);
        }
    }

    for (IArgumentationElement argumentationElement : module.getArgumentationElements()) {
        if (argumentationElement instanceof IModule) {
            getGSNDiagrams((IModule) argumentationElement, gsnDiagrams);
        }
    }

    return gsnDiagrams;
}

Get Solution presentation in Module presentation

Sample GSN Diagram:

gsn_module_nest_presentation

We can use INodePresentation.getChildren to get Strategy presentation in Module presentation.

public INodePresentation[] getChildrenStrategiesPresentation(IGsnDiagram gsnDiagram) throws InvalidUsingException {
    for (IPresentation presentation : gsnDiagram.getPresentations()) {
        IElement model = presentation.getModel();
        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.

Editting Model Viewpoint

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 {
    IModelEditorFactory modelEditorFactory = projectAccessor.getModelEditorFactory();
    GsnModelEditor modelEditor = modelEditorFactory.getModelEditor(GsnModelEditor.class);
    IFacet facet = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
    IModule module = facet.getRootElement(IModule.class);
    return modelEditor.createGoal(module, "Goal1");
}

Create a SupportedBy

// Transaction processing is required
public ISupportedBy createSupportedBy(IFacet facet) throws InvalidEditingException {
    IModelEditorFactory modelEditorFactory = projectAccessor.getModelEditorFactory();
    GsnModelEditor modelEditor = modelEditorFactory.getModelEditor(GsnModelEditor.class);
    IModule module = facet.getRootElement(IModule.class);
    IArgumentAsset source = modelEditor.createGoal(module, "Source");
    IArgumentAsset target = modelEditor.createStrategy(module, "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.

ProjectAccessor projectAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);

Create a GSN Diagrams

// Transaction processing is required
public IGsnDiagram createGsnDiagram() throws InvalidUsingException, InvalidEditingException {
    IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
    GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
    IFacet facet = projectAccessor.getFacet(IGsnFacet.FACET_SYMBOLIC_NAME);
    IModule module = facet.getRootElement(IModule.class);
    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 {
    INodePresentation parentNodePresentation = createNodePresentation(editor, module, location);
    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 {
    ProjectAccessor projectAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
    IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
    GsnDiagramEditor diagramEditor = diagramEditorFactory.getDiagramEditor(GsnDiagramEditor.class);
    diagramEditor.delete(gsnDiagram);
}

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