Wednesday, January 27, 2010

Examples On Alfresco JavScript API

Example1:
        
var today = new Date();
var folderString = today.getFullYear() + "_" + today.getMonth() + "_" + today.getDate() + "_" +   today.getHours() + "_" + today.getMinutes() + "_" +today.getSeconds();


document.createFolder(folderString);

Example2:

Monday, January 18, 2010

Customizing Defaults in Alfresco And Share

Setting default view as "Details View" in Alfresco.

Hi We can change the default view in alfresco after login.

Goto   \tomcat\webapps\alfresco\WEB-INF\classes\alfresco

change the file web-client-config.xml

Change the following code as per the requirement..

---------------------------------------------------------------------------------------------------
<!-- default values for the views available in the client -->
<view-defaults>
<browse>
<!-- allowable values: list|details|icons -->
<view>details</view>
<page-size>
<list>10</list>
<details>50</details>
<icons>9</icons>
</page-size>
</browse>
<forums>
<!-- allowable values: list|details|icons -->
<view>list</view>
<page-size>
<list>20</list>
<details>20</details>
<icons>20</icons>
</page-size>
</forums>
<forum>
<!-- allowable values: details -->
<view>details</view>
<page-size>
<details>20</details>
</page-size>
</forum>
<topic>
<!-- allowable values: details|bubble -->
<view>bubble</view>
<sort-column>created</sort-column>
<!-- allowable values: ascending|descending -->
<sort-direction>descending</sort-direction>
<page-size>
<bubble>5</bubble>
<details>20</details>
</page-size>
</topic>
</view-defaults>
</views>
</config>
---------------------------------------------------------------------------------------------------

How to Change Default Dashlets in Share.

to change default view of dashlets in share we need to change presets.xml which is located at
tomcat\webapps\share\WEB-INF\classes\alfresco\site-data\presets

Wednesday, January 13, 2010

Scheduled Actions In Alfresco

 A scheduled action has parts
  • A cron expression
  • A query template
  • An action template
At the times specified by the cron expression, the query template is used to generate a query, and the query is run to select a set of nodes i.e.,Spaces and Documents.

just we need to configure the scheduled action in an XML file which is located at config\alfresco\extension\

code here for scheduled-action-services-context.xml

here i am trying to run one script file for every  30 minutes.(make sure first upload that script file to Scripts)

-------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

<!--
Define the model factory used to generate object models suitable for use with freemarker templates.
-->
<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
</bean>
<bean id="alfresco_runScriptAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
<property name="actionName">
<value>script</value>
</property>
<property name="parameterTemplates">
<map>
<entry>
<key>
<value>script-ref</value>
</key>
<value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:scheduledwork.js"' )}</value>
</entry>
</map>
</property>
<property name="templateActionModelFactory">
<ref bean="templateActionModelFactory"/>
</property>
<property name="dictionaryService">
<ref bean="DictionaryService"/>
</property>
<property name="actionService">
<ref bean="ActionService"/>
</property>
<property name="templateService">
<ref bean="TemplateService"/>
</property>
</bean>
<bean id="alfresco_runScript" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
<property name="transactionMode">
<value>UNTIL_FIRST_FAILURE</value>
</property>
<property name="compensatingActionMode">
<value>IGNORE</value>
</property>
<property name="searchService">
<ref bean="SearchService"/>
</property>
<property name="templateService">
<ref bean="TemplateService"/>
</property>
<property name="queryLanguage">
<value>lucene</value>
</property>
<property name="stores">
<list>
<value>workspace://SpacesStore</value>
</list>
</property>
<!-- Find all nodes that do not have the aspect -->
<property name="queryTemplate">
<value>PATH:"/app:company_home"</value>
</property>
<property name="cronExpression">
<value>0 0/30 * * * ?</value>
</property>

