Myti Blog

Dec 07

[video]

Jul 22

Liferay: Disable the IE Compatibility View

If Internet Explorer detects that a web page is not compatible, the address bar displays the Compatibility View button. When you turn on Compatibility View, the Web site open appears as if you were using an earlier version of Internet Explorer.
However, this is an emulation of an earlier version of Explorer, which creates additional display problems when compared with other browsers like Firefox and Chrome.

The solution to this problem is to disable the choice (sometimes automatic) browser by entering this meta tag

<meta http-equiv="X-UA-Compatible" content="IE=edge">


In Liferay , this meta is to be included as soon as the first command after <head> portal_normal.vm within the file that is located in the Templates folder of the theme used.

<head>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
 
<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.4.2.min.js”>
</ script>
<title> $ the_title - $ company_name </ title>
$ theme.include ($ top_head_include)
</ head>

Jun 24

Split svn repository into multiple repositories

Sometimes it appends that a project is divided in different sub project. Each one then, can earn ti’s own prioriry and become a full project.

If everything was stored into the same svn repository, how can you move away one directory of it without loosing all the commit history?

Here’s how :

1. create a dump from the repository

To create a dump file use the svnadmin dump command or your svn online service admin page.

svnadmin dump [my repo url] | gzip > dump.gz

2. check the first directory level

use this script to check the first directory level contained in your dump file

gzcat dump.gz | egrep -a "^Node-path" | cut -d '/' -f 1 | cut -d ':' -f2 | sort | uniq

3. split into multiple dumps

Now it’s time to split this. To achieve this we can use svndumpfilter.

Exec this line for every directory you want to separate

gzcat dump.gz | svndumpfilter include directory1 | gzip > dump_directory1.gz

You can even separate more than one directory per file

gzcat dump.gz | svndumpfilter include directory1 directory2 | gzip > dump_directory12.gz

4. import every dump into different repositories

gzcat dump_directory1.gz | svnadmin load [my new repo url 1]
gzcat dump_directory2.gz | svnadmin load [my new repo url 2]

May 31

NFC operating modes

In these days you should probably heard talking about NFC. Through Google’s new mobile payment method news, rumors which talk about up coming iPhone’s NFC functionality and so on.

NFC (Near Field Communication) is a short-range (< 5cm) wireless communication technology. Working in Myti I got some opportunities to implements several mobile applications which based on this technology. Here I’d like to describe one of the many things I learned during the implementation of those applications. It’s about operating (using) modes of NFC. According to specification it has three different operating modes.

The first mode is Read/Write Mode. This mode gives ability to read and write a passive RFID tag using NFC enabled divides. Common example of utility of this mode is smart poster which you can get more information/contents from those posters by swiping your mobile device over it .

The second mode is communication between two NFC devices (P2P Mode). Using this mode divides can exchange data between each other like virtual business cars or photos.

The last mode is Card Emulation Mode. These devices can emulate an existing contactless card which give a possibility to communicate with contactless reader for example to make a payment by swiping over a payment terminal.

But unfortunately these operating modes depend on device implementation. Not every device has all these modes. I got a possibility to work with three NFC enabled mobile phones and only two of them (Nokia 6212 classic and Nokia 6131 NFC) have all three modes. The other phone (Samsung GT-5230N) doesn’t have P2P mode implemented.

It’s important to know about what are the operating modes and which devices support them before you start your NFC project.

May 03

Creating a osx app bundle in Java registered to a protocol url

Recently we extended our enterprise search engine bleen adding a desktop utility automatically launched clicking on a result link.

To achieve this we created a native applciation ( for windows and osx ) registered to the protocol url bleen://

In this tutorial we will see how to build this utility in Java for Mac OS X.

The base code is a simple java class displaying a Dialog

Application bundle

Creating a OSX application bundle is as easy as creating a directory structure following some simple rules.

Out directory tree will contain :

The following is a ant tast that creates the dir tree.

	
<target name="application-bundle" depends="jar" description="create mac Os X Application bundle">	
	<mkdir dir="${dist.appbundle}/Contents/MacOS" />
	<mkdir dir="${dist.appbundle}/Contents/Resources/Java" />
	<copy file="${auxes.dir}/JavaApplicationStub" todir="${dist.appbundle}/Contents/MacOS" />
	<exec executable="chmod">
		<arg value="755" />
		<arg value="${dist.appbundle}/Contents/MacOS/JavaApplicationStub" />
	</exec>
	<copy file="${auxes.dir}/Info.plist" todir="${dist.appbundle}/Contents" />
	<copy file="${auxes.dir}/icon.icns" todir="${dist.appbundle}/Contents/Resources" />
	<copy file="${dist.dir}/application.jar" todir="${dist.appbundle}/Contents/Resources/Java" />
	<copy file="lib/libreria1.jar" todir="${dist.appbundle}/Contents/Resources/Java"/>
