Project

General

Profile

Error creating issue java api

Added by daniel martin over 8 years ago

Hi,

I'm trying to create an issue from api Java in Eclipse. However when I create it is causing an error. What minimum data is needed to create the issue?

Thank you.

String uri = "https://xxxx";
        String apiAccessKey = "xxxxx";
        String projectKey = "sds-hgp-00291";
        Integer queryId = null; // any
        Integer idproyecto = 0;

        RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri,
                apiAccessKey);
        IssueManager issueManager = mgr.getIssueManager();
        ProjectManager projectManager = mgr.getProjectManager();
        List<Issue> issues = null;
        List<Project> projects = null;
        Issue issueToCreate = new Issue();
        try {
            issues = issueManager.getIssues(projectKey, queryId);
            projects = projectManager.getProjects();
        } catch (RedmineException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (Issue issue : issues) {
            System.out.println(issue.toString());
        }

        for (Project project : projects) {
            System.out.println(project.getName());
            System.out.println(project.getId());
            if (project.getName().equalsIgnoreCase("NAOS")) {
                issueToCreate.setProject(project);
            }
        }
        // Create issue

        issueToCreate.setSubject("test zzx");

        Calendar startCal = Calendar.getInstance();
        // have to clear them because they are ignored by Redmine and
        // prevent from comparison later
        startCal.clear(Calendar.HOUR_OF_DAY);
        startCal.clear(Calendar.MINUTE);
        startCal.clear(Calendar.SECOND);
        startCal.clear(Calendar.MILLISECOND);

        startCal.add(Calendar.DATE, 5);
        issueToCreate.setStartDate(startCal.getTime());

        Calendar due = Calendar.getInstance();
        due.add(Calendar.MONTH, 1);
        issueToCreate.setDueDate(due.getTime());

        //
        // assignee.setFullName("Daniel Martín Fernandez");
        // issueToCreate.set

        String description = "This is the description for the new task." 
                + "\nIt has several lines." + "\nThis is the last line.";
        issueToCreate.setDescription(description);

        float estimatedHours = 44;
        issueToCreate.setEstimatedHours(estimatedHours);

        try {

            Issue createdIssue = issueManager.createIssue(issueToCreate);
        } catch (RedmineException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // // Get issue by ID:
        // try {
        // Issue issue = issueManager.getIssueById(123);
        // } catch (RedmineException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }

    }