Showing posts with label Tridion Sites. Show all posts
Showing posts with label Tridion Sites. Show all posts

Tuesday, 28 January 2025

Write deployer extension for Tridion Sites 10

 To Write deployer extension for Tridion Sites with following steps

  1. Create a custom step class which implements "ExecutableStep" (com.sdl.delivery.deployer.api.processing.pipeline.ExecutableStep) interface
    • interface is available on udp-deployer-api-x.x.x-xxxx.jar which can be found on maven repo or in the deployer service installation directory.
  2. Override methods in CustomStep class
    • configure
      @Override
      public void configure(Configuration configuration) throws ConfigurationException {
      //this is section where we initialize step
      }
    • process
      @Override
      public ExecutableStepResult process(ProcessingContext processingContext, StepDataProvider stepDataProvider) throws ProcessingException {
      LOG.debug("Starting ExampleExtension");
      var location = getPackageUnzipLocation(processingContext, stepDataProvider);
      LOG.debug("ExampleExtension getPackageUnzipLocation location {}", location);
      TransportPackage transportPackage = new TransportPackage(location, stepDataProvider.getBinaryStorage());
      LOG.debug("ExampleExtension transportPackage {}", transportPackage);
      final String action = transportPackage.getAction();
      LOG.debug("PageStateNotifier action {}", action);
      final String transactionId = transportPackage.getTransactionId().toString();
      LOG.debug("Process Action {} for Transaction {}", action, transactionId);
      switch (action) {
      case DEPLOY_ACTION:
      LOG.info("Publish action triggerred");
      break;
      case UNDEPLOY_ACTION:
      LOG.info("UnPublish action triggerred");
      break;
      default:
      LOG.error("Invalid action {}", action);
      throw new ProcessingException("Invalid transport package action " + action);
      }
      return null;
      }
  3. Write a spring configuration
    • configuration class should be on package "com.sdl.delivery.spring.configuration"
    • Let's name it ExampleConfiguration
      package com.sdl.delivery.spring.configuration;

      import org.springframework.context.annotation.ComponentScan;
      import org.springframework.context.annotation.Configuration;

      @Configuration
      @ComponentScan(basePackages = {"org.rws.example"})
      public class ExampleConfiguration {
      }
    • above class allows your deployer extension to be developed on specific package for example in above ExampleConfiguration it scans package "org.rws.example" then you can implement your CustomStep on step 1 inside package "org.rws.example".
  4. Please also include following minimum java libraries for development of Tridion Sites deployer extension
    • udp-common-config-api-x.x.x-xxxx.jar
    • udp-common-config-x.x.x-xxxx.jar
    • udp-common-util-x.x.x-xxxx.jar
    • udp-core-x.x.x-xxxx.jar
    • udp-data-legacy-transport-x.x.x-xxxx.jar
    • udp-deployer-api-x.x.x-xxxx.jar
    • udp-deployer-web-extension-x.x.x-xxxx.jar
  5. x.x.x-xxxx denotes version of api available on installation directory of deployer service.
  6. After creating CustomStep, based on your project setup (i.e. maven or gradle) configure build steps which could generate a add-on package file in zip.
  7. zip file contains generated jar file and dependent jars those are not available on deployer service libraries, and manifest file requires for Addon service to specify type of Add-on.
  8. you can refer maven project which is having build step to generate Addon-package https://github.com/neeteshnarvaria/deployer-extension/blob/master/pom.xml
  9. example maven project generates example-deployer-extension.zip
  10. after all the steps we need to configure/update deployer-conf.xml
    • open in notepad and add custom pipeline after following pipelines, specifically after highlighted one in screenshot below
    • custom pipeline
      <Pipeline Id="Tridion-Example-Step" Action="Deploy,Undeploy" Verb="Process">
      <Steps>
      <Step Id="ExampleExtension" />
      </Steps>
      </Pipeline>
  11. after configuring/update deployer-conf.xml save and close the file.
  12. add the generated package on add-on using upload
  13. select add-on
  14. after upload on add-on it will show as "Pending State"
  15. We need to restart deployer service to activate the deployer extension add-on.
  16. Deployer status should show "Success".
  17. it is ready to use and we can check functionality by adding some logs.

