Login to jazz repository using java client
![]()
Hi All,
I like to login to the repository progrmmatically using java client. Could anyone share the login java code? Cheers, Jose |
9 answers
![]()
|
![]()
Hi Sam,
Thanks a lot. I have truied plugin project before to create the precondition and this is the first time I am trying the plain java application. Source code: package rtcdriver; import org.apache.commons.httpclient.auth.AuthenticationException; import org.eclipse.core.runtime.IProgressMonitor; import com.ibm.team.repository.client.ITeamRepository; import com.ibm.team.repository.client.TeamPlatform; import com.ibm.team.repository.common.TeamRepositoryException; public class TestDriver { public static ITeamRepository login(IProgressMonitor monitor) throws TeamRepositoryException { getRepository().registerLoginHandler(new ITeamRepository.ILoginHandler() { public ILoginInfo challenge(ITeamRepository repository) { return new ILoginInfo() { public String getUserId() { return StringConstants.USERID; } public String getPassword() { return StringConstants.USERPASSWORD; } }; } }); monitor.subTask("Contacting " + getRepository().getRepositoryURI() + "..."); getRepository().login(monitor); monitor.subTask("Connected"); return getRepository(); } private static ITeamRepository repo1=null; private static ITeamRepository getRepository() { if(repo1==null) { repo1 = TeamPlatform.getTeamRepositoryService().getTeamRepository(StringConstants.REPOSITORY_ADDRESS); } return repo1; } } Cheers, Jose I tried your code and StringConstans are not resolving. Do I need to import any additional package. quote="sdetweil"]
|
![]()
Hi Sam,
I tried your code and StringConstants are not resolving. Could you please take a look and update me how to run the code. Cheers, Jose Hi Sam, |
![]()
change the quoted strings to whatever userid/password required.. Sam |
![]()
Also, see the sample snippets. which have a working logon example
Sam |
![]()
Thanks Sam.
I dont find snippets with logon example. I have changed the userID and password to Strings. Do I need to pass REPOSITORY_ADDRESS like repo1 = TeamPlatform.getTeamRepositoryService().getTeamRepository("https://localhost:9443/ccm"); Cheers, Jose Also, see the sample snippets. which have a working logon example |
![]()
Hi Sam,
I am trying to create workitem using java API. Could you please update me how to set the enumeration attribute? Cheers, Simon Thanks Sam. Also, see the sample snippets. which have a working logon example |
![]()
Hi Sam,
Here is my sample code. I have some enum attributes on my Work item. Could you please update me how to set the value of the enum attribute? package rtctestlogin; import java.net.URI; import java.util.Arrays; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import com.ibm.team.foundation.common.text.XMLString; import com.ibm.team.process.client.IProcessClientService; import com.ibm.team.process.common.IProjectArea; import com.ibm.team.repository.client.ITeamRepository; import com.ibm.team.repository.client.TeamPlatform; import com.ibm.team.repository.client.ITeamRepository.ILoginHandler; import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo; import com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.workitem.client.IAuditableClient; import com.ibm.team.workitem.client.IWorkItemClient; import com.ibm.team.workitem.client.WorkItemOperation; import com.ibm.team.workitem.client.WorkItemWorkingCopy; import com.ibm.team.workitem.common.model.IAttribute; import com.ibm.team.workitem.common.model.ICategoryHandle; import com.ibm.team.workitem.common.model.IWorkItem; import com.ibm.team.workitem.common.model.IWorkItemHandle; import com.ibm.team.workitem.common.model.IWorkItemType; /** * Example code, see https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation. */ public class CreateWI { private static class LoginHandler implements ILoginHandler, ILoginInfo { private String fUserId; private String fPassword; private LoginHandler(String userId, String password) { fUserId= userId; fPassword= password; } public String getUserId() { return fUserId; } public String getPassword() { return fPassword; } public ILoginInfo challenge(ITeamRepository repository) { return this; } } private static class WorkItemInitialization extends WorkItemOperation { private String fSummary; private ICategoryHandle fCategory; public WorkItemInitialization(String summary, ICategoryHandle category) { super("Initializing Work Item"); fSummary= summary; fCategory= category; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem= workingCopy.getWorkItem(); workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); workItem.setCategory(fCategory); } } public static void main(String[] args) { boolean result; TeamPlatform.startup(); try { result= run(args); } catch (TeamRepositoryException x) { x.printStackTrace(); result= false; } finally { TeamPlatform.shutdown(); } if (!result) System.exit(1); } private static boolean run(String[] args) throws TeamRepositoryException { if (args.length != 7) { System.out.println("Usage: CreateWI <repositoryURI> <userId> <password> <projectArea> <workItemType> <summary> <category>"); return false; } String repositoryURI= args; String userId= args; String password= args; String projectAreaName= args; String typeIdentifier= args; String summary= args; String categoryName= args; ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI); teamRepository.registerLoginHandler(new LoginHandler(userId, password)); teamRepository.login(null); IProcessClientService processClient= (IProcessClientService) teamRepository.getClientLibrary(IProcessClientService.class); IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class); IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class); URI uri= URI.create(projectAreaName.replaceAll(" ", "%20")); IProjectArea projectArea= (IProjectArea) processClient.findProcessArea(uri, null, null); if (projectArea == null) { System.out.println("Project area not found."); return false; } IWorkItemType workItemType= workItemClient.findWorkItemType(projectArea, typeIdentifier, null); if (workItemType == null) { System.out.println("Work item type not found."); return false; } List<String> path= Arrays.asList(categoryName.split("/")); ICategoryHandle category= workItemClient.findCategoryByNamePath(projectArea, path, null); if (category == null) { System.out.println("Category not found."); return false; } WorkItemInitialization operation= new WorkItemInitialization(summary, category); IWorkItemHandle handle= operation.run(workItemType, null); IWorkItem workItem= auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null); System.out.println("Created work item " + workItem.getId() + "."); teamRepository.logout(); return true; } } Cheers, Jose Hi Sam, Thanks Sam. Also, see the sample snippets. which have a working logon example |
![]()
Hi Josthi,
You can find the snippets with a download of the Jazz Plain Java Client libraries. Please download this and there is clear, working code for all of the things you have asked for in this thread. |