ist-dresden / composum-nodes

Set of Apache Sling / AEM development tools: JCR browser, user and package management and more
https://www.composum.com/home/nodes.html
MIT License
55 stars 21 forks source link

Exporting node types #199

Closed pun-ky closed 4 years ago

pun-ky commented 4 years ago

is there any way to export node types via some endpoint / similar feature like: https://www.bounteous.com/sites/default/files/export-node-frpm-crx-lite.png ?

sample output file nodetypes.cnd:

<'sling'='http://sling.apache.org/jcr/sling/1.0'>
<'nt'='http://www.jcp.org/jcr/nt/1.0'>
<'oak'='http://jackrabbit.apache.org/oak/ns/1.0'>
<'jcr'='http://www.jcp.org/jcr/1.0'>
<'mix'='http://www.jcp.org/jcr/mix/1.0'>
<'rep'='internal'>
<'slingevent'='http://sling.apache.org/jcr/event/1.0'>

[sling:OrderedFolder] > sling:Folder
  orderable
  + * (nt:base) = sling:OrderedFolder version

[oak:Unstructured]
  - * (undefined) multiple
  - * (undefined)
  + * (nt:base) = oak:Unstructured version

[nt:linkedFile] > nt:hierarchyNode
  primaryitem jcr:content
  - jcr:content (reference) mandatory
pun-ky commented 4 years ago

seems that https://jackrabbit.apache.org/api/2.12/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.html need to be used and exposed in some servlet:

  final CompactNodeTypeDefWriter cnd = new CompactNodeTypeDefWriter((Writer)res.getWriter(), session, true);
            final NodeTypeIterator iter = session.getWorkspace().getNodeTypeManager().getAllNodeTypes();
            while (iter.hasNext()) {
                cnd.write((NodeTypeDefinition)iter.nextNodeType());
            }
            cnd.close();

I need this to be able to provide nodetypes.cnd file to OakPAL tool which validates packages before installing them on Sling.

stoerr commented 4 years ago

What do you actually need here - an export of one or several nodetypes given in the request (e.g. all nodetypes whose name is matching a given pattern), or the export of the nodetype(s) that apply to a given resource, or something else?

pun-ky commented 4 years ago

@stoerr as you can see on snippet above, it prints all nodetypes registered in oak repository. I need them to perform offline validation of package to be deployed using in-memory oak repository which will be fed by exported node types using this missing endpoint/servlet.

all nodetypes whose name is matching a given pattern

all node types without any filtering.

FYI I am upgrading Gradle Sling Plugin (fork of Gradle AEM Plugin) so that it will have all features of GAP too... but I got stuck on automatic node types synchronization because Composum/Sling does not provide endpoint/servlet for exporting these node types, I mean something like http://localhost:4502/crx/de/exportnodetype.jsp on AEM.

stoerr commented 4 years ago

@pun-ky Since you asked so nicely :-) and even provided the crucial code yourself, I whipped up a quick implementation for that. I hope that's what you need - it's in the new release 1.2.12 of the composum core. It's URL is /bin/cpm/nodes/debug/nodetypes and has an optional nameregex parameter where you could restrict the types if you need to - since you don't it's fine if you skip it and thus get everything. I also provided it in form of a Sling console plugin, since that was the form in which I had wished for it sometimes. Please let us know if there is some trouble.

pun-ky commented 4 years ago

It's okay. Thank you very much 👌🙂