Search This Blog

About Me

Highly experienced in implementation and customization of Alfresco. More than 11 years of experience working on Alfresco, versions ranging from 2.x to 5.x. Successfully processed innovative and tailored CMS solutions to meet ever-changing business requirements for multiple clients. Role Includes : Experience in Alfresco Upgrades, SOLR migration, Proposals, Team Handling, Delivery, Content Migration, POC's etc.. Extensive experience in client co ordination, working on offshore-onshore model and project take over. Technical Expertise Includes : Java, JSP, Servlet, JSF, JavaScript, AJAX, Spring, SQL, Hibernate, Web Services(REST). Specialities Includes : Content Migration, Product Customization, Business CMS Solutions, Workflow, Project Transition.

Wednesday, June 30, 2010

Code to apply Template using Alfresco Web Service Client


Below is a small code for applying a template to a content using web service API

Note – For applying a template, you need to set the template node ref as a template property

I have taken reference of alfresco out of the box document template.



Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String rootHome="/app:company_home";
String filename = "test.txt";
String templateID = "workspace://SpacesStore/a4d6ab23-989a-46c6-9c13-3ea2be97d208";
ParentReference contentReference = new ParentReference(storeRef, null, rootHome, Constants.ASSOC_CONTAINS, filename);
     contentReference.setChildName("cm:" + filename);
     NamedValue[] properties = new NamedValue[]
     {
             Utils.createNamedValue(Constants.PROP_NAME, filename),
             Utils.createNamedValue(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "template"), templateID)
     };
     create = new CMLCreate("1", contentReference, null, null,null, Constants.TYPE_CONTENT, properties);
     cml = new CML();
     cml.setCreate(new CMLCreate[] { create }); // Content Created
     result = WebServiceFactory.getRepositoryService().update(cml);

Thursday, April 22, 2010

Running Alfresco Community 3.2 First Foundation Client SDK

  1. Set up Tomcat bundled Alfresco alfresco-community-tomcat-3.2 on your local machine.

    You can download it here. Start it once before you run first foundation client.

  2. Download alfresco-community-sdk-3.2 from here.
  3. Open your eclipse, import alfresco-community-sdk-3.2.zip.
  4. Select projects Alfresco Embedded, SDK First Foundation Client
  5. Click on Finish
  6. Provide dir.root, db.username, db.password, db.driver, db.url into custom-repository.properties present in SDK Project.
  7. Add all the jars present in "\alfresco-community-tomcat-3.2\tomcat\webapps\alfresco\WEB-INF\lib" to your SDK project's build path
  8. Also add your respective database driver and servlet jar file as it's not provided into the lib.
  9. Now build the SDK project
  10. Make sure your tomcat is not running, if yes, shut it down. I do not know why but it is generating JVM Bind error when we run FFC with tomcat server running.
  11. Run First Foundation Client.

I hope you will not face any issues running it.

After it's been run successfully, start your tomcat, you will see a new file created in company home space.

Thursday, April 15, 2010

Overriding the default update action of alfresco



Alfresco's default update action just replaces the contents of the document without changing its name and other properties.

 
This blog deals with overriding the default update action with your customized one.

 
As update action consists of a dialog in which you needs to browse and select a new document from your local machine, a new upload jsp file needs to be written which will take care of the upload part and will perform the function which you have over ridden.

 
If you want to add a dialog on the action you provide, then you have to register it into 'web-client-config-dialogs-custom.xml' (here after we will mention it as 'dialogs-custom.xml')

Like, if you want to display your custom view details page on clicking of view details link action, you can define it here with bean reference for that particular jsp.

 
Suppose if you have defined your custom update link action on clicking which, you want your custom update jsp page should appear, you can define it here like –

 
[Note – I am just providing the update action and its dialog here, rest you can change as per the steps I have mentioned here]



Actions Tag in actions-custom.xml

 
<!-- Update document -->

     <action id="update_doc">

     <permissions>

     <permission allow="true">Write</permission>

     </permissions>

     <evaluator>org.alfresco.web.action.evaluator.UpdateDocEvaluator</evaluator>

     <label-id>update</label-id>

     <image>/images/icons/update.gif</image>

     <action-listener>#{CheckinCheckoutDialog.setupContentAction}</action-listener>

     <action>dialog:updateFile</action> <!-- Dialog Name -->    

<params>
     <param name="id">#{actionContext.id}</param>

     </params>

    </action>


  <!-- Dialog Tag in dialogs.xml -->   

 
<dialog name="updateFile" page="/jsp/extension/custom-update-file.jsp" managed-

bean="UpdateFileDialog" icon="/images/icons/update_large.gif" title-id="update"

        description-id="updatefile_description"/>

 
Now when you use customized update action link, your custom update jsp file will appear with update button.

When you select the file from your local system and click on update, your overridden method will get called.

 
Here is the class file with overridden Update method.

 
Do not forget to register your bean into faces-config-custom.xml

 
<managed-bean>
<description>The bean for the Update File Screen.</description>
<managed-bean-name> UpdateFileDialog</managed-bean-name>
<managed-bean-class>
com.test.update.UpdateFileDialog
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>property</property-name>
<value>#{CCProperties}</value>
</managed-property>
</managed-bean>

 

Adding a custom action in alfresco action column of the content and in view details page


Whenever you want to add any kind of action link into alfresco, you need to make changes into 'web-client-config-actions.xml' or 'web-client-config-actions-custom.xml'.

As alfresco says, it's better to make changes in custom file as it keeps you code separate from alfresco and is easy for debugging also.
Suppose you want to add an action 'Approved' for particular document.
You want this action to appear in actions column and in view details of your content.
Below are the steps of doing this

  1. Define an action in web-client-config-actions-custom.xml (here after we will mention it as 'actions-custom.xml') inside <alfresco-config> and <config> tags
    I am providing the whole action tag with description of each tag

<action id="approveDoc"> - A valid ID for your action
    <permissions>
       <permission allow="true">Write</permission> - Default Permissions
   </permissions>

<label>Profile Review Complete</label> - Label to display when you put your mouse over the action text

<label-id>approve_document</label-id> - Name to appear in JSP
   <image>/images/icons/green_tick.gif</image> - Icon to appear in JSP
  <action-listener>
            #{[YOUR BEAN NAME].[METHOD TO CALL]} – Bean method to call when action is performed
   </action-listener>
   <action>[Outcome]</action> - This is to navigate the page when action is completed
   <params>
       <param name="id">#{actionContext.id}</param> - Specifically for getting the node ref from context id
   
</params>
</action>

  1. Define an action-group in actions-custom.xml inside <alfresco-config> and <config> tag

    This action group name will need to be used for displaying the actions in JSP file

    /* For Actions column */
    <action-group id="approve_doc_actions_browse">
       <show-link>false</show-link>
       <style-class>inlineAction</style-class>
       <action idref="approveDoc" />
    </action-group>

    /* For view details page*/

    <action-group id="approve_doc_actions_details">
           <action idref="approveDoc" /> - The action which we have defined above
        
    </action-group>

3. Use below tag to display the action into the actions column of the content in browse page

<%-- Content Actions column --%>

<a:column id="fo_col18" actions="true" style="text-align:left"
rendered="#{NavigationBean.searchContext == null}">
    <f:facet name="header">
     <h:outputText id="fo_col-txt" value="#{msg.actions}"/>

</f:facet> 
<a:actionLink id="fo_col-act" value="#{r.name}" href="#{r.url}"
target="new" image="#{r.fileType16}" showLink="false" styleClass="inlineAction" />
<%-- actions are configured in web-client-config-actions.xml --%>
<r:actions id="fo_col-acts" value="approve_doc_actions_browse" context="#{r}"
showLink="false" styleClass="inlineAction" />

</a:column>



 

  1. Use below tag to display the action into view details page of the content

    <%-- Document Actions --%>

    <a:panel label="#{msg.actions}" id="actions-panel" border="white" bgcolor="white" titleBorder="lbgrey" expandedTitleBorder="dotted" titleBgcolor="white" style="text-align:center" progressive="true" expanded='#{DialogManager.bean.panels["actions-panel"]}'
    expandedActionListener="#{DialogManager.bean.expandPanel}">

        <r:actions id="actions_doc" value="fo_doc_details_actions"             context="#{DialogManager.bean.document}"
        verticalSpacing="3" style="white-space:nowrap" />

    </a:panel>

    1. Define the label text to be displayed in JSP in webclient.properties
        approve_document=Approved

  Now you have created your new customized action link.

Similarly you can create more actions and display it in one action group.

Wednesday, March 10, 2010

Different approaches of Accessing Alfresco Services

As alfresco services are the only tools we can use for making any changes inside alfresco. Here i am writing some of the approaches for getting them.

There are three approaches i have used till now for accessing the alfresco services ( Searchservice, NodeService etc) in a class.

1. Accessing through application context.

As mentioned in alfresco documentation and in examples too, we can get the application context object from alfresco utility class 'ApplicationContextHelper'

// Do not forget to include alfresco jars into your project
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();

Now from application context, get the service registry bean having all the registered services for alfresco, like this

ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

And from this service registry object you can get any alfresco services, for e.g like this

SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();


OR

You can get it by following these steps also

ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/application-context.xml");

ServiceRegistry registry = (ServiceRegistry)appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);


2. Getting services from repository directly

SearchService searchService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getSearchService();

3. Setting services into properties in faces context and accessing it directly just by declaring getters and setters

a. Register your bean into faces-config-custom.xml and set the services you want to use in your class between <manage-property> tag with property-name and value, for example, below i have declared search service to be used into the bean i am declaring


<managed-bean>
<description>{Bean Description You want to Provide}</description>
<managed-bean-name>{Bean Name}</managed-bean-name>
<managed-bean-class>
{Package Name.Bean Name}
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>searchService</property-name>
<value>#{SearchService}</value>
</managed-property>       
</managed-bean>


b. Declare and write the getters and setters for the properties you have declared and want to use in your class

public class TestClass
{
private SearchService searchService;
/** Your code */
public SearchService getSearchService() {
return searchService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
}