如何在CA Agile Central(AKA Rally)自定义应用程序中使用其ObjectID获取单个对象详细信息?

时间:2017-09-18 22:16:41

标签: rally

我有一个从Lookback API获取数据的应用程序。我在数据中获得User ObjectID,但是我想获取User的DisplayName而不是ObjectID。 Rally Lookback API不允许水合用户字段,因此在加载Lookback API数据时我不能拥有用户名。 我尝试使用用户对象ID过滤器创建商店以获取用户名,但我没有得到用户的名称,直到Lookback API数据加载完成。当Lookback API数据加载完成时,我的数据操作也已完成。因此,首次加载后加载用户名无用。我尝试将Store的async属性设置为false / true,不起作用。 有没有办法用Rally SDK 2.0实现这一目标? 这是代码块 -

//Lookback call
_getStoriesByUser: function (user_story_ids, user_oids, user_story_state, users) {
    this.acceptedByTM = [];
    var scheduleStates = [];
    scheduleStates.push('Accepted');
    scheduleStates.push('Released to Prod');

    var deferred = Ext.create('Deft.Deferred');
    var me = this;
    console.time("FetchingLBData");
    var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
        "context": this.getContext().getDataContext(),
        "fetch": ["ScheduleState", "_User", "_PreviousValues.ScheduleState"],
        "hydrate": ["ScheduleState"],
        "find": {
            "ObjectID": { "$in": user_story_ids },
            //"_User": { "$in": user_oids },
            "_TypeHierarchy": "HierarchicalRequirement",
            "ScheduleState": { "$in": scheduleStates },
            "_PreviousValues.ScheduleState": { "$ne": null },
            "Children": null
        },
        "sort": { "_ValidFrom": -1 }
    });

    snapshotStore.load({
        callback: function (records, operation) {
            if (operation.wasSuccessful()) {
                console.timeEnd("FetchingLBData");
                me.logger.log("LB US Count >>", records.length, records)
                var total_us_accepted_by_tm = 0;
                var tmAcceptedUS = 0;
                var nontmAcceptedUS = 0;
                var tm_accepted = [];
                Ext.Array.each(user_story_state, function (uss) {
                    Ext.Array.each(records, function (rec) {
                        if ((rec.get('ObjectID') == uss.ObjectID && rec.get('ScheduleState') == 'Accepted') && (uss.ScheduleState == 'Accepted' || uss.ScheduleState == 'Released to Prod')) {
                            total_us_accepted_by_tm += 1;
                            tm_accepted.push({ ObjectID: rec.get('ObjectID'), UserObjectID: rec.get('_User') });
                                var userName;
                                //userName = me._fetchUserName(rec.get('_User')).value;
                                me._fetchUserName(rec.get('_User')).then({
                                    success: function (records) {
                                        userName = records[0].get('DisplayName')
                                    },
                                    failure: function (error) {
                                        console.log('Error in Execution:', error)
                                    }
                                }).always(function() {
                                    console.log('Waiting for Update!');
                                });
                                //userName = rec.get('_User').DisplayName;
                                console.log('Accepted By Name: ', userName);

                                me.acceptedByTM.push({ ObjectID: rec.get('ObjectID'), UserObjectID: userName });
                                return false;

                        }
                    });

                });

                deferred.resolve(me.acceptedByTM);
            } else {
                deferred.reject('Problem querying lookback');
            }
        },
        scope: me
    });
    return deferred;
},

//Get User Details for a given user
_fetchUserName: function (userObjId) {
    var me = this;
    var userName;
    var userDetails;
    var deferred = Ext.create('Deft.Deferred');
    me.logger.log("Fetching User Information for User >>", userObjId);

    var userFilter = Ext.create('Rally.data.wsapi.Filter', {
        property: 'ObjectID',
        value: userObjId
    });

    userDetails = Ext.create('Rally.data.wsapi.Store', {
        model: 'User',
        fetch: ['ObjectID', 'DisplayName'],
        filters: userFilter,
        limit: 1,
        pageSize: 1
    });

    userDetails.load({
        scope: this,
        callback: function (records, operation, success) {
            console.log("Operation Status: ", operation.synchronous);
            if (success) {
                //userName = records[0].get('DisplayName');
                deferred.resolve(records);
            } else {
                deferred.reject(Ext.String.format("Error getting {0} count for {1}: {2}", 'User', userFilter.toString(), operation.error.errors.join(',')));
            }
        }
    });

    return deferred.promise;
}

1 个答案:

答案 0 :(得分:0)

为了简化操作,我可能只是从WSAPI中预先加载所有用户,并通过objectid构建它们的映射。这样您就可以获得所有数据,并且可以在处理回溯快照时直接进行查找。

这样的事情:

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    launch: function () {
        this._loadUsersFromWsapi().then({
            success: function (users) { 
                this.usersByOid = _.indexBy(users, function(user) {
                    return user.getId();
                });
                this._loadSnapshotData();
            },
            scope: this
        });
    },

    _loadUsersFromWsapi: function () {
        return Ext.create('Rally.data.wsapi.Store', {
            model: 'user',
            limit: Infinity,
            pageSize: 2000,
            fetch: ['ObjectID']
        }).load();
    },

    _loadSnapshotData: function () { 
        //Now in here for any given snapshot you can get the user
        //information by looking it up in the this.usersByOid map
        var userName = this._usersByOid[userObjectID].get('_refObjectName');
    }
});