Pages

Showing posts with label lego mindstorm. Show all posts
Showing posts with label lego mindstorm. Show all posts

Saturday, September 6, 2014

Atlassian Lego Jira plugin development: simple multi-functional plugin with services (Lego,RaspberryPi, Netty)

   Not so long time ago I've been doing  small presentation about how to create various plugins into  the Alassian ecosystem, mainly Jira and Confluence. I want to share some step how to deal with plugin that aggregates more functionalities (CRUD Servlet with Services, Project Template and REST api). 
One of the issue here is the version of the Atlassian libraries you will use for your development. Reason is obvious, compatibility and another repositories. So let's take a look on maven descriptor file pom.xml. 
...

    
      jfrog
      http://repo.jfrog.org/artifactory/libs-releases
    
    
      atlassian-public
      https://maven.atlassian.com/repository/public
      
        true
        never
        warn
      
      
        true
        warn
      
    
  
...

    5.0.4
    6.1.7
    2.5.0
    3.0.0-m24
    2.7.1
    2.18
    

    4.3.5
    2.1

    
    1.0-SNAPSHOT
    
    4.11
    1.8.5

...
  The nice thing on the plugin development is testing of all parts during the process. Atlassian provides some testing libraries (ex. jira-tests or jira-func-tests) in additions with others (harmcrest matcher, mockito, junit etc...) 
Img.1.: heart of the plugin -> descriptor file -> atlasssian-plugin.xml
The most important of the plugins is the heart (Img.1.) represented by descriptor file. 

  
    ${project.description}
    ${project.version}
    
    images/pluginIcon.png
    images/pluginLogo.png
  
  

  
    The LEGO CRUD Issue Plugin
    /issuecrud
  

  
  
  

  
  
    Lego CRUD Resources
    com.atlassian.auiplugin:ajs
    com.atlassian.auiplugin:jquery

    
      
    

    

    
    
    

    atl.general
  

  
    com.example.plugins.tutorial.servlet.LegoBrickService
  

  
  
    Provides Lego Brick services.
  

  
  
    

It shows which technologies (Soy ~ Google Closure, Blue-prints, Velocity ...) we use inside the plugin and which parts of jira core services we employ to make the plugin work according what we are expecting from it:
Img.2. - add1.: Lego Project Template is INSIDE like Intel
1. Lego project template (Img.2., Img.3.)
2. Lego Issue tracker 
3. Lego REST API 
Img.3. - add1.: Lego Template is there with Customised workflows and Issues
Add1.:: From the descriptor file we can read that for the template we do use Soy file. Closures allows us to dynamically generates the web page content
{namespace JIRA.Templates.ProjectLegoTemplates.Lego}
...
{template .renderLegoProjectTemplateExplanation}
    {getText('lego.project.template.info.page.description')}


    ...
    
  • {getText('lego.project.template.reason.1')}
  • {getText('lego.project.template.reason.2')}
  • {getText('lego.project.template.reason.3')}
