Saturday

Book Review : Alfresco 4 Enterprise Content Management Implementation



Last month,I got a review copy of this book from Packt Publishing and just finished reading.I would like to share my thoughts and opinions. Here I go.

The book starts with the chapter Introduction to alfresco which describes about alfresco architecture and its various components and products.Here the authors have also explained how can you get benefited from alfresco but they did not include topics like case management and contract management.

Chapter 2 focused about the alfresco installation in different operating systems.Good to see that the authors nicely explained about how to deploy alfresco bundle in tomcat.I believe it is very useful who are novice to alfresco.

Chapter 3 started with administration and few basic configurations about alfresco explorer user interface.Next chapter described about alfresco membership and security with how can you create users and groups using the above said UI.

Folder/content creation,library services (versioning,check in and check out),rules creation and management is introduced in next two chapters. Here the authors also clearly explained how an action can be scheduled using cron jobs.

Content modelling is introduced in chapter 7 which is a back bone of any DMS for managing metadata.This chapter well described different terminologies like type,aspects,associations and constraints related to alfresco content model.

Next chapter explained about both simple and advanced workflows. Here,The authors made a right choice to introduce activiti BPM frameworks. Advanced workflow creation and deployment using activiti with few examples are also well explained.

Basics of web script and its creation are available in next chapter. Nice to see the authors finally introduced alfresco share and administration in chapter 10. I thought alfresco share customization would have been introduced in very next chapter instead of alfresco explorer but that did not happen.

Search,search engines and its related basic configurations are described for alfresco explorer in next chapter.The last chapter explains about system monitoring and maintenance. Few tips related to data back up and upgrade to higher versions described here.

To conclude,I feel this book is the next version of Alfresco 3 Enterprise Content Management Implementation which is authored by all most the same authors.It is a bit surprising for me that the book is mostly focused on alfresco explorer and its basic customization instead of share. This book is basically about the installation,administration and few customization of alfresco explorer UI. The book is perfect for anyone who does not know alfresco at all and what alfresco can do for them.

How to create a custom header in share

To create a custom header in share server side , I follow this blog http://blogs.alfresco.com/wp/developer/2013/09/04/customizing-the-share-header-menu-part-1/ .

First of all, add the following lines of code  share-header.get.js.

Part-I ( Server side )

var myMenu = widgetUtils.findObject(model.jsonModel, "id", "HEADER_APP_MENU_BAR");
if (myMenu != null)
{

myMenu.config.widgets.push(
    {
      id: "HEADER_CUSTOM_MENU",
      name: "alfresco/menus/AlfMenuBarPopup",
      config: {
        label: "Custom Menu",
         widgets: [
                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu One"             

                     }
                 },

                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu Two"

                              }
                 },
                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu Three"
                    }
                 },
                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu Four"       

                          }
                 }
              ]      }
    }
  );  

// Add the client side menu creation snippet here
}

Put your share-header-get.js file in org.alfresco.share.header.custom-header folder
Don't forget to create your extension module

<extension>
   <modules>
      <module>
         <id>My CustomMenu</id>
         <auto-deploy>true</auto-deploy>
         <version>1.0</version>
         <customizations>
            <customization>
               <targetPackageRoot>org.alfresco.share.header</targetPackageRoot>
               <sourcePackageRoot>custom-header</sourcePackageRoot>
           </customization>
         </customizations>
      </module>
   </modules>
</extension>


The above snippet will add a menu called "Custom Menu" with four drop downs in header.

Part-I ( Client side )
Now we will try to create a header in client side as well ,like in share 4.2.c and prior versions.
So I ll create  the same menu in client side using dojo. Here I go. Add the below lines of code in share-header-get.js

myMenu.config.widgets.push(
    {
      id: "HEADER_CLIENT_SIDE_MENU",
      name: "alfresco/header/ClientSideMenu",
      config: {
                  label: "Client Side Menu",
              }
    }
  );


Create two javascript files called  ClientSideMenu.js ,ClientSideMenu-min.js and it should contain the following dojo snippets.

define(["dojo/_base/declare",
        "alfresco/header/AlfMenuBarPopup",
        "alfresco/core/CoreXhr",
        "dojo/_base/lang",
        "dojo/_base/array",
        "dojo/aspect",
        "dijit/registry",
        "alfresco/menus/AlfMenuGroup",
        "alfresco/header/AlfMenuItem",
        "alfresco/header/AlfCascadingMenu",
        "dojo/dom-style",
        "dijit/popup"],
        function(declare, AlfMenuBarPopup, AlfXhr, lang, array, aspect, registry, AlfMenuGroup, AlfMenuItem, AlfCascadingMenu, domStyle, popup) {
           return declare([AlfMenuBarPopup, AlfXhr], { 
              widgets: [
                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu Five"
                    }
                 },
                 {
                    name: "alfresco/header/AlfMenuItem",
                    config: {
                       label: "Menu Six"
                    }
                 }
              ],  
   });
});


This will create a menu called "Client Side Menu" along with two drop downs Menu Five and Menu Six. Here no need to add this js files in share-config-custom.xml file in order to manage the dependency as in share 4.2.c or prior. Those days now gone. That it!!

How to disable the rich text control in share using JS

I was trying with read-only="true" to disable the rich text control for meta data in share-config-custom.xml. But unfortunately it does not work for me. So I tried with the following code snippet to disable the cm:description field.

 var lookupObject = Alfresco.util.ComponentManager.find({name : "Alfresco.FormUI"});
 var me = lookupObject[0];
        var tinyInstance = Dom.get(me.parentId+'_prop_cm_description_ifr');
        var tinyToolBar = Dom.get(me.parentId+'_prop_cm_description_toolbargroup');
        tinyInstance.contentDocument.body.contentEditable = false;
        tinyToolBar.hidden = "true";

Dynamic List Constraints in Alfresco

In Alfresco Share, how do I populate the drop down values from a database. This is something possible using dynamic constraint. So here I go.

To achieve this you need to extend the "ListOfValuesConstraint" class which present in org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint package.

Step-1 (Extend the class):

package org.alfresco.diary.constraint;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import javax.faces.model.SelectItem;
import org.apache.log4j.Logger;


public class CustomConstraint extends ListOfValuesConstraint implements Serializable {

   private final Logger logger = Logger.getLogger(CustomConstraint.class);
   private static final long serialVersionUID=1;

   @Override
    public void setAllowedValues(List allowedValues) {
    }

    @Override
    public void setCaseSensitive(boolean caseSensitive) {
    }

   public void initialize() {
       super.setCaseSensitive(false);
       this.getDataFromDb();
    }

    protected void getDataFromDb() {

String driverName = "org.gjt.mm.mysql.Driver";
        String serverName = "localhost:3306";
        String dbName = "alfdiary";
        String userName = "alfdiary";
        String password = "alfdiary";

        List<String> allowedValue = new ArrayList<String>();

        try {
            Connection connection = null;
            Class.forName(driverName);
            String url = "jdbc:mysql://" + serverName +  "/" + dbName;
            connection = DriverManager.getConnection(url, userName, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select dropdowns from alfdiary");
            while (rs.next()) {
                allowedValue.add(rs.getString("dropdowns"));
            }
        }
        catch (Exception e) {}
super.setAllowedValues(allowedValue);
   }
}

Step-2 (Create Metadata Model):

Add the following configurations in your meta model.

<constraint name="alfdiary:dropDowns" type="org.alfresco.diary.constraint.CustomConstraint">
<parameter name="allowedValues">
<list></list>
</parameter>
</constraint>

Apply the above constraint to the metadata

Thats it!!!

Sunday

Uninstalling an amp module

Since it seems there is no certain ways to uninstall an amp module from alfresco, I tried with the following and its working fine. Though there is an uninstall command with alfresco-mmt.jar (as mentioned in alfresco wiki) but currently it is not supported.

1. Remove the current alfresco.war and share.war as required from your directory.
2. Rename your old .bak files to alfresco.war or share.war
3. Clean your temp/* and work/* files in case of tomcat
4. Restart the tomcat and see the changes.

There is another way to do this but it is very risk as it is recommended that "Don't touch the alfresco database".
https://forums.alfresco.com/en/viewtopic.php?t=11589