How to add linked content

[tab:Actions]

Requirements

In order to be able to perform this operation, the following conditions must be complied:

  • You must use a business user and therefore possess its credentials (username and password or token). Some applications have the right to edit content, in this case you can authenticate through its appId.

  • The user must be the owner of the content or must have the write access over the content.

 

Add linked content

In THRON you can create links between different content, these linked can be declined in two different types: we refer to attachments and recommended content; the difference is that in the first case you want to allow downloading of the content for other users, while in the second case you just wants to allow content’s viewing for other user’s since it may be related to the main content by its topic. For security reasons, not all the content can be linked to other, but only those having Shareboard’s flag “Content can be linked to other content” set to “true”.

You can use the service addLinkedContents in order to add linked content given their xcontentId; with the parameter linkType in the body of the request you can specify whether to add them as “RECOMMENDED” or as “DOWNLOADABLE”. In order to remove such content you can use the service removeLinkedContents.

A necessary condition in order to link one content to another is that the content does not have the "UNLINKABLE" property. If this is the case, such property has to be removed from the content itself before linking it to any other content. In order to do so, the first thing to do is to invoke a getContentDetail on the content you want to link. In the response you will find the properties object related to the content itself. Make sure that among those properties there is no "UNLINKABLE" property. If this is the case you will have to remove such property by invoking an updateContent

Note: The updateContent is a patch service, this means that if the content has more than one property, in order to remove just one of them you will still have to provide all the other properties. E.g. if the content has the following properties:

 

    "properties": [
            "COMMENTSALLOWED",
            "RATINGALLOWED",
            "UNLINKABLE"
        ],

 

in order to remove the unlinkable property, in the body of the updateContent request you will still have to provide "COMMENTSALLOWED" and "RATINGALLOWED".

Once the content has been made linkable, the function addLinkedContents , used to "tie" content to another, which is located within xcontents in the “content” package can be invoked.
In order to use it you must have a valid platform  token,  which can be obtained by logging in to platform.
The url of the request is structured as follows:

 

//[clientId]-view.thron.com/api/xcontents/resources/content/addLinkedContents

 

The headers that should be used for the request, which must be in POST are:

  • Content-Type : application / json
  • X - TokenId : XXXXX (using the token obtained through the login)

In the body of the request, you can paste the following JSON, filling required information:

 

{
  "clientId": "",
  "contentId": "",
  "linkedContents": {
    "contents": [
      {
        "xcontentId": "",
        "linkType": "",
        "position": 0
      }
    ]
  }
}

 

Where :

    • clientId: filled using the service code name (usually company name)
    • contentid: filled with the xcontentId of the content to be updated
    • linkedContents containing:
      • contents: array objects of MLinkedContent type, each object must have the following fields:
        • xcontentId: the id of the content that you want to connect
        • linkType: the type of connection you want to make, with these possible values:
          • RECOMMENDED for recommended content
          • DOWNLOADABLE for attachments
        • position: the position of the content in the lists.

[/tab] [tab:Code Samples][dropdown:PHP - ADDING LINKED CONTENT]

<?php
/**
 * @author THRON S.p.A.
 * @copyright 2015
 */
include_once ("package/Swagger.php");

/**
 * Config info
 */
$token = "";
$client_idTHRON = "";
$xcontentId = "";
$xcontentIdToAdd = "";
$server = "http://" . $client_idTHRON . "-view.thron.com";
$urlAddLinked = "/api/xcontents/resources/content/addLinkedContents";

// Creation of the client to make the call

$request = new APIClient($token, $server);

// Configuration of the request body

$requestBody = new MContentaddLinkedContentsReq();
$requestBody->clientId = $client_idTHRON;
$requestBody->contentId = $xcontentId;
$requestBody->linkedContents = new MLinkedContents();
$requestBody->linkedContents->contents = array();
$requestBody->linkedContents->contents[0] = new MLinkedContent();
$requestBody->linkedContents->contents[0]->xcontentId = $xcontentIdToAdd;

// $requestBody->linkedContents->contents[0]->linkType = "RECOMMENDED";

$requestBody->linkedContents->contents[0]->linkType = "DOWNLOADABLE";

// Configuration of the request Headers

$header = array(
    "Content-Type: application/json",
    "X-TOKENID:" . $token
);
try
    {
    $response = $request->callAPI($urlAddLinked, "POST", null, $requestBody, $header);
    var_dump($response);
    }

catch(Exception $e)
    {
    var_dump($e);
    }

?>

[/dropdown] [dropdown:JAVA - ADDING LINKED CONTENT]

/**

* Created by THRON S.p.A. on 06/11/14.

*/



import it.newvision.nvp.xcontents.model.MELinkType;

import it.newvision.nvp.xcontents.services.model.content.MLinkedContent;

import it.newvision.nvp.xcontents.services.model.content.MLinkedContents;

import it.newvision.nvp.xcontents.services.model.content.MResponseContent;

import it.newvision.nvp.xcontents.services.model.request.MContentaddLinkedContentsReq;

import it.newvision.nvp.xcontents.services.rest.JContentClient;



import org.codehaus.jackson.map.ObjectMapper;



import java.util.ArrayList;

import java.util.List;



public class addLinkedContent {



 public static void main(String[] args)

 {

  /*SETUP FILE*/

  String clientId = "CLIENTID"; // clientID

  String token = "TOKENID"; // token

  String xcontentId = "XCONTENTID"; // video xcontentID

  String addXcontentId = "XCONTENTID ADD"; // add

  MELinkType addXType = MELinkType.RECOMMENDED; // type add RECOMMENDED(MELinkType.RECOMMENDED) or DOWNLOADABLE (MELinkType.DOWNLOADABLE)



  //init object

  ObjectMapper mapper = new ObjectMapper();



  // UPDATE CONTENT API

  JContentClient linkContent = new JContentClient("http://" + clientId + "-view.thron.com/api/xcontents/resources");



  try {

   //--------------------------

   // ADD RECOMMENDED or DOWNLOADABLE  Content

   //--------------------------

   //set value linked content

   MLinkedContent linkedContent = new MLinkedContent();

   linkedContent.setXcontentId(addXcontentId); //add content id

   linkedContent.setLinkType(addXType);

   // list content link to content

   List < MLinkedContent > listLinkedContents = new ArrayList < MLinkedContent > ();

   listLinkedContents.add(linkedContent);

   // list content link to content

   MLinkedContents linkedContents = new MLinkedContents();

   linkedContents.setContents(listLinkedContents);

   //init request add

   MContentaddLinkedContentsReq contentaddLinkedContentsReq = new MContentaddLinkedContentsReq();

   contentaddLinkedContentsReq.setClientId(clientId);

   contentaddLinkedContentsReq.setContentId(xcontentId);

   contentaddLinkedContentsReq.setLinkedContents(linkedContents);

   //send request

   MResponseContent risReplace = linkContent.addLinkedContents(token, contentaddLinkedContentsReq, null);

   //result replace thumbnail content  video

   System.out.println(" add link content type:" + addXType.toString());

   System.out.println(mapper.writeValueAsString(risReplace));

  } catch (Exception e)

  {

   //error output

   System.out.println(e);

  }

 }

}

[/dropdown] [/tab]

Was this article helpful?
0 out of 0 found this helpful

Have more questions?

SUBMIT A REQUEST

Hai altre domande?

INOLTRA UNA RICHIESTA

Comments