</target>	

The result is a directory tree viewed ad a application document by OSX.

URL protocol

The application runtime information are stored in info.plist file.

We edited this file inserting a couple of new keys. These keys link out app to the protocol demo://

Now, the system will launch our utility every time the user clicks on a link starting with demo://

To allow osx to know out utility exist we must :

OpenURL

Now we reached our target but we don’t use the clicked url in our code, yet. 

To use it, we must relay on a system event osx raises to ask applications to manage urls. We use an extension library provided by Apple, registering a handler to the OpenURI event. 

public static void main(final String[] args) {
	Application.getApplication().setOpenURIHandler(
		new OpenURIHandler() {
			@Override 
			public void openURI(final OpenURIEvent pEvent) {
				JOptionPane.showMessageDialog (
					null, 
					pEvent.getURI().toString(), 
					“demo”,
					JOptionPane.ERROR_MESSAGE);
		}
	});
}

Dependencies

Note that our dependencies jar must be located in Contents/Resources/Java and every jar must be declared in Info.plist under the keys Java/Classpath

Download

You can find a demo project download on our public space in Assembla - link

References

Handling URL shemes in Cocoa

JavaApplicationStub

AppleJavaExtensions

MRJAdapter - java library to enhance osx integration

Apple doc - References to the java info.plist keys

Apple doc - References to application bundles creations

Apple javadoc - Javadoc for Apple Java extensions

Apr 01

Benvenuto Tomson

Da oggi abbiamo un nuovo collega. Tomson è uno sviluppatore java, viene dal Camerun e la seconda laurea (!) l’ha presa alla facoltà di Ingegneria di Brescia. Tomson mangerà pane-grails-e-liferay per le prossime settimane.
Buon lavoro!

Feb 23

Cloud computing e Enterprise Search

In questo periodo di forte fermento della IT, tutta eccitata dall’avvento del Cloud, quali sono le prospettive a medio periodo di una applicazione di Enterprise Search, per sua natura funzionante in rete locale (in-premise)?

Credo che l’Enterprise Search sarà uno dei pochi ambiti di applicazioni Enterprise che otterrà vantaggi dal Cloud.

Innanzitutto dal punto di vista tecnico può permettere di ricercare tra informazioni in rete come anche residenti nella nuvola.

Qualunque altra applicazione standard, non di nicchia, venduta nel mercato delle applicazioni in-premise si troverà davanti ad una esplosione di fornitori on-demand, del tutto comparabili dal punto di vista delle funzioni, con il vantaggio di approcci commerciali innovativi ed aggressivi.

Un gestionale commerciale qualsiasi (fatture, ordini bolle tc) avrà come concorrenti applicazioni di vari fornitori di tutto il mondo che si offrono cloud con prezzi a utente più bassi e nessun costo di infrastruttura.

Questo però non porterà alla completa distruzione del mercato delle applicazioni in-premise. Si avrà una “dispersione” nella nuvola di tutti i servizi standard e che non creano valore aggiunto.
Gli altri resteranno:


In questo contesto un sistema di Enterprise Search Engine può fare da enabler di applicazioni Cloud. E ne prende tutti i vantaggi.

Bleen, ad esempio, si propone come sistema unico per accedere a tutte le informazioni aziendali. Per “accedere” intendo trovare ed usare.
“Usare ” significa agire sull’oggetto trovato in modo rispettoso della sorgente dati o in modo innovativo.

Un cliente mi ha chiesto: “Ho un problema che vorrei mi risolvesse Bleen. Mi capita spesso di dovere richiamare backup di file dai miei DAT perché gli utenti li cancellano o li alterano in modo errato. Perché non fate gestire le versioni a Bleen?”
Io ho risposto: “Comprati Egnyte (applicazione cloud based che tra le varie cose ti fa il backup dei file nella rete gestendo le versioni. www.egnyte.com), ha costi bassi a utente e a tera”
E lui: “Ma vorrei che l’utente fosse autonomo nell’estrarre le versioni”
E io: “Ti faccio il connettore per Egnyte così l’utente cerca in Bleen, trova il file e le versioni e da lì fa il download.  Una unica interfaccia per tutti i sistemi. Una sola metafora da spiegare all’utente per agire sui dati dell’azienda”