<property name="jobName">
<value>jobD</value>
</property>
<property name="jobGroup">
<value>jobGroup</value>
</property>
<property name="triggerName">
<value>triggerA</value>
</property>
<property name="triggerGroup">
<value>triggerGroup</value>
</property>
<property name="scheduler">
<ref bean="schedulerFactory"/>
</property>
<property name="actionService">
<ref bean="ActionService"/>
</property>
<property name="templateActionModelFactory">
<ref bean="templateActionModelFactory"/>
</property>
<property name="templateActionDefinition">
<ref bean="alfresco_runScriptAction"/>
</property>
<property name="transactionService">
<ref bean="TransactionService"/>
</property>
<property name="runAsUser">
<value>System</value>
</property>
</bean>
</beans>

--------------------------------------------------------------------------------------------
Restart the alfresco Server. then these changes may effective.

About XML configuration file as written above :

the first block which is in bold  bean id="alfresco_runScriptAction", defines the action for scheduled task.

the second block bean id="alfresco_runScript" contains query and defination.

      i.e., in firsst block action Name and parameter Templates are there. where as in second block query and scheduler definations are there.

for more information on cron expression  http://wiki.alfresco.com/wiki/Scheduled_Actions#Cron_Explained



Wednesday, January 6, 2010

Creating AMPs In Alfresco To Change share UI .


Here I will explain How to create a AMP to change share login page UI.

Step.1 : Open Eclipse editor and Create a Java project. then it will create a default source folder. delete that folder.create the folders structure as shown below.


Step2: here build.xml and module.properties are two files. Create these two files

copy the below code and paste in buil.xml

---------------------------------------------------------------------------------------------------------------
<?xml version="1.0"?>

<project name="Sample Module" default="package-amp" basedir=".">

<property name="project.dir" value="."/>
<property file="${project.dir}/build.properties"/>
<property file="${project.dir}/module.properties"/>

<property name="build.dir" value="${project.dir}/build"/>
<property name="config.dir" value="${project.dir}/config"/>
<property name="jar.file" value="${build.dir}/lib/${module.id}.jar"/>
<property name="amp.file" value="${build.dir}/dist/${module.id}.amp"/>

<target name="mkdirs">
<mkdir dir="${build.dir}/dist" />
<mkdir dir="${build.dir}/lib" />
<mkdir dir="${build.dir}/classes" />
</target>

<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="${project.dir}/lib" includes="**/*.jar" />
<fileset dir="${alfresco.sdk.dir}/lib/server" includes="**/*.jar" />
</path>

<target name="clean">
<delete dir="${build.dir}" />
</target>

<target name="compile" depends="mkdirs">
<javac classpathref="class.path" debug="${debug}" srcdir="${project.dir}/source/java"
destdir="${build.dir}/classes" target="1.5" encoding="UTF-8"/>
<copy todir="${build.dir}/classes">
<fileset dir="${project.dir}/source/java" defaultexcludes="false">
<exclude name="**/*.java"/>
<exclude name="**/.svn/**"/>
<exclude name="**/CVS/**"/>
</fileset>
</copy>
</target>

<target name="package-jar" depends="compile">
<jar destfile="${jar.file}" encoding="UTF-8">
<fileset dir="${build.dir}/classes" excludes="**/custom*,**/*Test*" defaultexcludes="false" />
</jar>
</target>

<target name="package-amp" depends="package-jar" description="Package the Module" >
<zip destfile="${amp.file}" encoding="UTF-8">
<fileset dir="${project.dir}/build" includes="lib/*.jar" />
<fileset dir="${project.dir}" includes="config/**/*.*" excludes="**/module.properties" />
<fileset dir="${project.dir}">
<include name="module.properties"/>
<include name="file-mapping.properties" />
<include name="WEB-INF/**/*" />
<include name="lib/**/*" />
<exclude name="WEB-INF/alfresco.tld"/>
<exclude name="WEB-INF/repo.tld"/>
</fileset>
<zipfileset dir="source/web" prefix="web"/>
</zip>
</target>
</project>
----------------------------------------------------------------------------------------------------------------

copy the below code and paste in module.properties
---------------------------------------------------------------------------------------------------
# SDK Share UI module
module.id=ShareUI
module.title=Share UI Project
module.description= Project to build an amp file for Share UI
module.version=1.0
----------------------------------------------------------------------------------------------------

