in backend/plugins/zentao/tasks/story_convertor.go [44:134]
func ConvertStory(taskCtx plugin.SubTaskContext) errors.Error {
data := taskCtx.GetData().(*ZentaoTaskData)
db := taskCtx.GetDal()
storyIdGen := didgen.NewDomainIdGenerator(&models.ZentaoStory{})
boardIdGen := didgen.NewDomainIdGenerator(&models.ZentaoProject{})
accountIdGen := didgen.NewDomainIdGenerator(&models.ZentaoAccount{})
cursor, err := db.Cursor(
dal.From(&models.ZentaoStory{}),
dal.Join(`LEFT JOIN _tool_zentao_project_stories ON
_tool_zentao_project_stories.story_id = _tool_zentao_stories.id
AND _tool_zentao_project_stories.connection_id = _tool_zentao_stories.connection_id`),
dal.Where(`_tool_zentao_project_stories.project_id = ? and
_tool_zentao_project_stories.connection_id = ?`, data.Options.ProjectId, data.Options.ConnectionId),
)
if err != nil {
return err
}
defer cursor.Close()
convertor, err := api.NewDataConverter(api.DataConverterArgs{
InputRowType: reflect.TypeOf(models.ZentaoStory{}),
Input: cursor,
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Ctx: taskCtx,
Options: data.Options,
Table: RAW_STORY_TABLE,
},
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
toolEntity := inputRow.(*models.ZentaoStory)
domainEntity := &ticket.Issue{
DomainEntity: domainlayer.DomainEntity{
Id: storyIdGen.Generate(toolEntity.ConnectionId, toolEntity.ID),
},
IssueKey: strconv.FormatInt(toolEntity.ID, 10),
Title: toolEntity.Title,
Type: toolEntity.StdType,
OriginalType: "story",
OriginalStatus: toolEntity.Status,
ResolutionDate: toolEntity.ClosedDate.ToNullableTime(),
CreatedDate: toolEntity.OpenedDate.ToNullableTime(),
UpdatedDate: toolEntity.LastEditedDate.ToNullableTime(),
Priority: getPriority(toolEntity.Pri),
CreatorName: toolEntity.OpenedByName,
AssigneeName: toolEntity.AssignedToName,
Url: toolEntity.Url,
OriginalProject: getOriginalProject(data),
Status: toolEntity.StdStatus,
OriginalEstimateMinutes: int64(toolEntity.Estimate) * 60,
}
if toolEntity.Parent != 0 {
domainEntity.ParentIssueId = storyIdGen.Generate(data.Options.ConnectionId, toolEntity.Parent)
}
if toolEntity.OpenedById != 0 {
domainEntity.CreatorId = accountIdGen.Generate(data.Options.ConnectionId, toolEntity.OpenedById)
}
if toolEntity.AssignedToId != 0 {
domainEntity.AssigneeId = accountIdGen.Generate(data.Options.ConnectionId, toolEntity.AssignedToId)
}
if domainEntity.OriginalStatus == "closed-closed" {
domainEntity.OriginalStatus = "closed"
}
var results []interface{}
if domainEntity.AssigneeId != "" {
issueAssignee := &ticket.IssueAssignee{
IssueId: domainEntity.Id,
AssigneeId: domainEntity.AssigneeId,
AssigneeName: domainEntity.AssigneeName,
}
results = append(results, issueAssignee)
}
if toolEntity.ClosedDate != nil {
domainEntity.LeadTimeMinutes = int64(toolEntity.ClosedDate.ToNullableTime().Sub(toolEntity.OpenedDate.ToTime()).Minutes())
}
domainBoardIssue := &ticket.BoardIssue{
BoardId: boardIdGen.Generate(data.Options.ConnectionId, data.Options.ProjectId),
IssueId: domainEntity.Id,
}
results = append(results, domainEntity, domainBoardIssue)
return results, nil
},
})
if err != nil {
return err
}
return convertor.Execute()
}