0

除了其他数据之外,我还想要一份所有修改给定用户故事的人的列表。

我正在使用以下 JSON 数据查询 Rally Lookback REST API:

{ 
    "find" : { "FormattedID": "$STORY" }, 
    "fields" : ["ObjectID", "_ValidFrom", "_ValidTo", "Blocked", "c_KanbanState", "Owner"],
    "compress" : true 
}

通过这个查询,我得到了所有者的 OID,如下所示:

{
  "_ValidFrom": "2014-05-09T15:18:29.912Z",
  "_ValidTo": "9999-01-01T00:00:00.000Z",
  "ObjectID": 18326652440,
  "Blocked": false,
  "Owner": 13786838413,
  "c_KanbanState": "Accepted"
}

有没有办法给 Owner 字段补水?我想看“John Smith”,但我会选择“jsmith@example.com”。

如果我必须为此使用 WSAPI,有没有办法一次查询一组所有者 OID——如果是这样,一个样本会很有帮助——或者我需要遍历值的集合并查询每个业主个人?

4

3 回答 3

1

不幸的是,根据文档-

无法水合某些字段类型(例如用户)。

请参阅 文档的水合部分

于 2014-05-10T02:44:09.450 回答
1

正如 Trever 所说,在 Lookback API 中,用户字段不能被水合。

至于使用 wsapi 水合用户字段的示例,下面的代码使用shapshotstore获取快照 where '_PreviousValues.Blocked' : {$exists: true},然后使用Rally.data.ModelFactory获取每个快照中所有者的 DisplayName。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    scopeType: 'iteration',
    comboboxConfig: {
        labelWidth: 100,
        width: 300
    },
    launch: function() {
        var that = this;
        var iterationComboBox = Ext.create('Rally.ui.combobox.IterationComboBox',{
        listeners:{
            ready: function(combobox){
                                var iterationOid = combobox.getRecord().get('ObjectID'); 
                                that._loadStories(iterationOid);
            },
            select: function(combobox){
                                var iterationOid = combobox.getRecord().get('ObjectID'); 
                                this._loadStories(iterationOid);
            },
            scope: this  
        }
    });
        this.add(iterationComboBox);
    },

    _loadStories:function(iterationOid){
        var that = this;
        var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
            autoLoad:true,
            find: {
                '_TypeHierarchy': 'HierarchicalRequirement',
                '_ProjectHierarchy': 12352608219,    
                '_PreviousValues.Blocked' : {$exists: true},
                'Iteration': iterationOid

            },
            fetch: ['Name','FormattedID','ScheduleState','Blocked','_ValidFrom','_ValidTo', 'BlockedReason','Owner'], 
            order: 'OpenedDate DESC',
            hydrate: ['Blocked','ScheduleState'],
            compress: true,
            listeners: {
        load: function(store,records,success){
            console.log("loaded %i records", records.length);
                    that._onStoriesLoaded(snapshotStore, records);
        },
        scope:this
        }
        });        
    },
    _onStoriesLoaded:function(store, records){
         var that = this;
        var promises = [];
         _.each(records, function(story) {
            promises.push(that._hydrateOwner(story, that));
        });

        Deft.Promise.all(promises).then({
            success: function(results) {
                that._stories = results;
                console.log('that._stories', that._stories);
                that._makeGrid();
            }
        });
    },
    _hydrateOwner:function(story, scope){
        var deferred = Ext.create('Deft.Deferred');
        var that = scope;
        var  ownerDisplayName = null;
        var userOid = story.get('Owner');

        var storyBlocked = story.get('Blocked');
        Rally.data.ModelFactory.getModel({
            type: 'User',
            scope: this,
            success: function(model, operation) {
                fetch: ['UserName', 'DisplayName'],
                model.load(userOid, {
                    scope: this,
                    success: function(record, operation) {
                        owner = record.get('DisplayName');
                        var fid = story.get('FormattedID');
                        var state = story.get('ScheduleState');
                        var name  = story.get('Name');
                        var blocked = story.get('Blocked');

                        result = {
                                    "fid"       : fid,
                                    "name"      : name,
                                    "state"     : state,
                                    "blocked"   : blocked,
                                    "owner"     : owner    
                                };

                        deferred.resolve(result);    
                    }
                });
            }
        });

        return deferred;
    },

        _makeGrid: function() {

        if (this.down('#grid')) {
            this.down('#grid').destroy();
        }

        var gridStore = Ext.create('Rally.data.custom.Store', {
            data: this._stories
        });

        var _grid = Ext.create('Rally.ui.grid.Grid', {
            itemId: 'grid',
            store: gridStore,
            columnCfgs: [
                {
                    text: 'Name', dataIndex: 'name'
                },
                {
                    text: 'FormattedID', dataIndex: 'fid'
                },
                {
                    text: 'ScheduleState', dataIndex: 'state'
                },
                {
                    text: 'Blocked', dataIndex: 'blocked'
                },
                {
                    text: 'Owner', dataIndex: 'owner'
                }

            ]
        });

        this.add(_grid);
        this._grid.reconfigure(gridStore);
    }
});
于 2014-05-10T07:32:14.810 回答
1

并且补充一下尼克和特雷弗所说的,如果您想知道谁修改了给定的故事,您要查找的字段是“_User”。Owner 是所有者,_User 是创建修订版的人。可以调整 Nick 的示例代码以水合 _User,因为它只是像 Owner 一样的 OID。

一个警告:如果有人只更改了一个大文本字段(如描述),则不会创建快照,因此不会返回。

于 2014-05-10T13:45:33.777 回答