It's all about the answers!

Ask a question

How to resolve path of item in change


Boaz Nahum (1336) | asked Feb 04 '16, 11:01 a.m.
 I have a:

  1.  list of changes List<IChange>
  2. IWorkspaceConnection
  3. 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



permanent link
Boaz Nahum (1336) | answered Feb 04 '16, 1:32 p.m.
edited Feb 04 '16, 1:35 p.m.
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);
}

permanent link
Ralph Schoon (63.1k33646) | answered Feb 04 '16, 12:53 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Comments
Boaz Nahum commented Feb 05 '16, 3:24 a.m.

 Not sure you even bothered to read my question.

It is OK. I know every one is so busy.


Ralph Schoon commented Feb 05 '16, 3:39 a.m. | edited Feb 05 '16, 4:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Ralph Schoon commented Feb 05 '16, 4:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


permanent link
Michele Pegoraro (1.8k14118103) | answered Feb 04 '16, 11:16 a.m.
edited Feb 04 '16, 11:17 a.m.
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

Comments
Boaz Nahum commented Feb 04 '16, 12:15 p.m.

 Thank for the reply.


As i mentioned, I tried all the three item/before/after
Maybe I shouldn't use 'IConfiguration' ?

Thx
Boaz

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.