Feb 22

Ascii art in groovy

Giocando con groovy, ho scritto un semplice programma per trasformare un’immagine in “ascii art”.

(su gist trovate il codice completo)

Il programma è molto semplice: un ciclo recupera, per ogni pixel dell’immagine un intero (tramite il metodo image.getRGB) che rappresenta il valore RGB del pixel stesso.

Il metodo image.getRGB ritorna un unsigned integer nella forma AARRGGBB, quindi le istruzioni:

r = 0xff & (argb »16)

g = 0xff & (argb » 8)

b = 0xff & argb

servono naturalmente per recuperare i valori delle componenti R (rosso), G (verde) e B (blue).

Il valore massimo tra r, g, b è poi utilizzato per la scelta del carattere che rappresenta il pixel.

Naturalmente si possono pensare algoritmi più evoluti per la scelta del carattere, nonchè espandere il set di caratteri utilizzabili.

A titolo di esempio, questo è un fantastico ritratto del Venni trasformato in ascii art:

Cambiando le impostazioni del terminale si può anche ottenere il negativo :)

Feb 11

Leggere e denormalizzare una tabella con un campo XPath in Kettle

Lo step “Get Data From XML” di Kettle è decisamente versatile: ci permette, infatti, non solo di leggere e trasformare un file XML, ma ci consente anche di effettuare le medesime operazioni sfruttando un campo di una tabella, che usiamo come input. Come fare?

Innanzitutto, dovremo necessariamente alimentare il “Get Data From XML” con un “Table Input”:

Questa volta, la configurazione dello step sarà un po’ più complessa rispetto alla normale amministrazione, in cui viene alimentato da un file: in particolare, con questo disegno, non sarà infatti possibile che il sistema intuisca la struttura XPath che stiamo leggendo.

Per cui, dovremo prima specificare il campo di origine XML:

In seguito, andremo a definire il loop dell’XPath:

E, infine, i campi che andremo a generare tramite la denormalizzazione.

Anche in questo caso, non potremo sfruttare l’intelligenza del sistema nella definizione di questi ultimi (tramite la funzione “Preleva Campi”), ma dovremo specificarli manualmente.

Notate che, allo stesso modo, non avremo la possibilità di usufruire della funzione di anteprima contestualmente allo step, e non potremo fare altro che, prima, confermare le modifiche allo step, e, in un secondo momento, lanciare l’anteprima della trasformazione.

Un’ultima nota: personalmente, su Postgres, definire il datatype nel medesimo step (“Get Data From XML”) mi ha creato problemi, per cui, in un primo tempo, ho definito tutti i campi come String. In seguito, aggiungendo al flusso lo step “Select Values”, ho potuto alterare i datatype.

Mar 16

Grails portlets : eager fetching in service class

Developing portlets with Grails is great but there are still some issue to solve. Today I would talk about two problems related to GORM and Hibernate.

First: some GORM stuff works, while some others don’t and cause exceptions about the Hibernate session not being found.

For example, if we have a domain class like this:

class Car {
   Manufacturer manufacturer
   Engine engine
   Tyre tyres
   Integer seats
}

calling 

Car.get(id)

will works, but

Car.findByManufacturer()

won’t.

There are also different behaviours by calling this methods in the render phase or in the action phase.

Second: lazy load doesn’t work in .gsp views and portlet classes.

So writing

<label> ${car.manufacturer.name} </label>

cause an exception 

org.codehaus.groovy.runtime.InvokerInvocationException: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

and, of course, the portal isn’t able to render the page.

In summary, it turns out the problem is that the OpenSessionInViewFilter doesn’t work properly in a portlet environment.

I faced this problem a few days ago and I found this solution:

first of all, I suggest to put the code that use GORM in a service class and call the service method from the portlet class. That’s because service classes can get the hibernate session with no problems and use all of the cool dynamic methods for domain classes.

Then, that service method must use domain class dynamic methods with the fetch argument set to “eager”, so the model will be fully loaded.

Your renderView closure in the portlet class will look like this:

def renderView = {
   def cars = carService.loadAllCars()
   ['cars' : cars]
  }

and here is the service method:

def loadAllCars() {
   Car.findAll([fetch:[manufacturer:"eager", engine:"eager", tyres:"eager"]])
  }

Of course setting the fetch mode to eager leads into using fewer queries than the lazy mode, because the Car model and its associations will be loaded all at once. However, if you have many associations loaded with eager fetching you will have a lots of objects loaded into memory, so be careful and pay attention while designing your service methods.