Best practise "geman" TFS2013 integration for TL 1.9.13.0

LATEST Official version.
Questions and discussions - NO ISSUES
FOR ISSUES => http://mantis.testlink.org

Moderators: Amaradana, TurboPT, TL Developers

Best practise "geman" TFS2013 integration for TL 1.9.13.0

Postby christian_s » Tue Mar 10, 2015 1:25 pm

This is our best practise "geman" TFS2013 integration for TL 1.9.13.0 - We used a "mantisdbinterface.class.php" and changed relevant rows:

1.) Insert a new row "200" in "...\lib\functions\tlIssueTracker.class.php"

Code: Select all
var $systems = array( 1 =>  array('type' => 'bugzilla', 'api' => 'xmlrpc', 'enabled' => true, 'order' => -1),
                        2 =>  array('type' => 'bugzilla', 'api' => 'db', 'enabled' => true, 'order' => -1),
                        3 =>  array('type' => 'mantis', 'api' =>'soap', 'enabled' => true, 'order' => -1),
                        4 =>  array('type' => 'mantis', 'api' =>'db', 'enabled' => true, 'order' => -1),
                        5 =>  array('type' => 'jira', 'api' =>'soap', 'enabled' => true, 'order' => -1),
                        6 =>  array('type' => 'jira', 'api' =>'db', 'enabled' => true, 'order' => -1),
                        7 =>  array('type' => 'jira', 'api' =>'rest', 'enabled' => true, 'order' => -1),
                        8 =>  array('type' => 'fogbugz','api' =>'rest','enabled' => true, 'order' => -1),
                        9 =>  array('type' => 'fogbugz','api' =>'db','enabled' => true, 'order' => -1),
                       10 =>  array('type' => 'gforge','api' =>'soap','enabled' => false, 'order' => -1),
                       11 =>  array('type' => 'gforge','api' =>'db','enabled' => false, 'order' => -1),
                       12 =>  array('type' => 'eventum','api' =>'db', 'enabled' => false, 'order' => -1),
                       13 =>  array('type' => 'polarion', 'api' =>'soap', 'enabled' => false, 'order' => -1),
                       14 =>  array('type' => 'youtrack','api' =>'rest','enabled' => true, 'order' => -1),
                       15 =>  array('type' => 'redmine','api' =>'rest','enabled' => true, 'order' => -1),
                       16 =>  array('type' => 'redmine','api' =>'db','enabled' => false, 'order' => -1),
                       17 =>  array('type' => 'seapine','api' =>'soap','enabled' => false, 'order' => -1),
                       18 =>  array('type' => 'seapine','api' =>'db','enabled' => false, 'order' => -1),
                       19 =>  array('type' => 'trac','api' =>'xmlrpc','enabled' => true, 'order' => -1),
                       20 =>  array('type' => 'trackplus','api' =>'soap','enabled' => false, 'order' => -1),
                       21 =>  array('type' => 'trackplus','api' =>'db','enabled' => false, 'order' => -1),
                       200 =>  array('type' => 'tfs','api' =>'db','enabled' => true, 'order' => -1));


2.) Insert/Make/copy a new file with following name "...\lib\issuetrackerintegration\tfsdbInterface.class.php":

Code: Select all
<?php
/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 *
 * @filesource  tfsdbInterface.class.php
 * @since 1.9.4
 *
 * @internal revision
 * @since 1.9.10
 *
**/
class tfsdbInterface extends issueTrackerInterface
{
  private $code_status = array('Neu' => 'new','Entfernt' => 'feedback','Angefordert' => 'acknowledged',
                               'Entwurf' => 'confirmed','Aktiv' => 'assigned','Gelöst' => 'resolved','Geschlossen' => 'closed');
                        
  private $status_color = array('new'          => '#ffa0a0', # red,
                                'feedback'     => '#ff50a8', # purple
                                'acknowledged' => '#ffd850', # orange
                                'confirmed'    => '#ffffb0', # yellow
                                'assigned'     => '#c8c8ff', # blue
                                'resolved'     => '#cceedd', # buish-green
                                'closed'       => '#e8e8e8'); # light gray

  var $defaultResolvedStatus;


