• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kit-data-manager / ro-crate-java / #395

29 Apr 2025 06:46PM UTC coverage: 89.357%. First build
#395

Pull #233

github

Pfeil
fix: remove unnecessary Javadoc build step from CI configuration
Pull Request #233: Version 2.1.0

608 of 700 new or added lines in 28 files covered. (86.86%)

1889 of 2114 relevant lines covered (89.36%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.76
/src/main/java/edu/kit/datamanager/ro_crate/preview/StaticPreview.java
1
package edu.kit.datamanager.ro_crate.preview;
2

3
import edu.kit.datamanager.ro_crate.util.ZipUtil;
4
import java.io.File;
5
import java.io.IOException;
6
import java.util.Optional;
7

8
import net.lingala.zip4j.ZipFile;
9
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
10
import net.lingala.zip4j.model.ZipParameters;
11
import org.apache.commons.io.FileUtils;
12

13
/**
14
 * This class adds a static preview to the crate, which consists of a
15
 * metadataHtml file and a folder containing other files required to render
16
 * metadataHtml. If will be put unchanged to the writer output, i.e., a zip
17
 * file, folder, or stream.
18
 *
19
 * @author jejkal
20
 */
21
public class StaticPreview implements CratePreview {
22

23
    private final File metadataHtml;
24
    private final File otherFiles;
25

26
    public StaticPreview(File metadataHtml, File otherFiles) {
1✔
27
        this.metadataHtml = metadataHtml;
1✔
28
        this.otherFiles = otherFiles;
1✔
29
    }
1✔
30

31
    public StaticPreview(File metadataHtml) {
1✔
32
        this.metadataHtml = metadataHtml;
1✔
33
        this.otherFiles = null;
1✔
34
    }
1✔
35

36
    @Override
37
    public void saveAllToZip(ZipFile zipFile) throws IOException {
38
        if (this.metadataHtml != null) {
1✔
39
            ZipParameters zipParameters = new ZipParameters();
1✔
40
            zipParameters.setFileNameInZip("ro-crate-preview.html");
1✔
41
            zipFile.addFile(this.metadataHtml, zipParameters);
1✔
42
        }
43

44
        if (this.otherFiles != null) {
1✔
45
            zipFile.addFolder(this.otherFiles);
1✔
46
            zipFile.renameFile(this.otherFiles.getName() + "/", "ro-crate-preview_files/");
1✔
47
        }
48
    }
1✔
49

50
    @Override
51
    public void saveAllToFolder(File folder) throws IOException {
52
        if (folder == null || !folder.exists()) {
1✔
NEW
53
            throw new IOException("Preview target folder " + folder + " does not exist.");
×
54
        }
55
        
56
        if (this.metadataHtml != null) {
1✔
57
            File fileInCrate = folder.toPath().resolve("ro-crate-preview.html").toFile();
1✔
58
            FileUtils.copyFile(this.metadataHtml, fileInCrate);
1✔
59
        }
60
        if (this.otherFiles != null) {
1✔
61
            File folderName = folder.toPath().resolve("ro-crate-preview_files").toFile();
1✔
62
            FileUtils.copyDirectory(this.otherFiles, folderName);
1✔
63
        }
64
    }
1✔
65

66
    @Override
67
    public void saveAllToStream(String metadata, ZipOutputStream stream) throws IOException {
NEW
68
        ZipUtil.addFileToZipStream(stream, this.metadataHtml, "ro-crate-preview.html");
×
NEW
69
        if (this.otherFiles != null) {
×
NEW
70
            ZipUtil.addFolderToZipStream(stream, this.otherFiles, this.otherFiles.getName());
×
71
        }
NEW
72
    }
×
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc