Showing posts with label ContentManager. Show all posts
Showing posts with label ContentManager. Show all posts

Sunday, 16 June 2019

Extending Content Delivery Storage in SDL WEB 8.5 - Part 3

In the last blog, we saw what happened when we publish a new component, it only calls the create method, but when we re-publish an item it first calls the remove method and then create.

Remove Method


public void remove(int publicationId, int componentId, int componentTemplateId, ComponentPresentationTypeEnum componentPresentationType)
throws StorageException
{
log.debug("Custom storage remove Method");
super.remove(publicationId, componentId, componentTemplateId, componentPresentationType);
log.debug("Custom storage remove Method :- "+componentId);
 
}
Re-Publish an item


As you can see when I re-published an item, we have remove method invoked first and then create method. Next, is un-publish an item and see how it works/ in what sequence.


Un-Publish an Item

When we publish a new item only create method is called, re-publishing will call the remove method and then create and finally in un-publish only remove method is called.   


In the last two blogs, we learned how to set up and configure the project to build storage extension and Publishing a new item and in this blog, we saw other functionalities as well and how they are invoked, in what sequence/order, with this approach we can add/update/remove DCPs in custom storage e:g SOLR, ElasticSearch, MongoDB, etc.

This data can further be used for analytics and for third-party applications.


Happy Coding and Keep Sharing !!!



Extending Content Delivery Storage in SDL WEB 8.5 - Part 2

In the previous blog, we set up the project and configured all the required config and based on that we published a DCP and saw custom logs are available which means everything is working fine.

Today we are going to read the content of DCP and will see how Storage Extension work when we publish, re-publish and un-publish an item.

The Content is available in the form of Bytes and we need to convert that, below is the code snippet that will allow you to access the DCP content in your custom code.

public void create(ComponentPresentation itemToCreate, ComponentPresentationTypeEnum componentPresentationType)
throws StorageException
{
          super.create(itemToCreate,componentPresentationType);
          log.debug("Custom Code Create Method COMID :- " + itemToCreate.getComponentId());
          log.debug("Custom Storage create Method:- "+ itemToCreate.getContent());
          log.debug(String.valueOf(itemToCreate.getComponentId()));
          byte[] dcpComponent= itemToCreate.getContent();
          try
          {
                  componentPresentation = new String(dcpComponent,"UTF-8");
                  log.debug("Custom Storage create DCP :- " + componentPresentation);
          }
          catch (UnsupportedEncodingException ex)
          {
                  log.error("Custom Storage create Unsupported " + ex);
          }

}

DCP content

Publish a new component and in the deployer log file, you will see the DCP content but what will happen when we re-publish the same component or un-publish this. How we are going to manage that in the custom code, will see in the next blog, until then.


Happy Coding and Keep Sharing !!!





Thursday, 20 April 2017

View ALL Structure Group and Pages name in CMS in English

In my current project we are using SDL WEB 8.1 and DXA 1.5 ,client come up with the new request and wants to read all the items in CMS in english only, In the current implementation we have multiple locales, changing the component title to english from other multilingual language title is not the big challenge but when its come to changing the SG and Page name to english for multilingual site is an issue, because we are using DXA default implementation to render Sitemap,Breadcrumb and Navigation.

Client Requirement:- Client wants to read name of all the items in CMS in english, for content editor point of view and at the same time we need to manage the Navigation,Sitemap and Breadcrumb for the multilingual website.

One solution is that,we write our own custom TBB and push the output ,but its a lengthy process and time taking as well.What I did is I made the changes in the existing TBB code and its working fine.

Let's have a look

  1. Approach I followed.
  2. Changes required in the existing TBB and in CMS.
  3. How to debug the TBB.
  4. How to upload the updated TBB in CMS.
  5. And some Pre-requisites. 
Approach I followed:- I decide to create a common metadata schema and have linked component attached in it for both page and structure group and will read component value in the Generate Sitemap TBB, we can always made code tweaks in the existing one.,rather than creating new TBB.

Changes required in the existing TBB and in CMS:- Create a common Metadata schema and add link component field assign it to Structure group and Page.Update linked component field(s) value.Then, we need to update the existing SitemapItemData.cs model and add new property project name Sdl.Web.DataModel. Next is go to the GenerateSiteMap.cs file you will find this file in project Sdl.Web.Tridion.Templates and populate the value by reading the Metadata returned by the Tridion.ContentManager for StructureGroup and Page type.

How to debug the TBB:- There is a complete article available on SDL docx on how to debug the TBB.

How to upload the updated TBB:- You need to use TcmUploadAssembly.exe to upload the TBB this will ask you DLL source,CMS url,Item folder location(tcmID),userId and Password.I have created a batch file for this.
TBB Upload

Pre-Requisites:- To build the TBB code you are required to add reference of following DLLs.

  1. Tridion.Common
  2. Tridion.ContentManager
  3. Tridion.ContentManager.Common
  4. Tridion.ContentManager.Publishing
  5. Tridion.ContentManager.Templating
  6. Tridion.ExternalContentLibrary
  7. Tridion.ExternalContentLibrary.V2
  8. Tridion.Logging
  9. Tridion.TopologyManager.Client
  10. Microsoft.OData.Client

Once all the above changes are done you have successfully updated the TBB and added new field in Navigation.JSON ,now we need to update the code at CD side in DXA.

You need to update the following files in order to read the new field.

  1. Update the Link Model at Sdl.Web.Common.Models
  2. Update the SitemapItem Model at Sdl.Web.Common.Models both are available in DXA framework .
  3. Now, we need to assign the value in the updated model go to CreateLink() method at Sdl.Web.Tridion Class name DefaultProvider.cs and assign the new property.
  4. Build your code and Run.
  5. Debug Breadcrumb.CHTML and TopNavigation.CHTML page you will have new field value in the model returned.



Happy Coding and Keep Sharing !!!