Java tutorial
/* * Dashboard * Copyright 2014 Christian Robert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.perdian.apps.dashboard.mvc.modules.jira; import java.awt.BasicStroke; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.axis.TickUnits; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import de.perdian.apps.dashboard.services.jira.JiraService; import de.perdian.apps.dashboard.services.jira.dto.BurndownDto; import de.perdian.apps.dashboard.support.chart.ChartCreator; import de.perdian.apps.dashboard.support.chart.ChartStrokeDefinition; @Controller class JiraController { private JiraService jiraService = null; @RequestMapping(value = "/jira/overview/") @ResponseBody JiraControllerResponse doOverview(@ModelAttribute JiraControllerRequest controllerRequest) { JiraControllerResponse controllerResponse = new JiraControllerResponse(); controllerResponse.setOverview(this.getJiraService().loadOverview(controllerRequest.getRapidViewId(), controllerRequest.getStoryPointFieldName())); return controllerResponse; } @RequestMapping(value = "/jira/burndown/") @ResponseBody JiraControllerResponse doBurndown(@ModelAttribute JiraControllerRequest controllerRequest) { BurndownDto burndownDto = this.getJiraService().loadBurndown(controllerRequest.getRapidViewId(), controllerRequest.getBurndownBasis(), controllerRequest.getStoryPointFieldName()); // We want to have twenty lines at maximum, so let's adjust the steps // accordingly double maxSteps = 20; double incrementPerStep = burndownDto.getStoryPointsTotal() / maxSteps; int increment = (int) Math.max(1, Math.ceil(incrementPerStep)); TickUnits rangeTickUnits = new TickUnits(); for (int i = 0; i < burndownDto.getStoryPointsTotal(); i += increment) { rangeTickUnits.add(new NumberTickUnit(i + 1)); } TickUnits domainTickUnits = new TickUnits(); domainTickUnits.add(new NumberTickUnit(burndownDto.getDays().size() + 1)); ChartCreator chartCreator = new ChartCreator(controllerRequest); chartCreator.setTitle(controllerRequest.getTitle()); chartCreator.setDomainTickUnits(domainTickUnits); chartCreator.setRangeTickUnits(rangeTickUnits); chartCreator .addStrokeDefinition(new ChartStrokeDefinition(new BasicStroke(7f), chartCreator.getColor(), null)); chartCreator.addStrokeDefinition(new ChartStrokeDefinition(null, null, false)); chartCreator.addStrokeDefinition(new ChartStrokeDefinition(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f), chartCreator.getColor(), null)); chartCreator.setRangeAxisLabel( "worklog".equalsIgnoreCase(controllerRequest.getBurndownBasis()) ? "Worklog (Hours)" : "Storypoints"); JiraControllerResponse controllerResponse = new JiraControllerResponse(); controllerResponse.setBurndown(burndownDto); controllerResponse.setImageContent(chartCreator.createChartAsImageContent(burndownDto.toDataset())); return controllerResponse; } // ------------------------------------------------------------------------- // --- Property access methods --------------------------------------------- // ------------------------------------------------------------------------- JiraService getJiraService() { return this.jiraService; } @Autowired void setJiraService(JiraService jiraService) { this.jiraService = jiraService; } }