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.

3 comments:

  1. An excellent article. I have followed the steps.
    I am unable to search text entered in Title and Description text boxes. While I am able to search text within the file. Please let me know how can text in these two text boxes can be searched.

    ReplyDelete
  2. make sure that <index enabled="true"> . for both title and description properties.

    ReplyDelete
  3. How do you ensure that this aspect
    cm:generalclassifiable
    is import. Because with Alfresco Share this import:

    is not sufficent. Do you have a solution?
    Because I'd like to put the default aspect (cm:auditable) with my custom aspect.

    ReplyDelete