Jahia DX > How to change jcr:created...

0 (0 Good)
0 (0 Bad)

How to change jcr:created ... value ?

by  kamran »  2011/07/29 10:38

Hi,

Is it possible to modify somewhere meta-datas like :

  • jcr:created
  • jcr:createdBy
  • jcr:lastModified
  • jcr:lastModifiedBy

I have to migrate some content from an old (non-jahia) website and I want to keep these kind of information.

Thank for your help

Kamran

 

 

  (kamran)

Number of messages  31
Registration date
1 (1 Good)
0 (0 Bad)

Re: How to change jcr:created ... value ?

by  cflond »  2011/08/02 07:46

Hello Kamran,

First of all, there is two way to migrate your content :

 

1- Using the import feature of Jahia. It means that you have to format your data to a compliant XML format to be able to import it into Jahia.  For example if in your old web site you have an event, and you want to import it in a standard "Jahia Event", you have to format it like that :

 

  <event_14 endDate="2011-07-02T00:00:00.000+02:00" eventsType="show" j:defaultCategory="/sites/systemsite/categories/Marketing /sites/systemsite/categories/project /sites/systemsite/categories/Information_x0020_System /sites/systemsite/categories/Produit" j:lastPublished="2011-07-04T14:02:54.572+02:00" j:lastPublishedBy="root" j:published="true" jcr:created="2011-02-01T16:40:07.696+01:00" jcr:createdBy="root" jcr:lastModified="2011-02-01T16:40:14.671+01:00" jcr:lastModifiedBy="root" jcr:mixinTypes="jmix:categorized" jcr:primaryType="jnt:event" startDate="2011-06-30T00:00:00.000+02:00">
      <j:translation_fr body="&lt;p&gt;Du&amp;nbsp;23&amp;nbsp;au 26&amp;nbsp;f&amp;eacute;vrier 2009&amp;nbsp;et pour la 2&amp;egrave;me ann&amp;eacute;e cons&amp;eacute;cutive, l&amp;rsquo;Ecole d&amp;rsquo;Architecture de Columbia a organis&amp;eacute; sa s&amp;eacute;rie de conf&amp;eacute;rences sur les mat&amp;eacute;riaux. La conf&amp;eacute;rence &amp;laquo; Solid States : Changing Time for Concrete &amp;raquo; a mis le b&amp;eacute;ton &amp;agrave; l&amp;rsquo;honneur. En partenariat exclusif avec Acme, architectes, ing&amp;eacute;nieurs et universitaires de renom se sont retrouv&amp;eacute;s autour du b&amp;eacute;ton et ont &amp;eacute;voqu&amp;eacute; ses &amp;eacute;volutions futures et ses potentialit&amp;eacute;s &amp;agrave; une &amp;eacute;poque d&amp;rsquo;urbanisation effr&amp;eacute;n&amp;eacute;e.&lt;/p&gt; " jcr:language="fr" jcr:lastModified="2011-02-01T16:40:14.671+01:00" jcr:lastModifiedBy="root" jcr:mixinTypes="mix:title" jcr:primaryType="jnt:translation" jcr:title="Conférence « Solid States : Changing Time for Concrete » - Etape 1" location="New York" />
      <j:translation_en body="&lt;BODY&gt;  &lt;P&gt;For the 2nd year running, Columbia's Graduate School of Architecture organized a series of conferences on materials. The &quot;Solid States: Changing Time for Concrete&quot; conference focused on concrete.&lt;/P&gt;  &lt;P&gt;In exclusive partnership with Acme, leading architects, engineers and academics came together around the theme of concrete and turned the spotlight on its future developments and potential uses at a time of intense urbanization.&lt;/P&gt; &lt;/BODY&gt; " j:lastPublished="2011-07-04T14:02:54.572+02:00" j:lastPublishedBy="root" j:published="true" jcr:language="en" jcr:lastModified="2011-02-01T16:40:14.671+01:00" jcr:lastModifiedBy="root" jcr:mixinTypes="mix:title" jcr:primaryType="jnt:translation" jcr:title="“Solid States: Changing Time for Concrete” conference - Phase 1" location="New York" />
    </event_14>

With this method, modificationDate / lastmodifier and creationDate / creator specified in the XML are kept.

 

2- Using the REST API. You know that you can create content by doing HTTP POST on the repository. By default, you don't manage metadata, the system doesn't it for you. So if you want to play with metadata, you have to implement your own action, and then call it like this : 

POST > http://localhost:8080/cms/render/default/en/sites/ACME/home.myaction.do

In this action, you will be able to use the JAVA API to create your own node (see exampel here : http://www.jahia.com/community/documentation/jahiapedia/development/how-to_jcrcontent.html )

In your specific case, you should use a specific  addNode() method that takes into account metadata, instead of the basic one used in the previous example. Thanks to that you will be able to keep creationData but unfortunately not the modificationDate. Indeed, after a REST call, some code is executed to update metadatas. And it considers that the node was just updated and so modify the modificationDate to now() and the lastmodifier to the current user. Moreover, this method doesn't allow you to specify the creator. So you should create all your users in the system (or plug an existing ldap) and then create each user's contents with the user account.

So the process is (in pseudo code) :

foreach(users) {

foreach(currentUserContents)

 POST > http://path_where_you_want_your_content.migrateAction.do

}

 

Hope it will help ! Regards,


Charles

  • Re: How to change jcr:created ... value ?
    2011/08/03 14:59

    cflond <p> Hello Kamran,</p> <p> First of all, there is two way to migrate your content :</p> <p> &nbsp;</p> <p> 1- Using the import feature of Jahia. It means that you have to format your data to a compliant XML format to be able to import it into Jahia. &nbsp;For example if in your old web site you have an event, and you want to import it in a standard &quot;Jahia Event&quot;, you have to format it like that :</p> <p> &nbsp;</p> <div> &nbsp; &lt;event_14 endDate=&quot;2011-07-02T00:00:00.000+02:00&quot; eventsType=&quot;show&quot; j:defaultCategory=&quot;/sites/systemsite/categories/Marketing /sites/systemsite/categories/project /sites/systemsite/categories/Information_x0020_System /sites/systemsite/categories/Produit&quot; j:lastPublished=&quot;2011-07-04T14:02:54.572+02:00&quot; j:lastPublishedBy=&quot;root&quot; j:published=&quot;true&quot; jcr:created=&quot;2011-02-01T16:40:07.696+01:00&quot; jcr:createdBy=&quot;root&quot; jcr:lastModified=&quot;2011-02-01T16:40:14.671+01:00&quot; jcr:lastModifiedBy=&quot;root&quot; jcr:mixinTypes=&quot;jmix:categorized&quot; jcr:primaryType=&quot;jnt:event&quot; startDate=&quot;2011-06-30T00:00:00.000+02:00&quot;&gt;</div> <div> &nbsp; &nbsp; &nbsp; &lt;j:translation_fr body=&quot;&amp;lt;p&amp;gt;Du&amp;amp;nbsp;23&amp;amp;nbsp;au 26&amp;amp;nbsp;f&amp;amp;eacute;vrier 2009&amp;amp;nbsp;et pour la 2&amp;amp;egrave;me ann&amp;amp;eacute;e cons&amp;amp;eacute;cutive, l&amp;amp;rsquo;Ecole d&amp;amp;rsquo;Architecture de Columbia a organis&amp;amp;eacute; sa s&amp;amp;eacute;rie de conf&amp;amp;eacute;rences sur les mat&amp;amp;eacute;riaux. La conf&amp;amp;eacute;rence &amp;amp;laquo; Solid States : Changing Time for Concrete &amp;amp;raquo; a mis le b&amp;amp;eacute;ton &amp;amp;agrave; l&amp;amp;rsquo;honneur. En partenariat exclusif avec Acme, architectes, ing&amp;amp;eacute;nieurs et universitaires de renom se sont retrouv&amp;amp;eacute;s autour du b&amp;amp;eacute;ton et ont &amp;amp;eacute;voqu&amp;amp;eacute; ses &amp;amp;eacute;volutions futures et ses potentialit&amp;amp;eacute;s &amp;amp;agrave; une &amp;amp;eacute;poque d&amp;amp;rsquo;urbanisation effr&amp;amp;eacute;n&amp;amp;eacute;e.&amp;lt;/p&amp;gt; &quot; jcr:language=&quot;fr&quot; jcr:lastModified=&quot;2011-02-01T16:40:14.671+01:00&quot; jcr:lastModifiedBy=&quot;root&quot; jcr:mixinTypes=&quot;mix:title&quot; jcr:primaryType=&quot;jnt:translation&quot; jcr:title=&quot;Conf&eacute;rence &laquo; Solid States : Changing Time for Concrete &raquo; - Etape 1&quot; location=&quot;New York&quot; /&gt;</div> <div> &nbsp; &nbsp; &nbsp; &lt;j:translation_en body=&quot;&amp;lt;BODY&amp;gt; &nbsp;&amp;lt;P&amp;gt;For the 2nd year running, Columbia&#39;s Graduate School of Architecture organized a series of conferences on materials. The &amp;quot;Solid States: Changing Time for Concrete&amp;quot; conference focused on concrete.&amp;lt;/P&amp;gt; &nbsp;&amp;lt;P&amp;gt;In exclusive partnership with Acme, leading architects, engineers and academics came together around the theme of concrete and turned the spotlight on its future developments and potential uses at a time of intense urbanization.&amp;lt;/P&amp;gt; &amp;lt;/BODY&amp;gt; &quot; j:lastPublished=&quot;2011-07-04T14:02:54.572+02:00&quot; j:lastPublishedBy=&quot;root&quot; j:published=&quot;true&quot; jcr:language=&quot;en&quot; jcr:lastModified=&quot;2011-02-01T16:40:14.671+01:00&quot; jcr:lastModifiedBy=&quot;root&quot; jcr:mixinTypes=&quot;mix:title&quot; jcr:primaryType=&quot;jnt:translation&quot; jcr:title=&quot;&ldquo;Solid States: Changing Time for Concrete&rdquo; conference - Phase 1&quot; location=&quot;New York&quot; /&gt;</div> <div> &nbsp; &nbsp; &lt;/event_14&gt;</div> <p> With this method, modificationDate / lastmodifier and creationDate / creator specified in the XML are kept.</p> <p> &nbsp;</p> <p> 2- Using the REST API. You know that you can create content by doing HTTP POST on the repository. By default, you don&#39;t manage metadata, the system doesn&#39;t it for you. So if you want to play with metadata, you have to implement your own action, and then call it like this :&nbsp;</p> <p> POST &gt;&nbsp;http://localhost:8080/cms/render/default/en/sites/ACME/home.myaction.do</p> <p> In this action, you will be able to use the JAVA API to create your own node (see exampel here :&nbsp;<a href="http://www.jahia.com/community/documentation/jahiapedia/development/how-to_jcrcontent.html">http://www.jahia.com/community/documentation/jahiapedia/development/how-to_jcrcontent.html</a>&nbsp;)</p> <p> In your specific case, you should use a specific &nbsp;addNode() method that takes into account metadata, instead of the basic one used in the previous example. Thanks to that you will be able to keep creationData but unfortunately not the modificationDate. Indeed, after a REST call, some code is executed to update metadatas. And it considers that the node was just updated and so modify the modificationDate to now() and the lastmodifier to the current user. Moreover, this method doesn&#39;t allow you to specify the creator. So you should create all your users in the system (or plug an existing ldap) and then create each user&#39;s contents with the user account.</p> <p> So the process is (in pseudo code) :</p> <p> foreach(users) {</p> <p> foreach(currentUserContents)</p> <p> &nbsp;POST &gt; http://path_where_you_want_your_content.migrateAction.do</p> <p> }</p> <p> &nbsp;</p> <p> Hope it will help ! Regards,</p> <p> <br /> Charles</p>

  • Number of messages  42
    Registration date Aug 2, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: Re: How to change jcr:created ... value ?

    by  kamran »  2011/08/03 15:02

    Dear Charles,

    thanks a lot for your answer.

    Can you please confirm me that the first method (XML import) also works in the "LIVE" workspace ? (for the forum  for example).

    In the Repository Explorer of the live workspace I to an export of a topic of the forum and the erase this topic and do an import of the previously exported file. But I have an error in the logs :

    2011-08-04 10:50:07,645: ERROR [ImportJob] - Error when importing
    javax.jcr.PathNotFoundException: /sites/ACME/home/forum/r/s
        at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:540)
        at org.apache.jackrabbit.core.session.SessionItemOperation$4.perform(SessionItemOperation.java:97)
        at org.apache.jackrabbit.core.session.SessionItemOperation$4.perform(SessionItemOperation.java:93)
        at org.apache.jackrabbit.core.session.SessionItemOperation.perform(SessionItemOperation.java:187)
        at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:200)
        at org.apache.jackrabbit.core.SessionImpl.perform(SessionImpl.java:355)
        at org.apache.jackrabbit.core.SessionImpl.getItem(SessionImpl.java:751)
        at org.jahia.services.content.JCRSessionWrapper.getItem(JCRSessionWrapper.java:297)
        at org.jahia.services.content.JCRSessionWrapper.getNode(JCRSessionWrapper.java:332)
        at org.jahia.services.content.JCRSessionWrapper.getNode(JCRSessionWrapper.java:328)
        at org.jahia.services.content.JCRSessionWrapper.importXML(JCRSessionWrapper.java:427)
        at org.jahia.services.content.JCRSessionWrapper.importXML(JCRSessionWrapper.java:422)
        at org.jahia.services.content.JCRSessionWrapper.importXML(JCRSessionWrapper.java:417)
        at org.jahia.services.importexport.ImportExportBaseService.importXML(ImportExportBaseService.java:1022)
        at org.jahia.services.importexport.ImportJob.importContent(ImportJob.java:126)
        at org.jahia.services.importexport.ImportJob.executeJahiaJob(ImportJob.java:109)
        at org.jahia.services.scheduler.BackgroundJob.execute(BackgroundJob.java:133)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
    2011-08-04 10:50:07,645: ERROR [BackgroundJob] - Error executing job ImportJob.ImportJob-9ecbefd2-81b2-4640-b65b-633e4dccae55
    org.jahia.ajax.gwt.client.service.GWTJahiaServiceException: /sites/ACME/home/forum/r/s
        at org.jahia.services.importexport.ImportJob.importContent(ImportJob.java:134)
        at org.jahia.services.importexport.ImportJob.executeJahiaJob(ImportJob.java:109)
        at org.jahia.services.scheduler.BackgroundJob.execute(BackgroundJob.java:133)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
    2011-08-04 10:50:07,646: INFO  [JobRunShell] - Job ImportJob.ImportJob-9ecbefd2-81b2-4640-b65b-633e4dccae55 threw a JobExecutionException:
    org.quartz.JobExecutionException: org.jahia.ajax.gwt.client.service.GWTJahiaServiceException: /sites/ACME/home/forum/r/s [See nested exception: org.jahia.ajax.gwt.client.service.GWTJahiaServiceException: /sites/ACME/home/forum/r/s]
        at org.jahia.services.scheduler.BackgroundJob.execute(BackgroundJob.java:137)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
    Caused by: org.jahia.ajax.gwt.client.service.GWTJahiaServiceException: /sites/ACME/home/forum/r/s
        at org.jahia.services.importexport.ImportJob.importContent(ImportJob.java:134)
        at org.jahia.services.importexport.ImportJob.executeJahiaJob(ImportJob.java:109)
        at org.jahia.services.scheduler.BackgroundJob.execute(BackgroundJob.java:133)
        ... 2 more
    2011-08-04 10:50:07,646: INFO  [SchedulerService] - Background job ImportJob-9ecbefd2-81b2-4640-b65b-633e4dccae55 (of type ImportJob) finished with status 'failed' in 5 ms
    Error dumped to file /Applications/Ent-Jahia_xCM_v6.5.0.0/tomcat/temp/jahia-errors/2011_08_04/error-2011_08_04-10_50_07_650-31.txt in 22ms
    Error dumped to file /Applications/Ent-Jahia_xCM_v6.5.0.0/tomcat/temp/jahia-errors/2011_08_04/error-2011_08_04-10_50_07_672-32.txt in 48ms
    Error dumped to file /Applications/Ent-Jahia_xCM_v6.5.0.0/tomcat/temp/jahia-errors/2011_08_04/error-2011_08_04-10_50_07_727-33.txt in 62ms
    
    

    I have just deploy a forum in ACME, create a room named "r" and a Section named "s".

    Here is my Export/import file :

    <?xml version="1.0" encoding="UTF-8"?>
    <t xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
       xmlns:jnt="http://www.jahia.org/jahia/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
       xmlns:jmix="http://www.jahia.org/jahia/mix/1.0" xmlns:j="http://www.jahia.org/jahia/1.0"
       xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:rep="internal"
       jcr:created="2011-08-04T10:49:10.446+02:00" jcr:createdBy="root"
       jcr:lastModified="2011-08-04T10:49:10.824+02:00" jcr:lastModifiedBy="root"
       jcr:primaryType="jnt:topic" topicSubject="t">
      <t content="&lt;p&gt;  Lorem Ipsum T&lt;/p&gt; " j:nbOfVotes="0" j:sumOfVotes="0"
         jcr:created="2011-08-04T10:49:10.447+02:00" jcr:createdBy="root"
         jcr:lastModified="2011-08-04T10:49:10.824+02:00" jcr:lastModifiedBy="root"
         jcr:mixinTypes="jmix:accessControlled jmix:rating" jcr:primaryType="jnt:post"
         jcr:title="t">
        <j:acl jcr:primaryType="jnt:acl">
          <GRANT_u_root j:aceType="GRANT" j:principal="u:root"
                        j:protected="false" j:roles="owner"
                        jcr:primaryType="jnt:ace"/>
        </j:acl>
      </t>
    </t>

     

    Thanks

    Kamran

    Hello Kamran,

    First of all, there is two way to migrate your content :

     

    1- Using the import feature of Jahia. It means that you have to format your data to a compliant XML format to be able to import it into Jahia.  For example if in your old web site you have an event, and you want to import it in a standard "Jahia Event", you have to format it like that :

     

     
         
         
       

    With this method, modificationDate / lastmodifier and creationDate / creator specified in the XML are kept.

     

    Hope it will help ! Regards,


    Charles


      (kamran)

    Number of messages  31
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: Re: Re: How to change jcr:created ... value ?

    by  kamran »  2011/08/05 07:01

    Please find enclosed the actual response to my question :

     

    Hello,

    The first method only works on default workspace. It is a known issue for the live, we focus on the default workspace for this release, so the import interface of the current version of Jahia only works on default workspace. We are still working on it for live content.

    For now, you can use the second method : create an action as Charles describes to import your content. As he says, note that with the action, the modification date and modifier are not kept

    Best regards,

     
     

    Dear Charles,

    thanks a lot for your answer.

    Can you please confirm me that the first method (XML import) also works in the "LIVE" workspace ? (for the forum  for example).

      (kamran)

    Number of messages  31
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page