Copy a Noderef – either Non-Recursive or Recursive

I am replacing the CrossRepositoryCopyService().copy action since we are going from multiple repo’s to one. So I am replacing this service..

// RECURSIVE copy – but specific for multiple repo’s.
serviceRegistry.getCrossRepositoryCopyService() .copy(src, dst,new_name);

 

So I started by re-using the FileFolderService to copy a node from A to B. This works great, but it only copies the node & leaves all children of the source untouched (and more importantly un-copied)  => Non-recursive copy. The FileFolderService() has no recursive copy action available.

// Non-RECURSIVE copy of one node
FileInfo finf = serviceRegistry.getFileFolderService().copy(src, dst, new_name);
return finf.getNodeRef();
There are quite a lot of copy actions available in Alfresco, but this one seems quite elegant. Also the service name alone gives me some hope of giving me what i need.
Enter the CopyService()

 

// RECURSIVE copy

NodeRef copy2 = serviceRegistry.getCopyService().copy(src, dst, ContentModel.ASSOC_CHILDREN, QName.createQName(new_name), true);

and since I am here now – it also has a usefull

// NON-RECURSIVE copy

NodeRef copy = this.copyService.copy(src, dst, ContentModel.ASSOC_CHILDREN, QName.createQName(“newname”));
Big thanks to : http://kickjava.com/

Advertenties

Date Calendar GregorianCalendar

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

 

If I extract a date from a node in Alfresco, I cannot cast directly to Calendar or GregorianCalendar. So I cast the Serializable return type from Alfresco to the Date class.
Date d = (java.util.Date) nodeService.getProperty(nr, INCENTROmodel.STARTDATE);

 

But java.util.Date is depricated since Java 1.1
The date.getTime() function still works.
It return the amount of ms since the beginning of time (aka 1 jan 1970)
long gt = d.getTime();

 

And the GregorianCalendar knows this. So
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(gt);

Post no. 3_million_and_1 about the java.util.Date / java.util.Calendar / java.util.GregorianCalendar

Custom Behaviour

I`m trying to make my own custom behaviour in alfresco 3.4.4
This led me to a great example from the ECMArchitect – Jeff Potts.

Last week I got stuck on setting up & configuring his examples code.
I installed ANT and got that running, but Jeff’s example told me I had to configure the build.properties file.

(original version) 

alfresco.sdk.remote.home=/usr/local/bin/alfresco-sdk-2.1-enterprise/lib/remote
alfresco.sdk.server.home=/usr/local/bin/alfresco-sdk-2.1-enterprise/lib/server
alfresco.web.root=/usr/local/bin/apache/apache-tomcat-5.5.17/webapps/alfresco


After some searching I changed it into this : 

alfresco.sdk.remote.home=C:/alfresco-community-sdk-4.0.b/lib/remote
alfresco.sdk.server.home=C:/alfresco-community-sdk-4.0.b/lib/server
alfresco.web.root=C:/alfresco-enterprise-tomcat-3.4.4/tomcat/webapps/alfresco/

I didn’t have the SDK from alfresco installed, but now I downloaded it from the WIKI
( you should get this one: “Software Development Kit, including the source files” )

Unzipped to c: and referred the links to there. Then apparently we need to change windows backslashes (\\\\\\\\) into linux forwardslashes (////////)
Go figure….

So far so good, but I got some errors running ant in the C:\behavior-article\ folder.
This was solved by adjusting this line in the build.xml file :

(original)

<javac srcdir="${source.dir}" destdir="${bin.dir}" source="1.5" target="1.5" debug="on" fork="yes">
	<classpath refid="classpath"/>
</javac>

(my new version)

<javac srcdir="${source.dir}" destdir="${bin.dir}" source="1.5" target="1.5" includeantruntime="true" >
	<classpath refid="classpath"/>
</javac>

And so after adjusting this, it compiled correctly.
The ant deploy as described in jeff’s article worked in one go.
( as it should, but i was happy to see it working now)

And so now I get to play around the custom behaviour example….