... {/template} ...
and together with all messages having stored in property files makes internationalisation process latter much more easier. The whole project workflow together with issues is defined by *.json file
{
    "issue-type-scheme":
    {
        "name": "lego.project.template.issuetype.scheme.name",
        "description": "lego.project.template.issuetype.scheme.description",
        "issue-types": [
            {
                "key": "issueType1",
                "name": "New Lego Feature",
                "description": "A new Lego JSON feature of the product, which has yet to be developed.",
                "icon": "/images/icons/newfeature.png",
                "workflow": "wf1"
            },
            ...

    },
    "workflow-scheme":
    {
        "name": "lego.project.template.workflow.scheme.name",
        "description": "lego.project.template.workflow.scheme.description",
        "default-workflow": "wf1",
        "workflows": [
            {
                "key": "wf1",
                "name": "lego.project.template.workflow.wf1.name",
                "workflow-bundle": "/wfb/Issue-Tracking-Workflow.jwb"
            },
            ...
...
and the project is hooked with the JIRA system by using Blueprints API. Specifically implementing the interface AddProjectHook with @Overriden methods validate and configure .  
...
public class LegoProjectHook implements AddProjectHook {
    ...
    @Override
    public ValidateResponse validate(final ValidateData validateData) {
       ...
    }

    @Override
    public ConfigureResponse configure(final ConfigureData configureData) {
       ...
    }
...

  The result looks pretty cool because now we have inside the JIRA official Lego Project with its own issues and flows how to solve them. We can also track whole development. 
Img.4.: Lego Project inside the JIRA 
Add2.:: Lego issue tracker. 
   For those who has experiences with Lego MindStorm EV3 Java/Scala development it's nothing new to get an issue. The tracker is represented by the simple servlet that handles 
Img.5.:: Lego Issue Tracker
GET and POST request and allows to share the issue with others (Img.5). 
Img.6.: Velocity templates for LegoIssueTracker
   For generating the Lego issue tracker front-end (Img.6.) we use Velocity server-side template language. 
In side every template file (edit.vm, list.vm or new.vm) is possible to employ JavaScript to make for example cross-domain JSONP calls and get information from another resources (in my case RaspberryPi powered by Netty)
example: new.vm or edit.vm
...
function getRaspData(){
  jQuery.ajax({
    url: 'IP_ADDRESS',
    dataType: 'JSONP',
    jsonpCallback: 'callback',
    type: 'GET',
    success: function (data) {
      ...
      jQuery('input[name="ip"]').val(data.ip);
    }
  });
}
...
AJS.$(document).ready(function() {
   jQuery('.button-rasp').click(function() {
      console.log('RASP PI');
      ...
      getRaspData();
   });
});
...
...
...edit.vm - Velocity template language ...
...
<h1> Edit Lego issue $issue.getKey()</h1> #if ($errors.size()>0) ...
Now we are ready, according to the atlassian descriptor file, to create the Servlet implementaiton:
public class IssueCRUD extends HttpServlet {
    ...
    private static final String PLUGIN_STORAGE_KEY = "com.example.plugins.tutorial.servlet.lego";
    private static final String NO_IP_MESSAGE = "No IP Setup";
    ...
    private IssueService issueService;
    private ProjectService projectService;
    private SearchService searchService;
    private UserManager userManager;
    private TemplateRenderer renderer;
    private LegoBrickService legoBrickService;
    private static final String LIST_BROWSER_TEMPLATE = "/templates/list.vm";
    private static final String NEW_BROWSER_TEMPLATE = "/templates/new.vm";
    ...
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ...
    }
    ...
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ...
        User user = getCurrentUser(req);
        ...
     }
 ... 
After short coding session we have prepared also LegoIssue sending functionality 
Img.7.:: send the 1st Lego Issue to the LEGO project
The REST API in JIRA is power by JAX-RS - Jersey. It's easy to expose. Let's move back to the Atlassian descriptor file and define the access path. The whole work is then strait forward in our example:Add3.:: Lego REST api 
@Path("/")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public class RestLegoService {
…
   public RestLegoService(PluginSettingsFactory pluginSettingsFactory) {
        this.pluginSettingsFactory = pluginSettingsFactory;
    }
   @GET
   @Path("brick")
   public Response getLegoBrick() { 
   …
In the end we get appropriate JSON response by accessing the defined path. 

I hope this blog post helps in way to get a basic idea how to deal with Atlassian plugin development. In my case I don't want to use it as the reminder what I have done :)
Enjoy!
PS: I've used IntelliJ IDEA 13.x and SourceTree    
  

Monday, July 21, 2014

Lego Mindstorm EV3 -> Java8, LeJOS and Gradle with taste of Maven

Img.1. - Let's turn on the LegoBrick again and make remote project based on Gradle
The previous post about Lego MindStorm EV3 has been focused on its installation. I've touched how to install JavaJDK setup Wifi on LegoBrick + small sample "hello world" project.
This blog post is about setting up little more advanced project.

The simple HelloWorldGradle Remote project uses:
The legoBrick, connected to the WiFi, is possible to access remotely without problem using Java Remote Method Invocation, shortly RMI.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);
ev3Brick.setDefault();
Before we start working on the sample source code we create Gradle project. We can randomly choose the project as HelloWorldGradle. Important is to setup Gradle property file "build.gradle" correctly
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
version = '1.0'
repositories {
    mavenCentral()
    mavenLocal()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'lejos:ev3classes:1.0-SNAPSHOT'
    compile ('log4j:log4j:1.2.17'){
        exclude group: "com.sun.jdmk", module: "jmxtools"
        exclude group: "javax.jms", module: "jms"
        exclude group: "com.sun.jmx", module: "jmxri"
    }
    compile 'org.slf4j:slf4j-log4j12:1.7.5'
}
jar library "ev3classes" is very important!
This library creates the gateway into the lego hardware by using RMI because EV3 acts as the RMI Registry. You need to create it by yourself.
lejos
  ev3classes
  jar
  1.0-SNAPSHOT
  
    
      lejos
      dbusjava
      1.0-SNAPSHOT
    
    
      net.java.dev.jna
      jna
      3.2.7
    
  
  
    ${basedir}/src
    ev3classes
    install
    
      
        maven-compiler-plugin
        ${maven.compiler.version}
        
          ${java.version}
          ${java.version}
        
      
      
        org.apache.maven.plugins
        maven-jar-plugin
        ${maven.jar.version}
      
      
        maven-assembly-plugin
        ${maven.assembly.version}
        
          ${project.build.finalName}-${project.version}.jar
          
            jar-with-dependencies
          
        
        
          
            make-assembly
            package
            
              single
            
          
        
      
    
  
This library can be created by maven with usage of maven-assembly-plugin. The final *.jar file can then easily imported into the local maven cache.
Now we are ready to remotely access our Lego MindStorm robot and in our case let him to play some short song.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);
            ev3Brick.setDefault();
            Audio soundProcessor = ev3Brick.getAudio();
            List tones = new ArrayList<>(asList(0,1,2,3,4,5));
            tones.forEach(tone -> {
                soundProcessor.systemSound(tone);
            });
The sample LejOS remote project HelloWorldGradle is available here (GITHub).
Enjoy !

Wednesday, July 2, 2014

Lego Mindstorm EV3 -> LeJOS installation

Img.1.: let's begin and rock (part of my toys)
I do believe that the default lego software for EV3 is pretty awesome ;) but my interest belongs to java virtual machine which implies installation of LeJOS. 

required:
1. download leJOS_EV3_0.8.1-beta.tar.gz (last available)
2. download Java for Lego Mindstorm EV3 = ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014.tar.gz
3. 6 x AA Batteries 1.5V - rechargeable -> almost green energy

Let's prepare LeJOS SD card for the mission:
1. from the manual:  card must be bigger than 2GB and FAT32 
2. unpack leJOS file -> go to the folder -> copy the lejosimage.zip file to the SD Card
3. unpack lejosimage.zip
4. copy downloaded Java SE file to the CD-Card (SD Card root)
5. put SD-CARD to the Lego Brick and finally startup

To work with LeJOS comfortably is required to have WiFi connection via dongle (Img.2.). 
Then is possible to deploy directly for the IDE (IntelliJ IDEA 13.x in my case) to Lego Brick. 

Img.2.:: supported NetGear N150 USB Wireless Adapter
Prepare Wifi Connection:
1. Boot Brick and select Control -> Wifi -> select network with WPA2 
Img.3.:set the wifi password
2. Create a sample maven program (how to will be the topic of the next blog post)
Img.4.: favorite IDE IntelliJ IDEA 13.x with Maven Lego Project inside and upload command
for those who want to use maven directly for the deployment they need to configure maven-antrun-plugin

So now we have Lego Mindstorm EV3 ready for read development and sensors usage... 

  1. HelloWolrdGradle Remote Hardware usage example project
  2. more is coming soon...