Refer following git repo which contains sample deployer extension having custom step: https://github.com/neeteshnarvaria/deployer-extension

Thursday, 22 October 2020

SDL Tridion Sites GraphQL Page query

 Graphql url: http://localhost:8081/cd/api (domain can be changed)


{
  page(namespaceId:1,publicationId:8,pageId:689){
           rawContent{
        data
        content
      }
  }
}

namespaceId (1 is for Tridion Sites and 2 is for Tridion docs)


it will give json data under data keyword and content will be string.

Tuesday, 27 August 2019

Connect Net Tcp Tridion Sites coreservice client using java


Connect Tridion Net Tcp using java

Reference: jni4net
Problem: Access nettcp connector using java which is a .Net Component
Solution: We can create .Net Wrapper which will use Tridion Core Service assembly, and we can generate java proxy using jni4net, and we'll consume those java proxies as reference for java application.

First we will create Dot.net Class library project which will deal with CoreService Assembly
Let’s give name as NetTcpConnector

Add reference TridionCoreService assembly from Tridion Sites Installation


Now you’ll see reference on projects references

Add System.ServiceModel and System.Runtime.Serialization assembly to references as shown in image above.

Then we’ll create connector class which will perform Tridion sites operation on project

We do clean and build we’ll get output dll file

Next step is Generate Java proxy using Jni4net, here are following steps to achieve it.

We’ll first download jni4net proxy

Place zip file at somewhere in your machine and extract it.
You’ll see folder structure like
Now Open Visual Studio native command prompt tool

Navigate to Jni4Net bin directory to access proxygen.exe file

And run the command
.\proxygen.exe ../../NetTcpConnector/bin/Debug/NetTcpConnector.dll -wd ../../jni4net-wd -dp ../../NetTcpConnector/bin/Debug/Tridion.ContentManager.CoreService.Client.dll

Where –wd is working directory which keeps generated build file after executed proxygen.exe
-dp represent dependency dll which is used by NetTcpConnector.dll


After executing go to working directory

Go to working directory run build.cmd file

Which generated proxy jar and dll file which will be used by java application

First we copy following files from jni4net lib folder to place it new folder called Java-jni4net-proxies-references

Also copy generated proxies using jni4net from jni4net working directory to same folder “Java-jni4net-proxies-references“ which we are going to use on java application.


Then we’ll place original .dll and core service client dll to same folder
Now we’ll write java program which calls dotnet method and provide output on java console

Add jni4net.j-0.8.8.0.jar and NetTcpConnector.j4n.jar to class path of java application


Now we’ll call GetTridionVersion method which was implementd on don.net side.

Now we run main.java
We’ll see following console which shows output of GetTridion Version method


Wednesday, 10 April 2019

Connect Tridion sites Core service with Java


Introduction

Coreservice is used to perform operation on cms i.e. connect to cms, create content, create workflow etc.
To work with Coreservice with java we have to setup code which consume coreservice as wsdl soap client.

Repository

To check reference implementation please checkout
Here we have used maven to build application

Implementation 

Setup module to generate library from soap url.
1.          Setup build information on pom
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <id>wsdltoJava</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlUrls>
        <wsdlUrl>http://localhost:91/webservices/CoreService201701.svc?wsdl</wsdlUrl>
                        </wsdlUrls>
                        <vmArgs>
                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                        </vmArgs>
                        <keep>true</keep>
                        <sourceDestDir>src/main/resources/wsdl</sourceDestDir>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
2.         Run the maven command “mvn clean install”.
3.         You will have jar file generated on .m2 repository directory.

Once the library is generated add them to dependency and build path of application where we need to write coreservice operations
Sample code to connect application with Tridion coreservice.
QName qName = new QName(Q_NAME_URI, Q_NAME_LOCAL_PART);

Service service = CoreService201701.create(new URL(CMS_WSDL_URL), qName);

ICoreService iCoreService = service.getPort(ICoreService.class);

Authenticator myAuth = new Authenticator() {

    @Override

    protected PasswordAuthentication getPasswordAuthentication() {

        return new PasswordAuthentication(username, password.toCharArray());

    }

};