Step3:
Here I am going to change Login page of share and share footer.
for this  changes we need to change following files


1.slingshot-login.ftl

2.alfresco-templte.ftl

3.footer.get.html.ftl

4.footer.get.properties

5.header.get.html.ftl

                       change the required images and text in above files and create a project structure as shown below. then right click on build.xml and run as ant build.

        finally you will get a amp file in the build path as shown below.




Step4:
                 Next step is copy these amp file and place into amps folder  in which you are alfresco installed.
then go to apply_amps.bat file. copy this file and rename it with  share_apply_amps.bat, copy the code below.

--------------------------------------------------------------------------------------------------------
@echo off
rem -------
rem Script for apply AMPs to installed WAR
rem -------

set ALF_HOME=%~dp0
set CATALINA_HOME=%ALF_HOME%tomcat

if not exist "%ALF_HOME%SetPaths.bat" goto getpaths
call "%ALF_HOME%SetPaths.bat"
goto start

:getpaths
call "%ALF_HOME%bin\RegPaths.exe"
call "%ALF_HOME%SetPaths.bat"
del "%ALF_HOME%SetPaths.bat"

:start
echo This script will apply all the AMPs in %ALF_HOME%amps to the share.war file in %CATALINA_HOME%\webapps
if ""%1"" == ""nowait"" goto nowait1
echo Press control-c to stop this script . . .
pause
:nowait1
"%JAVA_HOME%\bin\java" -jar "%ALF_HOME%bin\alfresco-mmt.jar" install "%ALF_HOME%amps" "%CATALINA_HOME%\webapps\share.war" -directory "%2"
"%JAVA_HOME%\bin\java" -jar "%ALF_HOME%bin\alfresco-mmt.jar" list "%CATALINA_HOME%\webapps\share.war"
echo .
echo About to clean out tomcat/webapps/share directory and temporary files...
if ""%1"" == ""nowait"" goto nowait2
pause
:nowait2
rmdir /S /Q "%CATALINA_HOME%\webapps\share"
call "%ALF_HOME%bin\clean_tomcat.bat"

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

save the above file and close it.

Step5: Double click on  share_apply_amps.bat a window will appear. as shown below.


Restart the tomcat server and check the changes you have made.that login page will be changed and  as well as footer and header.



For More info go to :


7 mistakes developers make when customizing Alfresco Share

Monday, December 28, 2009

JavaScript To Create Spaces and Move Content to specific Spaces based on Name

// JavaScript Document

var rootSpaceName = companyhome.childByNamePath("Chandu"); //returns chandu
var childList = rootSpaceName.children;
var count = childList.length;
var test = new Array();

