07-27-2021 05:39 AM
You need to create a new folder. An error occurs when extracting parameters from the post request.
public class WebScriptPost extends DeclarativeWebScript{ @Autowired private NodeService nodeService; @Autowired private Repository repository; public final void setNodeService(final NodeService nodeService) { this.nodeService = nodeService; } protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { Map<String, Object> model = new HashMap<String, Object>(); String path = (String) req.getParameter("path"); String newFolderName = (String) req.getParameter("newFolderName"); System.out.println(path); System.out.println(newFolderName); model.put("path", path); model.put("newFolderName", newFolderName); NodeRef nodeRef = repository.findNodeRef("path", path.split("/")); NodeRef newDocumentNodeRef = nodeService.createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, newFolderName), LmrContentModel.getQName("cm:folder") ).getChildRef(); return model; } }
<webscript> <shortname>CreateFolder</shortname> <description>CreateFolder</description> <url>/create?path={path?}&newFolderName={newFolderName?}</url> <format default="json">extension</format> <authentication runas="admin">guest</authentication> <transaction>required</transaction> </webscript>
{"CreateFolder" : { "path" : "${path}", "newFolderName" : "${newFolderName}" } }
log error
2021-07-27 12:32:00,017 DEBUG [impl.customHistoryApp.LoginLogout] [http-nio-8080-exec-4] try to saveData in LoginLogout 2021-07-27 12:32:00,020 DEBUG [impl.customHistoryApp.LoginLogout] [http-nio-8080-exec-4] finished saveData in LoginLogout SX/Administration/Dictionaries/General null 2021-07-27 12:32:00,095 ERROR [extensions.webscripts.AbstractRuntime] [http-nio-8080-exec-4] Exception from executeScript: 06270024 Wrapped Exception (with status template): A QName must consist of a local name org.springframework.extensions.webscripts.WebScriptException: 06270024 Wrapped Exception (with status template): A QName must consist of a local name at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1139) at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171) at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:519) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:450) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587) at org.alfresco.repo.web.scripts.RepositoryContainer$4.doWork(RepositoryContainer.java:664) at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:623) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:668) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399) at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210) at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132) at org.alfresco.repo.web.scripts.AlfrescoWebScriptServlet.service(AlfrescoWebScriptServlet.java:43) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.alfresco.module.aosmodule.service.ContextRootFilter.doFilter(ContextRootFilter.java:93) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.alfresco.web.app.servlet.ClearSecurityContextFilter.doFilter(ClearSecurityContextFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: org.alfresco.service.namespace.InvalidQNameException: A QName must consist of a local name at org.alfresco.service.namespace.QName.createQName(QName.java:74) at alfresco.extension.templates.webscripts.repository.post_web.WebScriptPost.executeImpl(WebScriptPost.java:41) at org.springframework.extensions.webscripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:235) at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64) ... 44 more
path pulls out normally, newFolderName but no. Рelp please.
07-27-2021 10:41 AM
You seems to be getting the error at this method call: "findNodeRef", the path needs to be qname. else system thinks you are just passing the qname but not localname. In general a path looks like (QName:localname):
"/cm:SX/cm:Administration/cm:Dictionaries/cm:General"
Unrelated to the error, but seems you are also passing json in post request as well as in the request param. You should use either one of the two. It doesn't make sense to pass param and also pass json body. Its better to just use the json body in the request. To extract the json from request body use this approach:
final JSONObject requestPayload = new JSONObject(request.getContent().getContent());
The better way to create path based folders is to use TMDQ, and create the folders/subfolders based on path. Checkout this solution:
Explore our Alfresco products with the links below. Use labels to filter content by product module.