Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unzipped E-Ark and Pregenerated Checksum support #1

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/main/java/org/roda_project/commons_ip/model/IP.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
package org.roda_project.commons_ip.model;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;

import javax.xml.datatype.XMLGregorianCalendar;

Expand Down Expand Up @@ -47,7 +40,7 @@ public abstract class IP implements IPInterface {
private List<IPFile> schemas;
private List<IPFile> documentation;

private Map<String, ZipEntryInfo> zipEntries;
private final Map<String, ZipEntryInfo> zipEntries;
private String checksumAlgorithm;

private ValidationReport validationReport;
Expand Down Expand Up @@ -91,13 +84,13 @@ public IP(List<String> ipIds, IPType ipType, IPContentType contentType) {

@Override
public IP setId(String id) {
this.ids = Arrays.asList(id);
this.ids = Collections.singletonList(id);
return this;
}
public void setChecksum(final String checksum) {
this.checksumAlgorithm = checksum;
public void setChecksumAlgorithm(final String checksumAlgorithm) {
this.checksumAlgorithm = checksumAlgorithm;
}
public String getChecksum() {
public String getChecksumAlgorithm() {
return this.checksumAlgorithm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class IPContentType implements Serializable {
private static final long serialVersionUID = 1191075605637022551L;

public enum IPContentTypeEnum {
SFSB, RDB, ERMS, GEODATA, MIXED, OTHER;
SFSB, RDB, ERMS, GEODATA, MIXED, OTHER
}

private IPContentTypeEnum type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class IPHeader implements Serializable {
private transient Optional<XMLGregorianCalendar> modificationDate;
private IPEnums.IPStatus status;
private List<IPAgent> agents;
private List<IPAltRecordID> altRecordIDs;
private final List<IPAltRecordID> altRecordIDs;

public IPHeader() {
this.createDate = Utils.getCurrentTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class IPRepresentation {
private RepresentationContentType contentType;
private RepresentationStatus status;
private String description;
private List<IPAgent> agents;
private List<IPDescriptiveMetadata> descriptiveMetadata;
private List<IPMetadata> preservationMetadata;
private List<IPMetadata> otherMetadata;
private List<IPFile> data;
private List<IPFile> schemas;
private List<IPFile> documentation;
private final List<IPAgent> agents;
private final List<IPDescriptiveMetadata> descriptiveMetadata;
private final List<IPMetadata> preservationMetadata;
private final List<IPMetadata> otherMetadata;
private final List<IPFile> data;
private final List<IPFile> schemas;
private final List<IPFile> documentation;

public IPRepresentation() {
this.representationID = Utils.generateRandomAndPrefixedUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum MetadataTypeEnum {
PREMISRIGHTS("PREMIS:RIGHTS"), PREMISEVENT("PREMIS:EVENT"), TEXTMD("TEXTMD"), METSRIGHTS("METSRIGHTS"),
ISO191152003("ISO 19115:2003"), NAP("NAP"), EACCPF("EAC-CPF"), LIDO("LIDO"), OTHER("OTHER");

protected static final Map<String, MetadataTypeEnum> typeToEnum = new HashMap<>();
private static final Map<String, MetadataTypeEnum> typeToEnum = new HashMap<>();
static {
typeToEnum.put("LC-AV", MetadataTypeEnum.LCAV);
typeToEnum.put("PREMIS:OBJECT", MetadataTypeEnum.PREMISOBJECT);
Expand All @@ -35,7 +35,7 @@ public enum MetadataTypeEnum {

private final String type;

private MetadataTypeEnum(final String type) {
MetadataTypeEnum(final String type) {
this.type = type;
}

Expand Down Expand Up @@ -121,10 +121,9 @@ public boolean equals(Object obj) {
return true;
if (obj == null)
return false;
if (!(obj instanceof MetadataType))
if (!(obj instanceof MetadataType other))
return false;
MetadataType other = (MetadataType) obj;
return this.type == other.getType() && this.otherType.equals(other.getOtherType());
return this.type == other.getType() && this.otherType.equals(other.getOtherType());
}

public static MetadataType OTHER() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RepresentationContentType implements Serializable {
private static final long serialVersionUID = -5292855152678206771L;

public enum RepresentationContentTypeEnum {
MOREQ, SIARD, SIARD2, SMURF, SMURFERMS, SMURFSFSB, SIARDDK, GeoVectorGML, GeoRasterGeotiff, OTHER, MIXED;
MOREQ, SIARD, SIARD2, SMURF, SMURFERMS, SMURFSFSB, SIARDDK, GeoVectorGML, GeoRasterGeotiff, OTHER, MIXED
}

private RepresentationContentTypeEnum type;
Expand Down Expand Up @@ -85,10 +85,9 @@ public boolean equals(Object obj) {
return true;
if (obj == null)
return false;
if (!(obj instanceof RepresentationContentType))
if (!(obj instanceof RepresentationContentType other))
return false;
RepresentationContentType other = (RepresentationContentType) obj;
return this.type == other.getType() && this.otherType.equals(other.getOtherType());
return this.type == other.getType() && this.otherType.equals(other.getOtherType());
}

public static RepresentationContentType getMIXED() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RepresentationStatus implements Serializable {
private static final long serialVersionUID = 886952889995803542L;

public enum RepresentationStatusEnum {
ORIGINAL, OTHER;
ORIGINAL, OTHER
}

private RepresentationStatusEnum status;
Expand Down Expand Up @@ -87,11 +87,10 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof RepresentationStatus)) {
if (!(obj instanceof RepresentationStatus other)) {
return false;
}
RepresentationStatus other = (RepresentationStatus) obj;
return this.status == other.getStatus() && this.otherStatus.equals(other.getOtherStatus());
return this.status == other.getStatus() && this.otherStatus.equals(other.getOtherStatus());
}

public static RepresentationStatus getORIGINAL() {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/roda_project/commons_ip/model/SIPObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

public interface SIPObserver {

public void sipBuildRepresentationsProcessingStarted(int totalNumberOfRepresentations);
void sipBuildRepresentationsProcessingStarted(int totalNumberOfRepresentations);

public void sipBuildRepresentationProcessingStarted(int totalNumberOfFiles);
void sipBuildRepresentationProcessingStarted(int totalNumberOfFiles);

public void sipBuildRepresentationProcessingCurrentStatus(int numberOfFilesAlreadyProcessed);
void sipBuildRepresentationProcessingCurrentStatus(int numberOfFilesAlreadyProcessed);

public void sipBuildRepresentationProcessingEnded();
void sipBuildRepresentationProcessingEnded();

public void sipBuildRepresentationsProcessingEnded();
void sipBuildRepresentationsProcessingEnded();

public void sipBuildPackagingStarted(int totalNumberOfFiles);
void sipBuildPackagingStarted(int totalNumberOfFiles);

public void sipBuildPackagingCurrentStatus(int numberOfFilesAlreadyProcessed);
void sipBuildPackagingCurrentStatus(int numberOfFilesAlreadyProcessed);

public void sipBuildPackagingEnded();
void sipBuildPackagingEnded();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

public class ValidationReport {
private boolean valid;
private List<ValidationEntry> entries;
private Date date;
private final List<ValidationEntry> entries;
private final Date date;

public ValidationReport() {
valid = true;
Expand Down Expand Up @@ -179,24 +179,22 @@ private void getValidationEntryAttribute(StringBuilder sb, String attrClass, Str
}

private String getDefaultCss() {
StringBuilder sb = new StringBuilder();
sb.append("<style>").append(IPConstants.SYSTEM_LINE_SEP);
sb.append(
".valid {border-bottom: 1px solid black; border-left: 2px solid black;; margin-bottom: 10px; padding: 5px;}")
.append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".entry {display: block; margin-bottom: 10px;}").append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".entry div, .valid div {padding-left: 5px; padding-right: 5px;}").append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".level_info {border-bottom: 1px solid blue; border-left: 2px solid blue;}")
.append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".level_warning {border-bottom: 1px solid orange; border-left: 2px solid orange;}")
.append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".level_error {border-bottom: 1px solid red; border-left: 2px solid red;}")
.append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".entry .label, .valid .label {font-weight: bold;}").append(IPConstants.SYSTEM_LINE_SEP);
sb.append(".entry .label, .entry .value, .valid .label, .valid .value {display: inline; }")
.append(IPConstants.SYSTEM_LINE_SEP);
sb.append("</style>");
return sb.toString();
String sb = "<style>" + IPConstants.SYSTEM_LINE_SEP +
".valid {border-bottom: 1px solid black; border-left: 2px solid black;; margin-bottom: 10px; padding: 5px;}" +
IPConstants.SYSTEM_LINE_SEP +
".entry {display: block; margin-bottom: 10px;}" + IPConstants.SYSTEM_LINE_SEP +
".entry div, .valid div {padding-left: 5px; padding-right: 5px;}" + IPConstants.SYSTEM_LINE_SEP +
".level_info {border-bottom: 1px solid blue; border-left: 2px solid blue;}" +
IPConstants.SYSTEM_LINE_SEP +
".level_warning {border-bottom: 1px solid orange; border-left: 2px solid orange;}" +
IPConstants.SYSTEM_LINE_SEP +
".level_error {border-bottom: 1px solid red; border-left: 2px solid red;}" +
IPConstants.SYSTEM_LINE_SEP +
".entry .label, .valid .label {font-weight: bold;}" + IPConstants.SYSTEM_LINE_SEP +
".entry .label, .entry .value, .valid .label, .valid .value {display: inline; }" +
IPConstants.SYSTEM_LINE_SEP +
"</style>";
return sb;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BasicAIP extends IP implements AIP {
/**
* List of submission files.
*/
private List<IPFile> submissions;
private final List<IPFile> submissions;

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Path build(final Path destinationDirectory, final String fileNameWithoutE
BagitUtils.addRepresentationToZipAndBagit(this, getRepresentations(), zipEntries, buildDir);

// Create Bag
BagCreator.bagInPlace(buildDir, Arrays.asList(StandardSupportedAlgorithms.SHA256), false, metadata);
BagCreator.bagInPlace(buildDir, List.of(StandardSupportedAlgorithms.SHA256), false, metadata);

// Add bag files to zip
BagitUtils.addBagFileToZip(zipEntries, buildDir, BagitUtils.BAGIT_FILE_NAME);
Expand Down Expand Up @@ -250,7 +250,7 @@ private static SIP parseBagit(final Path source, final Path destinationDirectory
String value = nameValue.getValue();

if (IPConstants.BAGIT_PARENT.equals(key)) {
sip.setAncestors(Arrays.asList(value));
sip.setAncestors(Collections.singletonList(value));
} else {
if (IPConstants.BAGIT_ID.equals(key)) {
sip.setId(value);
Expand Down Expand Up @@ -313,4 +313,4 @@ private static SIP parseBagit(final Path source, final Path destinationDirectory
public Set<String> getExtraChecksumAlgorithms() {
return Collections.emptySet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
public final class BagitUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(BagitUtils.class);
private static final String BAGIT = "key-value";
protected static final String BAGIT_FILE_NAME = "bagit";
protected static final String BAGIT_INFO_FILE_NAME = "bag-info";
protected static final String BAGIT_MANIFEST_FILE_NAME = "manifest-";
protected static final String BAGIT_TAG_MANIFEST_FILE_NAME = "tagmanifest-";
static final String BAGIT_FILE_NAME = "bagit";
static final String BAGIT_INFO_FILE_NAME = "bag-info";
static final String BAGIT_MANIFEST_FILE_NAME = "manifest-";
static final String BAGIT_TAG_MANIFEST_FILE_NAME = "tagmanifest-";
private static final String BAGIT_FILE_EXTENSION = ".txt";

private BagitUtils() {
Expand Down Expand Up @@ -124,8 +124,8 @@ public static String generateMetadataFile(Path metadataPath) throws IllegalDataE
return outter.outputString(doc);
}

protected static void addRepresentationToZipAndBagit(IPInterface ip, List<IPRepresentation> representations,
Map<String, ZipEntryInfo> zipEntries, Path buildDir) {
static void addRepresentationToZipAndBagit(IPInterface ip, List<IPRepresentation> representations,
Map<String, ZipEntryInfo> zipEntries, Path buildDir) {
if (representations != null && !representations.isEmpty()) {
if (ip instanceof SIP) {
((SIP) ip).notifySipBuildRepresentationsProcessingStarted(representations.size());
Expand All @@ -144,7 +144,7 @@ protected static void addRepresentationToZipAndBagit(IPInterface ip, List<IPRepr
try {
Files.createDirectories(destination.getParent());
try (InputStream input = Files.newInputStream(file.getPath());
OutputStream output = Files.newOutputStream(destination);) {
OutputStream output = Files.newOutputStream(destination)) {
IOUtils.copyLarge(input, output);
String dataFilePath = IPConstants.DATA_FOLDER
+ buildDir.relativize(representationPath).resolve(file.getFileName());
Expand All @@ -167,7 +167,7 @@ protected static void addRepresentationToZipAndBagit(IPInterface ip, List<IPRepr
}
}

protected static void addBagFileToZip(Map<String, ZipEntryInfo> zipEntries, Path buildDir, String target) {
static void addBagFileToZip(Map<String, ZipEntryInfo> zipEntries, Path buildDir, String target) {
Path targetFile = buildDir.resolve(target + BAGIT_FILE_EXTENSION);
if (Files.exists(targetFile)) {
zipEntries.put(targetFile.toString(), new FileZipEntryInfo(targetFile.getFileName().toString(), targetFile));
Expand All @@ -176,7 +176,7 @@ protected static void addBagFileToZip(Map<String, ZipEntryInfo> zipEntries, Path
}
}

protected static Path extractBagitIPIfInZipFormat(final Path source, Path destinationDirectory)
static Path extractBagitIPIfInZipFormat(final Path source, Path destinationDirectory)
throws ParseException {
Path bagitFolderPath = destinationDirectory;
if (!Files.isDirectory(source)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,11 @@ private void setChecksum(final ZipEntryInfo zipEntryInfo, final String checksum,
throws IOException, NoSuchAlgorithmException {
zipEntryInfo.setChecksum(checksum);
zipEntryInfo.setChecksumAlgorithm(checksumType);
if (zipEntryInfo instanceof METSFileTypeZipEntryInfo) {
METSFileTypeZipEntryInfo f = (METSFileTypeZipEntryInfo) zipEntryInfo;
f.getMetsFileType().setCHECKSUM(checksum);
if (zipEntryInfo instanceof METSFileTypeZipEntryInfo f) {
f.getMetsFileType().setCHECKSUM(checksum);
f.getMetsFileType().setCHECKSUMTYPE(checksumType);
} else if (zipEntryInfo instanceof METSMdRefZipEntryInfo) {
METSMdRefZipEntryInfo f = (METSMdRefZipEntryInfo) zipEntryInfo;
f.getMetsMdRef().setCHECKSUM(checksum);
} else if (zipEntryInfo instanceof METSMdRefZipEntryInfo f) {
f.getMetsMdRef().setCHECKSUM(checksum);
f.getMetsMdRef().setCHECKSUMTYPE(checksumType);
}
}
Expand Down
Loading