diff --git a/CHANGES.md b/CHANGES.md index 56568c52..041466a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +# 7.2.0 +- adding collection history report (issue https://github.com/clarin-eric/curation-dashboard/issues/277) + # 7.1.2 - setting maximum CMDI file size to 100MB (issue https://github.com/clarin-eric/curation-dashboard/issues/275) - upgrading to Spring Boot 3.4.1 diff --git a/curation-api/src/main/java/eu/clarin/cmdi/curation/api/report/collection/CollectionHistoryReport.java b/curation-api/src/main/java/eu/clarin/cmdi/curation/api/report/collection/CollectionHistoryReport.java new file mode 100644 index 00000000..9e49f7ab --- /dev/null +++ b/curation-api/src/main/java/eu/clarin/cmdi/curation/api/report/collection/CollectionHistoryReport.java @@ -0,0 +1,78 @@ +package eu.clarin.cmdi.curation.api.report.collection; + +import eu.clarin.cmdi.curation.api.report.LocalDateTimeAdapter; +import eu.clarin.cmdi.curation.api.report.NamedReport; +import jakarta.xml.bind.annotation.*; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.TreeMap; +import java.util.TreeSet; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) +public class CollectionHistoryReport implements NamedReport { + @XmlAttribute + @XmlJavaTypeAdapter(LocalDateTimeAdapter.class) + public final LocalDateTime creationTime = LocalDateTime.now(); + private final TreeMap providerGroups = new TreeMap<>((pg1, pg2) -> pg1.compareTo(pg2)); + @XmlElement(name = "collection") + public Collection getCollections(){ + + return this.providerGroups.values(); + } + + public void addReport(String providerGroup, String isoDate, String fileName){ + + this.providerGroups.computeIfAbsent(providerGroup, k -> new ProviderGroup(k)).addReport(isoDate, fileName); + } + + @Override + public String getName() { + return this.getClass().getSimpleName(); + } + + @Override + public LocalDateTime getCreationTime() { + + return this.creationTime; + } + + @Override + public void setPreviousCreationTime(LocalDateTime previousCreationTime) { + + } + + @Override + public LocalDateTime getPreviousCreationTime() { + return null; + } + + @XmlRootElement + @XmlAccessorType(XmlAccessType.FIELD) + @RequiredArgsConstructor + @NoArgsConstructor(force = true) + private static class ProviderGroup{ + @XmlAttribute + public final String name; + @XmlElement(name = "report") + public TreeSet reports = new TreeSet<>((report1, report2) -> report2.isoDate.compareTo(report1.isoDate)); + + public void addReport(String isoDate, String fileName){ + this.reports.add(new Report(isoDate, fileName)); + } + } + @XmlRootElement + @XmlAccessorType(XmlAccessType.FIELD) + @RequiredArgsConstructor + @NoArgsConstructor(force = true) + public static class Report { + @XmlAttribute + public final String isoDate; + @XmlAttribute + public final String fileName; + } +} diff --git a/curation-app/src/main/java/eu/clarin/cmdi/curation/app/CurationApp.java b/curation-app/src/main/java/eu/clarin/cmdi/curation/app/CurationApp.java index e19dc7ef..cc323e3b 100644 --- a/curation-app/src/main/java/eu/clarin/cmdi/curation/app/CurationApp.java +++ b/curation-app/src/main/java/eu/clarin/cmdi/curation/app/CurationApp.java @@ -3,6 +3,7 @@ import eu.clarin.cmdi.curation.api.CurationModule; import eu.clarin.cmdi.curation.api.entity.CurationEntityType; import eu.clarin.cmdi.curation.api.report.collection.AllCollectionReport; +import eu.clarin.cmdi.curation.api.report.collection.CollectionHistoryReport; import eu.clarin.cmdi.curation.api.report.collection.CollectionReport; import eu.clarin.cmdi.curation.api.report.linkchecker.AllLinkcheckerReport; import eu.clarin.cmdi.curation.api.report.profile.AllProfileReport; @@ -33,6 +34,8 @@ import java.nio.file.Path; import java.time.LocalDateTime; import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Stream; /** @@ -46,6 +49,8 @@ @EnableConfigurationProperties @Slf4j public class CurationApp { + + private static final Pattern pattern = Pattern.compile("(\\S+)_(\\d{4}-\\d{2}-\\d{2}).html"); @Autowired private AppConfig conf; @@ -92,8 +97,9 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) { final AllCollectionReport allCollectionReport = new AllCollectionReport(); - final AllLinkcheckerReport allLinkcheckerReport = new AllLinkcheckerReport(); - + final AllLinkcheckerReport allLinkcheckerReport = new AllLinkcheckerReport(); + final CollectionHistoryReport collectionHistoryReport = new CollectionHistoryReport(); + conf.getDirectory().getIn().forEach(inPath -> { try { processCollection(inPath, allCollectionReport,allLinkcheckerReport ); @@ -103,8 +109,20 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) { } }); + // we create a meta report of all collection reports + Files.walk(conf.getDirectory().getOut().resolve("html").resolve("collection")).forEach(path -> { + + Matcher matcher; + + if(!path.getFileName().toString().startsWith("AllCollectionReport") && (matcher = pattern.matcher(path.getFileName().toString())).matches()) { + + collectionHistoryReport.addReport(matcher.group(1).replaceAll("_", " ").trim(), matcher.group(2), path.getFileName().toString()); + } + }); + storage.saveReport(allCollectionReport, CurationEntityType.COLLECTION, true); storage.saveReport(allLinkcheckerReport, CurationEntityType.LINKCHECKER, true); + storage.saveReport(collectionHistoryReport, CurationEntityType.COLLECTION, false); } // it's important to process profiles after collections, to fill the collection usage section of the profiles diff --git a/curation-app/src/main/resources/xslt/AllCollectionReport2HTML.xsl b/curation-app/src/main/resources/xslt/AllCollectionReport2HTML.xsl index ea4e3d97..cde3ac8d 100644 --- a/curation-app/src/main/resources/xslt/AllCollectionReport2HTML.xsl +++ b/curation-app/src/main/resources/xslt/AllCollectionReport2HTML.xsl @@ -101,6 +101,9 @@ + diff --git a/curation-app/src/main/resources/xslt/CollectionHistoryReport2HTML.xsl b/curation-app/src/main/resources/xslt/CollectionHistoryReport2HTML.xsl new file mode 100644 index 00000000..6b02185d --- /dev/null +++ b/curation-app/src/main/resources/xslt/CollectionHistoryReport2HTML.xsl @@ -0,0 +1,18 @@ + + + + +

+ + + + + /collection/ + + + + + +
+
+
\ No newline at end of file diff --git a/pom.xml b/pom.xml index 40998ad5..1e0bddd2 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 21 UTF-8 2.0.0 - 7.1.3-SNAPSHOT + 7.2.0-SNAPSHOT 4.12.1 2.11 12.3