GeoNetwork From Scratch I : The Phantom Catalog

This post was originally posted on the blog of a former company. But since they have decided to violate my authorship rights, here is a copy of it.

GeoNetwork, your friendly spatial catalog, never has been an easy software to deal with. But specially after the 3.0 version release, many things have changed. On this series of posts we will try to help new developers start with it.

GeoNetwork logo
The yoga man

The source code is available on a public repository on Github. This means that you can clone, fork and propose pushes of your custom changes. If you are not familiar with repositories of code or git, you should check this quick manual.

Continue reading “GeoNetwork From Scratch I : The Phantom Catalog”

What is GeoNetwork?

GeoNetwork is a server side application that allows you to maintain a geographic referenced metadata catalogue. This means: a search portal that allows to view metadata combined with maps.

GeoNetwork logo
The yoga man

Based on Free and Open Source Software, it strictly follows different standards for metadata, from Inspire to OGC. It implements the CSW interface to be able to interact with generic clients looking for data. It also has built-in harvesters to connect to other servers and populate data.

This has allowed GeoNetwork to expand to a lot of organizations. For example: the swiss geoportal or the brasilian one, not forgetting the New zealander. GeoNetwork is the most used open sourced spatial catalog in the world. You can find it in most of the public administrations that use free and open source software.

The catalogue deploys on a java application container (like tomcat or jetty). It works over the Jeeves framework. Jeeves is based on XSLT transformation server library. This allows a powerful development of interfaces, for humans (HTML) or machines (XML). Therefore, it makes metadata from GeoNetwork to be easily accessible by different platforms.

Recently half-refactored to Spring and AngularJS, GeoNetwork has a REST API and an event hook system to make extensions and customizations easier.

Annotations and Decorators in Java

Annotations on the code or decorators have become very common. They allow the programmer to add additional useful information about how to improve the code or change how to compile / run a particular class. They are a Java extension to allow aspect-oriented programming.

We have three types of annotations based on the moment of usage:

Information for the Compiler

These annotations allow the compiler to indicate whether or not to ignore errors and warnings or what to do with them. If you’ve worked with a Java IDE (like eclipse) probably you would have used this type of annotations. For example, you can use @Override on a function to indicate that you are overwriting a method defined on a parent class. 

This annotation is completely optional, but allows both the compiler and the developer to check that they are indeed overwriting existing hierarchical functionality.

For example:

public class Parent {     
    public void do(){
        System.out.println("Parent");
     }
}

public class Son extends Parent{     
    @Override
    public void do(){
        System.out.println("Son");
     }
}
Compiler-time and deployment-time processing

These annotations allow the compiler to add extra information about how to generate the code. By adding or modifying functionality from that in the source code you can alter how a class behaves. Also to create new classes (based on a file descriptor), etc …

These annotations will only be visible at this point. They are not compiled to the .class files. Therefore they are not available at runtime.

Runtime Annotations

You can use this annotations on runtime and they work on a very similar way as an interface.

Let’s see an example on how to create a Runtime Annotation and how can we use it. The annotation named MyAnnotation can be applied to elements oftype field:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
     public @interface MyAnnotation {
}

Now we can create an annotated class by this annotation:

public class myObject
 {
 @MyAnnotation
 public String field;
 }

This way, we can check by reflection if an object has an annotated field on any part of the code:

Class<?> res = objeto.getClass();
for (Field f : res.getFields()) {
     if (f.isAnnotationPresent(MyAnnotation.class)) {
          System.out.println("OK");
      }
}

More Information:

en_GBEnglish (UK)