From the grounds up, your Maven powered Alfresco dev box

mint alf mvn

The target

To start your Alfresco development experience, you need a development environment. Let’s say you’re more into this Maven and you’d rather leverage its capabilities instead of using the default ant based build system provided along with the SDK. In this tutorial, I’ll guide you through the process of setting up from scratch your development environment. And by saying “from scratch”, I really mean it: we’ll start from a fresh installed Linux box and the we will add piece over piece until we’ll be see the Alfresco flower on our browser. This will be a *basic* tutorial, just to put in place the foundation for later improvements.

I’m actually performing these steps in a virtual machine, so that next time a quick&dirty Alfresco PoC is required I might use this very same VM to start right away from a known, dev ready point.

UPDATE: the Maven project structure I end up with at the end of this article can be downloaded directly from GitHub.

Operating System

Ok, I assume you know your stuff and don’t want to get a bore-some lesson on how to install Linux. The whole internet is polluted by billions of guides and tutorial since 199x, anyway, so let’s just say I just completed the install process of Mint7 and I’m at my very first login. I would go for Mint8 if my current connection was fast enough to download it before I finish writing these notes, but whatever, there’s nothing really bad in v7.

Tools

The shopping list here includes a JDK, Maven and… well, that should be it, theoretically. Unfortunately, due to a nasty regression, we’re going to need a db. My choice goes to MySQL.

MySQL

First thing first, let’s install it:

~$ sudo apt-get install mysql-server

When this is done, we have to create the db Alfresco is going to use:

~$ mysql -u root
mysql> CREATE DATABASE alf_jetty;
mysql> GRANT ALL ON alf_jetty.* TO 'alfresco'@'%' IDENTIFIED BY 'alfresco';

Username and password are the default for the maven stuff we’re going to use.

Java

Java™ 5 has already passed on, let it rest in peace. Instead, go and install Java™ 6:

~$ sudo apt-get install sun-java6-jdk

Maven

Hold on the temptation of installing Maven 3 or to ask apt-get to do this task for you. We’re going to the official download page and following the links to get the latest stable 2.x release. You should end up with something like apache-maven-2.2.1-bin.tar.bz2 on your file system. Then do the following:

~$ cs /opt
~$ sudo tar xvjf apache-maven-2.2.1-bin.tar.bz2
~$ sudo ln -sfv /opt/apache-maven-2.2.1/bin/mvn /usr/bin/mvn

There are less intrusive ways to bring your downloaded application into your PATH, but this is the quickest possible. Let’s go on to the next step.

Plumbing

We’re almost there, we just have to lay down our projects. Let’s start with the Alfresco repo extension:

~$ mkdir -p development/alfresco-showcase
~$ cd development/alfresco-showcase
alfresco-showcase$ wget http://download.skuro.tk/alfresco-showcase/pom.xml
alfresco-showcase$ mvn archetype:generate -DarchetypeGroupId=com.sourcesense.alfresco \
 -DarchetypeArtifactId=maven-alfresco-extension-archetype \
 -DarchetypeVersion=1.9.1 \
 -DgroupId=it.sk.alfresco \
 -DartifactId=alfresco-showcase-extension \
 -Dversion=1.0-SNAPSHOT \
 -DarchetypeRepository=http://maven.alfresco.com/nexus/content/repositories/releases \
 -DinteractiveMode=false

The POM I’m making available here is just a very basically one, I’m using it here just for you to speed up the process.

UPDATE: as others pointed me out, it looks like you somehow need to download such a pom for the whole thing to stand up. That’s simply not true, I’m just building a more complex dev environment and it’s better if we have some structure in place. This includes having a parent project, along with its parent pom, with nested projects registered as its modules. These will come in the next posts. But that’s just part of the reason for this pom to be here: I also tend to be lazy, so that letting you download it was easier than explaining myself. Note to self: thou shalt not post anything at 2am.

First achievement

Ok, let’s stop here now and see what we’ve done by now. Go to the alfresco-showcase folder and type:

alfresco-showcase$ MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m" \
 mvn clean install -Prun

This will start a local jetty instance where Alfresco 3.2 community will be deployed. So, if you now point your browser to http://localhost:8080/alfresco you will finally see that flower we talked about at the beginning of this post.

Next steps

That’s it for now, but other blocks are still missing: what about AMPs? And WCM? And does Share fits in the picture? I’ll cover all the points in the next episodes of this series. See you there!

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Alfresco ACL on WCM WebForms, an howto

