Hello all,
I have a solution where a regionalized variation of a Content Fragment is intended to be used based on the resource path of the request. This allows us to seamlessly display region specific content from the matching variation without needing to manually select the variation from a component dialog and breaking the inheritance chain on our live copies. I've modified an existing solution that was already in place that simply created a
Map<String, ContentElement> elements of the Master variation and sent the map to the component to display. It's not extending the ContentFragment model, rather, we are using the direct path to the Content Fragment in the asset folder.
I injected my solution into this method by adding a check for a variationName. If a valid variationName exists and the ContentVariation is found with the variationName, then the value of the ContentElement is replaced with the value of the ContentVariation using ContentElement element.setValue(variationFragmentData). The solution works as intended in our authoring instances but throws a ContentFragmentException in our Publish instance with the error:
com.adobe.cq.dam.cfm.ContentFragmentException: Could not create modifiable property map.
at com.adobe.cq.dam.cfm.impl.PropertyElement.getVarProperties(PropertyElement.java:130) [com.adobe.dam.cq-dam-cfm-impl:0.11.98]
at com.adobe.cq.dam.cfm.impl.PropertyElement.getProperties(PropertyElement.java:137) [com.adobe.dam.cq-dam-cfm-impl:0.11.98]
at com.adobe.cq.dam.cfm.impl.PropertyElement.setContent(PropertyElement.java:319) [com.adobe.dam.cq-dam-cfm-impl:0.11.98]
I suspect this could have something to do with our author instances using the admin userID and our publish instances using anonymous userID. If this is indeed the case, is there another way to use the contentVariationElement in place of the Master element without running into permissions issues?
Documentation references:
ContentElement
ContentVariation
FragmentData
UPDATE:
After logging into my publish instance as admin, I can confirm it's a permissions issue. The jcr:write permissions are required to use ContentElement.setValue(FragmentData).
In it's old form, our helper function iterated through the ContentElements in the given ContentFragment and returned them in a map<String, ContentElement>. The limitation here is that only the master variation can be displayed as any variation content is stored in ContentVariation objects. Initially, in an effort to get around this without needing to refactor the other classes that use this helper class, I attempted to set the value of the content element with the FragmentData of the variation. This worked as expected on author but not on Publish, due to the permissions issue.
In the end, since we simply use the keys to display the content and since both ContentElements and ContentVariations share the same structure, I chose to change the Map signature to <String, Object> so the map could hold both objects and we could call the needed content using the keys as before. This solution did come with the caveat of having to refactor other classes and potentially needing to cast the Objects back to their original classes if the methods are ever needed in a future implementation. But this solution fixed the bug and fits our use case.
I would like to still leave this thread open to see if anyone else happens to see another solution that perhaps I have yet to consider.