AnsweredAssumed Answered

Accessing the node ref in custom java class

Question asked by srik on May 16, 2014
Latest reply on Jun 17, 2015 by gonial
Hi Team

I have the requirement like to download the file from alfresco repository to custom java class, so far I am able to get the node ref in my java class .By using the node ref I am not able to get the file downloaded in my java class .Can you please provide me the sample code to get the file in my custom java class.

so far this the code implemented .

I get the following error like :   error while getting the repository service. and also error staring the session.

public void convertPDF2SVG(String nodeRef){

                System.out.println("Node Reference: " + nodeRef + "\n\n");

                String fileName = "PDFTron PDF2SVG User Manual.pdf";
                System.out.println("After Endpoint address");

                /*Start the session/
                try {
                        System.out.println("Inside Try to start session");
                        AuthenticationUtils.startSession("admin", "admin");
                        System.out.println("Session started successfully");
                } catch (AuthenticationFault e1) {
                        System.out.println("Unable to start Session: "+e1.getMessage());
                } catch (Exception e){
                        System.out.println("Inside Catch: " + e.getMessage());

                /** Make sure Service Folder has been created,or download files will be failure */
                boolean Success = true;
                Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
                String parentSpace = "/app:company_home/cm:bneps";
                Reference SAMPLE_FOLDER = new Reference(storeRef, null, parentSpace);

                        WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, storeRef, null));
                        System.out.println("after getting repository service");
                catch (Exception exception)
                        System.out.println("Error while getting repository service");

                /**Download files,if exception then "Success = False" */
                                System.out.println("success in try block");
                                ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
                                Reference contentReference = new Reference(storeRef,null,parentSpace+"/cm:"+fileName);
                                Content[] readResult = Predicate(new Reference[]{contentReference}, storeRef, null), Constants.PROP_CONTENT);
                                for(Content content: readResult)
                                        String[] splitedUrl = content.getUrl().split("/");

                                                InputStream in=ContentUtils.getContentAsInputStream(content);

Srikanth S