Uploaded image for project: 'Service Packs and Hot Fixes'
  1. Service Packs and Hot Fixes
  2. MNT-11909

Folder created from template has incorrect primary path or name

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 4.2
    • Fix Version/s: 4.2.4
    • Component/s: Share Application
    • Labels:
      None
    • Environment:
      Linux and Alfresco Enterprise 4.2

      Description

      The folder that is created using the space template has an incorrect name behind the scenes in Alfresco - it keeps the name of the template, ie: 'Content Folder' rather than the name you provided. This means that the primary path is not correct. Changing the folder name in the properties will update the behind the scenes information. See the attached screenshots.

      Webscript - alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/folder-templates.post.desc.xml

      the js

      /**

      • Document List Component: Create New Node - create copy of node template in the Data Dictionary
        */
        function main()
        {
        // get the arguments - expecting the "sourceNodeRef" and "parentNodeRef" of the source node to copy
        // and the parent node to contain the new copy of the source.
        var sourceNodeRef = json.get("sourceNodeRef");
        if (sourceNodeRef == null || sourceNodeRef.length === 0) { status.setCode(status.STATUS_BAD_REQUEST, "Mandatory 'sourceNodeRef' parameter missing."); return; }

        var parentNodeRef = json.get("parentNodeRef");
        if (parentNodeRef == null || parentNodeRef.length === 0)

        { status.setCode(status.STATUS_BAD_REQUEST, "Mandatory 'parentNodeRef' parameter missing."); return; }

      // get the nodes and perform the copy - permission failures etc. will produce a status code response
      var sourceNode = search.findNode(sourceNodeRef),
      parentNode = search.findNode(parentNodeRef);
      if (sourceNode == null || parentNode == null)

      { status.setCode(status.STATUS_NOT_FOUND, "Source or destination node is missing for copy operation."); }

      var copy = sourceNode.copy(parentNode, true);
      copy.properties["cm:name"] = json.get("prop_cm_name").toString();
      copy.properties["cm:description"] = json.get("prop_cm_description").toString();
      copy.properties["cm:title"] = json.get("prop_cm_title").toString();
      copy.save();
      model.name = json.get("prop_cm_name").toString();
      }

      main();

      The copy.save() method does not change the primary path.

      1. Node browser.PNG
        60 kB
      2. template.png
        14 kB

        Activity

        Hide
        jkieley James Kieley added a comment -

        The work around for this is using the fileFolderService.
        We've implemented the groovy console so that we can execute java in a console for alfresco.
        The normal way would be to write a webscript in Java and deploy and run

        *NOTE* you must rename it to something that is not the current cm:name with the fileFolderService FIRST and it will update both the cm:name and the file/folder name
        and THEN rename it to what you actually want. If that doesn't work, try doing it in two different transactions.

        We were able to accomplish it with something like:
        example:

        String nodeRefString = "workspace://SpaceStore/61587c5a-5116-427d-a968-57098e1859a1"
        NodeRef nodeRef = new NodeRef(nodeRefString)

        NodeService nodeService = serviceRegistry.getNodeService()
        FileFolderService fileFolderService = serviceRegistry.getFileFolderService()
        fileFolderService.rename(nodeRef,"not13152")
        logger.warn(nodeService.getPaths(nodeRef,true).toString())

        fileFolderService.rename(nodeRef,"13152")
        logger.warn(nodeService.getPaths(nodeRef,true).toString())
        // renamed both the filename and cm:name

        Show
        jkieley James Kieley added a comment - The work around for this is using the fileFolderService. We've implemented the groovy console so that we can execute java in a console for alfresco. The normal way would be to write a webscript in Java and deploy and run * NOTE * you must rename it to something that is not the current cm:name with the fileFolderService FIRST and it will update both the cm:name and the file/folder name and THEN rename it to what you actually want. If that doesn't work, try doing it in two different transactions. We were able to accomplish it with something like: example: String nodeRefString = "workspace://SpaceStore/61587c5a-5116-427d-a968-57098e1859a1" NodeRef nodeRef = new NodeRef(nodeRefString) NodeService nodeService = serviceRegistry.getNodeService() FileFolderService fileFolderService = serviceRegistry.getFileFolderService() fileFolderService.rename(nodeRef,"not13152") logger.warn(nodeService.getPaths(nodeRef,true).toString()) fileFolderService.rename(nodeRef,"13152") logger.warn(nodeService.getPaths(nodeRef,true).toString()) // renamed both the filename and cm:name
        Hide
        chalford Charlie Halford added a comment -

        Interesting, thanks. In order to override the Alfresco folder-templates webscripts we'd need access to the FileFolderService, is that correct?

        Do you plan on either modifying the ScriptNode save() method to update the path when the cm:name changes, or exposing the FileFolderService to JavaScript so that you can modify the folder-templates.post webscript directly?

        Show
        chalford Charlie Halford added a comment - Interesting, thanks. In order to override the Alfresco folder-templates webscripts we'd need access to the FileFolderService, is that correct? Do you plan on either modifying the ScriptNode save() method to update the path when the cm:name changes, or exposing the FileFolderService to JavaScript so that you can modify the folder-templates.post webscript directly?
        Hide
        jkieley James Kieley added a comment -

        Well I'm not an alfresco developer, I'm just a fellow developer working with alfresco... I'm not sure how they will fix it in the end. This is just a work around until they actually fix the critical bug (which is really needed) we ran into the same issue as you, (the cm:name and file name being out of sync). You can use the fileFolderService to get the cm:name and file name back in sync, but this solution is still very hackish... Alfresco Developers should fix the real issue, by keeping the cm:name and file name in sync.

        Show
        jkieley James Kieley added a comment - Well I'm not an alfresco developer, I'm just a fellow developer working with alfresco... I'm not sure how they will fix it in the end. This is just a work around until they actually fix the critical bug (which is really needed) we ran into the same issue as you, (the cm:name and file name being out of sync). You can use the fileFolderService to get the cm:name and file name back in sync, but this solution is still very hackish... Alfresco Developers should fix the real issue, by keeping the cm:name and file name in sync.

          People

          • Assignee:
            closedbugs Closed Bugs
            Reporter:
            ezeng Eric Zeng
          • Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 7 hours
              7h