cancel
Showing results for 
Search instead for 
Did you mean: 

Prefill data, rules and/or execute actions on Site Creation

iblanco
Confirmed Champ
Confirmed Champ
I'm developing a custom Site preset. I've already defined the preset and the "placeholders" for the future custom components and dashlets, as well as the "out of the box" ones required in the site. So far so good.

Now I would like some data and some behaviour or rules automatically applied to some of the folders in the Site when it is created. I've a couple of approaches on mind for solving the problem but I don't feel very confortable with them, and they do have some caveats. I wonder if there isn't a cleaner way to do it.

First approach
Site's main folders have property "{http://www.alfresco.org/model/site/1.0}sitePreset" so I could make a rule for /Company Home/Sites folder that fires when a folder with the id of my preset is created. Other different but similar approach would be defining a Behaviour that is attached to "{http://www.alfresco.org/model/site/1.0}site" type's creation. The former seems easier if the action to be executed is a script and the later seems easier if yout intend to fire heavy "Java" actions. The second approach also seems easier to "install" as I don't know a easy way to bootstrap a rule to an already existing folder (is it possible at all?).

Once the Java action or Javascript launches we could just copy the required data. Each component's folder does not exist until it is first time accesed, so we would probably have to create them, but not like normal folders but using the Site's service API, other ways the Site might become corrupt.
But… what about the content ? AFAIK there is not such a thing as the "Site Discussion API" or the "Site Blog API".

Copying normal cm:content to the document library is said to work, but what about discussions, blogs or wikis ? Would it be possible just to have a "template" and copy it in place ?

In order to make this right we could call the same API's that Share calls. Does it make any sense ? Could the repository itself "call itself" ?

Second approach
The second approach would be making an "invisible" dashlet appear in the Site's dashboard. The only use of the dashlet would be executing the required actions to prefill the Site's content as soon as it is executed. The main "advantage" here is that we are requesting at the "Share" site so we could use the "remote" object to call the required APIs and generate all the content.
This idea has severarl tricks or gotchats:

    We have to control if it is the first executio, maybe with an aspect set in the site folder or even better, if it is possible, by taking out the dashlet by itself after execution.
    The dashlet would probably appear as an option to the person customizing the site.
    This smells like a really really really nasty hack
Buff, it's been a long post…. So… What do you think ? Does any of those approaches sound reasonable to you ?
10 REPLIES 10

zbennett
Champ in-the-making
Champ in-the-making
Hi iblanco,

I'm running 3.3, but I'm looking to do the same thing.  Have you found good documentation on creating new presets?  I've been staring at presets.xml, slack-jawed and not sure what to do with it.

As for your proposed approaches… Your first approach makes the most sense to me and your second approach does smell like a dirty hack.

What do you think about creating a private site and making sure the required folders exist in there (ie, discussions, etc…), then applying a rule to folders created in the main Sites folder that executes a script?  The script could copy the desired folders from your template site into the newly created site.

I'm just about to leave the office for the day, but I'll try this approach tomorrow and I'll post my results!

stevegreenbaum
Champ in-the-making
Champ in-the-making
I like your first approach. You've hit on a topic that I have also been giving some thought to, but I have been holding off on digging in since I've seen references in the roadmap to the inclusion of site templates - Q211.  I can live without this feature for now, so I have the option of waiting.  If you have wants/needs in this area that aren't covered by what is mentioned below you might want to get that entered into Jira for consideration.    This is from the roadmap wiki:

Site/Space Templates

Simplify creation of application specific sites and spaces and enforce standards though site and space templates. Create Sites based site templates to allow sites to include predefine spaces, content and rules. Allow spaces in the document library to be created from space templates that include other spaces, content, rules etc.

iblanco
Confirmed Champ
Confirmed Champ
Hi both,

I have developed the first approach. I made a behaviour that hooks to the creation of a site and at execution time it checks the preset. If the preset is not the desired one it just skips execution.

The behaviour configuration bean receives several parameters mos notably the preset name, that is checked on creation time and an action. I wanted the behaviour to be generic and reusable so I decided not to put in it what to do on creation time, instead it gets a "standard" Alfresco action.

So now I can develop Java actions and hook them using configuration, or use an already existing action or even better, hook the ScriptActionExecuter passing a script location to it, so I can execute a javascript executed in the claspath. I had some problem with this las step but I managed to achieve it.

Then I have created a script that fills some discussions topics and creates and fills a new datalist on creation time. It seemed quite complex at first as each application (discussions, datalist…) is differente from each other but by checking with Firebug the scripts Share itself calls I managed to find "the correct way" of doing its thing. Using the Alfresco Javascript Debugger in the repository, and looking to share code also was key, as I was able to inspect the siteService object and discover some API calls that are not present or correct in the wiki yet, for example getContainer does not seem to create a container if it does not exist, but you can check for existence with hasContainer and create it with createContainer.

Obviously having a prefilled site template would be a nicer option, and probably easier to maintain but for now I'm reasonably happy with the solution.

The idea of the rule in Company Home/Sites sounds good also and easier, but how is a rule bootstrapped from the classpath ? Sure there is an option but I'm not very experimented with this part of Alfresco.

Concerning documentation about defining a predefined site template, I used the Professional Alfresco. The book is not as good as I expected from the people in Alfresco Company but it was a quite good starting point for share, so although it's not a book you'll enjoy much it's at least worth the money. But don't take it as a complain about the book, we must admit that it is very very hard to write a better book about such a solution when it still is in fast evolution.

So far the best Alfresco development book I've read is Jeff Pott's Alfresco Developer Guide, but it doesn't talk about share, is older than that. I hope Jeff writes a second edition or a new book about share.

stevegreenbaum
Champ in-the-making
Champ in-the-making
Look at Alfresco Developer Guide - page 106 and 107 to see if that gives what you are looking for regarding deploying your rule action.

iblanco
Confirmed Champ
Confirmed Champ
Not really, that example registers and action and then sets a rule that runs that action, but doesn't solve the problem of setting the rule on extension's installation time.

stevegreenbaum
Champ in-the-making
Champ in-the-making
Sorry, I was referring to the line in the book saying use Ant Deploy script. I've never looked at those scripts, but I wonder if they contain what you are looking for.  There are supposed to be sample scripts that come with the book.

zbennett
Champ in-the-making
Champ in-the-making
Hi all,

I've accomplished much of this using JavaScript and rules. I wrote up some tutorials about it last week and posted them on a new blog. The tutorials include all of the code you need to accomplish what I've accomplished and they should be easy enough for anyone to follow (even non-programmer Alfresco newbies, for the most part).

Here are some links you may find useful:

How to add custom Site dashboard preset types to Alfresco Share: http://zandadev.com/zach/alf/?p=21
Creating a Site Template, Part 1: Folders, Files, and Rules: http://zandadev.com/zach/alf/?p=37

I plan to post more tutorials as I solidify the processes I develop, as the blog is going to serve as documentation for my current project.

stevegreenbaum
Champ in-the-making
Champ in-the-making
Thank you for posting this solution.

nikes
Champ on-the-rise
Champ on-the-rise
deep copy javascript function doesn't copy the permissions assigned to the source folder.

it was available in 3.1 community edition but not available in 3.3g.

I copied copyPermissons in CopyServiceImpl from 3.1 to 3.3g, now permissions are getting copied but Share manage permissions pop up shows default permissions only.

any idea why Share interface is not showing copied permissions?

thanks for any help.

@iblanco
I hope I haven't hijacked your post, since its related to custom site template solution 🙂
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.