Authenticator.setDefault(myAuth);

Where parameters are
private static final String CMS_WSDL_URL = getPropertyValue("wsdlUrl");

private static final String Q_NAME_URI = getPropertyValue("qNameUri");

private static final String Q_NAME_LOCAL_PART = getPropertyValue("qNameLocalPart");

And parameters configured on application.properties are
wsdlUrl=http://localhost:91/webservices/CoreService201701.svc?wsdl

qNameUri=http://www.sdltridion.com/ContentManager/CoreService

qNameLocalPart=CoreService201701

After connection have made then we will have iCoreService object which will help us to perform coreservice operations

For example to get CMS version
iCoreService.getApiVersion();


Please go through repository for example.

Monday, 4 March 2019

Custom URL extension with Tridion Sites

Custom URL extension with Tridion Sites

Introduction

Custom URL extension is a feature/functionality which helps Content Editor to select data from 3rd party service.
There are two Steps to Implement Custom URL.
1.       Tridion Sites Configuration - Define URL in CM Schema, which serves the data for Component field specified.
2.       Configure Service as Web Application - Host Web application on CM Web Application as virtual directory.

Tridion Sites Configuration

Custom URL is configured on Schema level i.e.
For example we have created Test Schema – TestTeaser
a.       Tridion Sites CM provide functionality of Custom URL on Schema 

b.      Set the value of custom URL, See below How to create web page which serves data to CM fields.
c.       For Example /CustomUrlExtension/Index.html

d.      Once value is set on schema then create component then you would see hyper link on field for which we have setup custom URL

e.       Then once you click on this you would see webpage on popup

f.        Then select any value from list

g.       Once submit value will be appeared on CM field and pop up is closed.

 

Setup Web Page/Web Application which serves data for headline

1.       To create Web Page which server data for CM field needs to have following PopupInit.js on page included
<script type="text/javascript" language="javascript" src="/WebUI/Core/Controls/Popup/PopupInit.js"></script>
2.       Here we are using https://jsonplaceholder.typicode.com/posts for to get some example data.
3.       Sample web page view


Here is sample code for web page which will appear as pop up

<html>
<
head>
    <
style>
        ::
-webkit-scrollbar {
           
width: 12px;
        }

        ::
-webkit-scrollbar-track {
           
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
           
border-radius: 10px;
        }

        ::
-webkit-scrollbar-thumb {
           
border-radius: 10px;
           
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
        }
    </
style>
    <
script type="text/javascript" language="javascript" src="/WebUI/Core/Controls/Popup/PopupInit.js"></script>
</
head>
<
body onload="loadData()">
<
div class="scrolling-data" style="margin-left: 40%;">
    <
form name="myForm">
        <
div id="title" style="font-size: 50;">Select the Post</div>
        <
br>
        <
div id="posts" style="height: 75vh;width: 70vh;overflow: scroll;overflow-x: hidden;">
        </
div>
    </
form>
    <
button type="button" onclick="checkeSelectedValue()">Submit</button>
</
div>
</
body>
<
script>
   
var data = '';

   
function loadData() {
       
var xhttp = new XMLHttpRequest();
       
xhttp.onreadystatechange = function () {
           
if (this.readyState == 4 && this.status == 200) {
               
data = this.responseText;
               
var jsonData = JSON.parse(data);
               
jsonData.forEach(function (post) {
                   
var d1 = document.getElementById('posts');
                   
d1.insertAdjacentHTML('beforeend', '<input type="radio" name="post" id="' + post.id + '" value="' + post.title + '">' + post.title + '</input><br>');
                });
            }
        };
       
xhttp.open("GET", "https://jsonplaceholder.typicode.com/posts", true);
       
xhttp.send();
    }

   
function checkeSelectedValue() {

       
var post = document.querySelector('input[name = "post"]:checked').value;
       
var fields = window.dialogArguments.getFields();
       
if (fields && fields.length > 0) {
           
fields[0].setValues([post]);
        }
       
window.close();

    }
</
script>
</
html>




On Submit web page will set the value to CM field and the close current window.