Question

I am trying to create a file using FileFolderService in alfresco, But I am getting exception and the details are provided below. So can anyone help me!

Site name: mysite File Name: will be passed as request parameter and a new file with the passed in value to be created in Document library of the site.

Code snippet:

ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
String fileName = req.getParameter("fileName");
NodeRef folder = new NodeRef("avm://mysite/-1;www;avm_webapps;ROOT;documentLibrary");
fileFolderService.create(folder, fileName, ContentModel.TYPE_CONTAINER);

Exception thrown:

ERROR [extensions.webscripts.AbstractRuntime] [http-bio-8080-exec-4] Exception from executeScript - redirecting to status template error: 11100002 Wrapped Exception (with status template): 11100016 Invalid node type for AVM.
 org.springframework.extensions.webscripts.WebScriptException: 11100002 Wrapped Exception (with status template): 11100016 Invalid node type for AVM.
    at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)
    at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
    at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:433)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:433)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:495)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:533)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:349)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
Was it helpful?

Solution

You are attempting to access items in the DM repository using AVM-like paths. If you do not understand the difference between the two then I would suggest doing some background reading such as the Professional Alfresco book.

You could try something like the following code, but I have not tested this myself.

String siteName = "blah", newFile = "My New File";
String path = "app:company_home/st:sites/cm:" + siteName + "/cm:documentLibrary";
List<String> pathElements = Arrays.asList(str.split("/"));
NodeRef rootNode = nodeService.getRootNode(new StoreRef("workspace", "SpacesStore"));
NodeRef dlNode = fileFolderService.resolveNamePath(rootNode, pathElements);
NodeRef newNode = fileFolderService.create(dlNode, newFile, ContentModel.TYPE_CONTENT).getNodeRef();

You will want to set some properties and content for the node, but that will at least create it for you. You can find more examples in the Alfresco FirstFoundationClient SDK project.

Exactly how you inject the objects nodeService and fileFolderService depends on what container your code is running in, but in the case of a Java-backed web script then you can inject in the dependencies via Spring config by referencing the NodeService and FileFolderService beans. Try to avoid using the serviceRegistry if you can.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top