for(var i=0; i
{
var childName = childList[i].properties.name;
var child = childList[i];

if(!child.isContainer)
{
var newSpace = childName.substring(0,4);
var ind = 0;

if(!contains(childList, newSpace, test))
{
var newSpaceName = rootSpaceName.createFolder(newSpace);
child.move(newSpaceName);
test[ind++]=newSpaceName;
}
else
{
var existingSpace = rootSpaceName.childByNamePath(newSpace);
child.move(existingSpace)
}
}
}

function contains(childList, newSpace,test)
{
for(var i = 0; i < childList.length; i++)
{
if(childList[i].properties.name == newSpace)
{
return true;
}
}
for(var i = 0; i < test.length; i++)
{
if(test[i].properties.name == newSpace)
{
return true;
}
}
return false;
}


Thursday, December 10, 2009

Audit Configuration in Alfresco

Auditing is disabled by default, To enable auditing, some changes we need to made.
 here i explained in detailed where we need to change different audit related files.

go to auditConfig.xml, U can find this file in tomcat\webapps\alfresco\WEB-INF\classes\alfresco folder
change the value of enabled to true in place of false.

------------------------------------------------------------
<Audit xmlns="http://www.alfresco.org/model/audit/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" enabled="true" auditInternal="false" mode="all">
----------------------------------------------------------------------
**and copy this file into extension folder.

Next go to extension folder in alfresco root i.e.,\tomcat\shared\classes\alfresco\extension\

create a new file, name it as a custom-audit-services-context.xml and add this below code
-----------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
<!-- The configuration of the audit model -->

<bean id="auditConfiguration" class="org.alfresco.repo.audit.AuditConfigurationImpl">
<property name="config">
<value>alfresco/extension/auditConfig.xml</value>
</property>
</bean>
</beans>
--------------------------------------------------------------------------------------------------

to turn on debug for audit information change log4j.properties which is located in

\tomcat\webapps\alfresco\WEB-INF\classes      uncomment the line  which is shown below...

log4j.logger.org.alfresco.repo.audit.model=DEBUG


also you can enable alfresco-global.properties which is located in \tomcat\shared\classes
---------------------------------------
#Audit Configuration
   audit.enabled = true
----------------------------------------

Also Enable file service and folder service in auditConfig.xml

-------------------------------------------------------------------------------
<!-- The File/Folder Service -->

<Service name="FileFolderService" mode="none">
<Method name="rename" mode="all"/>
<Method name="move" mode="all"/>
<Method name="copy" mode="all" auditInternal="true"/>
<Method name="create" mode="all"/>
<Method name="delete" mode="all"/>
<Method name="makeFolders" mode="all"/>
<Method name="getWriter" mode="all"/>
<Method name="getReader" mode="all"/>
</Service>

<Service name="ContentService" mode="none">
<Method name="getWriter" mode="all"/>
<Method name="transform" mode="all"/>
<Method name="getReader" mode="all"/>
</Service>
-------------------------------------------------------------------------------


Restart the server  you will find tomcat screen like shown below


and add some documents to alfresco change some properties for that  documents like opening,editing, and set permissions to that documents
Next go to ViewDetails on that document you have edited, click preview in template and select show_audit.ftl from the dropdown menu. you should be able to see all of the actions you just carried out on that document.
you will find the screen as shown below.









Bookmark and Share

Wednesday, December 9, 2009

Writing a Hello World Dashlet for Alfresco Share

 Alfresco Share is the new social computing application of Alfresco 3.0. It is built upon Surf Framework, a light-weight, component-based, REST-oriented web application framework which allows extension through scripting and templating.


In this KB, we will go through the basic steps to create a new Hello World dashlet and then deploy and test it on Alfresco Share.
Just like developing any other webscript, let us first create a new XML file, name it as helloworld.get.desc.xmland add following lines


It provides basic configuration information about the dashlet such as name, description and url for the service endpoint. The key element of this configuration file is the family setting which has to be user-dashlet in order for Alfresco share to recognize it as a dashlet and make it available for end user to select when they customize their share dashboards.
Since this is a simple Hello World dashlet, we really don’t need the javascript component or we can just create an empty javascript file with the name helloworld.get.js.
Now let us work on the presentation part of this dashlet, a freemarker template with the namehelloworld.get.html.ftl.


As we can see, it prints out the “Hello Word” text as the dashlet body as well as a “Hello World” title.
To make a step further, we can also create a message properties file and reference the messages inside the freemarker template. So let us create a properties file helloworld.get.properties and put the following entry in it
hello.world = Hello World
Once the properties file is ready, we can reference the hello world message using API ${msg(”hello.world”)} in the freemarker template file.


Now with all the files ready, we can deploy them to Alfresco Share. Since Alfresco Share will look for its webapp classpath for the scripts, we can create a new folder demo under the share\WEB-INF\classes\alfresco folder and place all our files over there.
To make Alfresco Share to load the new dashlet, we need to go to Share webscript management page, e.g.http://localhost:8080/share/service/.
Hello World Dashlet
Click the Refresh Web Scripts button at the bottom of the page and if you see the number of total webscript incremented by one, the dashlet has been deployed successfully.
Log on to Alfresco Share and click  Customize Dashboard button and you will see the “Hello World” dashlet is there and is available to be added to your dashboard.


Collected from  http://drquyong.com/myblog/?cat=15