Ejemplo n.º 1
0
function compareImportedReqs(&$dbHandler, $arrImportSource, $tprojectID, $reqSpecID)
{
    $reqCfg = config_get('req_cfg');
    $labels = array('type' => $reqCfg->type_labels, 'status' => $reqCfg->status_labels);
    $verbose = array('type' => null, 'status' => null);
    $cache = array('type' => null, 'status' => null);
    $cacheKeys = array_keys($cache);
    $unknown_code = lang_get('unknown_code');
    $reqMgr = new requirement_mgr($dbHandler);
    $arrImport = null;
    if ($loop2do = count($arrImportSource)) {
        $getOptions = array('output' => 'minimun');
        $messages = array('ok' => '', 'import_req_conflicts_other_branch' => '', 'import_req_exists_here' => '');
        foreach ($messages as $key => $dummy) {
            $messages[$key] = lang_get($key);
        }
        for ($idx = 0; $idx < $loop2do; $idx++) {
            $msgID = 'ok';
            $req = $arrImportSource[$idx];
            // Check:
            // If item with SAME DOCID exists inside container
            // If there is a hit
            //     We will follow user option: update,create new version
            //
            // If do not exist check must be repeated, but on WHOLE test project
            //  If there is a hit -> we can not create
            //    else => create
            //
            //
            // 20100321 - we do not manage yet user option
            $check_in_reqspec = $reqMgr->getByDocID($req['docid'], $tprojectID, $reqSpecID, $getOptions);
            if (is_null($check_in_reqspec)) {
                $check_in_tproject = $reqMgr->getByDocID($req['docid'], $tprojectID, null, $getOptions);
                if (!is_null($check_in_tproject)) {
                    $msgID = 'import_req_conflicts_other_branch';
                }
            } else {
                $msgID = 'import_req_exists_here';
            }
            foreach ($cacheKeys as $attr) {
                if (isset($labels[$attr][$req[$attr]])) {
                    if (!isset($cache[$attr][$req[$attr]])) {
                        $cache[$attr][$req[$attr]] = lang_get($labels[$attr][$req[$attr]]);
                    }
                    $verbose[$attr] = $cache[$attr][$req[$attr]];
                } else {
                    $verbose[$attr] = sprintf($unknown_code, $req[$attr]);
                }
            }
            $arrImport[] = array('req_doc_id' => $req['docid'], 'title' => trim($req['title']), 'scope' => $req['description'], 'type' => $verbose['type'], 'status' => $verbose['status'], 'expected_coverage' => $req['expected_coverage'], 'node_order' => $req['order'], 'check_status' => $messages[$msgID]);
        }
    }
    return $arrImport;
}
 /**
  * create a req spec tree on system from $xml data
  *
  *
  *  
  */
 function createFromXML($xml, $tproject_id, $parent_id, $author_id, $filters = null, $options = null)
 {
     $user_feedback = null;
     $items = $this->xmlToMapReqSpec($xml);
     $req_mgr = new requirement_mgr($this->db);
     $copy_reqspec = null;
     $copy_req = null;
     $getOptions = array('output' => 'minimun');
     $has_filters = !is_null($filters);
     $my['options'] = array('actionOnDuplicate' => "update");
     $my['options'] = array_merge($my['options'], (array) $options);
     $labels = array('import_req_spec_created' => '', 'import_req_spec_skipped' => '', 'import_req_spec_updated' => '', 'import_req_spec_ancestor_skipped' => '', 'import_req_created' => '', 'import_req_skipped' => '', 'import_req_updated' => '');
     foreach ($labels as $key => $dummy) {
         $labels[$key] = lang_get($key);
     }
     if ($has_filters) {
         if (!is_null($filters['requirements'])) {
             foreach ($filters['requirements'] as $reqspec_pos => $requirements_pos) {
                 $copy_req[$reqspec_pos] = is_null($requirements_pos) ? null : array_keys($requirements_pos);
             }
         }
     }
     $loop2do = count($items);
     $container_id[0] = is_null($parent_id) || $parent_id == 0 ? $tproject_id : $parent_id;
     // items is an array of req. specs
     $skip_level = -1;
     for ($idx = 0; $idx < $loop2do; $idx++) {
         $rspec = $items[$idx]['req_spec'];
         $depth = $rspec['level'];
         if ($skip_level > 0 && $depth >= $skip_level) {
             $msgID = 'import_req_spec_ancestor_skipped';
             $user_feedback[] = array('doc_id' => $rspec['doc_id'], 'title' => $rspec['title'], 'import_status' => sprintf($labels[$msgID], $rspec['doc_id']));
             continue;
         }
         $req_spec_order = isset($rspec['node_order']) ? $rspec['node_order'] : 0;
         // 20100320 -
         // Check if req spec with same DOCID exists, inside container_id
         // If there is a hit
         //	  We will go in update
         // If Check fails, need to repeat check on WHOLE Testproject.
         // If now there is a HIT we can not import this branch
         // If Check fails => we can import creating a new one.
         //
         // Important thing:
         // Working in this way, i.e. doing check while walking the structure to import
         // we can end importing struct with 'holes'.
         //
         $check_in_container = $this->getByDocID($rspec['doc_id'], $tproject_id, $container_id[$depth], $getOptions);
         $skip_level = $depth + 1;
         $result['status_ok'] = 0;
         $msgID = 'import_req_spec_skipped';
         if (is_null($check_in_container)) {
             $check_in_tproject = $this->getByDocID($rspec['doc_id'], $tproject_id, null, $getOptions);
             if (is_null($check_in_tproject)) {
                 $msgID = 'import_req_spec_created';
                 $result = $this->create($tproject_id, $container_id[$depth], $rspec['doc_id'], $rspec['title'], $rspec['scope'], $rspec['total_req'], $author_id, $rspec['type'], $req_spec_order);
             }
         } else {
             $msgID = 'import_req_spec_updated';
             $reqSpecID = key($check_in_container);
             $result = $this->update($reqSpecID, $rspec['doc_id'], $rspec['title'], $rspec['scope'], $rspec['total_req'], $author_id, $rspec['type'], $req_spec_order);
             $result['id'] = $reqSpecID;
         }
         $user_feedback[] = array('doc_id' => $rspec['doc_id'], 'title' => $rspec['title'], 'import_status' => sprintf($labels[$msgID], $rspec['doc_id']));
         if ($result['status_ok']) {
             $skip_level = -1;
             $container_id[$depth + 1] = $reqSpecID = $result['id'];
             $reqSet = $items[$idx]['requirements'];
             $create_req = (!$has_filters || isset($copy_req[$idx])) && !is_null($reqSet);
             if ($create_req) {
                 $items_qty = isset($copy_req[$idx]) ? count($copy_req[$idx]) : count($reqSet);
                 $keys2insert = isset($copy_req[$idx]) ? $copy_req[$idx] : array_keys($reqSet);
                 for ($jdx = 0; $jdx < $items_qty; $jdx++) {
                     $req = $reqSet[$keys2insert[$jdx]];
                     // Check:
                     // If item with SAME DOCID exists inside container
                     // If there is a hit
                     //	   We will follow user option: update,create new version
                     //
                     // If do not exist check must be repeated, but on WHOLE test project
                     // 	If there is a hit -> we can not create
                     //		else => create
                     //
                     //
                     // 20100321 - we do not manage yet user option
                     $msgID = 'import_req_skipped';
                     $check_in_reqspec = $req_mgr->getByDocID($req['docid'], $tproject_id, $reqSpecID, $getOptions);
                     if (is_null($check_in_reqspec)) {
                         $check_in_tproject = $req_mgr->getByDocID($req['docid'], $tproject_id, null, $getOptions);
                         if (is_null($check_in_tproject)) {
                             $req_mgr->create($result['id'], $req['docid'], $req['title'], $req['description'], $author_id, $req['status'], $req['type'], $req['expected_coverage'], $req['node_order']);
                             $msgID = 'import_req_created';
                         }
                     } else {
                         // function update($id,$version_id,$reqdoc_id,$title, $scope, $user_id, $status, $type,
                         // 				   $expected_coverage,$node_order=null,$skip_controls=0)
                         //
                         // Need to get Last Version no matter active or not.
                         // What to do if is Frozen ??? -> now ignore and update anyway
                         $reqID = key($check_in_reqspec);
                         $last_version = $req_mgr->get_last_version_info($reqID);
                         $result = $req_mgr->update($reqID, $last_version['id'], $req['docid'], $req['title'], $req['description'], $author_id, $req['status'], $req['type'], $req['expected_coverage'], $req['node_order']);
                         $msgID = 'import_req_updated';
                     }
                 }
                 $user_feedback[] = array('doc_id' => $req['docid'], 'title' => $req['title'], 'import_status' => sprintf($labels[$msgID], $req['docid']));
             }
             // if($create_req)
         }
         // if($result['status_ok'])
     }
     return $user_feedback;
 }
Ejemplo n.º 3
0
/**
 * process_req
 *
 * @internal revisions:
 * 20110601 - asimon - add a new (valid) direct link to output if a nonexistent version of a valid req is requested
 * 20110530 - asimon - BUGID 4298: refactored this function to be able to operate with specific versions
 */
function process_req(&$dbHandler, $docID, $tprojectID, $tprojectPrefix, $version)
{
    $ret = array('url' => null, 'msg' => null);
    // First step: get this requirement's database ID by its Doc-ID (only if this Doc-ID exists).
    $req_mgr = new requirement_mgr($dbHandler);
    $req = $req_mgr->getByDocID($docID, $tprojectID);
    $req = is_null($req) ? null : current($req);
    $req_id = is_null($req) ? null : $req['id'];
    $version_id = null;
    if (is_null($req_id)) {
        $ret['msg'] = sprintf(lang_get('req_not_found'), $docID, $tprojectPrefix);
    }
    // Second step: If the requirement exists and a version was given, we have to check here if this specific version exists, too.
    if (!is_null($req_id) && !is_null($version) && is_numeric($version)) {
        $req = $req_mgr->get_by_id($req_id, null, $version);
        $req = is_null($req) ? null : current($req);
        // does this requirement really have the correct version number?
        $version_id = !is_null($req) && $req['version'] == $version ? $req['version_id'] : null;
        if (is_null($version_id)) {
            // add direct link to current version to output
            $req_url = $_SESSION['basehref'] . 'linkto.php?load&tprojectPrefix=' . urlencode($tprojectPrefix) . '&item=req&id=' . urlencode($docID);
            $ret['msg'] = sprintf(lang_get('req_version_not_found'), $version, $docID, $tprojectPrefix);
            $ret['msg'] .= sprintf(" <a href=\"{$req_url}\">%s</a>", lang_get('direct_link_on_wrong_version'));
            $req_id = null;
        }
    }
    // Third and last step: set cookie and build the link (only if the requested item really was found).
    if (!is_null($req_id)) {
        if (!is_null($version_id)) {
            // link to open in requirement frame must include version
            $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req_id}&req_version_id={$version_id}";
        } else {
            // link to open in requirement frame does not include a version, it was not requested
            $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req_id}";
        }
        $cookie = buildCookie($dbHandler, $req_id, $tprojectID, 'ys-requirement_spec');
        setcookie($cookie['value'], $cookie['path'], TL_COOKIE_KEEPTIME, '/');
    }
    return $ret;
}
Ejemplo n.º 4
0
/**
 * process_req
 *
 */
function process_req(&$dbHandler, $docID, $tprojectID, $tprojectPrefix)
{
    $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy', 'req_specs', 'tcversions'));
    $ret = array();
    $ret['url'] = null;
    $ret['msg'] = sprintf(lang_get('req_not_found'), $docID, $tprojectPrefix);
    $req_mgr = new requirement_mgr($dbHandler);
    $req = $req_mgr->getByDocID($docID, $tprojectID);
    if (!is_null($req)) {
        // link to open in requirement frame
        $req = current($req);
        $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req['id']}";
        $cookie = buildCookie($dbHandler, $req['id'], $tprojectID, 'ys-requirement_spec');
        setcookie($cookie['value'], $cookie['path'], TL_COOKIE_KEEPTIME, '/');
    }
    return $ret;
}