现在的位置: 首页 > 综合 > 正文

使用Plain Java API 创建RTC WorkItem

2017年05月20日 ⁄ 综合 ⁄ 共 3111字 ⁄ 字号 评论关闭

基本概念:

   

 下载Java lib 库文件:

      https://jazz.net/wiki/bin/view/Main/RtcSdk20

 创建代码(使用Plain Java API):

   

public class CreateWorkItem {
	
	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: CreateWorkItem <repositoryURI> <userId> <password> <projectArea> <workItemType> <summary> <category>");
			return false;
		}
		
		String repositoryURI= args[0];
		String userId= args[1];
		String password= args[2];
		String projectAreaName= args[3];
		String typeIdentifier= args[4];
		String summary= args[5];
		String categoryName= args[6];
		
		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 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;
	}
}

 

   更详细的步骤,看这里:

    https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation

【上篇】
【下篇】

抱歉!评论已关闭.