/**
  * 
  * 
  */
 function generateDocID($id, $tproject_id)
 {
     $field_size = config_get('field_size');
     $item_info = $this->get_by_id($id);
     // Check if another req with same DOC ID exists on target container,
     // If yes generate a new DOC ID
     $getOptions = array('check_criteria' => 'like', 'access_key' => 'doc_id');
     $itemSet = $this->getByDocID($item_info['doc_id'], $tproject_id, null, $getOptions);
     $target_doc = $item_info['doc_id'];
     $instance = 1;
     if (!is_null($itemSet)) {
         // doc_id has limited size => we need to be sure that generated id will not exceed DB size
         $nameSet = array_flip(array_keys($itemSet));
         // 6 magic from " [xxx]"
         $prefix = trim_and_limit($item_info['doc_id'], $field_size->docid - 6);
         $target_doc = $prefix . " [{$instance}]";
         while (isset($nameSet[$target_doc])) {
             $instance++;
             $target_doc = $prefix . " [{$instance}]";
         }
     }
     return $target_doc;
 }
Пример #2
0
 /**
  * 
  *
  */
 function generateDocID($id, $tproject_id)
 {
     $item_info = $this->get_by_id($id);
     $item_info = $item_info[0];
     // Check if another req with same DOC ID exists on test project (MASTER CONTAINER),
     // If yes generate a new DOC ID
     $getOptions = array('check_criteria' => 'like', 'access_key' => 'req_doc_id');
     $itemSet = $this->getByDocID($item_info['req_doc_id'], $tproject_id, null, $getOptions);
     $target_doc = $item_info['req_doc_id'];
     $instance = 1;
     if (!is_null($itemSet)) {
         $safety_len = 2;
         // use t
         $mask = $this->reqCfg->duplicated_docid_algorithm->text;
         // req_doc_id has limited size then we need to be sure that generated id will
         // not exceed DB size
         $nameSet = array_flip(array_keys($itemSet));
         $prefix = trim_and_limit($item_info['req_doc_id'], $this->fieldSize->req_docid - strlen($mask) - $safety_len);
         // $target_doc = $prefix . " [{$instance}]";
         $target_doc = $prefix . sprintf($mask, $instance);
         while (isset($nameSet[$target_doc])) {
             $instance++;
             $target_doc = $prefix . sprintf($mask, $instance);
         }
     }
     return $target_doc;
 }
Пример #3
0
/**
 * Imports data from DocBook XML
 *
 * @return array of map
 *
 */
function importReqDataFromDocBook($fileName)
{
    $req_cfg = config_get('req_cfg');
    $docbookCfg = $req_cfg->importDocBook;
    $xmlReqs = null;
    $xmlData = null;
    $field_size = config_get('field_size');
    $simpleXMLObj = simplexml_load_file($fileName);
    $num_elem = count($simpleXMLObj->{$docbookCfg->requirement});
    $idx = 0;
    foreach ($simpleXMLObj->{$docbookCfg->requirement} as $xmlReq) {
        // get all child elements of this requirement
        $title = "";
        $description = "";
        $children = $xmlReq->children();
        foreach ($children as $child) {
            $nodeName = $child->getName();
            if ($nodeName == $docbookCfg->title) {
                $title = (string) $child;
            } else {
                if ($nodeName == $docbookCfg->ordered_list) {
                    $list = "";
                    foreach ($child->children() as $item) {
                        if ($item->getName() == $docbookCfg->list_item) {
                            if ($item->count() == 0) {
                                $list .= "<li>" . (string) $item . "</li>";
                            } else {
                                foreach ($docbookCfg->list_item_children as $ck) {
                                    if (property_exists($item, $ck)) {
                                        $list .= "<li>" . (string) $item->{$ck} . "</li>";
                                    }
                                }
                            }
                        }
                    }
                    $description .= "<ul>" . $list . "</ul>";
                } else {
                    if ($nodeName == $docbookCfg->table) {
                        $description .= getDocBookTableAsHtmlString($child, $docbookCfg);
                    } else {
                        if ($nodeName == $docbookCfg->paragraph) {
                            $description .= "<p>" . (string) $child . "</p>";
                        } else {
                            $description .= "<p>" . (string) $child . "</p>";
                        }
                    }
                }
            }
        }
        $xmlData[$idx]['description'] = $description;
        $xmlData[$idx]['title'] = trim_and_limit($title, $field_size->req_title);
        // parse Doc ID from requirement title
        // first remove any weird characters before the title. This could be probably omitted
        $xmlData[$idx]['title'] = preg_replace("/^[^a-zA-Z_0-9]*/", "", $xmlData[$idx]['title']);
        // get Doc ID
        //
        // this will create Doc ID as words ended with number
        // Example: Req BL 20 Business Logic
        // Doc ID: Req BL 20
        //if (preg_match("/[ a-zA-Z_]*[0-9]*/", $xmlData[$i]['title'], $matches))
        //{
        //  $xmlData[$i]['req_doc_id'] = $matches[0];
        //}
        // this matches first two words in Title and adds counter started from 1
        // Doc ID is grouped (case insensitive), so different groups have their own counter running
        // Example: Req BL Business Logic
        // Doc ID: Req BL 1
        // Note: Doc ID doesn't need trim_and_limit since it is parsed from Title
        // new dBug($xmlData[$idx]['title']);
        if (preg_match("/[ ]*[a-zA-Z_0-9]*[ ][a-zA-Z_0-9]*/", $xmlData[$idx]['title'], $matches)) {
            $index = strtolower($matches[0]);
            if (!isset($counter[$index])) {
                $counter[$index] = 0;
            }
            $counter[$index]++;
            $xmlData[$idx]['docid'] = $matches[0] . " " . $counter[$index];
        } else {
            $xmlData[$idx]['docid'] = uniqid('REQ-');
        }
        $xmlData[$idx]['node_order'] = $idx;
        $xmlData[$idx]['expected_coverage'] = 0;
        $xmlData[$idx]['type'] = TL_REQ_TYPE_FEATURE;
        $xmlData[$idx]['status'] = TL_REQ_STATUS_VALID;
        $idx++;
    }
    return $xmlData;
}
Пример #4
0
/**
 * Imports data from DocBook XML
 *
 * 20081103 - sisajr
 */
function importReqDataFromDocBook($fileName)
{
    $req_cfg = config_get('req_cfg');
    $docbookCfg = $req_cfg->importDocBook;
    // $docbookCfg->requirement= "sect3";
    // $docbookCfg->title= "title";
    // $docbookCfg->paragraph= "para";
    // $docbookCfg->ordered_list="orderedlist";
    // $docbookCfg->list_item="listitem";
    // $docbookCfg->table="informaltable";
    // $docbookCfg->table_group="tgroup";
    // $docbookCfg->table_head="thead";
    // $docbookCfg->table_body="tbody";
    // $docbookCfg->table_row="row";
    // $docbookCfg->table_entry="entry";
    // $docbookCfg->list_item_children = array('para','title');
    // $docbookCfg->table_entry_children = array('para');
    $xmlReqs = null;
    $xmlData = null;
    $field_size = config_get('field_size');
    $simpleXMLObj = simplexml_load_file($fileName);
    $num_elem = count($simpleXMLObj->sect1);
    $idx = 0;
    foreach ($simpleXMLObj->sect1 as $xmlReq) {
        // get all child elements of this requirement
        // $title = (string)$xmlReq->title;
        // echo $title . '<br>';
        $title = "";
        $description = "";
        $children = $xmlReq->children();
        foreach ($children as $child) {
            $nodeName = $child->getName();
            // echo 'node name:' . $nodeName .'<br>';
            if ($nodeName == $docbookCfg->title) {
                // echo 'INSIDE::' . $nodeName . '<br>';
                $title = (string) $child;
                // echo '$title:' . $title .'<br>';
            } else {
                if ($nodeName == $docbookCfg->ordered_list) {
                    // echo 'INSIDE' . $nodeName . '<br>';
                    $list = "";
                    foreach ($child->children() as $item) {
                        // echo 'xxx' . $item->getName() . '<br>';
                        if ($item->getName() == $docbookCfg->list_item) {
                            if ($item->count() == 0) {
                                $list .= "<li>" . (string) $item . "</li>";
                            } else {
                                foreach ($docbookCfg->list_item_children as $ck) {
                                    if (property_exists($item, $ck)) {
                                        $list .= "<li>" . (string) $item->{$ck} . "</li>";
                                    }
                                }
                            }
                        }
                    }
                    $description .= "<ul>" . $list . "</ul>";
                } else {
                    if ($nodeName == $docbookCfg->table) {
                        // echo 'INSIDE: ' . $nodeName . '<br>';
                        $description .= getDocBookTableAsHtmlString($child, $docbookCfg);
                    } else {
                        if ($nodeName == $docbookCfg->paragraph) {
                            $description .= "<p>" . (string) $child . "</p>";
                        } else {
                            $description .= "<p>" . (string) $child . "</p>";
                        }
                    }
                }
            }
        }
        // echo '$description:' . '<xmp>' . $description . '</xmp>' . '<br>';
        $xmlData[$idx]['description'] = $description;
        $xmlData[$idx]['title'] = trim_and_limit($title, $field_size->req_title);
        // parse Doc ID from requirement title
        // first remove any weird characters before the title. This could be probably omitted
        $xmlData[$idx]['title'] = preg_replace("/^[^a-zA-Z_0-9]*/", "", $xmlData[$idx]['title']);
        // get Doc ID
        //
        // this will create Doc ID as words ended with number
        // Example: Req BL 20 Business Logic
        // Doc ID: Req BL 20
        //if (preg_match("/[ a-zA-Z_]*[0-9]*/", $xmlData[$i]['title'], $matches))
        //{
        //	$xmlData[$i]['req_doc_id'] = $matches[0];
        //}
        // this matches first two words in Title and adds counter started from 1
        // Doc ID is grouped (case insensitive), so different groups have their own counter running
        // Example: Req BL Business Logic
        // Doc ID: Req BL 1
        // Note: Doc ID doesn't need trim_and_limit since it is parsed from Title
        // new dBug($xmlData[$idx]['title']);
        if (preg_match("/[ ]*[a-zA-Z_0-9]*[ ][a-zA-Z_0-9]*/", $xmlData[$idx]['title'], $matches)) {
            $index = strtolower($matches[0]);
            if (!isset($counter[$index])) {
                $counter[$index] = 0;
            }
            $counter[$index]++;
            $xmlData[$idx]['req_doc_id'] = $matches[0] . " " . $counter[$index];
        }
        $idx++;
    }
    new dBug($xmlData);
    return $xmlData;
}