Friday 29 April 2016

WCF RestService over CoreService

WCF RestService over CoreService 

Introduction 

This service is created to get data from SDL Tridion CM Database ,currently this service is tested with SDL Tridion 2013 SP1


In this service you will see many methods are exposed and message format JSON and XML output.

Methods which are available
  1. GetComponentByTcmUri
  2. GetSchemaByTcmUri
  3. GetAllCategoriesWithInPubByTcmUri
  4. GetKeywordByCategoryID
  5. GetPageTempletByPubID
  6. GetComponentTemplateByPubID
  7. GetTemplateBuildingBlockByPubID
  8. GetPageByPubID
  9. GetStructureGroupByPubID
  10. GetMultimediaComponentByPubID
  11. GetPublicationList
  12. GetUserList 


Example
To request a categories from the Tridion CM Database.
http://domainname/RestService.svc/GetAllCategoriesWithInPubByTcmUri/{TCMURI}/{messageformat}
http://domainname/RestService.svc/GetAllCategoriesWithInPubByTcmUri/0-1048-1/JSON

You can download the code from here

Happy coding and keep sharing :)

Thursday 28 April 2016

SDL Tridion 2013 SP1 SmartTarget With Fredhopper on Windows Machine

Fredhopper: SDL Fredhopper is a Customer Experience Management tool which provides a seamless, targeted and fully personalized website experience to the end users. The SDL Fredhopper enables the marketing team to target a specific segment of customer with all the right products or content which suits them best.

SmartTarget: SmartTarget is an add-on for SDL Tridion which integrates SDL Tridion with SDL Fredhopper. SmartTarget acts as a bridge between SDL Tridion and SDL Fredhopper so that Marketers can create, update and manage targeted and personalized content for SDL Tridion driven website.

1      configure fredhopper


 The document is developed for SDL Tridion 2013 SP1, smart target 2014 and fredhopper-7.5-revision-13.You first need to configure fredhopper. Assuming Odata Services and CD is already confirmed.

·         extract fredhopper-7.5-revision-13 in C :

      To download Fredhopper Link you would required valid credentials to login 


·         follow below command to configure the fredhopper

·         You need designated service account with username fredhopper  to configure fredhopper

·         ..\fredhopper\config Create a topology.txt in your Fredhopper config folder
                   # The topology file defines your indexing and live servers
                   # instance name | host | preset | indexer | comment
                      SmartTarget|localhost|1|-|Indexer and Preview environment for demo setup                                           SmartTargetLive|localhost|2|SmartTarget|Live Query Server for demo setup

       Where:
     SmartTarget is the Indexer Server (for getting content into Fredhopper)
                SmartTargetLive is the Query Server (for getting content out of Fredhopper)

1.       Open command prompt cmd /admin and execute the below commands in sequence always in new window.
o    bin\deployment-agent
 
o    bin\setup-cluster

  1. In the ..\fredhopper\data\instances\SmartTarget folder, create a folder \custom.
3.  Copy configuration-management-rest-extension.jar and smarttarget_api_extension.jar to the \custom folder. 
4.  In the  ..\fredhopper\SmartTarget\data\fas-xml-incremental folder, create a folder \catalog01
And Copy the metadata.xml file to the \catalog01 folder. 
5.  Copy the trigger-types.xml and business.xml to C:\fredhopper\data\instances\SmartTarget\config folder. 
6.  Copy the STJob.kjb file to the ..\fredhopper\data\instances\etl folder. 
7.  Start up the SmartTarget or SmartTargetLive instance using the command:
8.  Execute below commands
o    bin\instance SmartTarget start

o    bin\deployment-agent-client –location localhost invoke SmartTarget qserver stop
o    bin\deployment-agent-client –location localhost invoke SmartTarget qserver start

o    bin\run-etl-job STjob.kjb “-DINSTANCE=SmartTarget” “-DTRIGGER=load-data”
 “-DUNIVERSE=catalog01” “-DEXECUTIONPATH=C:/fredhopper/data/instances/SmartTarget/custom”

           9.       Browse to the Fredhopper Business Manager:
     10. http://localhost:8180/fredhopper/admin/ 
   
          11.   Use the credentials admin/admin to log on. (The Business Manager connects to the Indexer Server.)
    
      

      2.Steps for Smart Target static implementation:

Install SmartTarget 2014 available in installation media

Click On Targeting Option







1   .      Create PT for page
1.1.  Add Extract Components from Page tbb.
1.2. Create DWT(Suppose name as ST Region DWT) having content as
<tcdl:region id="Sidebar" type="SmartTarget">

