BuildLife Hashes Per Time Period

Report on all the hashes in build lives based on time periods.. 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 java.text.*;
import java.util.*;

ReportMetaData rmd = new ReportMetaData();

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss z");

TextParamMetaData startDateParam = new TextParamMetaData();

startDateParam.setName("startDateStr");
startDateParam.setLabel("Start Date");
startDateParam.setDescription("The Interval Start Date yyyy-MM-dd kk:mm:ss z");
startDateParam.setRequired(true);

Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);

startDateParam.setDefaultValue(DATE_FORMAT.format(cal.getTime()));

rmd.addParameter(startDateParam);

TextParamMetaData endDateParam = new TextParamMetaData();

endDateParam.setName("endDateStr");
endDateParam.setLabel("End Date");
endDateParam.setDescription("The Interval End Date yyyy-MM-dd kk:mm:ss z");
endDateParam.setRequired(true);
endDateParam.setDefaultValue(DATE_FORMAT.format(new Date()));

rmd.addParameter(endDateParam);

Project[] projects = ProjectFactory.getInstance().restoreAllActive();
String[] labels = new String[projects.length + 1];
String[] values = new String[projects.length + 1];

labels[0] = "All";
values[0] = "all";

for (int i = 1; i < projects.length + 1; i++) {
  labels[i] = projects[i - 1].getName();
  values[i] = projects[i - 1].getId().toString();
}

SelectParamMetaData projectParams = new SelectParamMetaData();

projectParams.setLabels(labels);
projectParams.setValues(values);
projectParams.setName("projectId");
projectParams.setLabel("Project");
projectParams.setDescription("The Project To Report On Or All");
projectParams.setRequired(true);

rmd.addParameter(projectParams);

// Configure columns
rmd.addColumn("Build Life Id");
rmd.addColumn("Project");
rmd.addColumn("Workflow");
rmd.addColumn("Artifact Set");
rmd.addColumn("File");
rmd.addColumn("Hash");

// Lastly, return the meta data
return rmd;

Report Script:

import com.urbancode.anthill3.dashboard.*;
import com.urbancode.anthill3.domain.reporting.*;
import com.urbancode.anthill3.domain.project.*;
import com.urbancode.anthill3.domain.workflow.*;
import com.urbancode.anthill3.domain.buildlife.*;
import com.urbancode.codestation2.server.*;
import com.urbancode.codestation2.domain.artifacts.*;
import com.urbancode.anthill3.domain.workflow.WorkflowStatusEnum;
import com.urbancode.commons.fileutils.digest.*;
import com.urbancode.anthill3.runtime.paths.*;
import com.urbancode.devilfish.services.var.*;
import java.util.*;
import java.text.*;

BuildLifeWorkflowCaseSummary[] retrieveBuildLifeWorkflowCaseSummary() {
  BuildLifeWorkflowCaseSummary[] result = null;

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss z");

Date startDate = DATE_FORMAT.parse(startDateStr);
  Date endDate = DATE_FORMAT.parse(endDateStr);

if (projectId.equals("all")) {
    result = DashboardFactory.getInstance().getBuildLifeWorkflowSummaries(null, startDate, endDate);
  }
  else {
    result = DashboardFactory.getInstance().getBuildLifeWorkflowSummaries(new Long(projectId), startDate, endDate);
  }

return result;
}
void createBuildLifeRow(BuildLife buildLife,
                        BuildLifeWorkflowCaseSummary summary,
                        CodestationCompatableArtifactSet set,
                        File file,
                        DigestProperties digestProperties,
                        ReportOutput output) {
  ReportRow row = new ReportRow(output, "Build Life");
  row.setColumnValue("Build Life Id", summary.getBuildLifeId().toString());
  row.setColumnValue("Project", summary.getProjectName());
  row.setColumnValue("Workflow", summary.getWorkflowName());
  row.setColumnValue("Artifact Set", set.getName());
  row.setColumnValue("File", file.getName());
  row.setColumnValue("Hash", digestProperties.getDigestInfo(file));

output.addRow(row);
}

void createBuildLifeRows(BuildLife buildLife,
                         BuildLifeWorkflowCaseSummary summary,
                         ReportOutput output) {
  CodestationRepositoryFileHelper repo = CodestationRepositoryFileHelper.getInstance();
  CodestationCompatableArtifactSet[] setNames = repo.getPopulatedBuildLifeArtifactSetList(buildLife);
  for (int i = 0; i < setNames.length; i++) {
    CodestationCompatableArtifactSet set = setNames[i];
    String rawRepoLifeSetPath = CodestationPathHelper.getInstance().getSetPath(buildLife, set);
    String repoLifeSetPath = VarService.getInstance().resolve(rawRepoLifeSetPath);
    File baseSetDir = new File(repoLifeSetPath);

File[] fileArray = repo.getBuildLifeArtifactSetFileInfo(buildLife, set);
    File digestFile = repo.getBuildLifeArtifactSetDigestFile(buildLife, set);

DigestProperties digestProperties = new DigestProperties(digestFile);

for (int j = 0; j < fileArray.length; j++) {
      File file = fileArray[j];
      if (!".ahs.dig".equals(file.getName())) {
        createBuildLifeRow(buildLife, summary, set, file, digestProperties, output);
      }
    }
  }
}

ReportOutput output = new ReportOutput(metaData);
BuildLifeWorkflowCaseSummary[] summaries = retrieveBuildLifeWorkflowCaseSummary();

for (int i = 0; i < summaries.length; i++) {
  BuildLifeWorkflowCaseSummary summary = summaries[i];

boolean failed = (summary.getStatus() == WorkflowStatusEnum.FAILED || summary.getStatus() == WorkflowStatusEnum.ERROR);
    
if (!failed) {
    Workflow workflow = WorkflowFactory.getInstance().restore(summary.getWorkflowId());
    if (workflow.isOriginating()) {
      BuildLife buildLife = BuildLifeFactory.getInstance().restore(summary.getBuildLifeId());
      createBuildLifeRows(buildLife, summary, output);
    }
  }
}

return output; 

Related Content

AnthillPro Template Reports
Report Templates