using free and open source software in the geology space

Alfresco 5.0, SDK 2.1 and Field Photos

Introduction

This article might be of interest to you if you about to embark on creating a new content model for photos (or any other type of file) in Alfresco, and you want to get started quickly. If you have not already done so, though, you may wish to install Alfresco using a setup wizard first, to see how a fresh install of Alfresco handles photos. By default, when you upload photos, Alfresco will read EXIF data including latitudes and longitudes, and description, author, and a number of other fields. See http://docs.alfresco.com/community/concepts/download-community.html to download and install Alfresco using a set up wizard, and then experiment by uploading photos into the ‘My Files’ area.

If you need to add extra information fields to your photos (or any other file type), the SDK is the recommended way to customise Alfresco, and the RAD (rapid application development) feature of the Alfresco SDK 2.1 is very nice. Rather than going through a cycle where you make a few changes to configuration files, then compile, create .war’s/.amp’s, apply them, and restart your system – which can takes minutes each time – the RAD system detects when you save a config file, and then reloads components of the system relevant to that file – in seconds – allowing you to check the result of your change in the ‘Alfresco Share’ interface almost immediately.

This tutorial is for Mac OSX – it is an accurate record of setting up a MacBook Air with 4 GB of memory. You might be able to use the instructions for linux (eg. Ubuntu), also, with small modifications.

Preparation

It is important to have a nice clean install of the latest Java Development Kit (JDK) – not just a JRE – from Oracle. Preferably delete any old installations of java. At the time of writing the package was jdk-8u45-macosx-x64.dmg. Install this and test like so …

Correction kindly supplied by Douglas Paes ..
Instead of that, I had to include the property below into the alfresco-global.properties file:
ooo.exe=/Applications/LibreOffice.app/Contents/MacOS/soffice

Also, to enable thumbnails and previewing of photos, add the path to ImageMagick in /runner/target/tomcat/webapps/repo/WEB-INF/classes/alfresco-global.properties like so ..

objc[1420]: Class JavaLaunchHelper is implemented in both
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/libinstrument.dylib.
One of the two will be used. Which one is undefined.

.. it seems that this has no affect, so ignore it.

Set up MAVEN_OPTS environment string – add the following to ~/.bash_profile

An Aside: Proxy servers make life more difficult. If you are in an office, there is probably a proxy server between you and the internet. If you can avoid working behind a proxy server, then I suggest you do so. An example problem I have experienced is .. when opening http://localhost:8080/share, an error ‘INFO: Unable to retrieve License information from Alfresco: 400‘ appears in the log. When this happens, a login using the default credentials admin/admin fails. If you can’t avoid working behind a proxy server, ensure that your ‘Bypass Proxy’ list includes ‘localhost’ and ‘localhost:8080’.

Create and start up the SDK alfresco instance

chmod +x run.sh
./run.sh

Note that the first time you run this, about 1 GB of files (mainly JARs) will be downloaded, so this might take a long time. Subsequent times that you run this, it will take a few minutes. When run.sh displays the following line, the system is almost ready to use.

INFO: Starting ProtocolHandler ["http-bio-8080"]

After the above line appears, test the SDK Alfresco instance by browsing to http://localhost:8080/share and check that you can log in as admin/admin.

.. and then you can switch back to your browser at http://localhost:8080/share and test the change you have made. (We will do this in a following section.)

Time-saver – In Eclipse, hold down the Option(Alt) key while expanding a folder, and all sub-folders will be expanded – so that you can see ALL files in the sub-folders under that folder – don’t use this for a top-level folder, though – you can hang the system.

Important note about share-config-custom.xml

If share-config-custom.xml is located in its standard location .. /share-amp/src/main/resources/META-INF/
.. then changes made to it in Eclipse will not flow through the the SDK Alfresco instance on the fly.
If you move it in the following folder .. /share-amp/src/main/amp/config/alfresco/web-extension
.. then the rapid testing will work fine.https://github.com/Alfresco/alfresco-sdk/issues/299
(Later, when your development is finished, and you are creating a production AMP, you should move this file back to the META-INF folder.)

Create a field photo content model

Add the content below to /share-amp/src/main/amp/config/alfresco/web-extension/messages/custom.properties

type.gs_fieldphoto=Field Photo

This will allow you to change the type of an uploaded photo to ‘Field Photo’.

Add the content below to /repo-amp/src/main/amp/config/alfresco/module/repo-amp/model/content-model.xml
This defines the metadata fields for photos – this includes exif information.

Customize the ‘Edit Properties’ form

As mentioned above, move share-config-custom.xml from /share-amp/src/main/resources/META-INF/ to /share-amp/src/main/amp/config/alfresco/web-extension
Add the content below. This will order the fields on the Edit Properties form, puts the fields into 4 groups, and defines drop-down list values for 2 of the fields.

Test your system using Alfresco share

Click on the name of the photo to display a full view of the photo. To the right of the photo, choose ‘Change Type’ and choose ‘Field Photo’.

Click ‘Edit Properties’ – you should now see a list of all photo metadata fields grouped into 4 groups. Click ‘Cancel’ at the base of the properties form.

Click ‘View on Google Maps’ – note the location recorded by the phone is quite inaccurate – the photo was taken on the shore line. Note also that the iPhone 4S that took this photo only records longitudes and latitude to 4 decimal places. Alfresco stores the coordinates to 6 decimal places.

Experiment with /share-amp/src/main/amp/config/alfresco/web-extension/share-config-custom.xml and test the result in Alfresco Share – http://localhost:8080/share.

Lichen-covered rocks – west coast, Tasmania

Handy source code list command

The following shows a useful command to list only the files under the share-amp and repo-amp src folders. Run this from the top folder of your project – in my example this is ‘field-photos’.

Order of the Bee – an independent organisation of the Alfresco community. Web-site includes good technical and non-technical posts and other information, focussed mainly on Alfresco Community Edition (CE).