</tcdl:region>

1.3.  Default Finish Actions
1.4.  Open Template Building Block to create PT for page(Suppose name as Smart Target PT)
1.5.  Drag DWT “ST Region DWT” to PT “Smart Target PT”
1.6.  Add SmartTarget Query tbb
1.7.  Add Promotions tbb
1.8.  Add Show SmartTarget Navigation tbb
1.9.  Add Search SmartTarget tbb
1.10.Add Show SmartTarget Items tbb
1.11.Add Apply SmartTarget Settings tbb
1.12. Configure parameter values of above tbbs
1.13.Run PT with page and check if it is working fine

2  .      Create dynamic CT for promotion component
Create a dynamic Component Template (Suppose SendContentToFredhopper) in Template Builder which uses the “Add to SmartTarget” Template Building Block to send content to Fredhopper.
2.1. Add Default DreamWeaver Component Design DWT
2.2.  Add “Add to SmartTarget” tbb
2.3.  Add Default finish action tbb
2.4.  Save and close CT.
2.5.  Add your promotion component schema(Suppose Promotion) as a linked schema

3  .      Create promotion component
Create a component (Suppose “ST Promotion”) with schema “Promotion”.

4  .      Create Promotion
Create a promotion by going to Targeting Tab of CME. Use Trigger as current date.

5  .      Create page
Create a page using PT “Smart Target PT” having component “ST Promotion” and CT “SendContentToFredhopper”.



Execute your Page

Happy Coding and Keep sharing :)

WCF RestService over Broker API

Introduction 

This service is created to get data from SDL Tridion Broker Database using broker API ,currently this service is tested with SDL Tridion 2013 SP1  


In this service you will see many methods are exposed and message format JSON and XML output.

Methods which are available

  1. Get Components by SchemaID
  2. Get Page by URL
  3. Get Page by TcmId 
  4. Get ComponentPresentation By TcmId
  5. Get multipleComponentPresentation By TcmId 
  6. Get ComponentPresentation By PublishedDate
  7. Get ComponentPresentation By SchemaID







Example
To request a page from the Tridion broker.
http://domainname/Tridion2013SP1Provider.svc/GetPagebyUrl/{publicationId}/{format}?url={url} 
http://domainname/Tridion2013SP1Provider.svc/GetPagebyUrl/2073/xml?url=/Collection/index.aspx

You can download the code from here

Happy coding and keep sharing :)

Tuesday 19 April 2016

Install SDL Web 8.1.1 on single machine

Required software for sample single-machine installation

  1. Microsoft Windows Server 2012 R2 (64-bit)
  2. Microsoft SQL Server 2012 SP2
  3. IIS 8.5 (included with Web Server role)
  4. Web Server role, Application Server role
  5. Oracle Java 8, Microsoft .NET Framework 4.5.2
  6. A domain system user for running various low-level services MTSUser

Step 1 .
Install Databases using  Windows PowerShell command line navigate to the the SDL Web installation files Database\MSSQL folder.

**** I have used and run all the power shell command using  Windows PowerShell ISE and run as administrator ****

Install Content Manager database.ps1
Install Topology Manager database.ps1
Install Content Data Store.ps1


Step 2
Access to the SDL web 8.1.1 media and run SDLWeb8CM.exe Provide all the required input and click on next.

Step 3
Ensure that the environment variable JAVA_HOME exists and refers to a compatible Java instance.


Step 4
Setting up Content Delivery for the sample single-machine installation 
create a folder called contentdeployer\ with a subfolder called roles\
From the installation media, copy the following folders with all of their contents, including subfolders, into the contentdeployer\roles\ folder:

  • deployer\
  • discovery\
  • preview\
  • session\
Update
contentdeployer\roles\deployer\standalone\config\cd_deployer_conf.xml
<Property Name="tcdl.target.language" Value="ref" />

contentdeployer\roles\deployer\standalone\config\cd_storage_conf.xml

<Item typeMapping="Page" cached="false" storageId="defaultFile"/>
  1. Open contentdeployer\resources\quickinstall\setenv.ps1 for editing.

Open contentdeployer\resources\quickinstall\setenv.ps1 for editing.and 
update the server name,database name,username,password,DEFAULT_FILE
 path and DEFAULT_DATA_FILE
navigate to contentdeployer\resources\quickinstall and run 
./quickinstall.ps1 -license C:\cd_licences.xml -enable-discovery -enable-deployer -enable-preview -enable-session'

Step 5
Create a Topology Type 
Add-TtmCdTopologyType -Id SampleTopologyType -Name StagingOnlyType -EnvironmentPurposes "Staging"

