It's all about the answers!

Ask a question

Why is IProjectAreaHandle.getOrigin() returning null ?


Andrew Soloninka (5511924) | asked Dec 26 '12, 10:23 p.m.
 I am trying to programatically create a Team Area when the state of a work item changes. The code I am using is listed below:

1 IProjectAreaHandle projectAreaHandle = workitem.getProjectArea();
2 ITeamRepository repository = (ITeamRepository)projectAreaHandle.getOrigin();
3 IProjectArea projectArea = (IProjectArea)repository.itemManager().fetchCompleteItem(projectAreaHandle, IItemManager.DEFAULT, monitor);
4 List<ITeamArea> teamList = (projectArea).getTeamAreas();
5 //create a new team name
6 TeamNameGenerator generator = new TeamNameGenerator(teamList);
7 String teamName = generator.generate();
8 //Get the service to create a new Team Area
9 IProcessItemService service = (IProcessItemService)repository.getClientLibrary(IProcessItemService.class);
10 //Create a new Team Area
11 ITeamArea teamArea = createNewTeamArea(monitor, projectArea, teamName, service);

When I run this code, the Repository in Line 2 comes up null which prevents me from getting the Project Area in Line 3 and Process Item Service in Line 9 which are needed for creating the Team Area in Line 11. Is there another way of getting the Repository. The work item is being created manually as part of an existing Project Area. Both of these are being save to the the repository. Can someone explain why projectAreaHandle.getOrigin() returns null? Is there another way to get the Team Repository?

Comments
Andrew Soloninka commented Dec 27 '12, 11:08 p.m. | edited Dec 27 '12, 11:55 p.m.

I replaced line 2 with:


ITeamRepositoryService repositoryService = TeamPlatform.getTeamRepositoryService();
ITeamRepository repository = repositoryService.getTeamRepository(getPublicRepositoryURL());

The repository was now not null but I got an error indicating I was not logged into the repository. 

Then I added the line:

repository.login(monitor); 

I got java.lang.IllegalStateException. Why am I not logged into the Repository when the client shows that I am? and how do I solve this? 

One answer



permanent link
Andrew Soloninka (5511924) | answered Dec 31 '12, 1:12 p.m.
edited Dec 31 '12, 5:22 p.m.
 I got past the IllegalStateException by replacing Line 2 with:

//Log into the Team Repository
String aUserID = "TestJazzAdmin1";
String aPassword = "TestJazzAdmin1";
repository.registerLoginHandler(new LoginHandler(aUserID, aPassword));
repository.login(monitor);

I also needed to create 2 Static inner classes:

private static class LoginHandler implements ITeamRepository.ILoginHandler {
 
private String eUserID;
private String ePassword;
private LoginHandler(String userID, String password){
eUserID = userID;
ePassword = password;
}
public ITeamRepository.ILoginHandler.ILoginInfo challenge(ITeamRepository repository) {
 
return new LoginInfo(eUserID, ePassword);
}
}//End LoginHandler inner class
 
private static class LoginInfo implements ITeamRepository.ILoginHandler.ILoginInfo {

private String fUserId;
private String fPassword;

private LoginInfo(String userId, String password) {

fUserId= userId;
fPassword= password;

}
@Override
public String getPassword() {
 
return fPassword;
}

@Override
public String getUserId() {
 
return fUserId;
}
}//End LoginInfo inner class


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.