Tuesday, February 23, 2010

Accessing Alfresco repository in Share.

Hi, Here i am trying to explain how to access alfresco repository in alfresco share.

Here i am going to create a dashlet that will display all the spaces and content for particular site based upon site name.

(note: every time alfresco will create space or content in Company Home > Sites , which is depends upon site activities in alfresco share.)


Step1: Create a site in share, name it as chandu as follows



Step2: next go to alfresco and  create webscript  in alfreso for that we need two files create those two files

a)siteacts.get.desc.xml
b)siteacts.get.json.ftl

code to add in siteacts.get.desc.xml
-------------------------------------------------------------------------------------------------------
 <webscript>
    <shortname>Document Property</shortname>
    <description>It provides documents name and date of creation and Creator property</description>
    <url>/sample/siteacts.json?siteName={sitename)</url>
    <authentication>user</authentication>
    <transaction>required</transaction>
</webscript>
--------------------------------------------------------------------------------------------------------

code to add in siteacts.get.json.ftl
---------------------------------------------------------------------------------------------------------
{
<#assign dateformat="yyyy/MM/dd">
"siteacts" : [

<#macro recurse_macro node>

<#if node.isContainer>
{
    "name" : "${node.properties.name}" ,
  
    "creator" : "${node.properties.creator}",

   "createdDate" : "${node.properties.created?string(dateformat)}"
 },

<#list node.children as child>
    <#if child.isContainer>
         <@recurse_macro node=child/>
    <#else>
 {   
    "name" : "${child.properties.name}" ,
  
    "creator" : "${child.properties.creator}",

   "createdDate" : "${child.properties.created?string(dateformat)}"
 }
  ,</#if>
    </#list>
</#if>
</#macro>

<@recurse_macro node=companyhome.childByNamePath["Sites/${args.siteName}"] />

]
}
-----------------------------------------------------------------------------------------------------------
Step3: add these two files into
                      Company Home > Data Dictionary > Web Scripts > org > alfresco > sample 

Refresh the webscripts , for this go to  http://localhost:8080/alfresco/service/, click on Click on Refresh Web Scripts.

if is it successfully completed you will get the message like

Maintenance Completed
Reset Web Scripts Registry; registered 335 Web Scripts. Previously, there were 334.

      then check the webscript using below URI


http://localhost:8080/alfresco/service/sample/siteacts.json?siteName=chandu


here add the name of the site that you need. in my case it is chandu.


you will get the output will be like this
------------------------------------------------------------------------------------------------------------------------------
{
"siteacts" : [



{
    "name" : "chandu" ,
  
    "creator" : "admin",

   "createdDate" : "2010/02/23"
 },


{
    "name" : "documentLibrary" ,
  
    "creator" : "admin",

   "createdDate" : "2010/02/23"
 },



{
    "name" : "links" ,
  
    "creator" : "admin",

   "createdDate" : "2010/02/23"
 },



]
}

------------------------------------------------------------------------------------------------------

Step4: next step is to create dashlet in the share. for that we need three files.

a)siteacts.get.desc.xml
b)siteacts.get.html.ftl
c)siteacts.get.js

code for siteacts.get.desc.xml
-----------------------------------------------------------------------------------------
<webscript>
   <shortname>Site Activities</shortname>
   <description>Dashlet to list Site Activities from Alfresco</description>
   <family>site-dashlet</family>
   <url>/components/dashlets/siteactivites</url>
</webscript>
-------------------------------------------------------------------------------------------
note that here i added this as site dashlet not a user dashlet. code to add in siteacts.get.js

----------------------------------------------------------------------------------------
var connector = remote.connect("alfresco");
var data = connector.get("/sample/siteacts.json?siteName=" + page.url.templateArgs.site);

// create json object from data
var result = eval('(' + data + ')');
model.siteactivites= result["siteacts"];
------------------------------------------------------------------------------------------
code to add in siteacts.get.html.ftl
------------------------------------------------------------------------------------
<table>
<tr>
    <th>Name </th>
    <th>Creator </th>
    <th>Date of Creation </th>
</tr>
<#list siteactivites as x>
<tr>
    <td>${x.name}</td>
    <td>${x.creator}</td>
    <td>${x.createdDate}</td>
</tr>
</#list>
</table>
------------------------------------------------------------------------------------
place all these files into
\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\dashlets


Step5: next refresh the share webscripts using this URI http://localhost:8080/share/service/

click on refresh webscripts. is it is successes you will get the message like. as follows

Maintenance Completed
Reset Web Scripts Registry; registered 176 Web Scripts. Previously, there were 175.

next go to the site http://localhost:8080/share/page/site/chandu/dashboard

click on customise dashboard ., and add dashlet in to the site .


the dashlet will be updated if any activites performed on this site.

