Git Product home page Git Product logo

redmine-java-api's Introduction

Redmine/Chiliproject Java API.

Gradle dependency:

dependencies {
    compile 'com.taskadapter:redmine-java-api:<current-version>'
}

Check the latest release version in Maven Central

Sample code.

Obtain transport required for fluent-style calls

The new (February 2019) 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();

Get list of issues

String uri = "https://www.hostedredmine.com";
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());
}

Multi-values search for issues

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 = issueManager.getIssues(params);

Redmine searches for "Open" issues by default. You can specify "all" in your Map if you want:

params.put("status_id", "*");    

Get related objects when retrieving issues

issue = issueManager.getIssueById(123, Include.journals, Include.relations, Include.attachments, 
                          Include.changesets, Include.watchers);
journals = issue.getJournals();

Create an issue

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();

Get issue by Id

Issue retrievedIssue = issueManager.getIssueById(123);

Set custom field value on issue

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();

Get all projects

List<Project> projects = mgr.getProjectManager().getProjects();

Free-form search for users

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

See IntegrationTestHelper class:

final Optional<KeyStore> builtInExtension = getExtensionKeystore();
if (builtInExtension.isPresent()) {
    return RedmineManagerFactory.createConnectionManagerWithExtraTrust(
            Collections.singletonList(builtInExtension.get()));
}

redmine-java-api's People

Contributors

alexeyongithub avatar maxkar avatar imalygin avatar matthiasblaesing avatar zmd avatar bcmedeiros avatar alexey-twilio avatar imk avatar ciasnmic avatar albfan avatar keritaf avatar mkhokhlov avatar wurmy avatar jeeeyul avatar a11n avatar marob avatar mpscholz avatar javiertuya avatar alecharp avatar amuniz avatar kenneth-sperow avatar luisescamillamartin avatar panekzogen avatar karottenreibe avatar kkkon avatar manuelsanchezortiz avatar cuckoom avatar milechner avatar rabahi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.