This report has to be used in conjunction with a report template such as the HTML Template.
Meta-Data Script:
import com.urbancode.anthill3.domain.project.*; import com.urbancode.anthill3.domain.reporting.*; import com.urbancode.anthill3.domain.userprofile.*; import java.text.SimpleDateFormat; import java.util.*; ReportMetaData rmd = new ReportMetaData(); // Add some projects to choose from SelectParamMetaData params = new SelectParamMetaData(); Project[] allMyProjectsArray = ProjectFactory.getInstance().restoreAllActive(); String[] labels = new String[allMyProjectsArray.length + 1]; String[] values = new String[allMyProjectsArray.length + 1]; for (int i = 0; i < allMyProjectsArray.length; i++) { labels[i] = allMyProjectsArray[i].getName(); values[i] = allMyProjectsArray[i].getId().toString(); } labels[allMyProjectsArray.length] = "All"; values[allMyProjectsArray.length] = "all"; params.setLabels(labels); params.setValues(values); params.setName("project"); params.setLabel("Project"); params.setDescription("Select the project to evaluate successful and failed executions of that project. Or select 'All' to display all projects together."); rmd.addParameter(params); // Add the months to choose from SelectParamMetaData monthParams = new SelectParamMetaData(); TimeZone timeZone = UserProfileFactory.getTimeZone(); Calendar cal = Calendar.getInstance(timeZone); int monthsToHave = 12; String[] monthLabels = new String[monthsToHave]; String[] monthValues = new String[monthsToHave]; SimpleDateFormat monthOnly = new SimpleDateFormat("MMMM"); for (int i = 1; i <= monthsToHave; i++) { monthLabels[monthsToHave - i] = monthOnly.format(cal.getTime()); monthValues[monthsToHave - i] = "" + cal.get(Calendar.MONTH); cal.add(Calendar.MONTH, -1); } monthParams.setLabels(monthLabels); monthParams.setValues(monthValues); monthParams.setName("month"); monthParams.setLabel("Month"); monthParams.setDescription("Select the month to run this report against."); rmd.addParameter(monthParams); // Configure columns rmd.addColumn("Action"); rmd.addColumn("Environment"); rmd.addColumn("Latest Stamp"); rmd.addColumn("Build Life"); rmd.addColumn("Agent(s)"); rmd.addColumn("Status"); rmd.addColumn("Build Date"); rmd.addColumn("Deploy Date"); return rmd;
Report Script:
import com.urbancode.anthill3.dashboard.*; import com.urbancode.anthill3.domain.reporting.*; import com.urbancode.anthill3.domain.userprofile.*; import com.urbancode.anthill3.domain.workflow.*; import com.urbancode.anthill3.domain.buildlife.*; import com.urbancode.commons.util.Duration; import java.util.*; // Get the timezone for the current user TimeZone timeZone = UserProfileFactory.getTimeZone(); Calendar cal = Calendar.getInstance(timeZone); // Figure out the project to use. "project" is the name of the parameter in the meta data script. It's provided here. Long projectId = null; if (project == null || project.equals("all")) { // leave as null; } else { projectId = Long.parseLong(project); } // Get workflows for the last month int monthId = Integer.parseInt(month); // Get workflows for the last month int monthId = Integer.parseInt(month); if (monthId > cal.get(Calendar.MONTH) ) { // We are looking at last year not the future cal.add(Calendar.YEAR, -1); } cal.set(Calendar.MONTH, monthId); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); startDate = cal.getTime(); cal.add(Calendar.MONTH, 1); endDate = cal.getTime(); BuildLifeWorkflowCaseSummary[] summaries = DashboardFactory.getInstance().getBuildLifeWorkflowSummaries(projectId, startDate, endDate); ReportOutput output = new ReportOutput(metaData); for (int i = 0; i < summaries.length; i++) { try { buildLife = BuildLifeFactory.getInstance().restore(summaries[i].getBuildLifeId()); workflow = WorkflowCaseFactory.getInstance().restore(summaries[i].getCaseId()); originating = WorkflowCaseFactory.getInstance().restoreOriginatingForBuildLife(buildLife); // Only include non-originating workflows if (!workflow.getWorkflow().isOriginating() && workflow.getServerGroup().getShortName() != null && !workflow.getServerGroup().getShortName().equals("DEV")) { // Calculate Duration Duration duration = new Duration(summaries[i].getStartDate(),summaries[i].getEndDate()); // calculate the agent(s) invloved jobs = workflow.getJobTraceArray(); String agents = ""; for (int j = 0; j < jobs.length; j++) { agents += (jobs[j].getAgent().getName() + " "); } ReportRow row = new ReportRow(output, "1"); row.setColumnValue("Action", summaries[i].getWorkflowName()); row.setColumnValue("Environment", workflow.getServerGroup().getName()); row.setColumnValue("Latest Stamp", summaries[i].getLatestStamp()); row.setColumnValue("Build Life", summaries[i].getBuildLifeId().toString()); row.setColumnValue("Agent(s)",agents); row.setColumnValue("Status", summaries[i].getStatus().getName()); row.setColumnValue("Build Date", originating.getEndDate() == null ? "Running": String.valueOf(originating.getEndDate())); row.setColumnValue("Deploy Date", summaries[i].getEndDate() == null ? "Running": String.valueOf(summaries[i].getEndDate()) + "\n"); output.addRow(row); } } catch (Exception e) { ReportRow row = new ReportRow(output, "1"); row.setColumnValue("Action", summaries[i].getWorkflowName()); row.setColumnValue("Environment", "Error"); row.setColumnValue("Latest Stamp", "Error"); row.setColumnValue("Build Life", summaries[i].getBuildLifeId().toString()); row.setColumnValue("Agent(s)","Error"); row.setColumnValue("Status", "Error"); row.setColumnValue("Build Date", originating.getEndDate() == null ? "Running": String.valueOf(originating.getEndDate())); row.setColumnValue("Deploy Date", "Error" + "\n"); output.addRow(row); } } return output;
Related Content