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

amit_wmw
Champ in-the-making
Champ in-the-making
That means that a file has been uploaded on a node and if you have a node, below method is use to get nodeRef of that node.
NodeRef nodeRef = JCRNodeRef.getNodeRef(Node);

rgds-
Amit.

pamela
Champ in-the-making
Champ in-the-making
That means that a file has been uploaded on a node and if you have a node, below method is use to get nodeRef of that node.
NodeRef nodeRef = JCRNodeRef.getNodeRef(Node);

rgds-
Amit.


but i don't know where to get my node..  :cry:

what im trying to do is to write a query using lucene, then try to get its nodeRef, but i can't seem to make it work.
i uploaded the file inside the company home (app:company_home), and my file's name is generated by timestamp :

String name = "RequestMembership (" + System.currentTimeMillis() + ")";
RequestImage.setChildName("cm:" + name);

i have seen an example on how to query then get its nodeRef after, but i dont know how i can put in here:

ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "HERE"");
NodeRef companyHome = resultSet.getNodeRef(0);

the path plus the name of my image..

:cry:

lotharm
Champ on-the-rise
Champ on-the-rise
You could use a combination of PATH query and property query:


ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "+PATH:\"/app:company_home/*\" +@cm\\:name:\"RequestMembership*\"");
NodeRef companyHome = resultSet.getNodeRef(0);

This wiki lucene search page might help you further with a lot of examples at http://wiki.alfresco.com/wiki/Search

Regards,
  lothar

pamela
Champ in-the-making
Champ in-the-making
thanks amit!

i used webscripts and js to search using lucene Smiley Happy

i did this and it worked:

var docs = search.luceneSearch(" @cm\\:name:\""+args.filename+"\"");
   var log = "";

    for (var i=0; i<docs.length; i++)
            {
                   log += "NodeRef: " + docs.nodeRef + "\r\n";
             }

         logFile.content = log;


i called the webscripts in adobe flex via httpservice and passed the name of my file to the webscripts, and it works perfectly for calling my workflow Smiley Happy

alihammad
Champ in-the-making
Champ in-the-making
@Lothar

Thanks a lot, your suggestion helped me .