Saturday 12 October 2013

Alfresco Remote debugging in Eclipse (Windows)



1.  Open command prompt window (Start –> Run –> cmd). If you do note have administrator permission then create shortcut of cmd.exe and run this as a Administrator.
2.  Go to “tomcat\bin” folder (e.g. cd c:\alfresco\tomcat\bin).
3.  Enter the command tomcat6w.exe //ES//alfrescoTomcat which launches the service configuration dialog box. 
4. Click on the JAVA tab and enter the following text at the bottom of the “Java Options” field as per the below screenshot (note that that line break is significant):
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n



Alfresco service dialog box.
5.  Close the dialog box and restart alfresco.


Eclipse setting.
1.      Open Eclipse.
2.  Select “Debug Configurations…” from the “Run” pull-down menu.
3.  Double-click “Remote Java Application” to create a “New_configuration” profile.
4.  On the “Connect” tab, browse to the project you want to debug.
5.  Change the “Port” in “Connection Properties” to 8000(or any not used).
6.  Leave all the rest at the defaults and click the “Debug” button to start debugging!


      Happy Coding.

Wednesday 9 October 2013

Create Custom Alfreco Content Types Step by Step



There are few out of the box content models are available which can be used to design the custom content types.

File
Namespace
dictionaryModel.xml
model/dictionary/1.0
systemModel.xml
model/system/1.0
system/registry/1.0
system/modules/1.0
contentModel.xml
model/content/1.0
bpmModel.xml
model/bpm/1.0
forumModel.xml
model/forum/1.0

All these models are placed in WEB-INF\classes\alfresco\model.

Create Sample Custom Model

Hope development environment and Alfresco 4.x already in place. We can use two approaches for building the alfresco custom application. One using the war file creation and other is amp creation. It depends on the requirement which is applicable for you.

For custom content model need to follow below steps
1)      Create directory structure
2)      Create a model file
3)      Create custom model context file
4)      Create property file for resource bundle
5)      Create custom web-client-config
6)      Build war or amp
7)      Deploy in tomcat and Restart

Create Directory structure

I would suggest to follow the following the directory structure which is easy to maintain for  large scale development.


      Create a model file

Create content model file sampleContentModel.xml in /src/main/config/model.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="ss:contentmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
       <!-- Optional meta-data about the model -->
       <description>Sample Content Model</description>
       <author>Saket S</author>
       <version>1.1</version>

       <imports>
              <!-- Import Alfresco Dictionary Definitions -->
              <import uri="http://www.alfresco.org/model/dictionary/1.0"
                     prefix="d" />
              <!-- Import Alfresco Content Domain Model Definitions -->
              <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
              <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" />
       </imports>

       <namespaces>
              <namespace uri="http://www.saketsaraf.com/model/content/1.0"
                     prefix="ss" />
       </namespaces>

       <types>
              <type name="ss:sampleFolder">
                     <title>Sample Folder</title>
                     <parent>cm:folder</parent>
              </type>
              <type name="ss:sampleContent">
                     <title>Sample Content</title>
                     <parent>cm:content</parent>
                     <properties>
                           <property name="ss:name">
                                   <type>d:text</type>
                           </property>
                     </properties>
              </type>
       </types>
</model>


In above code
  • <parent> is a type of content which could be file or folder or custom. 
  • <namespace> uri could be anything with proper format. Version plays very important role and it should be incremental for major changes.

Create custom model context file

For context file either you can create custom context file or make an entry in existing module-context.xml file. Depends on complexity of application you can make the decision.
For this example will create the custom context file sample-bootstrap-context.xml in /src/main/config/context/ folder.

<beans>

<bean id="extensioniop.dictionaryBootstrap" 
parent="dictionaryModelBootstrap" 
depends-on="dictionaryBootstrap">
              <property name="models">
                     <list>
                        <value>
             alfresco/module/${artifactId}/model/sampleContentModel.xml
                        </value>
                     </list>
              </property>
              <property name="labels">
                     <list>
       <value>
               alfresco.module.${artifactId}.messages.webclient
       </value>
                     </list>
              </property>
       </bean>
      
       <bean id="sample_alfresco_module.resourceBundlesWebApp" class="org.alfresco.web.app.ResourceBundleBootstrap">
              <property name="resourceBundles">
                     <list>
        <value>
alfresco/module/${artifactId}/messages/webclient
         </value>
                     </list>
              </property>
       </bean>
</beans>


In above code {artifactId} is module id which mentioned in the pom file. So whenever this code deploys in alfresco it resides in Module folder with the {artifactId} value.

Create property file for resource bundle

Create property file webclient.properties in /src/main/config/messages.

name=Name
sample-folder=Sample Folder

 Create custom web-client-config

 In web-clinet-config file add the following lines in particular sections

       <config evaluator="node-type" condition="ss:sampleContent">
              <property-sheet>
                     <show-property name="ss:name"
                           display-label-id="name" />
              </property-sheet>
       </config>
       <config evaluator="string-compare" condition="Content Wizards">
              <content-types>
                     <type name="ss:sampleContent" />
              </content-types>
       </config>

       <config evaluator="node-type" condition="ss:sampleFolder">
       </config>
       <!-- To add in custom Space Types -->
       <config evaluator="string-compare" condition="Space Wizards">
             <folder-types>
                 <type name="ss:sampleFolder" description="Sample Folder" 
                 display- label="Sample Folder" />
              </folder-types>
       </config>


       <config evaluator="string-compare" condition="Action Wizards">
          <specialise-types>
              <type name="ss:sampleFolder" display-label-id="sample-folder" />
          </specialise-types>
       </config>
       <config evaluator="string-compare" condition="Advanced Search">
         <folder-types>
              <type name="ss:sampleFolder" display-label-id="sample-folder" />
         </folder-types>
           </config>



Build war or amp

Time to build the war or amp file using maven or ant. Verify the logs if any error.

      Deploy in tomcat and Restart

Deploy the war in tomcat and restart the server.


 Login to alfresco and verify the sample code. You should be able to see the custom content type and folder

 
 









Happy Coding.