When it comes to setting up an Alfresco WebProjects, you configure it to make use of a set of WebForms already available on the Alfresco repository. From that moment on, every user with write rights on the web project will be able to pick one web form and push some content through it into the AVM repository. But what if you want to forbid some users to actually make use of some web forms? The default Alfresco doesn’t present any GUI control that allows you to define web forms level ACLs, but in facts there’s a way to define them in an easy way, without the need of any real customization. Let’s see how to do that on the Alfresco WCM we setup in the previous chapters of this series.

The idea

So, we want to be able to relate web forms and users or groups, thus restricting access to web forms depending on your credentials. We want to configure a number of web forms to be available on the web project, while users will see only the ones they’ve access to when trying to create some contents, so that dropdowns and links will appear only when it’s appropriate. Moreover, we do not want to waste our time on custom code, we just want Alfresco to do its job.

The way we are going to address this requirement is through the use of real ACL setup configured on the web forms themselves, so that the Alfresco permission checks will be able to trim the list of available web forms to the users whenever they ask for create content. Sounds reasonable, right?

Bug!

As a disclaimer, I must say the proposed approach doesn’t work with a vanilla Alfresco3.2r because of a nasty bug that will throw Exceptions all over the place once you configured restrictive ACLs on web forms. Thanks to the OpenSource nature of Alfresco, and thanks to Brad Davis that provided a patch for it, we can just change the Alfresco source code and we’ll be able to go forward. While we wait for a real mavenized Alfresco, this involves having the Alfresco SDK properly installed on your system, apply the patch and upload it to your local maven repo. To ease your life, you can just go with this last step using this patched Alfresco WAR and type:

utopia-II:Downloads skuro$ mvn install:install-file -DartifactId=alfresco -DgroupId=org.alfresco -Dversion=3.2r -Dtype=war -Dclassifier=community-patched -Dfile=alfresco-3.2r-community-patched.war

After that you have to switch to this artifact in your alfresco-extension project’s pom dependencies.

Define the ACL

Now start up Alfresco and login as the admin. To prove the ACL effectiveness, we will need two users and one group. In the following I’ll assume the users are called bob and todd and the group, where only bob is listed, is called full-access.

Now go to the Company Home/Data Dictionary/Web Forms folder and open the property sheet of the article web form folder.

You’ll be now able to customize the permissions on this level by clicking on Manage Space users, that will bring you to the ACL managing wizard. Uncheck the Inherit Parent Space Permissions box and then click on Invite.., setting up the full-access group to have the Coordinator role.

Test it

We’re already done! Now, try to log in into Alfresco with the two users and verify that only bob can actually see the article web form appearing on the UI.

Conclusion

This technique allows for a whole lot of use cases, where different divisions are not allowed to author content of different types. The only drawback of this solution is that when you have more than one web project per Alfresco instance, and you want to reuse the web forms, you will need to setup different groups for the different web projects (this will almost always be the case, anyway) and do the ACL configuration twice. Not that big deal, of course, but the lack of any centralized ACL managing tool will make it harder to maintain the permissions schemes.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Are you good at Javascript? #1

javascript

I’m not, really. Still I’ve been debugging some JS code just to remember why I was not so excited in the past about the language: your code needs to cope with browser specific crap.

Now, are you good at Javascript? If so, without running it, have a look at the following code:

var array = [
    {
        key : 'value',
        foo : 'bar'
    },
    {
        key : 'eulav',
        foo : 'rab'
    },
];

for (var i = 0 ; i < array.length ; i++)
{
    console.log ("key -> " + array[i].key);
    console.log ("foo -> " + array[i].foo);
}

How many elements does the array variable holds?

That code actually hides an Evil™ syntax detail I discovered today. Now, since I’ve been recently approached by the viral ideas of somebody, I felt compelled to fully understand the above code (and the bug we worked together from which this example came out). So if you really want some hints about what the hell is this all about:

  • if you’re not running Microsoft IE7, chances are you’re not going to see anything weird in the console output :P
  • section 11.1.4 of the ECMAScript v3 spec tells you all you need to know about the array initializers

After all, I’ll be probably continuing to study this “suddenly-a-hot-chick” Javascript thing, hoping to find a better world where my eventual code will be living into than that I found in the old days.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter