/********************************************* * Adds the specified test case and any potential children to a list of cases to commit * Params: * taskRefID - the ref id of the test case to create an entry for * index - the local index of the task in the current list of backlog items to addto add * previousItem - the previous item add the current one after * parent - a reference to the parent * Returns: * A list of entries that can be used to commit a number of items to a sprint *********************************************/ std::vector<HPMTaskCreateUnifiedEntry> HansoftUtils::createCommitEntryList(HPMUniqueID taskRefID, unsigned &index, HPMTaskCreateUnifiedReference &previousItem, HPMTaskCreateUnifiedReference parent) { HPMSdkSession *session = SessionManager::getInstance().Session(); std::vector<HPMTaskCreateUnifiedEntry> testCases; HPMTaskCreateUnifiedEntry entry = createCommitEntry(taskRefID, index, previousItem, parent); // We need to set the parent to be using local ID as it isn't created yet. parent.m_bLocalID = true; parent.m_RefID = index; index++; testCases.push_back(entry); if (session->TaskRefUtilHasChildren(taskRefID)) { previousItem = parent; HPMTaskEnum childrenEnum = session->TaskRefUtilEnumChildren(taskRefID, false); for (unsigned int i = 0; i < childrenEnum.m_Tasks.size(); ++i) { std::vector<HPMTaskCreateUnifiedEntry> childrenEntries = createCommitEntryList(childrenEnum.m_Tasks[i], index, previousItem, parent); index++; testCases.insert(testCases.end(), childrenEntries.begin(), childrenEntries.end()); // Set the id to the current task so that the next created task will end up after this one. previousItem.m_bLocalID = true; previousItem.m_RefID = index; } } return testCases; }
void PriorityCopy() { auto project_id = FindProjectByName(project_); if (!project_id.IsValid()) return; auto program_backlog_id = GetProductBacklog(project_id); if (!program_backlog_id.IsValid()) return; auto destination_column = FindColumn(program_backlog_id, destination_); if (destination_column.m_Name == "") return; int count = 0; HPMUniqueID first; map<HPMUniqueID, HPMUniqueID> dictionary; for (auto task : session_->TaskRefUtilEnumChildren(program_backlog_id, true).m_Tasks) { auto previous = session_->TaskRefGetPreviousWorkPriorityID(task); dictionary[previous] = task; if (previous.m_ID == -2) first = task; count++; } if (dictionary.size() == 0) { wcout << "No items in backlog, nothing to do.\r\n"; return; } vector<HPMUniqueID> sorted; auto item = first; while (dictionary.find(item) != dictionary.end()) { sorted.push_back(item); item = dictionary[item]; } if (dictionary.size() > 1) sorted.push_back(item); int index = 1; for (auto task_ref : sorted) { HPMUniqueID task = session_->TaskRefGetTask(task_ref); session_->TaskSetCustomColumnData(task, destination_column.m_Hash, to_string(index++), false); } wcout << "Copied: " << count << " tasks.\r\n"; }
/********************************************* * Resets the workflow status and returns the item to the backlog. * Params: * taskRefID - the ref id delete and reset. *********************************************/ void HansoftUtils::resetAndDeleteTask(HPMUniqueID taskRefID) { HPMSdkSession *session = SessionManager::getInstance().Session(); HPMTaskEnum childrenEnum = session->TaskRefUtilEnumChildren(taskRefID, false); for (unsigned int i = 0; i < childrenEnum.m_Tasks.size(); ++i) { resetAndDeleteTask(childrenEnum.m_Tasks[i]); } HPMUniqueID taskID = session->TaskRefGetTask(taskRefID); int workFlowID = session->TaskGetWorkflow(taskID); if (workFlowID != -1) { //TODO: Actually reset the workflow to a state name. session->TaskSetWorkflowStatus(taskID, 1, EHPMTaskSetStatusFlag_None); } HPMUniqueID proxyID = session->TaskGetProxy(taskID); if (proxyID.IsValid()) session->TaskDelete(proxyID); }