Skip to content

Commit 2f862ba

Browse files
committed
issue #233
1 parent 2b93362 commit 2f862ba

File tree

5 files changed

+796
-72
lines changed

5 files changed

+796
-72
lines changed

curation-api/src/main/java/eu/clarin/cmdi/curation/api/utils/FileStorage.java

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
@Component
3838
public class FileStorage {
3939

40-
private final Pattern creationTimePattern = Pattern.compile("creationTime=\"(.+)\"");
40+
private final Pattern creationTimePattern = Pattern.compile("creationTime=\"(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\"");
4141

42-
private final Pattern previousCreationTimePattern = Pattern.compile("previousCreationTime=\"(.+)\"");
42+
private final Pattern previousCreationTimePattern = Pattern.compile("previousCreationTime=\"(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\"");
4343

4444
/**
4545
* The Conf.
@@ -100,16 +100,9 @@ public void saveReport(NamedReport report, CurationEntityType entityType, boolea
100100
}
101101
}
102102

103-
Path xmlFilePath = saveReportAsXML(report, entityType);
104-
105-
Path htmlFilePath = saveReportAsHTML(report, entityType);
106-
107-
108-
if (makeStampedCopy) {
109-
copyStampedFile(xmlFilePath, report);
110-
copyStampedFile(htmlFilePath, report);
111-
}
103+
saveReportAsXML(report, entityType, makeStampedCopy);
112104

105+
saveReportAsHTML(report, entityType, makeStampedCopy);
113106
}
114107

115108
/**
@@ -134,7 +127,7 @@ public void checkOutputPath() {
134127
* @param entityType the entity type
135128
* @return the path
136129
*/
137-
public Path saveReportAsXML(NamedReport report, CurationEntityType entityType) {
130+
public Path saveReportAsXML(NamedReport report, CurationEntityType entityType, boolean makeStampedCopy) {
138131

139132
Path outputPath = getOutputPath(report.getName(), entityType, "xml");
140133

@@ -172,6 +165,22 @@ public Path saveReportAsXML(NamedReport report, CurationEntityType entityType) {
172165
log.error("can't marshall report '{}'", report.getName());
173166
}
174167

168+
if(makeStampedCopy){
169+
170+
String stampedFileName = report.getName() + "_" + report.getCreationTime().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".xml";
171+
172+
Path stampedPath = outputPath.getParent().resolve(stampedFileName);
173+
174+
try {
175+
Files.copy(outputPath, stampedPath, StandardCopyOption.REPLACE_EXISTING);
176+
}
177+
catch (IOException e) {
178+
179+
log.error("can't copy file '{}' to stamped file '{}'", outputPath, stampedPath);
180+
throw new RuntimeException(e);
181+
}
182+
}
183+
175184
return outputPath;
176185
}
177186

@@ -182,7 +191,7 @@ public Path saveReportAsXML(NamedReport report, CurationEntityType entityType) {
182191
* @param entityType the entity type
183192
* @return the path
184193
*/
185-
public Path saveReportAsHTML(NamedReport report, CurationEntityType entityType) {
194+
public Path saveReportAsHTML(NamedReport report, CurationEntityType entityType, boolean makeStampedCopy) {
186195

187196
Path outputPath = getOutputPath(report.getName(), entityType, "html");
188197

@@ -213,6 +222,51 @@ public Path saveReportAsHTML(NamedReport report, CurationEntityType entityType)
213222

214223
}
215224

225+
if(makeStampedCopy){
226+
227+
String stampedFileName = report.getName() + "_" + report.getCreationTime().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".html";
228+
229+
Path stampedPath = outputPath.getParent().resolve(stampedFileName);
230+
231+
resourceName = "/xslt/" + report.getClass().getSimpleName() + "2HTMLStamped.xsl";
232+
233+
InputStream in = this.getClass().getResourceAsStream(resourceName);
234+
235+
if(in != null){
236+
237+
xslt = new StreamSource(in);
238+
239+
try {
240+
transformer = factory.newTransformer(xslt);
241+
242+
transformer.transform(new JAXBSource(JAXBContext.newInstance(report.getClass()), report),
243+
new StreamResult(stampedPath.toFile()));
244+
}
245+
catch (TransformerConfigurationException e) {
246+
247+
log.error("can't load resource '{}'", resourceName);
248+
throw new RuntimeException(e);
249+
250+
}
251+
catch (TransformerException | JAXBException e) {
252+
253+
log.error("can't transform report '{}'", report.getName());
254+
255+
}
256+
}
257+
else{
258+
259+
try {
260+
Files.copy(outputPath, stampedPath, StandardCopyOption.REPLACE_EXISTING);
261+
}
262+
catch (IOException e) {
263+
264+
log.error("can't copy file '{}' to stamped file '{}'", outputPath, stampedPath);
265+
throw new RuntimeException(e);
266+
}
267+
}
268+
}
269+
216270
return outputPath;
217271
}
218272

@@ -235,19 +289,4 @@ private Path getOutputPath(String reportName, CurationEntityType entityType, Str
235289

236290
return outPath.resolve(filename);
237291
}
238-
239-
private void copyStampedFile(Path path, NamedReport report) {
240-
String stampedFileName = path.getFileName().toString().replace(".",
241-
"_" + report.getCreationTime().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".");
242-
Path stampedPath = path.getParent().resolve(stampedFileName);
243-
try {
244-
Files.copy(path, stampedPath, StandardCopyOption.REPLACE_EXISTING);
245-
}
246-
catch (IOException e) {
247-
248-
log.error("can't copy file '{}' to stamped file '{}'", path, stampedPath);
249-
throw new RuntimeException(e);
250-
}
251-
}
252-
253292
}

curation-app/src/main/resources/xslt/CollectionReport2HTML.xsl

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,47 @@
1717
<head>
1818
</head>
1919
<body>
20-
<div class="creationTime">
21-
created at
22-
<xsl:value-of select="./@creationTime"/>
23-
</div>
24-
<xsl:text> </xsl:text>
25-
<div class="creationTime">
26-
(<a>
27-
<xsl:attribute name="href">
28-
<xsl:text>/collection/</xsl:text>
29-
<xsl:value-of select="//fileReport/provider"/>
30-
<xsl:text>_</xsl:text>
31-
<xsl:value-of select="substring(./@previousCreationTime, 1, 10)" />
32-
<xsl:text>.html</xsl:text>
33-
</xsl:attribute>
34-
<xsl:text>previous report</xsl:text>
35-
</a>)
36-
</div>
37-
<div class="download">
38-
download as
39-
<a>
40-
<xsl:attribute name="href">
41-
<xsl:text>/download/collection/</xsl:text>
42-
<xsl:value-of select="//fileReport/provider"/>
43-
<xsl:text>_</xsl:text>
44-
<xsl:value-of select="substring(./@creationTime, 1, 10)" />
45-
</xsl:attribute>
46-
<xsl:text>xml</xsl:text>
47-
</a>
48-
<xsl:text> </xsl:text>
49-
<a>
50-
<xsl:attribute name="href">
51-
<xsl:text>/download/collection/</xsl:text>
52-
<xsl:value-of select="//fileReport/provider"/>
53-
<xsl:text>_</xsl:text>
54-
<xsl:value-of select="substring(./@creationTime, 1, 10)" />
55-
<xsl:text>?format=json</xsl:text>
56-
</xsl:attribute>
57-
<xsl:text>json</xsl:text>
58-
</a>
20+
<div>
21+
<div class="creationTime">
22+
created at
23+
<xsl:value-of select="./@creationTime"/>
24+
<xsl:text> </xsl:text>
25+
(<a>
26+
<xsl:attribute name="href">
27+
<xsl:text>/collection/</xsl:text>
28+
<xsl:value-of select="//fileReport/provider"/>
29+
<xsl:text>_</xsl:text>
30+
<xsl:value-of select="substring(./@previousCreationTime, 1, 10)" />
31+
<xsl:text>.html</xsl:text>
32+
</xsl:attribute>
33+
<xsl:text>previous report</xsl:text>
34+
</a>)
35+
</div>
36+
<div class="download">
37+
download as
38+
<a>
39+
<xsl:attribute name="href">
40+
<xsl:text>/download/collection/</xsl:text>
41+
<xsl:value-of select="//fileReport/provider"/>
42+
<xsl:text>_</xsl:text>
43+
<xsl:value-of select="substring(./@creationTime, 1, 10)" />
44+
</xsl:attribute>
45+
<xsl:text>xml</xsl:text>
46+
</a>
47+
<xsl:text> </xsl:text>
48+
<a>
49+
<xsl:attribute name="href">
50+
<xsl:text>/download/collection/</xsl:text>
51+
<xsl:value-of select="//fileReport/provider"/>
52+
<xsl:text>_</xsl:text>
53+
<xsl:value-of select="substring(./@creationTime, 1, 10)" />
54+
<xsl:text>?format=json</xsl:text>
55+
</xsl:attribute>
56+
<xsl:text>json</xsl:text>
57+
</a>
58+
</div>
59+
<div class="clear"/>
5960
</div>
60-
<div class="clear"/>
6161
<h1>Collection Report</h1>
6262
<h3>
6363
Collection name:

0 commit comments

Comments
 (0)