cancel
Showing results for 
Search instead for 
Did you mean: 

Node does not exist after upload file

agey
Champ in-the-making
Champ in-the-making
Hi all,

I deployed an Alfresco extension that basically it consists in a new interface. Sometimes, we have a problem when an user upload a file and then the user wants to see it, the application returns an error: Node does not exist. If I search it from Node browse of Admin Console it is in correct space. Only when I restart Alfresco I can see the file in its space. What could be the problem?

I use Alfresco versión 3.0, MySQL 5 and Tomcat 6.0.

Thanks a lot in advance,
4 REPLIES 4

mrogers
Star Contributor
Star Contributor
Where do you see the exception?

If it is in your code then let's see it.  And more details of the exception.

agey
Champ in-the-making
Champ in-the-making
Hi mroger,

My application consists in creating dossiers that are spaces in Alfresco. These dossiers have infomation and files. Information about each dossier is stored in another database, not in alfresco database, because we want to create and modify data and files to request in dossiers from friendly interface and without restart application.

When a file requested is attached to one dossier (upload to one space in Alfresco) the Alfresco reference is stored in the other database. Then, the application shows dossier information and files but somtimes returns an error because it can't find the file just uploaded.

If we enter into Alfresco and navigate through the nodes, it doesn't find. If we search it from node browse of admin console it is into correct node but when we click on it, returns the error. Only when we restart the application the file is into correct node and the application doesn´t return any error.

This is the code to upload a document:

public void registerOtrosDocumentos(Integer numDossier, File file,
         String fileName){

      String container = ExpedienteModel.DOSSIER_DOCUMENTS;
      this.saveFile(numDossier, file, fileName, container);
     
   }

private NodeRef saveFile(Integer numDossier, File file, String fileName, String container){

      String xpath = "/app:company_home/" +
      "cm:" + DossierModel.DOSSIER_NAME_PREFIX + numDossier+ container;
      StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
      NodeRef rootNodeRef = serviceRegistry.getNodeService().getRootNode(storeRef);

      List<NodeRef> results = this.serviceRegistry.getSearchService()
      .selectNodes(rootNodeRef, xpath, null, this.serviceRegistry.getNamespaceService(), false);

      String name;
      if(fileName == null){
         name = file.getName();
      }else{
         name = fileName;
      }
      FileInfo fileInfo = this.serviceRegistry.getFileFolderService().create(
            results.get(0),
            name,
            ContentModel.TYPE_CONTENT);
      NodeRef fileNodeRef = fileInfo.getNodeRef();

      ContentWriter writer = this.serviceRegistry.getContentService()
      .getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);

      writer.setEncoding(getEncoding());
      if (file != null)
      {
         writer.putContent(file);
      }

      return fileNodeRef;
   }

And this is the code to show the files of a dossier:

public List<Documents> getDocuments(Integer numDossier)
      throws FileNotFoundException{

      List<Documents> docs = new ArrayList<Documents>();
      String xpath = "/app:company_home/" +
      "cm:" + DossierModel.DOSSIER_NAME_PREFIX + numDossier+
      DossierModel.DOSSIER_DOCUMENTS + "/*";
      StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
      NodeRef rootNodeRef = serviceRegistry.getNodeService().getRootNode(storeRef);
      List<NodeRef> results = this.serviceRegistry.getSearchService()
      .selectNodes(rootNodeRef, xpath, null, this.serviceRegistry.getNamespaceService(), false);
     
      for(NodeRef nodeRef: results){
         if(nodeRef!=null){
            Node node = new Node(nodeRef);
            if(node != null){
               String url = DownloadContentServlet.generateDownloadURL(nodeRef, node.getName());
               docs.add(new Documents(node.getName(), url, nodeRef.getId()));
            }
         }        
      }
      if(docs.size()>0){
         return docs;
      }else{  
         return null;
      }

   }

Appreciate any suggestions on the cause of error and how to solve it.

Thanks,

openpj
Elite Collaborator
Elite Collaborator
Probably you should encode in ISO9075 the XPath for the file location, try in this way:
String xpath = "/app:company_home/" +
      "cm:" + ISO9075.encode(DossierModel.DOSSIER_NAME_PREFIX + numDossier+ container);
Hope this helps.

agey
Champ in-the-making
Champ in-the-making
Hi OpenPj,

Thank you very much for your reply. I will try it.