fix: jira获取模板报错

This commit is contained in:
chenjianxing 2021-12-16 20:22:14 +08:00 committed by jianxing
parent 9b94963669
commit e3fa37a6f1
14 changed files with 161 additions and 88 deletions

View File

@ -0,0 +1,21 @@
package io.metersphere.commons.constants;
public enum CustomFieldType {
INPUT("input"),TEXTAREA("textarea"),
SELECT("select"),MULTIPLE_SELECT("multipleSelect"),
RADIO("radio"),CHECKBOX("checkbox"),
MEMBER("member"), MULTIPLE_MEMBER("multipleMember"),
DATE("date"),DATETIME("datetime"),
INT("int"),FLOAT("float"),
MULTIPLE_INPUT("multipleInput"),RICH_TEXT("richText");
String value;
CustomFieldType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,18 @@
package io.metersphere.commons.utils;
import java.lang.reflect.Method;
public class LicenseUtils {
public static boolean valid() {
try {
Class<?> aClass = Class.forName("io.metersphere.xpack.license.util.LicenseCache");
Method get = aClass.getMethod("valid");
System.out.println("====");
return (boolean) get.invoke(null);
} catch (Exception e) {
LogUtil.error(e);
e.printStackTrace();
return false;
}
}
}

View File

@ -7,6 +7,7 @@ import io.metersphere.base.mapper.IssuesMapper;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.TestCaseIssuesMapper; import io.metersphere.base.mapper.TestCaseIssuesMapper;
import io.metersphere.base.mapper.ext.ExtIssuesMapper; import io.metersphere.base.mapper.ext.ExtIssuesMapper;
import io.metersphere.commons.constants.CustomFieldType;
import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.constants.IssuesStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*; import io.metersphere.commons.utils.*;
@ -64,6 +65,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
protected String workspaceId; protected String workspaceId;
protected String userId; protected String userId;
protected String defaultCustomFields; protected String defaultCustomFields;
protected boolean isThirdPartTemplate;
public String getKey() { public String getKey() {
@ -366,13 +368,31 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
protected String syncIssueCustomField(String customFieldsStr, JSONObject issue) { protected String syncIssueCustomField(String customFieldsStr, JSONObject issue) {
List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(customFieldsStr); List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(customFieldsStr);
Set<String> names = issue.keySet();
customFields.forEach(item -> { customFields.forEach(item -> {
String fieldName = item.getCustomData(); String fieldName = item.getCustomData();
Object value = issue.get(fieldName); Object value = issue.get(fieldName);
if (value != null) { if (value != null) {
if (value instanceof JSONObject) { if (value instanceof JSONObject) {
if (!fieldName.equals("assignee") && !fieldName.equals("reporter")) { // 获取不到账号名 JSONObject valObj = ((JSONObject) value);
item.setValue(((JSONObject)value).getString("id")); String accountId = valObj.getString("accountId");
JSONObject child = valObj.getJSONObject("child");
if (child != null) {// 级联框
List<Object> values = new ArrayList<>();
if (StringUtils.isNotBlank(valObj.getString("id"))) {
values.add(valObj.getString("id"));
}
if (StringUtils.isNotBlank(child.getString("id"))) {
values.add(child.getString("id"));
}
item.setValue(values);
} else if (StringUtils.isNotBlank(accountId)) {
// 用户选择框
if (isThirdPartTemplate) {
item.setValue(accountId);
}
} else {
item.setValue(valObj.getString("id"));
} }
} else if (value instanceof JSONArray) { } else if (value instanceof JSONArray) {
List<Object> values = new ArrayList<>(); List<Object> values = new ArrayList<>();
@ -387,6 +407,12 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
} else { } else {
item.setValue(value); item.setValue(value);
} }
} else if (names.contains(fieldName)) {
if (item.getType().equals(CustomFieldType.CHECKBOX.getValue())) {
item.setValue(new ArrayList<>());
} else {
item.setValue(null);
}
} }
}); });
return JSONObject.toJSONString(customFields); return JSONObject.toJSONString(customFields);
@ -463,4 +489,12 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
issue.setCreator(SessionUtils.getUserId()); issue.setCreator(SessionUtils.getUserId());
issue.setNum(nextNum); issue.setNum(nextNum);
} }
public boolean isThirdPartTemplate() {
Project project = projectService.getProjectById(projectId);
if (project.getThirdPartTemplate() != null && project.getThirdPartTemplate() && LicenseUtils.valid()) {
return true;
}
return false;
}
} }

View File

@ -294,6 +294,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
@Override @Override
public void syncIssues(Project project, List<IssuesDao> issues) { public void syncIssues(Project project, List<IssuesDao> issues) {
isThirdPartTemplate = isThirdPartTemplate();
issues.forEach(item -> { issues.forEach(item -> {
try { try {
IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(item.getId()); IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(item.getId());

@ -1 +1 @@
Subproject commit dae3bfa8015fefe44c0c7a7517a43a5da93e6950 Subproject commit 23fd955ff25ccf19f115c9d37a970e0caba6986d

View File

@ -18,7 +18,7 @@
<template-select :data="form" scene="API_CASE" prop="caseTemplateId" ref="caseTemplate"/> <template-select :data="form" scene="API_CASE" prop="caseTemplateId" ref="caseTemplate"/>
</el-form-item> </el-form-item>
<el-form-item v-if="xpackEable" :label-width="labelWidth" :label="$t('使用第三方平台模板')" prop="scenarioCustomNum"> <el-form-item v-if="xpackEable && form.platform === 'Jira'" :label-width="labelWidth" :label="$t('使用第三方平台模板')" prop="scenarioCustomNum">
<el-switch v-model="form.thirdPartTemplate"></el-switch> <el-switch v-model="form.thirdPartTemplate"></el-switch>
</el-form-item> </el-form-item>
@ -231,7 +231,7 @@ export default {
if (platforms.indexOf(platform) === -1) { if (platforms.indexOf(platform) === -1) {
for (let i = 0; i < this.platformOptions.length; i++) { for (let i = 0; i < this.platformOptions.length; i++) {
if (this.platformOptions[i].value === platform) { if (this.platformOptions[i].value === platform) {
this.platformOptions.splice(1, i); this.platformOptions.splice(i, 1);
break; break;
} }
} }

View File

@ -66,14 +66,12 @@
import MsEditDialog from "@/business/components/common/components/MsEditDialog"; import MsEditDialog from "@/business/components/common/components/MsEditDialog";
import MsTable from "@/business/components/common/components/table/MsTable"; import MsTable from "@/business/components/common/components/table/MsTable";
import MsTableColumn from "@/business/components/common/components/table/MsTableColumn"; import MsTableColumn from "@/business/components/common/components/table/MsTableColumn";
import {getRelateIssues, testCaseIssueRelate} from "@/network/Issue"; import {getRelateIssues, isThirdPartEnable, testCaseIssueRelate} from "@/network/Issue";
import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem"; import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem";
import {ISSUE_STATUS_MAP} from "@/common/js/table-constants"; import {ISSUE_STATUS_MAP} from "@/common/js/table-constants";
import MsTablePagination from "@/business/components/common/pagination/TablePagination"; import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import {getPageInfo} from "@/common/js/tableUtils"; import {getPageInfo} from "@/common/js/tableUtils";
import {getCurrentProjectID} from "@/common/js/utils"; import {getCurrentProjectID} from "@/common/js/utils";
import {getIssueTemplate} from "../../../../../network/custom-field-template";
import {LOCAL} from "@/common/js/constants";
export default { export default {
name: "IssueRelateList", name: "IssueRelateList",
components: {MsTablePagination, IssueDescriptionTableItem, MsTableColumn, MsTable, MsEditDialog}, components: {MsTablePagination, IssueDescriptionTableItem, MsTableColumn, MsTable, MsEditDialog},
@ -94,14 +92,9 @@ export default {
}, },
props: ['caseId'], props: ['caseId'],
created() { created() {
getIssueTemplate() isThirdPartEnable((data) => {
.then((template) => { this.isThirdPart = data;
if (template.platform === LOCAL) { });
this.isThirdPart = false;
} else {
this.isThirdPart = true;
}
});
}, },
methods: { methods: {
open() { open() {

View File

@ -27,6 +27,7 @@
<el-tab-pane :label="$t('test_track.case.relate_issue')" name="bug"> <el-tab-pane :label="$t('test_track.case.relate_issue')" name="bug">
<test-case-issue-relate <test-case-issue-relate
v-if="tabActiveName === 'bug'"
:plan-id="planId" :plan-id="planId"
:read-only="readOnly && !(isTestPlan)" :read-only="readOnly && !(isTestPlan)"
:case-id="caseId" ref="issue"/> :case-id="caseId" ref="issue"/>
@ -118,7 +119,9 @@ export default {
if (this.tabActiveName === 'demand') { if (this.tabActiveName === 'demand') {
this.getDemandOptions(); this.getDemandOptions();
} else if (this.tabActiveName === 'bug') { } else if (this.tabActiveName === 'bug') {
this.$refs.issue.getIssues(); if (this.$refs.issue) {
this.$refs.issue.getIssues();
}
} else if (this.tabActiveName === 'relationship') { } else if (this.tabActiveName === 'relationship') {
this.$refs.relationship.open(); this.$refs.relationship.open();
} else if (this.tabActiveName === 'attachment') { } else if (this.tabActiveName === 'attachment') {

View File

@ -97,8 +97,7 @@ import MsTableColumn from "@/business/components/common/components/table/MsTable
import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem"; import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem";
import {ISSUE_STATUS_MAP} from "@/common/js/table-constants"; import {ISSUE_STATUS_MAP} from "@/common/js/table-constants";
import IssueRelateList from "@/business/components/track/case/components/IssueRelateList"; import IssueRelateList from "@/business/components/track/case/components/IssueRelateList";
import {deleteIssueRelate, getIssuesByCaseId} from "@/network/Issue"; import {deleteIssueRelate, getIssuePartTemplateWithProject, getIssuesByCaseId} from "@/network/Issue";
import {getIssueTemplate} from "@/network/custom-field-template";
import {getCustomFieldValue, getTableHeaderWithCustomFields} from "@/common/js/tableUtils"; import {getCustomFieldValue, getTableHeaderWithCustomFields} from "@/common/js/tableUtils";
import {LOCAL} from "@/common/js/constants"; import {LOCAL} from "@/common/js/constants";
export default { export default {
@ -132,34 +131,34 @@ export default {
}, },
}, },
created() { created() {
getIssueTemplate() getIssuePartTemplateWithProject((template, project) => {
.then((template) => { this.currentProject = project;
this.issueTemplate = template; this.issueTemplate = template;
if (this.issueTemplate.platform === LOCAL) { if (this.issueTemplate.platform === LOCAL) {
this.isThirdPart = false; this.isThirdPart = false;
} else { } else {
this.isThirdPart = true; this.isThirdPart = true;
} }
if (template) { if (template) {
let customFields = template.customFields; let customFields = template.customFields;
for (let fields of customFields) { for (let fields of customFields) {
if (fields.name === '状态') { if (fields.name === '状态') {
this.status = fields.options; this.status = fields.options;
break; break;
}
} }
} }
this.fields = getTableHeaderWithCustomFields('ISSUE_LIST', this.issueTemplate.customFields); }
if (!this.isThirdPart) { this.fields = getTableHeaderWithCustomFields('ISSUE_LIST', this.issueTemplate.customFields);
for (let i = 0; i < this.fields.length; i++) { if (!this.isThirdPart) {
if (this.fields[i].id === 'platformStatus') { for (let i = 0; i < this.fields.length; i++) {
this.fields.splice(i, 1); if (this.fields[i].id === 'platformStatus') {
break; this.fields.splice(i, 1);
} break;
} }
} }
this.$refs.table.reloadTable(); }
}); this.$refs.table.reloadTable();
});
}, },
methods: { methods: {
statusChange(param) { statusChange(param) {

View File

@ -3,7 +3,7 @@
<el-scrollbar> <el-scrollbar>
<el-form :model="form" :rules="rules" label-position="right" label-width="80px" ref="form"> <el-form :model="form" :rules="rules" label-position="right" label-width="80px" ref="form">
<el-form-item v-if="!enableThirdPartTemplate" :label="$t('commons.title')" prop="title"> <el-form-item :label="$t('commons.title')" prop="title">
<el-input v-model="form.title" autocomplete="off" class="top-input-class"></el-input> <el-input v-model="form.title" autocomplete="off" class="top-input-class"></el-input>
<el-tooltip :content="$t('commons.follow')" placement="bottom" effect="dark" v-if="!showFollow"> <el-tooltip :content="$t('commons.follow')" placement="bottom" effect="dark" v-if="!showFollow">
<i class="el-icon-star-off" style="color: #783987; font-size: 25px; margin-left: 15px;cursor: pointer;position: relative;top: 5px" @click="saveFollow" /> <i class="el-icon-star-off" style="color: #783987; font-size: 25px; margin-left: 15px;cursor: pointer;position: relative;top: 5px" @click="saveFollow" />
@ -81,12 +81,8 @@ import {
getCurrentUser, getCurrentUser,
getCurrentUserId, getCurrentUserId,
getCurrentWorkspaceId, getCurrentWorkspaceId,
hasLicense
} from "@/common/js/utils"; } from "@/common/js/utils";
import {getIssueTemplate} from "@/network/custom-field-template"; import {enableThirdPartTemplate, getIssuePartTemplateWithProject} from "@/network/Issue";
import {getIssueThirdPartTemplate} from "@/network/Issue";
import {getCurrentProject} from "@/network/project";
import {JIRA} from "@/common/js/constants";
import CustomFiledFormItem from "@/business/components/common/components/form/CustomFiledFormItem"; import CustomFiledFormItem from "@/business/components/common/components/form/CustomFiledFormItem";
export default { export default {
@ -154,26 +150,16 @@ export default {
return getCurrentProjectID(); return getCurrentProjectID();
}, },
enableThirdPartTemplate() { enableThirdPartTemplate() {
return hasLicense() && this.currentProject && this.currentProject.thirdPartTemplate && this.currentProject.platform === JIRA; return enableThirdPartTemplate(this.currentProject);
}, },
}, },
methods: { methods: {
open(data) { open(data) {
this.result.loading = true; this.result.loading = true;
this.$nextTick(() => { this.$nextTick(() => {
getCurrentProject((responseData) => { getIssuePartTemplateWithProject((template, project) => {
this.currentProject = responseData; this.currentProject = project;
if (hasLicense() && this.currentProject && this.currentProject.thirdPartTemplate && this.currentProject.platform === JIRA) { this.init(template, data);
getIssueThirdPartTemplate()
.then((template) => {
this.init(template, data);
});
} else {
getIssueTemplate()
.then((template) => {
this.init(template, data);
});
}
}); });
}); });

View File

@ -168,7 +168,7 @@ import {
import MsTableHeader from "@/business/components/common/components/MsTableHeader"; import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem"; import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem";
import IssueEdit from "@/business/components/track/issue/IssueEdit"; import IssueEdit from "@/business/components/track/issue/IssueEdit";
import {getIssues, getIssueThirdPartTemplate, syncIssues} from "@/network/Issue"; import {getIssuePartTemplateWithProject, getIssues, syncIssues} from "@/network/Issue";
import { import {
getCustomFieldValue, getCustomFieldValue,
getCustomTableWidth, getCustomTableWidth,
@ -176,11 +176,9 @@ import {
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import MsContainer from "@/business/components/common/components/MsContainer"; import MsContainer from "@/business/components/common/components/MsContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer"; import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import {getCurrentProjectID, getCurrentWorkspaceId, hasLicense} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
import {getIssueTemplate} from "@/network/custom-field-template";
import {getProjectMember} from "@/network/user"; import {getProjectMember} from "@/network/user";
import {JIRA, LOCAL} from "@/common/js/constants"; import {LOCAL} from "@/common/js/constants";
import {getCurrentProject} from "@/network/project";
export default { export default {
name: "IssueList", name: "IssueList",
@ -218,7 +216,6 @@ export default {
members: [], members: [],
isThirdPart: false, isThirdPart: false,
creatorFilters: [], creatorFilters: [],
currentProject: null
}; };
}, },
watch: { watch: {
@ -232,20 +229,8 @@ export default {
getProjectMember((data) => { getProjectMember((data) => {
this.members = data; this.members = data;
}); });
getIssuePartTemplateWithProject((template) => {
getCurrentProject((responseData) => { this.initFields(template);
this.currentProject = responseData;
if (hasLicense() && this.currentProject.thirdPartTemplate && this.currentProject.platform === JIRA) {
getIssueThirdPartTemplate()
.then((template) => {
this.initFields(template);
});
} else {
getIssueTemplate()
.then((template) => {
this.initFields(template);
});
}
}); });
this.getIssues(); this.getIssues();
}, },

@ -1 +1 @@
Subproject commit 992bf5c0bc50e23ced47cdb1aa87e3061c3a6a5d Subproject commit f806258070e9ca2cda08e48aa47952d31eb2a60a

View File

@ -3,6 +3,7 @@ import {CUSTOM_TABLE_HEADER} from "@/common/js/default-table-header";
import {updateCustomFieldTemplate} from "@/network/custom-field-template"; import {updateCustomFieldTemplate} from "@/network/custom-field-template";
import i18n from "@/i18n/i18n"; import i18n from "@/i18n/i18n";
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
import {timestampFormatDate} from "@/common/js/filter";
export function _handleSelectAll(component, selection, tableData, selectRows, condition) { export function _handleSelectAll(component, selection, tableData, selectRows, condition) {
if (selection.length > 0) { if (selection.length > 0) {
@ -492,6 +493,8 @@ export function getCustomFieldValue(row, field, members) {
} }
return values; return values;
} }
} else if (field.type === 'datetime') {
return timestampFormatDate(item.value);
} }
return item.value; return item.value;
} }

View File

@ -2,6 +2,9 @@ import {post, get} from "@/common/js/ajax";
import {getPageDate} from "@/common/js/tableUtils"; import {getPageDate} from "@/common/js/tableUtils";
import {getCurrentProjectID, hasLicense} from "@/common/js/utils"; import {getCurrentProjectID, hasLicense} from "@/common/js/utils";
import {baseGet, basePost} from "@/network/base-network"; import {baseGet, basePost} from "@/network/base-network";
import {getCurrentProject} from "@/network/project";
import {JIRA, LOCAL} from "@/common/js/constants";
import {getIssueTemplate} from "@/network/custom-field-template";
export function buildIssues(page) { export function buildIssues(page) {
let data = page.data; let data = page.data;
@ -10,9 +13,6 @@ export function buildIssues(page) {
if (data[i].customFields) { if (data[i].customFields) {
data[i].customFields = JSON.parse(data[i].customFields); data[i].customFields = JSON.parse(data[i].customFields);
} }
// if (data[i].platform !== 'Local') {
// page.result = buildPlatformIssue(data[i]);
// }
} }
} }
} }
@ -108,3 +108,33 @@ export function getIssueThirdPartTemplate() {
}) })
}); });
} }
export function getIssuePartTemplateWithProject(callback) {
getCurrentProject((project) => {
let currentProject = project;
if (enableThirdPartTemplate(currentProject)) {
getIssueThirdPartTemplate()
.then((template) => {
if (callback)
callback(template, currentProject);
});
} else {
getIssueTemplate()
.then((template) => {
if (callback)
callback(template, currentProject);
});
}
});
}
export function enableThirdPartTemplate(currentProject) {
return hasLicense() && currentProject && currentProject.thirdPartTemplate && currentProject.platform === JIRA;
}
export function isThirdPartEnable(callback) {
getCurrentProject((project) => {
if (callback)
callback(project.platform !== LOCAL);
});
}