The new fluent-style API (v. 4.x) requires a transport instance for most calls.
First, create an instance of RedmineManager and then obtain its transport:
RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri, apiAccessKey);
Transport transport = mgr.getTransport();
Issue issue = ...
List<CustomFieldDefinition> customFieldDefinitions = mgr.getCustomFieldManager().getCustomFieldDefinitions();
// sample implementation for getCustomFieldByName() is in CustomFieldResolver (test class).
// in prod code you would typically know the custom field name or id already
CustomFieldDefinition customField1 = getCustomFieldByName(customFieldDefinitions, "my_custom_1");
String custom1Value = "some value 123";
issue.addCustomField(CustomFieldFactory.create(customField1.getId(), customField1.getName(), custom1Value));
issueManager.update(issue);
Create project
Project project = new Project(transport)
.setName("Upload project")
.setIdentifier("uploadtmpproject")
.create();
Map<String, String> params = new HashMap<>();
params.put("name", name);
List<User> list = userManager.getUsers(params);
Create a group and add user to it
Group group = new Group(transport)
.setName("group")
.create();
User user = new User(transport).set(...)
.create();
userManager.addUserToGroup(user, group);
Delete user
user.delete();
Get time entries
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);
Using a custom (e.g. self-signed) SSL certificate
Supposing you have:
caTrustStore: a Collection<KeyStore> object that has the custom CAs to use
Then the following function will return a RedmineManager object that uses those TrustStores
to connect to 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());
}
}
For another example, see IntegrationTestHelper class:
请发表评论