This project contains a version of the app generated by Apache Isis' simpleapp archetype, but converted to use the isis-script DSL developed by Torsten Juergeleit.
Isis Script DSL is implemented with xtend and so provides a plugin for Eclipse IDE. It is also possible to build the app from the command line using Maven.
Here’s the SimpleObject
domain class, written in isis-script:
@PersistenceCapable(identityType=IdentityType.DATASTORE, schema="simple", table="SimpleObject")
@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="id")
@Version(strategy=VersionStrategy.VERSION_NUMBER, column="version")
@Queries(#[
@Query(name = "find", language = "JDOQL",
value = "SELECT FROM domainapp.dom.modules.simple.SimpleObject"),
@Query(name = "findByName", language = "JDOQL",
value = "SELECT FROM domainapp.dom.modules.simple.SimpleObject WHERE name.indexOf(:name) >= 0")
])
@Unique(name="SimpleObject_name_UNQ", members = #["name"])
@DomainObject()
@DomainObjectLayout(bookmarking = BookmarkPolicy.AS_ROOT, cssClassFa = "fa-flag")
entity SimpleObject {
@Column(allowsNull="false", length = 40)
@Title(sequence="1")
@Property(editing = Editing.DISABLED)
property String name
@Property(optionality=OPTIONAL)
property Integer count
@Action(domainEvent = UpdateNameDomainEvent)
action SimpleObject updateName {
@Parameter(maxLength = 40)
@ParameterLayout(named = "New name")
parameter String newName {
default {
getName
}
}
body {
setName(newName)
this
}
validate {
if (newName.contains("!"))
TranslatableString.tr("Exclamation mark is not allowed")
else null
}
event UpdateNameDomainEvent
}
title {
TranslatableString.tr("Object: {name}", "name", name)
}
}
By way of comparison, the original Java version is:
@PersistenceCapable(identityType=IdentityType.DATASTORE, schema="simple", table="SimpleObject")
@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="id")
@Version(strategy=VersionStrategy.VERSION_NUMBER, column="version")
@javax.jdo.annotations.Queries({
@javax.jdo.annotations.Query(
name = "find", language = "JDOQL",
value = "SELECT FROM domainapp.dom.modules.simple.SimpleObject "),
@javax.jdo.annotations.Query(
name = "findByName", language = "JDOQL",
value = "SELECT FROM domainapp.dom.modules.simple.SimpleObject WHERE name.indexOf(:name) >= 0 ")
})
@javax.jdo.annotations.Unique(name="SimpleObject_name_UNQ", members = {"name"})
@DomainObject
@DomainObjectLayout(bookmarking = BookmarkPolicy.AS_ROOT, cssClassFa = "fa-flag")
public class SimpleObject implements Comparable<SimpleObject> {
public TranslatableString title() {
return TranslatableString.tr("Object: {name}", "name", getName());
}
private String name;
@javax.jdo.annotations.Column(allowsNull="false", length = 40)
@Title(sequence="1")
@Property(
editing = Editing.DISABLED
)
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public static class UpdateNameDomainEvent extends ActionDomainEvent<SimpleObject> {
public UpdateNameDomainEvent(final SimpleObject source, final Identifier identifier, final Object... arguments) {
super(source, identifier, arguments);
}
}
@Action(domainEvent = UpdateNameDomainEvent.class )
public SimpleObject updateName(
@Parameter(maxLength = 40)
@ParameterLayout(named = "New name")
final String name) {
setName(name);
return this;
}
public String default0UpdateName() {
return getName();
}
public TranslatableString validateUpdateName(final String name) {
return name.contains("!")? TranslatableString.tr("Exclamation mark is not allowed"): null;
}
public Long getVersionSequence() {
return (Long) JDOHelper.getVersion(this);
}
@Override
public int compareTo(final SimpleObject other) {
return ObjectContracts.compare(this, other, "name");
}
@javax.inject.Inject
@SuppressWarnings("unused")
private DomainObjectContainer container;
}
The most obvious difference is that the DSL includes keywords such as action
, under which all the supporting methods are gathered. In contrast, the Java version has to group related methods together by naming convention (updateName(…)
, validateUpdateName(…)
and default0UpdateName()
).
Full details of the isis-script DSL can be found on the github repo
In addition, the body of isis-script methods are written in XTend, which provides a whole host of features over and above vanilla Java.
As Torsten’s blog post shows, isis-script includes an Eclipse plugin. This provides:
-
automatic generation of Java code from isis-script
-
syntax highlighting
-
intellisense
-
markers
-
outlining
Currently isis-script is still in development, so you’ll need to build it locally. It’s pretty easy to do, though.
Clone the isis-script
repo, and build using mvn:
git clone https://github.com/vaulttec/isis-script.git
git checkout develop
mvn clean install
All being well the code should run compile (I built using commit 9c31ad52f6995e1af9dd75f4668d67ee2f3d04cb
, Sept 2015):
Note
|
Do be aware, though: the first time I did this took about an hour (albeit on a moderately slow network). Thereafter it takes about 1 minute to recompile. |
Download Eclipse (the vanilla Java edition will suffice).
Then install plugins using Help > Install Software
:
-
the isis-script plugin, at https://raw.githubusercontent.com/vaulttec/isis-script/updatesite/
-
the datanucleus plugin, at http://www.datanucleus.org/downloads/eclipse-update/
Clone this repo:
git clone https://github.com/isisaddons/isis-app-simpledsl
I also recommend you build this from the command line before importing into Eclipse:
mvn clean install
This should ensure that all the generated directories exist when we do the import.
Import the project into Eclipse using File>Import
:
then Maven > Existing Maven Projects
:
then select the source:
when done the source code should be shown in the package explorer:
The source file is shown in an "Isis editor":
The editor’s context menu can be used to navigate to the corresponding generated (Java) source:
The corresponding member is automatically highlighted:
And from the generated Java you can also navigate back to the source:
Next, configure DataNucleus plugin as per the instructions on the Apache Isis website
Note the persistent-unit
name in the manifest:
Open up the dom
project properties:
and specify this persistence unit for the enhancer plugin:
Finally, back on the dom
project’s context menu, enable auto-enhancement:
Let’s take a quick look at the features available in the editor. To start with, the editor provides context sensitive intellisense:
There’s also a quick outline view (ctrl+O
), great for quick navigation:
The outline is also available as a view:
Finally, any syntax errors are shown as markers and also in the problem view:
You should be able to run the app either from Eclipse IDE, or from the command line.
To run within Eclipse, you’ll find that the webapp/ide/eclipse/launch
directory contains some .launch
configurations. These are set up to run Isis' org.apache.isis.WebServer
(which bootstraps an embedded Jetty server).
You can run the app from the context menu of one of these .launch
files:
and the console shows the app starting:
Browsing to http://localhost:8080/wicket should hit the sign-in page (login sven/pass
):
and you can then use the app as normal:
You can also build and then from the command line. To build:
mvn clean install
and to run use either:
mvn jetty:run
or if you prefer a splash screen:
mvn -P self-host antrun:run