// 文档复用时将已批准的工作项状态设置为初始状态
/**
if (!workItem.isPersisted()) {
if (workItem.status.id === 'approved' || workItem.status.id === 'inreview') {
workItem.setEnumerationValue('status', 'draft');
workItem.save();
}
}
**/
//if (!workItem.isPersisted()) {
//自动评审
/*
var dataSvc = trackerService.getDataService();
var enumType = com.polarion.subterra.base.data.model.TypeFactory.getEnumType("SystemConfig");
polarionLog.error("enumType.class:" + enumType);
var SystemConfigEnumeration = dataSvc.getEnumerationForEnumId(enumType, workItem.getContextId());
var ASPICEProjectOption = SystemConfigEnumeration.wrapOption("ASPICEProject");
var ASPICEProject = ASPICEProjectOption.getName();
var SystemConfigs = enumCfgService.getGlobalOptions("SystemConfig");
var ASPICEProjects = "";
for (var i = 0; i < SystemConfigs.size(); i++) {
var SystemConfig = SystemConfigs.get(i);
if ("ASPICEProject" === SystemConfig.getId()) {
ASPICEProjects = SystemConfig.getName();
}
}
if (ASPICEProjects.indexOf(workItem.getProjectId()) != -1) {
automaticApprove();
changeLinkedWI();
//自动设置解决状态
autoFillResolution();
}
*/
/**
* 判断是否是ASPICE项目
*/
function isASPICEProject() {
var d = workItem.getProject().getDescription();
if (d !== null) {
return d.toString().toLowerCase().indexOf("aspice") >= 0;
}
return false;
}
if (isASPICEProject()) {
//自动评审
automaticApprove();
//状态自动变更
changeLinkedWI();
//自动设置解决状态
autoFillResolution();
}
function autoFillResolution() {
var resolutionCfg = {
"customerrequirement": "done,rejected",
"systemrequirement": "done,rejected",
"softwarerequirement": "done,rejected",
"systemarchitechture": "done,rejected",
"softwarearchitechture": "done,rejected",
"swittestcase": "approved,rejected",
"swqttestcase": "approved,rejected",
"sysittestcase": "approved,rejected",
"sysqttestcase": "approved,rejected",
"issue": "done,cancelled",
"bug": "done,cancelled",
"changerequest": "done,rejected,cancelled",
"release": "published,rejected",
"QAaudit": "cancelled,completed",
"NCitem": "done,obsoleted",
"risk": "rejected,completed",
"dfema": "rejected",
"task": "done,rejected",
"reviewWorkItem": "approved,rejected",
"workpackage": "completed",
"milestone": "cancelled,completed"
};
var type = workItem.type.id;
var status = workItem.status.id;
if (resolutionCfg[type] && resolutionCfg[type].indexOf(status) != -1) {
workItem.setEnumerationValue("resolution", status);
workItem.save();
}
}
function addPlanRecords(plan, pItem) {
var items = pItem.getLinkedWorkItemsBack();
for (var i = 0; i < items.size(); i++) {
var item = items.get(i);
if ("milestone,task".indexOf(item.type.id) != -1) continue;
plan.addRecord(item);
addPlanRecords(plan, item);
}
}
function changeLinkedWI() {
var changeLinkedWITypes = "softwarerequirement,softwarearchitechture,systemarchitechture";
if (changeLinkedWITypes.indexOf(workItem.type.id) != -1) {
var s = workItem.status.id;
var itemsDirect = workItem.getLinkedWorkItemsDirect();
for (var i = 0; i < itemsDirect.size(); i++) {
var d = itemsDirect.get(i);
var itemsBack = d.getLinkedWorkItemsBack();
var change = true;
for (var j = 0; j < itemsBack.size(); j++) {
var b = itemsBack.get(j);
if (s !== b.status.id) {
change = false;
break;
}
if (change) {
d.setEnumerationValue('status', s);
d.save();
}
}
}
}
}
function getApprovedStatus(itemType) {
switch (itemType) {
case "configurationitem":
return "identified";
default:
return "approved";
}
}
function automaticApprove() {
var unHandleType = "changerequest,";
if ('inreview' === workItem.status.id && unHandleType.indexOf(workItem.getType().getId()) == -1) {
polarionLog.warn('post-save workitem type:' + workItem.getType().getId() + ',status:' + workItem.status.id);
var approvals = workItem.getApprovals();
var allReviewed = false;
var nextStatus = getApprovedStatus(workItem.getType().getId());
var approvalsArray = approvals.toArray();
for (var index = 0; index < approvalsArray.length; index++) {
allReviewed = true;
var approvalStruct = approvalsArray[index];
var status = approvalStruct.getStatus().getId();
polarionLog.warn('post-save workitem type:' + status);
if ('waiting' === status || 'disapproved' === status) {
allReviewed = false;
break;
}
}
if (allReviewed) {
workItem.setEnumerationValue("status", nextStatus);
if ('draft' === workItem.status.id) {
for (var index = 0; index < approvalsArray.length; index++) {
var approval = approvalsArray[index];
workItem.setApprovalStatus(approval.getUser(), workItem.getProject().getApprovalStatusEnum().wrapOption("waiting"));
}
}
workItem.save();
}
//子计划状态变更未已审批时,根据包含的里程碑自动创建Iteration类型的Plan,并把里程碑下的工作包和任务加到Iteration中。
if ("subplan" === workItem.type.id && "approved" === nextStatus) {
//scriptUtils.createMilestone(workItem);
var itemsBack = workItem.getLinkedWorkItemsBack();
for (var j = 0; j < itemsBack.size(); j++) {
var item = itemsBack.get(j);
if ("milestone" !== item.type.id) continue;
var iteration = trackerService.getPlanningManager().createPlan(item.getProjectId(), item.getTitle().replaceAll(" ", "_"));
addPlanRecords(iteration, item);
iteration.setName(item.getTitle());
var temp = trackerService.getPlanningManager().getPlan(item.getProjectId(), "iteration", null);
iteration.copyFromTemplate(temp);
iteration.save();
polarionLog.error(new Date() + "::::iteration created !!!!!!");
item.setEnumerationValue("relatedPlan", item.getTitle().replaceAll(" ", "_"));
item.save();
}
}
}
}
//}
/**
* @meta func/cond
* @name
* @desc
@param aa @type: String Demo, @default: A
*/
var msg = '';
var SystemConfigs = enumCfgService.getGlobalOptions("SystemConfig");
var ASPICEProjects = "";
for (var i = 0; i < SystemConfigs.size(); i++) {
var SystemConfig = SystemConfigs.get(i);
if ("ASPICEProject" === SystemConfig.getId()) {
ASPICEProjects = SystemConfig.getName();
}
}
function isASPICEProject() {
var d = workItem.getProject().getDescription();
if (d !== null) {
//msg = d.toString().toLowerCase().indexOf("aspice") >= 0;
return d.toString().toLowerCase().indexOf("aspice") >= 0;
}
return false;
}
if (isASPICEProject()) {
msg = checkApprove();
}
function checkApprove() {
var approvals = workItem.getApprovals();
var approvalsArray = approvals.toArray();
var reviewed = false;
for (var index = 0; index < approvalsArray.length; index++) {
var approvalStruct = approvalsArray[index];
var status = approvalStruct.getStatus().getId();
polarionLog.warn('post-save workitem type:' + status);
if ('waiting' !== status) {
reviewed = true;
break;
}
}
if (reviewed && 'draft' === workItem.status.id) {
return "The current is not review time, so you can not review.";
}
return "";
}
msg;