  /**
   * Construct and connect to BTS.
   *
   * @param str $type (see tlIssueTracker.class.php $systems property)
   * @param xml $cfg
   **/
  function __construct($type,$config,$name)
  {
   
    parent::__construct($type,$config,$name);
    if( !$this->isConnected() )
    {
      return false;
    }

    $this->interfaceViaDB = true;
    $this->defaultResolvedStatus = array();
    $this->defaultResolvedStatus[] = array('code' => 'Gelöst', 'verbose' => 'resolved');
    $this->defaultResolvedStatus[] = array('code' => 'Geschlossen', 'verbose' => 'closed');
   
    $this->setResolvedStatusCfg();
   
    $this->methodOpt['buildViewBugLink'] = array('addSummary' => true, 'colorByStatus' => true);
    $this->guiCfg = array('use_decoration' => true);
    if( property_exists($this->cfg, 'statuscfg') )
    {
      $this->setStatusCfg();
    }
  }

 
  /**
   * Return the URL to the bugtracking page for viewing
   * the bug with the given id.
   *
   * @param int id the bug id
   *
   * @return string returns a complete URL to view the bug
   **/
  function buildViewBugURL($id)
  {
    return $this->cfg->uriview . urlencode($id);
  }

  /**
   *
   **/
  function getIssue($id)
  {
    $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
    if (!$this->isConnected())
    {
      return false;
    }
    $sql = "/* $debugMsg */ SELECT ID AS id, State AS status, Title AS summary FROM dbo.WorkItemsAre " .
           " WHERE ID = " . intval($id);
   
    $rs = $this->dbConnection->fetchRowsIntoMap($sql,'id');
    $issue = null;
    if( !is_null($rs) )
    {
      $issueOnTfsDB = current($rs);
      $issue = new stdClass();
      $issue->IDHTMLString = "<b>{$id} : </b>";
      $issue->summaryHTMLString = $issueOnTfsDB['summary'];
      $issue->statusCode = $issueOnTfsDB['status'];
      $issue->isResolved = isset($this->resolvedStatus->byCode[$issue->statusCode]);

      if( isset($this->code_status[$issue->statusCode]) )
      {
        $issue->statusVerbose = $this->code_status[$issue->statusCode];
      }
      else
      {
        // give info to user on Event Viewer
        $msg = lang_get('MANTIS_status_not_configured');
        $msg = sprintf($msg,$issueOnTfsDB['status']);
        logWarningEvent($msg,"MANTIS INTEGRATION");
        $issue->statusVerbose = 'custom_undefined_on_tl';
      }

      $issue->statusHTMLString = $this->buildStatusHTMLString($issue->statusVerbose);
      $issue->statusColor = isset($this->status_color[$issue->statusVerbose]) ?
      $this->status_color[$issue->statusVerbose] : 'white';
     
    }
    return $issue; 
  }


 
  /**
   * Returns the status of the bug with the given id
   * this function is not directly called by TestLink.
   *
   * @return string returns the status of the given bug (if found in the db), or false else
   **/
  function getBugStatus($id)
  {
    if (!$this->isConnected())
    {
      return false;
    }
    $issue = $this->getIssue($id);
    return (!is_null($issue) && $issue) ? $issue->statusVerbose : null;
  }

 
    /**
   * checks is bug id is present on BTS
   *
   * @return integer returns 1 if the bug with the given id exists
   **/
  function checkBugIDExistence($id)
  {
    $status_ok = 0;
    $query = "SELECT State AS status FROM dbo.WorkItemsAre WHERE ID='" . $id ."'";
    $result = $this->dbConnection->exec_query($query);
    if ($result && ($this->dbConnection->num_rows($result) == 1))
    {
      $status_ok = 1;   
    }
    return $status_ok;
  }
 
  /**
   * checks id for validity
   *
   * @param string issueID
   *
   * @return bool returns true if the bugid has the right format, false else
   **/
  function checkBugIDSyntax($issueID)
  {
    return $this->checkBugIDSyntaxNumeric($issueID);
  }

  /**
   *
   *
   **/
  function buildStatusHTMLString($statusVerbose)
  {
    $str = '';
    if ($statusVerbose !== false)
    {
      // status values depends on your mantis configuration at config_inc.php in $g_status_enum_string,
      // below is the default:
      //'10:new,20:feedback,30:acknowledged,40:confirmed,50:assigned,80:resolved,90:closed'
      // With this replace if user configure status on mantis with blank we do not have problems
      //
      $tlStatus = str_replace(" ", "_", $statusVerbose);
      $str = lang_get('issue_status_' . $tlStatus);
      if($this->guiCfg['use_decoration'])
      {
        $str = "[" . $str . "] ";
      }
    }
    return $str;
  }


  function getMyInterface()
  {
    return $this->cfg->interfacePHP;
  }

  public static function getCfgTemplate()
  {
      $template = "<!-- Template " . __CLASS__ . " -->\n" .
                "<issuetracker>\n" .
                "<dbhost>DATABASE SERVER NAME</dbhost>\n" .
                "<dbname>DATABASE NAME</dbname>\n" .
                "<dbtype>mssql</dbtype>\n" .
                "<dbuser>USER</dbuser>\n" .
                "<dbpassword>PASSWORD</dbpassword>\n" .
                "<uriview>http://localhost:8080/tfs/DefaultCollection/CS3/_workitems#_a=edit%26id=</uriview>\n" .
                "<uricreate>http://localhost:8080/tfs/DefaultCollection/CS3/_workItems/create/Fehler</uricreate>\n" .
                "<!-- Optional -->\n" .
                "<statuscfg>\n" .
                "<status><code>Neu</code><verbose>new</verbose><color>#ffa0a0</color></status>\n" .
                "<status><code>Entfernt</code><verbose>feedback</verbose><color>#ff50a8</color></status>\n" .
                "<status><code>Angefordert</code><verbose>acknowledged</verbose><color>#ffd850</color></status>\n" .
                "<status><code>Entwurf</code><verbose>confirmed</verbose><color>#ffffb0</color></status>\n" .
                "<status><code>Aktiv</code><verbose>assigned</verbose><color>#c8c8ff</color></status>\n" .
                "<status><code>Gelöst</code><verbose>resolved</verbose><color>#cceedd</color></status>\n" .
                "<status><code>Geschlossen</code><verbose>closed</verbose><color>#e8e8e8</color></status>\n" .
                "</statuscfg>\n" .
                "<!-- Configure This if you want NON STANDARD BEHAIVOUR for considered issue resolved -->\n" .
                "<resolvedstatus>\n" .
                "<status><code>Gelöst</code><verbose>resolved</verbose></status>\n" .
                "<status><code>Geschlossen</code><verbose>closed</verbose></status>\n" .
                "</resolvedstatus>\n" .
                "</issuetracker>\n";
    return $template;
  }
 
  public function setStatusCfg()
  {
    $statusCfg = (array)$this->cfg->statuscfg;
    foreach($statusCfg['status'] as $cfx)
    {
      $e = (array)$cfx;
      $this->code_status[$e['code']] = $e['verbose'];
      $this->status_color[$e['verbose']] = $e['color'];
    }
  }

  public function getCodeStatus()
  {
      return $this->code_status;
  }

  public function getStatusColor()
  {
      return $this->status_color;
  }

}
?>


3.) Now you can make a new "IssueTracker" in "IssueTrackerManagement" with following infos (change all relevant Tags). In <uriview> we have to change %26 from "getcfgtemplate" to ?amp; then it works:

Code: Select all
<issuetracker>
<dbhost>DATABASE SERVER NAME</dbhost>
<dbname>DATABASE NAME</dbname>
<dbtype>mssql</dbtype>
<dbuser>USER</dbuser>
<dbpassword>PASSWORD</dbpassword>
<uriview>http://localhost:8080/tfs/DefaultCollection/CS3/_workitems#_a=edit?amp;id=</uriview>
<uricreate>http://localhost:8080/tfs/DefaultCollection/CS3/_workItems/create/Fehler</uricreate>
<!-- Optional -->
<statuscfg>
<status><code>Neu</code><verbose>new</verbose><color>#ffa0a0</color></status>
<status><code>Entfernt</code><verbose>feedback</verbose><color>#ff50a8</color></status>
<status><code>Angefordert</code><verbose>acknowledged</verbose><color>#ffd850</color></status>
<status><code>Entwurf</code><verbose>confirmed</verbose><color>#ffffb0</color></status>
<status><code>Aktiv</code><verbose>assigned</verbose><color>#c8c8ff</color></status>
<status><code>Geloest</code><verbose>resolved</verbose><color>#cceedd</color></status>
<status><code>Geschlossen</code><verbose>closed</verbose><color>#e8e8e8</color></status>
</statuscfg>
<!-- Configure This if you want NON STANDARD BEHAIVOUR for considered issue resolved -->
<resolvedstatus>
<status><code>Geloest</code><verbose>resolved</verbose></status>
<status><code>Geschlossen</code><verbose>closed</verbose></status>
</resolvedstatus>
</issuetracker>


4.) Maybe you have to change the german strings to english and make some inserts in the language file "strings.txt"

5.) For us this best practise works fine and we can make new tickets in TFS2013 and save the id to testlink.
christian_s
TestLink user
 
Posts: 1
Joined: Wed Mar 04, 2015 1:36 pm

Re: Best practise "geman" TFS2013 integration for TL 1.9.13.

Postby archonwang1981 » Fri Mar 13, 2015 8:39 am

WOW! Great!
U can submit it as a new merge request as well.
archonwang1981
Advanced user
 
Posts: 24
Joined: Sat Jun 01, 2013 7:02 am


Return to TestLink 1.9



Who is online

Users browsing this forum: No registered users and 2 guests