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