AnsweredAssumed Answered

Not able to delete or edit a leaf node

Question asked by renju on Apr 7, 2011
Hi All,
I am new to Alfresco and just started implementing some sample projects bundeled with Alfresco SDK 3.4 in eclipse. I tries the firstfoundationclient and it works fine. Now I am trying to do some operations like add, delete, edit , version, search file nodes. I am able to add a file be it pdf or word or any format in any folder and able to search also. But when I tried to delete a file using the following code, its not deleting. The code as such not giving any exception, and shows executed successfully but the file is still there.I tried to use node.remove() also, but no use. Also I tried to overwrite the content of an excel file but its not happening. Please find below the code which I used. I have commented the delete node code. Please help me on this.

//Added by Renju for testing delete node
    public static void doSearchExample(ServiceRegistry serviceRegistry) throws Exception
       System.out.println("Starting doSearch ….");
       // Setup Spring and Transaction Service
        ApplicationContext context = ApplicationContextHelper.getApplicationContext();
        // Retrieve Repository
        Repository repository = (Repository)context.getBean("JCR.Repository");
        System.out.println("got repository ….");

        // Login to workspace
        // Note: Default workspace is the one used by Alfresco Web Client which contains all the Spaces
        //       and their documents
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
        System.out.println("got session ….");
        System.out.println("Start searching ..");
            Workspace workspace = session.getWorkspace();
            QueryManager queryManager = workspace.getQueryManager();
            //Query query = queryManager.createQuery("//app:company_home/app:dictionary/*[@cm:content = 'Renju']", Query.XPATH);
            Query query = queryManager.createQuery("//app:company_home/app:dictionary/*[jcr:contains(., 'Renju')]", Query.XPATH);

            QueryResult result = query.execute();
            //Get the node service
            NodeService nodeService = serviceRegistry.getNodeService();
            ContentService contentService = serviceRegistry.getContentService(); //Content service
            for (NodeIterator it = result.getNodes(); it.hasNext(); )
              System.out.println("In for ..");
              Node n = it.nextNode();
              if(n.getProperty("cm:title").getString().equals("Excel File Sample by Renju in Dictionary"))
               // check for JCR 'read' permission
                 session.checkPermission("app:company_home/app:dictionary", "set_property");

                 /*//Delete the Excel file                                 
                 if (nodeService.exists(nodeRef) == true)
                 System.out.println("Excel file removed .."); */
                 //Edit the content of the file
                 //File newFile = new File("Q:/Renju/Projects/Enterprise Manager/File System Management/ReplacedContent.xlsx");
                 //InputStream in = (InputStream)(new FileInputStream(newFile));
                 //n.setProperty("cm:title", "Excel File Sample Title modified");
                 //System.out.println("Excel file title modified successfully ..");
                 // n.setProperty("cm:content", in);
                 NodeRef nodeRef = JCRNodeRef.getNodeRef(n);
                 ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
                  writer.setMimetype(MimetypeMap.MIMETYPE_EXCEL);//Commented by Renju to test other content types
                  File excelFile = new File("Q:/Renju/Projects/Enterprise Manager/File System Management/ReplacedContent.xlsx");
                  System.out.println("Excel file title modified successfully ..");            

                 /* // checkout, fix wiki title and checkin again
                  n.setProperty("cm:title", "The Rose");
                  n.checkin(); */
            System.out.println("After for ..");
        } catch(Exception exc) {
           System.out.println("The following exception occured after fetching the file");

Thanks and Regards,