download the entire code here download code .

Thursday, February 4, 2010

Creating New Model And Advance Search Configuration.

We can add new Models in Alfresco with two ways.

Procedure-1:
        Create a new model XML file with the name exampleModel.xml ( although this may be any name as required). register this model with the repository by using another file called example-model-context.xml.
create one properties file as webclient.properties.and add property sheet for model in web-client-config-custom.xml.
               place these  files in to \tomcat\shared\classes\alfresco\extension.
          restart the server and you will get the new model values in alfresco.
Procedure-2:  
          here also we need to create model file exampleModel.xml,  webclient.properties, web-client-config-custom.xml.but place the  exampleModel.xml into Data Dictionary > Models
and  webclient.properties, web-client-config-custom.xml into Data Dictionary > Web Client Extension.
      Then go to web client admin console(http://localhost:8080/alfresco/faces/jsp/admin/webclientconfig-console.jsp) and type reload to reload the web client.

while uploading  exampleModel.xml in the first procedure make sure that model should be in Active. please check the model active box.and here we no need to restart the server.

Next  i am going to explain about the first procedure to create new model.

In Every Model it Contains the following Information
  1.Definition of new Model
  2.Importing Alfresco Dictionary Definitions.
  3.Introduction of new name spaces defined by model.
  4. Definition of new Content Type.


1.Definition of new Model

  <model name="tm:mynewmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

Here i written my Model name as tm:mynewmodel. . if we required any more information we can write the following code to know about model.

<description>Example custom Model</description>
<author>Chandu</author>
<version>1.0</version>


2.Importing Alfresco Dictionary Definitions.
If you need to import any new model you need to write import statement as follows.

 <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" />
 </imports>

3.Introduction of new namespaces defined by  model.

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

4. Definition of new Content Type:
here i am taking 3 types in model.  i.e, Production Dept,Finance Dept,Testing Dept. in this each dept type i added one mandatory-aspect. to add poperties for particular  dept. in the next step i will add aspects.
 ----------------------------------------------------------------------------------------------------
<types>
        <type name="tm:production">
            <title>Production Department</title>
            <parent>cm:content</parent>
            <mandatory-aspects>
                <aspect>cm:generalclassifiable</aspect>
                <aspect>tm:productionDetails</aspect>
            </mandatory-aspects>
        </type>
        <type name="tm:finance">
            <title>My Company Finance Department</title>
            <parent>cm:content</parent>
            <mandatory-aspects>
                <aspect>cm:generalclassifiable</aspect>
                <aspect>tm:financeDeptDetails</aspect>
            </mandatory-aspects>
        </type>
        <type name="tm:testing">
            <title>My Company Testing Department</title>
            <parent>cm:content</parent>
            <mandatory-aspects>
                <aspect>cm:generalclassifiable</aspect>
                <aspect>tm:testingDeptDetails</aspect>
            </mandatory-aspects>
        </type>
</types>
-------------------------------------------------------------------------------------------------------
It is very important to follow a specific sequence while defining a new content model.
here is the code for aspects.
--------------------------------------------------------------------------------------
<aspects>
    <aspect name="tm:productionDetails">
        <title>Compnay Prodution Department</title>
            <properties>
                <property name="tm:productid">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
                <property name="tm:productName">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
            </properties>
    </aspect>
    <aspect name="tm:financeDeptDetails">
        <title>Compnay Finance Department</title>
            <properties>
                <property name="tm:financedeptid">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
                <property name="tm:financedeptloc">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
            </properties>
    </aspect>   
    <aspect name="tm:testingDeptDetails">
        <title>Compnay Testing Department</title>
        <properties>
                <property name="tm:testingdeptid">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
                <property name="tm:testingdeptloc">
                    <type>d:text</type>
                    <index enabled="true">
                        <atomic>true</atomic>
                        <stored>true</stored>
                        <tokenised>true</tokenised>
                    </index>
                </property>
            </properties>
    </aspect>
</aspects>
------------------------------------------------------------------------------------------------------
If the attribute enabled for index is set to true, then this property will be indexed in
the search engine. If this is false, there will be no entry for this property in the index.
If the option Atomic is set to true, then the property is indexed in the transaction. If
not, the property is indexed in the background.

If the option Stored is set to true, then the property value is stored in the index and
may be obtained through the Lucene low-level query API.

If the option Tokenized is set to true, then the string value of the property is
tokenized before indexing; if it is set to false, then it is indexed as it is, as a single
string.

next step is to write UI code in web-client-config-custom.xml.

------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>

<alfresco-config>
   
    <config evaluator="aspect-name" condition="tm:productionDetails">
        <property-sheet>
            <separator name="prod" display-label-id="prodDeptHeader" component-generator="HeaderSeparatorGenerator" />
            <show-property name="tm:productid" display-label-id="productid" />
            <show-property name="tm:productName" display-label-id="productName"/>           
        </property-sheet>
    </config>
    <!--  add aspect properties to property sheet -->
    <config evaluator="aspect-name" condition="tm:financeDeptDetails">
        <property-sheet>
           <separator name="finan" display-label-id="finanDeptHeader" component-generator="HeaderSeparatorGenerator" />
            <show-property name="tm:financedeptid" display-label-id="financedeptid" />
            <show-property name="tm:financedeptloc" display-label-id="financedeptloc"/>
        </property-sheet>
    </config>
    <config evaluator="aspect-name" condition="tm:testingDeptDetails">
        <property-sheet>
            <separator name="test" display-label-id="testingDeptHeader" component-generator="HeaderSeparatorGenerator" />
            <show-property name="tm:testingdeptid" display-label-id="testingdeptid" />
            <show-property name="tm:testingdeptloc" display-label-id="testingdeptloc"/>
        </property-sheet>
    </config>
      
  
    <!--  add types to add content list -->
    <config evaluator="string-compare" condition="Content Wizards">
        <content-types>
            <type name="tm:production"/>
            <type name="tm:finance"/>
            <type name="tm:testing"/>
        </content-types>
    </config>
    <config evaluator="string-compare" condition="Action Wizards">
        <aspects>
            <aspect name="tm:productid" />
            <aspect name="tm:productName"/>
            <aspect name="tm:financedeptid"/>
            <aspect name="tm:financedeptloc"/>
            <aspect name="tm:testingdeptid"/>
            <aspect name="tm:testingdeptloc"/>
        </aspects>       
        <specialise-types>
            <type name="tm:production"/>
            <type name="tm:finance"/>
            <type name="tm:testing"/>
        </specialise-types>
    </config>

</alfresco-config>
-------------------------------------------------------------------------------------------------------
next step is to write properties file for above configuration. i.e., webclient.properties
create a file with webclient.properties and add the below code.

------------------------------------------------------------------
#Prodution Department
prodDeptHeader = Production Department
productid = Product ID
productName = Product Name

#Finance Department
finanDeptHeader = Finance Department
financedeptid = Finance Dept ID
financedeptloc = Dept Location

#Testing Department
testingDeptHeader = Testing Department
testingdeptid = Testing Dept ID
testingdeptloc = Testing Location
------------------------------------------------------------------

next step is register this model with the repository. for that add a new file as  example-model-context.xml.
 add  the following code.
------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <!-- Registration of new models -->   
    <bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/exampleModel.xml</value>
            </list>
        </property>
    </bean>
         
</beans>
-------------------------------------------------------------------------------------------------

place these  files in to \tomcat\shared\classes\alfresco\extension.
Restart the server and add some content u will get the screen as shown below.
if you want to select Production Department, select that one click next




you will find the screen as shown below with two additional properties.




Our next step is to make these model as searchable. for that we need to add some code to  web-client-config-custom.xml

that i will explain as followed


Advance Search Configuration:

to get the Properties in advance search which we are created just now using above Model we need to add the following code

--------------------------------------------------------------------------------
<config evaluator="string-compare" condition="Advanced Search">
        <advanced-search>
            <folder-types>
             </folder-types>
            <content-types>
                <type name="tm:production"/>
                <type name="tm:finance"/>
                <type name="tm:testing"/>
            </content-types>
            <custom-properties>
                <meta-data aspect="tm:productionDetails" property="tm:productidr" display-label-id="productid"/>
                <meta-data aspect="tm:financeDeptDetails" property="tm:financedeptloc" display-label-id="financedeptloc" />
                <meta-data aspect="tm:testingDeptDetails" property="tm:testingdeptloc" display-label-id="testingdeptloc" />              
            </custom-properties>
        </advanced-search>
    </config>
----------------------------------------------------------------------------

Restart the server

and click on advance search which is at right corner of alfresco. you will find the ui as shown below.



Thanks.

Tuesday, February 2, 2010

Audit Surf

 In Previous post i explained about to enable audit. and also how to enable debugging.

here i will explain about audit surf which was created by atolcd .

you can download the code from forge. Click Here.

different versions of audit surf is availabe  in this forge .


Here is the best article to understand  the audit surf.

Audit Surf Article

i will explain more about to customize audit surf.  

Monday, February 1, 2010

FTP Server Configuration in Alfresco

To Enable FTP

   Go to  \tomcat\shared\classes\alfresco\extension\   rename file-servers-custom.xml.sample to file-servers-custom.xml.
Add this code

<config evaluator="string-compare" condition="FTP Server">
<serverEnable enabled="true"/>
<authenticator type="alfresco">
</authenticator>
</config>

Then Restart the alfresco.