cancel
Showing results for 
Search instead for 
Did you mean: 

How to get NodeRef of an already uploaded file?

amit_wmw
Champ in-the-making
Champ in-the-making
Hello,

I am having a content file (say Amit.txt) in company Home. And assuming that I have a custom method by name checkOut(String A), where parameter “String A” is Amit.txt that will be send by any invoking class. Now can you please suggest me how to get NodeRef for Amit.txt? Below is the full code scenario where I want to use this(basically its to checkout Amit.txt in company home itself).

#####################################################################

public void checkOut(String A){
      //this.fileRef=fileRef;
      
          try{
         
         ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
         Repository repository = (Repository)context.getBean("JCR.Repository");
         Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
         
         NodeRef NR= ????????????????????
         
         
         ChildAssociationRef Parent=nodeSevice.getPrimaryParent(NR);
                  
         FileInfo fileinfo = fileFolderService.getFileInfo(NR);

         fileRef = fileinfo.getNodeRef();

         CheckOutCheckInService checkOutCheckInService= serviceRegistry.getCheckOutCheckInService();

         checkOutCheckInService.checkout(fileRef, Parent.getParentRef(), ContentModel.ASSOC_CONTAINS, ContentModel.TYPE_CONTAINER);
         
         
         session.save();
         }
         catch (Exception exp ){
         System.out.println (" error while creating nodes " + exp);
         exp.printStackTrace();
         }
         
         }


#####################################################################################

Thanks
Amit.
14 REPLIES 14

lotharm
Champ on-the-rise
Champ on-the-rise
To get the NodeRef with JCR is described in the wiki at:
http://wiki.alfresco.com/wiki/Introducing_the_Alfresco_Java_Content_Repository_API#Mixing_JCR_and_Al...
Regards
  lothar

amit_wmw
Champ in-the-making
Champ in-the-making
Lothar, thanks for the quick reply!

But the link you suggested above speaks all about Node and not NodeRef and for my code scenario I need NodeRef, because I am making use of checkout method of checkOutCheckInService class, which requires NodeRef.

Please suggest.

Thanks
Amit

lotharm
Champ on-the-rise
Champ on-the-rise
The example code of the section shows how to convert the JCR node to an Alfresco NodeRef by the use of the helper class JCRNodeRef:

// convert the JCR Node to an Alfresco Node Reference
NodeRef nodeRef = JCRNodeRef.getNodeRef(jcrNode);

The JCR Node has to be obtained first using one of the JCR lookup methods.

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks dear!

Similarly ,do you know any way to get Node out of a NodeRef? If please share. Will be kind.

kind regards-
Amit.

lotharm
Champ on-the-rise
Champ on-the-rise
A direct lookup by id might work for the other way round:

Node jcrNode = session.getNodeByUUID(nodeRef.getId());

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks a lot for all your help! Kind of you!

Amit.

pamela
Champ in-the-making
Champ in-the-making
Hi!

im really new at this, where do you invoke these codes? to get the noderef?
sorry if you think this question is silly, but i really dont know where…  :roll:

amit_wmw
Champ in-the-making
Champ in-the-making
Hi Pamela,

You have to explore your question a bit more. Do you mean to say where we are writing and executing this codes? Or you want to know anything in particular about Noderef?

And remember silly mistakes leads to big problems, similarly correcting silly mistakes lead people to great success 🙂

Amit.

pamela
Champ in-the-making
Champ in-the-making
my problem is a bit like yours, but i want to simultaneously get the noderef of the file immediately after i upload it…

help me  :roll: