How to resolve path of item in change
I have a:
- list of changes List<IChange>
- IWorkspaceConnection
- IConfiguration
I searching for a way to find the 'remote path' of the item in IChange. But the path relevant to the change.
From the
I tried to use 'IConfiguration.fetchCompleteItem' applied on 'IChange.item()'
But i case item already deleted from the component, all I got is null.
In other cases I get the current path in the component, not the path in the change. For example, If the change was move/rename then the path in the change is different than the current exists one.
Thank
Boaz
3 answers
Hi, I suggest you to use IChange.beforeState() and IChange.afterState() instead of item(). The first could be used in case of deletion and both should reflect move/rename changes.
And you can use configuration.determineAncestorsInHistory
And you can use configuration.determineAncestorsInHistory
Please see if
Getting your stuff - using the RTC SDK to zip a repository workspace helps.
Getting your stuff - using the RTC SDK to zip a repository workspace helps.
Comments
Not sure you even bothered to read my question.
It is OK. I know every one is so busy.
I am not superman that knows all, and I can't tell you. I would have to do the programming myself, spending maybe a day or so to be able to give you a valid answer. So all I can do in a case like this is to point you to examples I know work.
I know this has likely been discussed here already. Please try https://www.google.com/search?q=path+item+changeset+site:jazz.net and look into some of the questions and answers as well.
Well, the code below will find the full remote path of IChange.beforeState() and IChange.afterState()
And it works even in case item already deleted from the component.
Reading the documents, I didn't understand why 'determineAncestorsInHistory' does the trick.
* @param itemOfState item with valid state like {@link IChange#beforeState()} or {@link IChange#afterState()}
* @return Full state IVersionable and path in repository. Null if not found.
*/
@Nullable
Pair<IVersionable, Path> getItemFullState(IVersionableManager versionableManager,
IConfiguration configuration,
IVersionableHandle itemOfState,
IProgressMonitor monitor) throws TeamRepositoryException {
IVersionable versionable;
try {
versionable = versionableManager.fetchCompleteState(itemOfState, monitor);
} catch (ItemNotFoundException e) {
return null;
}
if (versionable == null) {
return null;
}
List<IAncestorReport> list =
configuration.determineAncestorsInHistory(Collections.singletonList(itemOfState), getMonitor());
// more check need here list.size() == 1
IAncestorReport ancestorReport = list.get(0);
Path path = null;
for (Object o : ancestorReport.getNameItemPairs()) {
INameItemPair nameItemPair = (INameItemPair)o;
String name = nameItemPair.getName();
if (name != null) {
if (path == null) {
path = Paths.get(name);
} else {
path = path.resolve(name);
}
}
}
return new Pair<>(versionable, path);
}