Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

CRX Package Import Order

Avatar

Former Community Member

Hello,

AEM 6.1.

 

We are mass migrating content into AEM via CRX Package. The nodes are created correctly but they appear in the CRX not in a alphabetically order.

Is there a way to order the nodes in a alphabetically order by using a script after the import or setting a specific attribut in the .conten.xml before the import?  

P.ex:

    - Folder

        -node b

        -node c

        -node a

change order to:

    -Folder

       -node a

       -node b

       -node c

 

 

Kind regards,

 

Jerry

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

the folder has the type cq:page . 

 

It seems to be a problem with order of adding content to the package before importing.

 

For anybody interested in a workaround to sort the children alphabetically in CRX  with Linux (no guarantee):

USER=admin PASS=<pass> URL="http://localhost:4502" DIRECTORY=<directory for which the children should appear in a sorted order> echo $DIRECTORY | grep -Po '[^/a-zA-Z0-9-_]' if [ $? -eq 0 ]; then echo " $DIRECTORY - does not seem to be a correct directory" fi HTTP_STATUS_CODE=`curl -s -I -u $USER:$PASS $URL$DIRECTORY.1.json | grep -P "HTTP(.*) 200 OK" | wc -l` if [ $HTTP_STATUS_CODE -ne 1 ]; then echo "- $URL$DIRECTORY does not exist. Exiting" exit 1 fi children=`curl -s -u $USER:$PASS $URL$DIRECTORY.1.json | grep -Po '"[^"]*":{' | grep -Po '[^"](.*)[^":{]'` if [ $? -ne 0 ]; then echo "- Problem parsing children. Exiting" exit 1 fi sorted_children=`for i in $children do if [ $i != "jcr:content" ]; then echo $i fi done | sort` count=1 echo "  - New sort order:" for i in $sorted_children do curl -s -u $USER:$PASS -F":order=$count"  $URL$DIRECTORY/$i  > /dev/null echo "    - $i " if [ $? -ne 0 ]; then echo "- Problem ordering children. Exiting" exit 1 fi count=$((count+1)) done

View solution in original post

3 Replies

Avatar

Level 10

WHen packages are installed - the nodes are not ordered (for example /content/dam). They appear the same way as they were when the package was created. 

TO order them - you would have to write custom logic using the JCR API. You can use a method such as: 

http://www.day.com/maven/jcr/1.0/7.1.7_Moving_and_Copying.html

However - from a performance perspective - there is no benefit in ordering the nodes.  

Avatar

Level 2

If Folder node primaryType  is  nt:Folder or sling:Folder , the child nodes should be alphabetically sorted.

If folder type is sling:OrderedFolder, the results might contain nodes ordered the way it were put into repository by a package or code.

Avatar

Correct answer by
Former Community Member

the folder has the type cq:page . 

 

It seems to be a problem with order of adding content to the package before importing.

 

For anybody interested in a workaround to sort the children alphabetically in CRX  with Linux (no guarantee):

USER=admin PASS=<pass> URL="http://localhost:4502" DIRECTORY=<directory for which the children should appear in a sorted order> echo $DIRECTORY | grep -Po '[^/a-zA-Z0-9-_]' if [ $? -eq 0 ]; then echo " $DIRECTORY - does not seem to be a correct directory" fi HTTP_STATUS_CODE=`curl -s -I -u $USER:$PASS $URL$DIRECTORY.1.json | grep -P "HTTP(.*) 200 OK" | wc -l` if [ $HTTP_STATUS_CODE -ne 1 ]; then echo "- $URL$DIRECTORY does not exist. Exiting" exit 1 fi children=`curl -s -u $USER:$PASS $URL$DIRECTORY.1.json | grep -Po '"[^"]*":{' | grep -Po '[^"](.*)[^":{]'` if [ $? -ne 0 ]; then echo "- Problem parsing children. Exiting" exit 1 fi sorted_children=`for i in $children do if [ $i != "jcr:content" ]; then echo $i fi done | sort` count=1 echo "  - New sort order:" for i in $sorted_children do curl -s -u $USER:$PASS -F":order=$count"  $URL$DIRECTORY/$i  > /dev/null echo "    - $i " if [ $? -ne 0 ]; then echo "- Problem ordering children. Exiting" exit 1 fi count=$((count+1)) done
The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----