Search This Blog

Thursday 19 September 2019

Custom Namespace for metadata properties of assets


Use case

Add custom metadata properties to schema of an asset. Update properties manually or through bulk upload on the metadata node of an asset. Custom properties should be persisted to the binary.

Approach

Its common knowledge that any updates to metadata node of an asset trigger metadata writeback workflow which writes the metadata to the binary/renditions.

For writeback to write a property to the binary the property should have a namespace attached. Else the properties without namespace are ignored.

This premise can be confirmed by following the below steps.

  1. Add a property w/o namespace ex. "testProperty" on the metadata node of the asset from crx and give it some random value.
  2. Add a custom namespace(xyz) and add a property(xyz:testProperty) with custom namespace on the metadata node of the asset.
  3. Run the metadata writeback. Properties on the metadata node should be written to original rendition.
  4. Download the original rendition, rename it and upload it again to AEM.
  5. "testProperty" is not available, while the xyz:testProperty is available on the asset metadata node.
Conclusion: XMP writback doesnt work for properties w/o namespaces.

There are other consequences of not having namespaces for custom properties like Bulk upload (tools like url-asset-importer or csvimporter) wont work for properties w/o namespaces.


Implementation


Creating a custom namespace

  1. Open crx explorer. http://localhost:4504/crx/explorer/index.jsp > Node Type Administration > Namespaces > Add >
    a.   Enter a url for the namespace (ex. “http://my-namespace”)b. Enter the Prefix (ex.  “custom”).

     2. Use url-asset-importer to import the xls.
         http://localhost:4504/etc/acs-commons/manage-controlled-processes.html





Adding namespace to code


Add namespace in nodetypes.cnd






Saturday 7 September 2019

Add on/off time in page properties for experience fragment's


Publishing Experience fragments


Use case

Activate and deactivate the components on the page instead of deactivating the whole page based on some preconfigured date.

Approach

So basically requirement is to be able to configure on/off time for experience fragments similar to how its done for cq:page.
OOTB on/off time is not available in the page properties dialog of the experience fragments.

Hypothesis was if we add the on/off time in the page properties of the experience fragments it should work seamlessly like it works for normal pages as experience fragments is also cq:page resourcetype.




Implementation

Overlay xf dialog from /libs/cq/experience-fragments/components/xfpage/cq:dialog  to /apps/<project>/components/structure/xfpage/cq:dialog and add on/off time fields to it.



1.     Copy the dialog from /libs/cq/experience-fragments/components/xfpage/cq:dialog  inside the custom xf component.




2.     Add the on/off date fields remaining stuff. Sling resource merger would render the merged output of the libs and apps dialog.


Works seamlessly as expected!