Content Delivery environment (in one line)
**Here while executing this command I have faced one issue If you want to use OAuth authentication on your Discovery service, you firstly need to register TokenServiceCapability ** StackExchange


Add-TtmCdEnvironment -Id SampleCD -EnvironmentPurpose "Staging" -DiscoveryEndpointUrl http://localhost:8082/discovery.svc 

  -AuthenticationType OAuth -ClientId cmuser -ClientSecret PASSWORD


Create a Topology
Add-TtmCdTopology -Id SampleTopology -Name StagingOnly -CdTopologyTypeId SampleTopologyType -CdEnvironmentIds SampleCD

Define a Web site 
Add-TtmWebsite -Id ApplicaitonName  -CdEnvironmentId SampleCD -BaseUrls http://localhost:82

Step 6
Publication and Testing Application
  1. create a demo publication and create Business Process Types, go to target type tab and select topology type which you have created and save and close
  2. Right click on you demo publication go to general tab and select Business Process Types
  3. Map you publication and webapplication run below command 
    1. Add-TtmMapping -Id ApplicaitonNamewebmapping -PublicationID PUBURI -WebApplicationId ApplicaitonName_RootWebApp
    2. PUBURI  is your publication URL tcm:0-8-1
Step 7
Update your Deployer cd_storage_conf and add

 <Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultFile"
                     defaultFilesystem="false">
                <Root Path="C:\ApplicaitonName" />
            </Storage>
            <Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultDataFile"
                     defaultFilesystem="true" defaultStorage="true">
                <Root Path="C:\ApplicaitonName\data" />
  </Storage>
and add item in the ItemTypes
<Item typeMapping="Page" cached="false" storageId="defaultFile"/>

Step 8
Go to your demo publication and create SC and Default page with default page template and publish 

Hit your site URL :)



Happy coding and keep sharing 


Monday 14 March 2016

Get List of all users in WEB 8. A basic alchemy plugin


Basic Steps 
1.    Download the Developer pack from visual studio gallery Link.
2.    Alchemy version that I have used can be downloaded from Alchemy4Tridion Version: 0.8.0.0 link.
3.    Create a project selecting "Starter Plugin Project" template change the project name .
4.    Build the project and navigate to the generated .a4t file.
5.    Drag and drop the file in alchemy window.



You can read the basics of an Alchemy plugin in the documentation 

Lets update the files go to : PluginControllers.cs  go to action methods and using CoreService client we can get the list of all users created in CM.

public string GetUserList()
   {
      List<TridionUserDetails> AuthorList = new List<TridionUserDetails>();
      var filter = new UsersFilterData { IsPredefined = false };
      var users = Client.GetSystemWideList(filter);
       foreach (TrusteeData user in users)
            {
AuthorList.Add(new TridionUserDetails(user.Id, user.Description,user.Title, user.IsEditable));
            }
               
          }            
      var output = JsonConvert.SerializeObject(AuthorList);
           
      return output.ToString();
   }

public class TridionUserDetails
{
    private string tcmuri;
    private string name;
    private string title;
    private bool? isEditable;


    public TridionUserDetails(string tcmuri, string name, string title, bool? isEditable)
    {
        this.tcmuri = tcmuri;
        this.name = name;
        this.title = title;
        this.isEditable = isEditable;


    }

    public string Tcmuri
    {
        get { return tcmuri; }
        set { tcmuri = value; }
    }

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    public string UserId
    {
        get { return title; }
        set { title = value; }
    }

    public bool? IsEditable
    {
        get { return isEditable; }
        set { isEditable = value; }
    }



}
Here, i have converted the output into JSON :) .later on you can consume this JSON on the popup window using Javascript e:g angular.js.

Command.JS file 

/**
 * Creates an anguilla command using a wrapper shorthand.
 *
 * Note the ${PluginName} will get replaced by the actual plugin name.
 */
Alchemy.command("${PluginName}", "GetUserList", {

    /**
     * If an init function is created, this will be called from the command's constructor when a command instance
     * is created.
     */
    init: function () { 
    },

    /**
     * Whether or not the command is enabled for the user (will usually have extensions displayed but disabled).
     * @returns {boolean}
     */
    isEnabled: function () {
        return true;
    }, 
    /**
     * Whether or not the command is available to the user.
     * @returns {boolean}
     */
    isAvailable: function () {
        return true;
    }, 
    /**
     * Executes your command. You can use _execute or execute as the property name.
     */
    execute: function () { 
       var progress = $messages.registerProgress("Getting ready to GetUserList...", null); 
        // This is the Promise pattern that the webapi proxy js exposes. Look at another example to
        // see how the callback method can also be used. Your WebAPI controller's route and route prefix
        // attributes controls how the namespace is generated.
        Alchemy.Plugins["${PluginName}"].Api.Service.GetUserList()
            .success(function (message) {
                //first arg in success is what's returned by your controller's action
                $messages.registerGoal(message);
            })
            .error(function (type, error) {
                // first arg is string that shows the type of error ie (500 Internal), 2nd arg is object representing
                // the error.  For BadRequests and Exceptions, the error message will be in the error.message property.
                $messages.registerError("There was an error", error.message);
            })
            .complete(function () {
                // this is called regardless of success or failure.
               // progress.finish();
            });
    }
});

If you wants to open pop-up then you need to create .aspx page in the views folder 

var url = "${ViewsUrl}/ListOfUsers.aspx?uri=" + message;
popup = $popup.create(url, "menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width=800,height=800", null);
popup.open();

PluginCommandSet.CS

public PluginCommandSet()
{
     // we only need to add the name of our command
     AddCommand("GetUserList");
}

PluginContextMenuExtension.CS

public PluginContextMenuExtension()
        {
            AssignId = ""; 
            // Use this property to specify where in the context menu your items will go
            InsertBefore = Constants.ContextMenuIds.MainContextMenu.SendItemLink; 
            // Use AddItem() or AddSubMenu() to add items for this context menu 
            //       element id      title        command name
            AddItem("Get_User_List_cm", "GetUsersList", "GetUsersList"); 
            // Add a dependency to the resource group that contains the files/commands that this toolbar extension will use.
            Dependencies.Add<PluginResourceGroup>(); 
            // apply the extension to a specific view.
            Apply.ToView(Constants.Views.DashboardView);
        }

PluginResourceGroup.CS 

public PluginResourceGroup()
        {
            // only the filename of our JS files are needed
            AddFile("Command.js");
            // only the filename of our CSS files are needed
            AddFile("Styles.css");
            // add genertic type param to reference our command set
            AddFile<PluginCommandSet>();

            // Adds the web api proxy JS to this resource group... this allows us to call
            // our webapi service without any 3rd party libs.
            AddWebApiProxy();

            // AddWebApiProxy() includes Alchemy.Core as a dependency already... if not using
            // the proxy you can remove the comment from below.

            // Dependencies.AddAlchemyCore();
        }

PluginRibbonToolbarButton.CS

  public PluginRibbonToolbarButton()
        {
            // The unique identifier used for the html element created.
            AssignId = "GetUsersListButton";

            // The name of the command to execute when clicked
            Command = "GetUsersList";

            // The label of the button.
            Name = "GetUsersList";

            // The page tab to assign this extension to. See Constants.PageIds.
            PageId = Constants.PageIds.HomePage;

            // Option GroupId, put this into an existing group (not capable if using a .ascx Control)
            GroupId = Constants.GroupIds.HomePage.ShareGroup;

            // The tooltip label that will get applied.
            Title = "GetUsersList";

            // Add a dependency to the resource group that contains the files/commands that this toolbar extension will use.
            Dependencies.Add<PluginResourceGroup>();

            // apply the extension to a specific view.
            Apply.ToView(Constants.Views.DashboardView, "DashboardToolbar");
        }


And Image files in the Images folder and update the Style.css.i have added two files user16.png and user32.png


/**
 * Style the context menu button... #Get_User_List_cm is defined in our Context Menu Extension class' AssignId property
 */
.contextmenu #Get_User_List_cm> .image {
    background-image: url('${ImgUrl}user16.png');
}

/**
 * Style the ribbon tool bar button... #GetUsersListButton is defined in our Ribbon Toolbar Button class' AssignId property
 */
/* main icon in full ribbon mode */
.ribbontoolbar #GetUsersListButton.button .image, .ribbontoolbar #GetUsersListButton.button .image
{
    background-image: url('${ImgUrl}user32.png');
}

/* main icon in minimized ribbon mode */
.ribbontoolbar.minimized #GetUsersListButton.button .image, .ribbontoolbar.minimized #GetUsersListButton.button .image
{
    background-image: url('${ImgUrl}user16.png');
}

After Updating all the files built your project and navigate to the generated .a4t file 




Open Alchemy In CM and  Drag and drop the .a4t  file in alchemy window.



    Refresh the CM session  and go to Content Explorer 




      Here you can see new option is added which is GetUserList click on it and you will get the list of users

      





Happy Coding and keep Sharing !!!!