Skip to content

Instantly share code, notes, and snippets.

@spilth
Created July 28, 2010 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spilth/494932 to your computer and use it in GitHub Desktop.
Save spilth/494932 to your computer and use it in GitHub Desktop.
import com.urbancode.anthill3.dashboard.*;
import com.urbancode.anthill3.domain.environmentgroup.*;
import com.urbancode.anthill3.domain.project.*;
import com.urbancode.anthill3.domain.servergroup.*;
import com.urbancode.anthill3.domain.workflow.*;
import com.urbancode.anthill3.domain.lifecycle.*;
import com.urbancode.anthill3.domain.status.*;
import com.urbancode.anthill3.domain.summary.buildworkflow.*;
import java.util.Date;
import java.text.DateFormat;
String reportGroup = "Foo";
Date date = new Date();
String dateString = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG).format(date);
Project[] projects = ProjectFactory.getInstance().restoreForProjectProperty("report.group", reportGroup);
List environmentGroupList = new ArrayList();
List lifeCycleModelList = new ArrayList();
Map environmentGroupNames = new HashMap();
Map lifeCycleModelNames = new HashMap();
HashMap getLifeCycleModelHashMap(Project project) {
LifeCycleModel lifeCycleModel = project.getLifeCycleModel();
if (!lifeCycleModelNames.containsKey(lifeCycleModel.getName())) {
HashMap lifeCycleModelHash = new HashMap();
lifeCycleModelHash.put("name", lifeCycleModel.getName());
lifeCycleModelHash.put("statuses", lifeCycleModel.getStatusGroup().getStatusArray());
lifeCycleModelNames.put(lifeCycleModel.getName(), lifeCycleModelHash);
}
return lifeCycleModelNames.get(lifeCycleModel.getName());
}
HashMap getEnvironmentGroupHashMap(Project project) {
// Project Environment Group
EnvironmentGroup environmentGroup = project.getEnvironmentGroup();
if (!environmentGroupNames.containsKey(environmentGroup.getName())) {
HashMap environmentGroupHash = new HashMap();
environmentGroupHash.put("name", environmentGroup.getName());
// Environment Group Environments
ServerGroup[] environments = environmentGroup.getServerGroupArray();
List environmentList = new ArrayList();
for (int e = 0; e < environments.length; e++) {
ServerGroup environment = environments[e];
HashMap environmentHash = new HashMap();
environmentHash.put("name", environment.getName());
environmentHash.put("shortname", environment.getShortName());
environmentList.add(environmentHash);
}
environmentGroupHash.put("environments", environmentList);
environmentGroupHash.put("projects", new ArrayList());
environmentGroupList.add(environmentGroupHash);
environmentGroupNames.put(environmentGroup.getName(), environmentGroupHash);
}
return environmentGroupNames.get(environmentGroup.getName());
}
Project project = null;
for (int p = 0; p < projects.length; p++) {
project = projects[p];
HashMap projectHash = new HashMap();
projectHash.put("name", project.getName());
projectHash.put("id", project.getId());
HashMap environmentGroupHash = getEnvironmentGroupHashMap(project);
HashMap lifeCycleModelHash = getLifeCycleModelHashMap(project);
environmentGroupHash.put("lifeCycleModel", lifeCycleModelHash);
// Build Summaries
BuildWorkflowSummary[] buildSummaries = BuildWorkflowSummaryFactory.getInstance().restoreLatestBuildWorkflowSummaryForEachProfileOfProject(project.getId());
projectHash.put("builds", buildSummaries);
// Status Summaries
List summaryList = new ArrayList();
StatusSummary[] statusSummaries = DashboardFactory.getInstance().getMostRecentSummaryForEachStatus(project);
HashMap statusHash = new HashMap();
for (int s = 0; s < statusSummaries.length; s++) {
StatusSummary statusSummary = statusSummaries[s];
statusHash.put(statusSummary.getStatusName(), statusSummary);
}
projectHash.put("statuses", statusHash);
ArrayList projectList = (ArrayList) environmentGroupHash.get("projects");
projectList.add(projectHash);
}
context.put("reportGroup", reportGroup);
context.put("environmentGroups", environmentGroupList);
context.put("date", dateString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment