Cleaned code. Add hasToRefresh check.

This commit is contained in:
Christian P. MOMON 2020-01-22 19:10:43 +01:00
parent e877955e95
commit 094920c087
10 changed files with 60 additions and 29 deletions

View File

@ -3,8 +3,8 @@
# priority setting: DEBUG < INFO < WARN < ERROR
log4j.rootLogger = DEBUG, console
log4j.logger.fr.devinsy.xidyn = INFO
log4j.logger.org.april.agirstatool = INFO
log4j.logger.fr.devinsy.xidyn = WARN
#--
log4j.appender.console = org.apache.log4j.ConsoleAppender

View File

@ -25,6 +25,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import org.apache.commons.io.FileUtils;
import org.april.agirstatool.charts.DateCount;
@ -473,6 +475,54 @@ public class AgirStatool
return result;
}
/**
* Checks for to refresh.
*
* @param project
* the project
* @return true, if successful
*/
public boolean hasToRefresh(final Project project)
{
boolean result;
if (project == null)
{
result = false;
}
else
{
File target = new File(this.targetDirectory, project.getPath());
if (target.exists())
{
if (project.hasIssue())
{
LocalDateTime lastFileUpdate = LocalDateTime.ofEpochSecond(target.lastModified() / 1000, 0, ZoneOffset.UTC);
if (project.issueStats().getLastUpdate().isAfter(lastFileUpdate))
{
result = true;
}
else
{
result = false;
}
}
else
{
result = false;
}
}
else
{
result = true;
}
}
//
return result;
}
/**
* List projects.
*
@ -590,7 +640,7 @@ public class AgirStatool
}
for (Project project : projects)
{
logger.info("Fetching Created/Closed history for " + project.getName());
logger.debug("Fetching Created/Closed history for " + project.getName());
if (project.hasIssue())
{
{
@ -605,7 +655,7 @@ public class AgirStatool
}
}
}
logger.info("Fetching Created/Closed history done.");
logger.debug("Fetching Created/Closed history done.");
// Transform as tree.
for (Project project : projects)
@ -831,8 +881,9 @@ public class AgirStatool
{
try
{
if (project != null)
if (hasToRefresh(project))
{
logger.info("Refresh project page for {}", project.getName());
String page = ProjectPage.build(project);
FileUtils.write(new File(this.targetDirectory, project.getIdentifier() + ".xhtml"), page, StandardCharsets.UTF_8);
}

View File

@ -52,8 +52,6 @@ public class ChartBarView
try
{
logger.info("Building chartBar view…");
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartBarView.xhtml"));
String code = XidynUtils.extractBodyContent(source);

View File

@ -52,8 +52,6 @@ public class ChartPolarView
try
{
logger.info("Building polar chart view…");
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartPolarView.xhtml"));
String code = XidynUtils.extractBodyContent(source);

View File

@ -62,8 +62,6 @@ public class CreatedConcludedCountChartView
try
{
logger.info("Building created/closed x months chart view…");
if (project.hasIssue())
{
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView.xhtml"));
@ -113,7 +111,7 @@ public class CreatedConcludedCountChartView
try
{
logger.info("Building created/concluded chart view…");
logger.debug("Building created/concluded chart view…");
if (project.hasIssue())
{
@ -162,8 +160,6 @@ public class CreatedConcludedCountChartView
{
String result;
logger.info("Building created/closed x months chart view…");
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
//
@ -180,8 +176,6 @@ public class CreatedConcludedCountChartView
{
String result;
logger.info("Building created/closed x months chart view…");
result = buildYear(title, project, LocalDate.now().getYear() - 1);
//
@ -253,8 +247,6 @@ public class CreatedConcludedCountChartView
{
String result;
logger.info("Building created/closed x months chart view…");
LocalDate start = LocalDate.of(year, 1, 1).minusDays(7);
LocalDate end = LocalDate.of(year + 1, 1, 1).minusDays(1);

View File

@ -45,8 +45,6 @@ public class IssueStatChartView
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Maybe", "New", "Confirmed", "Ongoing", "Waiting", "Resolved");
StringList values = new StringList();
values.append(project.issueStats().getMaybeCount());
@ -76,8 +74,6 @@ public class IssueStatChartView
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Maybe", "Active", "Resolved");
StringList values = new StringList();
values.append(project.issueStats().getMaybeCount());

View File

@ -51,7 +51,7 @@ public class ProjectPage
try
{
logger.info("Building project page " + project.getName() + "");
logger.debug("Building project page {}…", project.getName());
TagDataManager data = new TagDataManager();

View File

@ -54,7 +54,7 @@ public class ProjectsGroupedView
try
{
logger.info("Building ProjectsGrouped view…");
logger.debug("Building ProjectsGrouped view…");
TagDataManager data = new TagDataManager();

View File

@ -52,7 +52,7 @@ public class ProjectsRawView
try
{
logger.info("Building ProjectsRaw view…");
logger.debug("Building ProjectsRaw view…");
TagDataManager data = new TagDataManager();

View File

@ -46,8 +46,6 @@ public class UnassignedPolarChartView
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Confirmed", "Ongoing", "Waiting", "Resolved", "Rejected", "Closed");
StringList values = new StringList();
IssueStats stats = project.issueStats();
@ -78,8 +76,6 @@ public class UnassignedPolarChartView
{
String result;
logger.info("Building issue stat chart view…");
StringList labels = new StringList("Started", "Resolved", "Concluded");
StringList values = new StringList();
IssueStats stats = project.issueStats();