Maven引用
<dependency>
<groupId>com.taskadapter</groupId>
<artifactId>redmine-java-api</artifactId>
<version>4.0.0.preview.3</version>
</dependency>
通过关键值 获取连接。Redmine 需要开启API
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey);
Transport transport = mgr.getTransport();
获取某个项目所有列表 list集合
String uri = "";
String apiAccessKey = "somekey";
String projectKey = "taskconnector-test";
Integer queryId = null; // any
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey);
// override default page size if needed
mgr.setObjectsPerPage(100);
List<Issue> issues = mgr.getIssueManager().getIssues(projectKey, queryId);
for (Issue issue : issues) {
System.out.println(issue.toString());
高级筛选
Params params = new Params()
.add("set_filter", "1")
.add("f[]", "summary")
.add("op[summary]", "~")
.add("v[summary]", "another")
.add("f[]", "description")
.add("op[description]", "~")
.add("v[description][]", "abc");
result = mgr.getIssueManager().getIssues(params);
issues.getTotalFoundOnServer() // 获取总数
issues.getResultsNumber() //结果最多获取数为25
issues.getResults() //以List集合形式 返回结果条目,包含缺陷id 标题
创建一个问题
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey);
Version ver = new Version().setId(512);
IssueCategory cat = new IssueCategory(transport).setId(673);
ProjectManager projectManager = manager.getProjectManager();
Project projectByKey = projectManager.getProjectByKey("testid");
Issue issue = new Issue(mgr.getTransport(), projectId)
.setSubject("test123")
.setTargetVersion(ver)
.setCategory(cat);
.setProjectId(projectId)
.create();
添加一条用例
package com.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dao.DengjiDao;
import com.dao.QushiDao;
import com.dao.UserDao;
import com.dao.ZhuangtaiDao;
import com.pojo.Dengji;
import com.pojo.Qushi;
import com.pojo.Zhuangtai;
import com.taskadapter.redmineapi.IssueManager;
import com.taskadapter.redmineapi.Params;
import com.taskadapter.redmineapi.ProjectManager;
import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.RedmineManager;
import com.taskadapter.redmineapi.RedmineManagerFactory;
import com.taskadapter.redmineapi.bean.CustomField;
import com.taskadapter.redmineapi.bean.Issue;
import com.taskadapter.redmineapi.bean.IssueCategory;
import com.taskadapter.redmineapi.bean.News;
import com.taskadapter.redmineapi.bean.Project;
import com.taskadapter.redmineapi.bean.Tracker;
import com.taskadapter.redmineapi.bean.Version;
import com.taskadapter.redmineapi.internal.ResultsWrapper;
import com.taskadapter.redmineapi.internal.Transport;
@Controller
public class Caitest {
@Autowired
private DengjiDao dd;
@Autowired
private ZhuangtaiDao zz;
@Autowired
private QushiDao qq;
public static void main(String[] args) throws Exception {
ResultsWrapper<Issue> issues2 = null;
String uri = "http://192.168.xxx.xxx/redmine/";
String apiAccessKey = "权限key";
String projectKey = "xxx项目"; //项目名
int id = 103;
Integer queryId = null;
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey);
IssueManager issueManager = mgr.getIssueManager();
Transport transport = mgr.getTransport();
Version ver1 = new Version().setId(137); //关联的项目版本号对应id
Tracker tracker = new Tracker().setId(4); // id4 类型为测试用例
ProjectManager projectManager = mgr.getProjectManager();
Project projectByKey = projectManager.getProjectById(id);
IssueCategory cat = new IssueCategory(transport);
Issue issue = new Issue(mgr.getTransport(), id);
issue.setProjectId(103); // 项目id
issue.setCategory(cat);
issue.setTargetVersion(ver1); // 版本
issue.setTracker(tracker);
CustomField customField = new CustomField();
issue.setDescription("描述"); //问题描述
CustomField customField = new CustomField(); //创建自定义字段
customField.setId(2); //自定义字段值为id2
//Issue retrievedIssue = issueManager.getIssueById(20792); //可以使用此方法获取自定义字段的id值
// System.out.println(retrievedIssue.getCustomFields().toString());
customField.setName("预期执行结果"); //自定义字段
customField.setValue("TC0002"); //字段内容
issue.addCustomField(customField); //添加
issue.create();//创建
}
}
获取所有项目
List<Project> projects = mgr.getProjectManager().getProjects();
通过ID获取相应问题
Issue retrievedIssue = issueManager.getIssueById(123);
获取时间条目
TimeEntryManager timeEntryManager = redmineManager.getTimeEntryManager();
final Map<String, String> params = new HashMap<>();
params.put("project_id", projectId);
params.put("activity_id", activityId);
final List<TimeEntry> elements = timeEntryManager.getTimeEntries(params);
使用自定义SSL证书场景 进行访问
假设有:
caTrustStore:具有要使用的自定义CA的Collection <KeyStore>对象
然后,以下函数将返回一个RedmineManager对象,该对象使用那些TrustStores连接到Redmine:
public RedmineManager connectToRedmine(String apiAccessKey, String url) throws IOException {
try {
ClientConnectionManaget connectionManager =
RedmineManagerFactory.createConnectionManagerWithExtraTrust(caTrustStore);
HttpClient client = RedmineManagerFactory.getNewHttpClient(url, connectionManager);
return RedmineManagerFactory.createWithApiKey(url, apiAccessKey, client);
} catch (Exception e) {
System.out.println("Could not connect to Redmine");
throw new IOException(e.getMessage());
}
}
示例2:
Optional builtInExtension = getExtensionKeystore();
if (builtInExtension.isPresent()) {
return RedmineManagerFactory.createConnectionManagerWithExtraTrust(
Collections.singletonList(builtInExtension.get()));
}
加好友
@好 留下联系方式 哈哈