In this blog­post I want you to show you an exam­ple of the cus­tom node type cq:PollConfig. This can be used to import data at a cer­tain inter­val, or to do oth­er actions that are inter­val based.

Instead of writ­ing cus­tom code to fire events, I will show you an exam­ple where­by an Importer is called from the CQ-con­tain­er.

Let’s get started

The first step I am going to do is to add the cq:PollConfig mix­in to a jcr:content node.

To do this you have to click the ‘Mix­ins…’ but­ton on the top of your page in CRXDE Lite and select cq:PollConfig.

After adding the Mix­in you can con­fig­ure the cq:PollConfig prop­er­ties.

The fol­low­ing prop­er­ties will be set

- inter­val (Long, val­ue ‘600’)

- source (String, val­ue ‘myImporter:myDataSource’)

OSGi Component

Now that we have con­fig­ured every­thing on the con­tent node we have to wire an OSGi com­po­nent that will be exe­cut­ed via the cq:PollConfig.

Here you see an exam­ple of an importer that is wired via the source-prop­er­ty (set to ‘myim­porter’)

@Component(metatype = false, enabled = true, label = “Cus­tom importer”)
@Service
@Property(name = Importer.SCHEME_PROPERTY, val­ue = “myim­porter”)
pub­lic class MyIm­porter imple­ments Importer {

pub­lic void importData(String scheme, String data­Source, Resource tar­get)
throws Impor­tEx­cep­tion {

// this is my importer
System.out.println(“Date : ” + new Date().toString());
System.out.println(“scheme : ” + scheme);
System.out.println(“datasource : ” + data­Source);
System.out.println(“target : ” + target.getPath());

}
}

The wiring between the con­tent and the OSGi-com­po­nent is done via the Importer.SCHEME_PROPERTY. This is match­ing the first part of the source-prop­er­ty.

The sec­ond part of the source-prop­er­ty is ‘data­source’, this is the sec­ond argu­ment in the import­Da­ta-method

For the OSGi-com­po­nent class­es are used from the polling-bun­dle. Make sure you add this depe­den­cy to your maven pom-files.

<groupId>com.day.cq</groupId>
<artifactId>cq-polling-importer</artifactId>

If you have fol­lowed all the steps cor­rect­ly you will the fol­low­ing out­put in the CQ-con­sole:

Date : Fri Mar 01 16:18:30 CET 2013
scheme : myim­porter
data­source : mydata­source
tar­get : /content/test/jcr:content

Related documentation

Cus­tom Node Types

Importer

Hap­py cod­ing!

@heervisscher

0 comments