Skip to content

Commit 2089dc9

Browse files
authored
Harmonize excel data export and include missed properties (#999)
* replace measurement templates * Move sample templates * Remove templates and correct autosizing of columns * Switch to new xlsx generation for sample metadata download * remove duplicate class * File name by experiment name instead of project code * Adapt to confounding variables * Move ROCrate export * remove unused field * Use downloadComponent * Move classes * Remove FileDownloadStreamProvider.java * Reduce complexity * Centralize file name formatting * Adapt filename for proteomics measurements * Change file name pattern --------- Co-authored-by: KochTobi <[email protected]>
1 parent 9a4d3bc commit 2089dc9

File tree

76 files changed

+2084
-2071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2084
-2071
lines changed
-116 Bytes
Binary file not shown.

user-interface/src/main/java/life/qbic/datamanager/export/FileFormatSupplier.java

-28
This file was deleted.

user-interface/src/main/java/life/qbic/datamanager/export/docx/DocxSupplier.java

-67
This file was deleted.

user-interface/src/main/java/life/qbic/datamanager/export/yaml/YamlSupplier.java

-34
This file was deleted.

user-interface/src/main/java/life/qbic/datamanager/export/TempDirectory.java user-interface/src/main/java/life/qbic/datamanager/files/TempDirectory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package life.qbic.datamanager.export;
1+
package life.qbic.datamanager.files;
22

33
import java.io.IOException;
44
import java.nio.file.Files;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package life.qbic.datamanager.files.export;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
import life.qbic.datamanager.files.export.FileSupplier.FormatException;
6+
import org.docx4j.openpackaging.exceptions.Docx4JException;
7+
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
8+
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
9+
10+
@FunctionalInterface
11+
public interface DocxBuilder<T> {
12+
13+
14+
record Section(String title, List<?> content) {
15+
16+
public Object titleAsParagraph(MainDocumentPart mainDocumentPart) {
17+
return mainDocumentPart.createStyledParagraphOfText("Heading1", title);
18+
}
19+
20+
@Override
21+
public List<?> content() {
22+
return Collections.unmodifiableList(content);
23+
}
24+
}
25+
26+
private static void addSection(MainDocumentPart mainDocumentPart, Section section) {
27+
mainDocumentPart.addObject(section.titleAsParagraph(mainDocumentPart));
28+
section.content().forEach(mainDocumentPart::addObject);
29+
}
30+
31+
static Object createTitle(MainDocumentPart mainDocumentPart, String title) {
32+
return mainDocumentPart.createStyledParagraphOfText("Title", title);
33+
}
34+
35+
static Object createSubtitle(MainDocumentPart mainDocumentPart, String subTitle) {
36+
return mainDocumentPart.createStyledParagraphOfText("Subtitle", subTitle);
37+
}
38+
39+
40+
List<Object> createContent(MainDocumentPart mainDocumentPart, T input);
41+
42+
default WordprocessingMLPackage buildFrom(T payload) {
43+
try {
44+
var result = WordprocessingMLPackage.createPackage();
45+
var mainDocument = result.getMainDocumentPart();
46+
List<Object> content = createContent(mainDocument, payload);
47+
for (Object part : content) {
48+
if (part instanceof Section section) {
49+
addSection(mainDocument, section);
50+
} else {
51+
mainDocument.addObject(part);
52+
}
53+
}
54+
return result;
55+
} catch (Docx4JException e) {
56+
throw new FormatException("Creating docx package failed. ", e);
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package life.qbic.datamanager.files.export;
2+
3+
import java.io.File;
4+
import org.docx4j.openpackaging.exceptions.Docx4JException;
5+
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
6+
7+
public class DocxFileSupplier implements FileSupplier {
8+
9+
private final WordprocessingMLPackage wordPackage;
10+
11+
DocxFileSupplier(WordprocessingMLPackage wordPackage) {
12+
this.wordPackage = wordPackage;
13+
14+
}
15+
16+
public static DocxFileSupplier supplying(WordprocessingMLPackage wordPackage) {
17+
return new DocxFileSupplier(wordPackage);
18+
}
19+
20+
21+
@Override
22+
public File getFile(String fileName) {
23+
try {
24+
File file = new File(fileName);
25+
wordPackage.save(file);
26+
return file;
27+
} catch (Docx4JException e) {
28+
throw new FormatException("Creating docx package failed.", e);
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package life.qbic.datamanager.files.export;
2+
3+
import java.time.LocalDate;
4+
import java.time.format.DateTimeFormatter;
5+
6+
public class FileNameFormatter {
7+
8+
private static final String SPACE_REPLACEMENT = "-";
9+
private static final String PART_JOINER = "_";
10+
11+
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
12+
13+
private FileNameFormatter() {
14+
15+
}
16+
17+
18+
public static String formatWithTimestampedContext(LocalDate timestamp, String projectPart,
19+
String experimentPart, String type, String extension) {
20+
return DATE_FORMATTER.format(timestamp)
21+
+ PART_JOINER
22+
+ replaceSpaces(projectPart)
23+
+ PART_JOINER
24+
+ replaceSpaces(experimentPart)
25+
+ PART_JOINER
26+
+ replaceSpaces(type)
27+
+ "." + replaceSpaces(extension);
28+
}
29+
30+
private static String replaceSpaces(String projectPart) {
31+
return projectPart.replaceAll("\\s", SPACE_REPLACEMENT);
32+
}
33+
34+
public static String formatWithVersion(String filename, int version,
35+
String extension) {
36+
return replaceSpaces(filename) + "_" + "v" + version + "." + replaceSpaces(extension);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package life.qbic.datamanager.files.export;
2+
3+
import java.io.File;
4+
5+
@FunctionalInterface
6+
public interface FileSupplier {
7+
8+
File getFile(String fileName);
9+
10+
class FormatException extends RuntimeException {
11+
12+
public FormatException(String message) {
13+
super(message);
14+
}
15+
16+
public FormatException(String message, Throwable cause) {
17+
super(message, cause);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)