Hello,
Using Javascript in a custom app, I try to retrieve the revision history of a delete feature thanks to the Rally SDK 2.1 WSAPI.
I manage to retrieve the delete feature information this way:
function loadFeaturesCurrentRecycleBin() {
var features = Ext.create('Rally.data.wsapi.Store', {
model: 'RecycleBinEntry',
fetch: true,
filters: [{
property: 'ID',
operator: 'in',
value: ['F14921']
}
],
listeners: {
load: loadedFeaturesCurrentRecycleBin,
scope: this
},
});
features.load();
};
function loadedFeaturesCurrentRecycleBin(store, features) {
console.log(' - ' + (features ? features.length : 0) + ' features retrieved from recycle bin...');
console.log(features);
};
Only part of the feature information is available from the recycle bin, and the revision history isn't available, not event its _ref attribute:
If I had a revision history reference, like for a feature that is not deleted, I could retrieve its revision history.
The following example shows how to retrieve the revision history for all the features I have in memory in gvRetrievedFeaturesBeingLoaded[] array. In short, it is based on :
var _onModelCreated = function(model) {
var promises = [];
for (var i in gvRetrievedFeaturesBeingLoaded) {
var f = gvRetrievedFeaturesBeingLoaded[i];
var revisionHistoryRef = f.RevisionHistory._ref;
promises.push(model.load(Rally.util.Ref.getOidFromRef(revisionHistoryRef)));
}
Deft.Promise.all(promises).then(
(histories) => { _onModelLoaded(histories); },
(rejectReason) => { console.log(rejectReason); }
);
};
Full example:
function loadFeaturesRevisionHistoryCurrent() {
console.log(' - search for features rank revision hstory...');
var _getRevisionHistory = function() {
this._revisionModel = Rally.data.ModelFactory.getModel({
type: 'RevisionHistory',
scope: this,
success: _onModelCreated
});
};
var _onModelCreated = function(model) {
var nbFeaturesWithRevisionHistory = 0;
var promises = [];
for (var i in gvRetrievedFeaturesBeingLoaded) {
var f = gvRetrievedFeaturesBeingLoaded[i];
if (f.RevisionHistory) {
if (f.RevisionHistory.Revisions) {
if (f.RevisionHistory.Revisions.Count > 0) {
nbFeaturesWithRevisionHistory ++;
var revisionHistoryRef = f.RevisionHistory._ref;
promises.push(model.load(Rally.util.Ref.getOidFromRef(revisionHistoryRef)));
}
}
}
}
if (promises.length > 0) {
Deft.Promise.all(promises).then(
(histories) => { _onModelLoaded(histories); },
(rejectReason) => { console.log(rejectReason); }
);
} else {
console.log(' - no feature hstory to be retrieved.');
loadStoriesCurrent();
}
};
var _onModelLoaded = function(histories) {
var promises = [];
_.each(histories, function(history){
var revisions = history.get('Revisions');
revisions.store = history.getCollection('Revisions',{
fetch:['Description', 'CreationDate', 'RevisionHistory'],
filters: [{
property: 'Description',
operator: 'contains',
value: 'Rank',
caseSensitive: false
}
],
});
promises.push(revisions.store.load());
});
if (promises.length > 0) {
Deft.Promise.all(promises).then(
(revhistories) => { _attachRevisionsToFeatures(revhistories); },
(rejectReason) => { console.log(rejectReason); }
);
} else {
console.log(' - no revision hstory to be retrieved.');
loadStoriesCurrent();
}
};
var _attachRevisionsToFeatures = function(revhistories) {
console.log(' - ' + (revhistories ? revhistories.length : 0) + ' rank revision histories retrieved...');
_.each(revhistories, function(revisions){
if (revisions.length > 0 ) {
var historyRefTheRevisionsBelongTo = revisions[0].data.RevisionHistory._ref;
for (var i in gvRetrievedFeaturesBeingLoaded) {
var f = gvRetrievedFeaturesBeingLoaded[i];
if (f.RevisionHistory) {
if (f.RevisionHistory.Revisions) {
if (f.RevisionHistory.Revisions.Count > 0) {
if (f.RevisionHistory._ref == historyRefTheRevisionsBelongTo) {
f.RetrievedRevisionsRank = revisions;
break;
}
}
}
}
}
}
});
loadStoriesCurrent();
};
_getRevisionHistory();
};
So, as I have no revision history reference I could build my query from, I tried to query all existing revision histories in order to try to identify a reference toward my deleted feature identifiers (ObjectID, ID, _ref) but I get no result at all...
Attempt 1:
function loadFeaturesRevisionHistoryFromRecycleBin() {
var _getRevisionHistory = function() {
this._revisionModel = Rally.data.ModelFactory.getModel({
type: 'RevisionHistory',
scope: this,
success: _onModelCreated
});
};
var _onModelCreated = function(model) {
var promises = [];
promises.push(model.load());
Deft.Promise.all(promises).then(
(histories) => { _onModelLoaded(histories); },
(rejectReason) => { console.log(rejectReason); }
);
};
var _onModelLoaded = function(histories) {
console.log(' - ' + (histories ? histories.length : 0) + ' histories retrieved...');
};
_getRevisionHistory();
};
Attempt 2:
function loadRevHistories() {
var artefacts = Ext.create('Rally.data.wsapi.Store', {
model: 'RevisionHistory',
fetch: true,
listeners: {
load: loadedRevHistories,
scope: this
},
});
artefacts.load();
};
function loadedRevHistories(store, rh) {
console.log(' - ' + (rh ? rh.length : 0) + ' rh retrieved...');
};
So, in the end, I have 2 questions:
- is there a way to retrieve the revision history of a deleted feature?
- is there a way to retrieve the full list of all the revision histories, without specifying a reference to the model?
Thanks for any help :)
Greg.