Skip to content

Commit

Permalink
1)Updated template for ARELDA metadata; 2)Added validation for a bunc…
Browse files Browse the repository at this point in the history
…h of metadata form fields; 3)Updated configuration loading logic; 4)Small update to metadata.xml.

------------------------------------------------------------
1)
Submission number is not mandatory anymore, Submission office and Records creator are. Made an appropriate update fo the ARELDA template.

2)
Mainly mandatory status and length of fields are validated.

3)
For the templates and schemas added logic which overrides older files in the configuration folder. Checking only if file exsist caused that some old templates stayed and there was old UI representation for metadata form, similar with schemas, old schemas caused metadata.xml validation errors.

For other configuration files I'm not sure if they can be replaced in such way. There is an open issue in GitHub to validate configuration files, this approach could be better, but not sure about performance:
keeps#260
keeps#314

4)
Empty <schutzfrist> caused xsd validation erro for metadata.xml, now it is added only when there is a value from user.

There could be similar places in metadata.xml generation, not sure if they need an update, at least no more errors.
  • Loading branch information
dshvorack committed Mar 21, 2018
1 parent 677ac40 commit b9cca57
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 29 deletions.
59 changes: 54 additions & 5 deletions src/main/java/ch/scope/sipcreator/Ech0160Sip.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,65 @@ private void initializeParameters(){
);
}

public String validateMetadataFields(){
if (ech0160SipDescription.getSubmissionNumber() == null || ech0160SipDescription.getSubmissionNumber().isEmpty()){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_SUBMISSION_NUMBER);
public String validateMetadataFields() throws Exception{
//submission number
if(ech0160SipDescription.getSubmissionNumber() != null && ech0160SipDescription.getSubmissionNumber().length() > 100){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_SUBMISSION_NUMBER_MAX_LENGTH, "" + ech0160SipDescription.getSubmissionNumber().length());
}
else if (ech0160SipDescription.getProtectionTime() != null && !ech0160SipDescription.getProtectionTime().isEmpty()) {

//submission office
String submissionOffice = ech0160SipDescription.getSubmissionOffice();

if(submissionOffice == null || submissionOffice.isEmpty()){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_SUBMISSION_OFFICE_MANDATORY);
}else if(submissionOffice.length() > 200){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_SUBMISSION_OFFICE_MAX_LENGTH, "" + submissionOffice.length());
}

//records creator
String recordsCreator = ech0160SipDescription.getRecordsCreator();

if(recordsCreator == null || recordsCreator.isEmpty()){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_RECORDS_CREATOR_MANDATORY);
}else if(recordsCreator.length() > 200){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_RECORDS_CREATOR_MAX_LENGTH, "" + recordsCreator.length());
}

//system name
String systemName = ech0160SipDescription.getSystemName();

if(systemName != null && systemName.length() > 1000){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_SYSTEM_NAME_MAX_LENGTH, "" + systemName.length());
}

//registry
String registry = ech0160SipDescription.getRegistry();

if(registry != null && registry.length() > 200){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_REGISTRY_MAX_LENGTH, "" + registry.length());
}

//protection category
String protectionCategory = ech0160SipDescription.getProtectionCategory();

if (protectionCategory != null && protectionCategory.length() > 100){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_PROTECTION_CATEGORY_MAX_LENGTH, "" + protectionCategory.length());
}

//protection time
String protectionTime = ech0160SipDescription.getProtectionTime();

if (protectionTime != null && !protectionTime.isEmpty()) {
int intValue;
try{
Integer.parseInt(ech0160SipDescription.getProtectionTime());
intValue = Integer.parseInt(protectionTime);
}catch (NumberFormatException ex){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_PROTECTION_TIME);
}

if(intValue < 0){
return I18n.t(Constants.I18N_ECH0160_SIP_VALIDATION_PROTECTION_TIME_UNSIGNED);
}
}

return null;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/ch/scope/sipcreator/Ech0160SipCreator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.scope.sipcreator;

import javafx.application.Platform;
import org.roda.rodain.core.Constants;
import org.roda.rodain.core.I18n;
import org.roda.rodain.core.creation.SimpleSipCreator;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/scope/sipcreator/utils/NodesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static String getInhaltsverzeichnis(Ech0160SipDescription ech0160SipDescr
+ " </entstehungszeitraum>\n"
+ " <ablieferungsnummer>" + escapeXml(ech0160SipDescription.getSubmissionNumber()) + "</ablieferungsnummer>\n"
+ " <schutzfristenkategorie>" + escapeXml(ech0160SipDescription.getProtectionCategory()) + "</schutzfristenkategorie>\n"
+ " <schutzfrist>" + escapeXml(ech0160SipDescription.getProtectionTime()) + "</schutzfrist>\n"
+ ((ech0160SipDescription.getProtectionTime() == null || ech0160SipDescription.getProtectionTime().isEmpty()) ? "" :
" <schutzfrist>" + escapeXml(ech0160SipDescription.getProtectionTime()) + "</schutzfrist>\n")
+ " <provenienz>\n"
+ " <aktenbildnerName>" + escapeXml(ech0160SipDescription.getRecordsCreator()) + "</aktenbildnerName>\n"
+ " <systemName>" + escapeXml(ech0160SipDescription.getSystemName()) + "</systemName>\n"
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/org/roda/rodain/core/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,18 @@ private static void copyMetadataTemplates() throws IOException {
for (String templ : templates) {
String templateName = Constants.CONF_K_PREFIX_METADATA + templ.trim() + Constants.CONF_K_SUFFIX_TEMPLATE;
String fileName = internalConfig.getString(templateName);
String resourcePath = Constants.FOLDER_TEMPLATES + Constants.MISC_FWD_SLASH + fileName;
// copy the sample to the templates folder too, if it doesn't exist
// already
if (!Files.exists(templatesPath.resolve(fileName))) {
// already or if it is of old version
if (
!Files.exists(templatesPath.resolve(fileName))
||
ClassLoader.getSystemResource(resourcePath).openConnection().getLastModified()
>
Files.getLastModifiedTime(templatesPath.resolve(fileName)).toMillis()
) {
Files.copy(
ClassLoader.getSystemResourceAsStream(Constants.FOLDER_TEMPLATES + Constants.MISC_FWD_SLASH + fileName),
ClassLoader.getSystemResourceAsStream(resourcePath),
templatesPath.resolve(fileName), StandardCopyOption.REPLACE_EXISTING);
}
}
Expand All @@ -205,15 +212,24 @@ private static void copyAndProcessSchemas() throws IOException {
}

for (String currentFileName: schemaFileNames){
if (!Files.exists(schemasPath.resolve(currentFileName))){

String resourcePath = Constants.FOLDER_TEMPLATES + Constants.MISC_FWD_SLASH + currentFileName;

//copy schema file if configuration folder does not contain it
//or if configuration folder contains older version of it
if (
!Files.exists(schemasPath.resolve(currentFileName))
||
ClassLoader.getSystemResource(resourcePath).openConnection().getLastModified()
>
Files.getLastModifiedTime(schemasPath.resolve(currentFileName)).toMillis()
){
Path outputFile = schemasPath.resolve(currentFileName);
if (!outputFile.toFile().getParentFile().exists()){
outputFile.toFile().mkdirs();
}

Files.copy(
ClassLoader.getSystemResourceAsStream(Constants.FOLDER_TEMPLATES + Constants.MISC_FWD_SLASH + currentFileName),
ClassLoader.getSystemResourceAsStream(resourcePath),
outputFile, StandardCopyOption.REPLACE_EXISTING);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/roda/rodain/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,16 @@ public final class Constants {
public static final String I18N_ECH0160_SIP_CREATOR_METADATA_GENERATION = "Ech0160SipCreator.metadataGeneration";
public static final String I18N_ECH0160_SIP_CREATOR_FORM_DATA_NOT_VALID = "Ech0160SipCreator.error.formDataNotValid";
public static final String I18N_ECH0160_SIP_CREATOR_METADATA_NOT_VALID = "Ech0160SipCreator.error.metadataNotValid";
public static final String I18N_ECH0160_SIP_VALIDATION_SUBMISSION_NUMBER = "Ech0160Sip.validation.submissionNumber";
public static final String I18N_ECH0160_SIP_VALIDATION_PROTECTION_TIME = "Ech0160Sip.validation.protectionTime";
public static final String I18N_ECH0160_SIP_VALIDATION_SUBMISSION_NUMBER_MAX_LENGTH = "Ech0160Sip.validation.submissionNumberMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_SUBMISSION_OFFICE_MANDATORY = "Echo160Sip.validation.submissionOfficeMandatory";
public static final String I18N_ECH0160_SIP_VALIDATION_SUBMISSION_OFFICE_MAX_LENGTH = "Ech0160Sip.validation.submissionOfficeMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_RECORDS_CREATOR_MANDATORY = "Ech0160Sip.validation.submissionRecordsCreatorMandatory";
public static final String I18N_ECH0160_SIP_VALIDATION_RECORDS_CREATOR_MAX_LENGTH = "Ech0160Sip.validation.submissionRecordsCreatorMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_SYSTEM_NAME_MAX_LENGTH = "Ech0160Sip.validation.systemNameMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_REGISTRY_MAX_LENGTH = "Ech0160Sip.validation.registryMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_PROTECTION_CATEGORY_MAX_LENGTH = "Ech0160Sip.validation.protectionCategoryMaxLength";
public static final String I18N_ECH0160_SIP_VALIDATION_PROTECTION_TIME = "Ech0160Sip.validation.protectionTimeNumber";
public static final String I18N_ECH0160_SIP_VALIDATION_PROTECTION_TIME_UNSIGNED = "Ech0160Sip.validation.protectionTimeUnsigned";

/*
* ENUMs
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/properties/lang.properties
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ IPContentType.SMURF=SMURF
Ech0160SipCreator.metadataGeneration = Generating metadata: %d of %d files processed.
Ech0160SipCreator.error.formDataNotValid = Form data for sip %s is not valid.
Ech0160SipCreator.error.metadataNotValid = Generated metadata for SIP %s is not valid. See logs for details.

Ech0160Sip.validation.submissionNumber = Submission number is mandatory.
Ech0160Sip.validation.protectionTime = Protection time value have to be a number.
Ech0160Sip.validation.submissionNumberMaxLength = Submission number max length is 100, current length is {}.
Echo160Sip.validation.submissionOfficeMandatory = Submission office is mandatory.
Ech0160Sip.validation.submissionOfficeMaxLength = Submission office max length is 200, current length is {}.
Ech0160Sip.validation.submissionRecordsCreatorMandatory = Records creator is mandatory.
Ech0160Sip.validation.submissionRecordsCreatorMaxLength = Records creator max length is 200, current length is {}.
Ech0160Sip.validation.systemNameMaxLength = System name max length is 1000, current length is {}.
Ech0160Sip.validation.registryMaxLength = Registry max length is 200, current length is {}.
Ech0160Sip.validation.protectionCategoryMaxLength = Protection category max length is 100, current length is {}.
Ech0160Sip.validation.protectionTimeNumber = Protection time value have to be a number.
Ech0160Sip.validation.protectionTimeUnsigned = Protection time have to be an unsigned integer.
13 changes: 10 additions & 3 deletions src/main/resources/properties/lang_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ IPContentType.SMURF=Semantically Marked Up Record Format
Ech0160SipCreator.metadataGeneration = Die Metadaten werden generiert: %d von %d Dateien verarbeitet.
Ech0160SipCreator.error.formDataNotValid = Die Formulardaten für das sip %s sind ungültig.
Ech0160SipCreator.error.metadataNotValid = Die generierten Metadaten für das SIP %s sind ungültig. Die Details sind in den Protokollen beschrieben.
Ech0160Sip.validation.submissionNumber = Die Ablieferungsnummer ist obligatorisch.
Ech0160Sip.validation.protectionTime = Die Schutzfristdauer muss eine Zahl sein.
Ech0160Sip.validation.submissionNumberMaxLength = Maximale Länge der Ablieferungsnummer ist 100. Die aktuelle Länge ist {}.
Echo160Sip.validation.submissionOfficeMandatory = Abgebende Stelle ist obligatorisch.
Ech0160Sip.validation.submissionOfficeMaxLength = Maximale Länge der abgegende Stelle ist 200. Die aktuelle Länge ist {}.
Ech0160Sip.validation.submissionRecordsCreatorMandatory = Datensatzhersteller ist obligatorisch.
Ech0160Sip.validation.submissionRecordsCreatorMaxLength = Maximale Länge des Datensatzherstellers ist 200. Die aktuelle Länge ist {}.
Ech0160Sip.validation.systemNameMaxLength = Maximale Länge des Systemnamens ist 1000. Die aktuelle Länge ist {}.
Ech0160Sip.validation.registryMaxLength = Maximale Länge der Registrierung ist 200. Die aktuelle Länge ist {}.
Ech0160Sip.validation.protectionCategoryMaxLength = Maximale Länge der Schutzkategorie ist 100. Die aktuelle Länge ist {}.
Ech0160Sip.validation.protectionTimeNumber = Die Schutzfristdauer muss eine Zahl sein.
Ech0160Sip.validation.protectionTimeUnsigned = Die Schutzzeit muss eine vorzeichenlose Ganzzahl sein..
13 changes: 10 additions & 3 deletions src/main/resources/properties/lang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ IPContentType.SMURF=SMURF
Ech0160SipCreator.metadataGeneration = Generating metadata: %d of %d files processed.
Ech0160SipCreator.error.formDataNotValid = Form data for sip %s is not valid.
Ech0160SipCreator.error.metadataNotValid = Generated metadata for SIP %s is not valid. See logs for details.

Ech0160Sip.validation.submissionNumber = Submission number is mandatory.
Ech0160Sip.validation.protectionTime = Protection time value have to be a number.
Ech0160Sip.validation.submissionNumberMaxLength = Submission number max length is 100, current length is {}.
Echo160Sip.validation.submissionOfficeMandatory = Submission office is mandatory.
Ech0160Sip.validation.submissionOfficeMaxLength = Submission office max length is 200, current length is {}.
Ech0160Sip.validation.submissionRecordsCreatorMandatory = Records creator is mandatory.
Ech0160Sip.validation.submissionRecordsCreatorMaxLength = Records creator max length is 200, current length is {}.
Ech0160Sip.validation.systemNameMaxLength = System name max length is 1000, current length is {}.
Ech0160Sip.validation.registryMaxLength = Registry max length is 200, current length is {}.
Ech0160Sip.validation.protectionCategoryMaxLength = Protection category max length is 100, current length is {}.
Ech0160Sip.validation.protectionTimeNumber = Protection time value have to be a number.
Ech0160Sip.validation.protectionTimeUnsigned = Protection time have to be an unsigned integer.
10 changes: 5 additions & 5 deletions src/main/resources/templates/arelda.xml.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{~field name="title" order='2' auto-generate='title' labeli18n="crosswalks.dissemination.html.ech0160.title" label="{\"en\": \"SIP title\",\"de\": \"SIP titel\"}" xpath="//*:title/string()"}}

{{~field name="sbumissionNumber" order='5' labeli18n="crosswalks.dissemination.html.ech0160.submissionNumber" label="{\"en\": \"Submission number *\",\"de\": \"Ablieferungs nummer *\"}" }}
{{~field name="sbumissionNumber" order='5' labeli18n="crosswalks.dissemination.html.ech0160.submissionNumber" label="{\"en\": \"Submission number\",\"de\": \"Ablieferungs nummer\"}" }}
<!-- xpath="//*:snumber/string()" -->

{{~field name="submissionOffice" order='10' labeli18n="crosswalks.dissemination.html.ech0160.submissionOffice" label="{\"en\": \"Submission office\",\"de\": \"Abliefernde Stelle\"}" }}
{{~field name="submissionOffice" order='10' labeli18n="crosswalks.dissemination.html.ech0160.submissionOffice" label="{\"en\": \"Submission office *\",\"de\": \"Abliefernde Stelle *\"}" }}
<!-- xpath="//*:submissionOffice/string()" -->

{{~field name="creationPeriodFrom" order='20' type='date' labeli18n="crosswalks.dissemination.html.ech0160.date.from" label="{\"en\": \"Creation period from\",\"de\": \"Entstehung von\"}" }}
Expand All @@ -12,7 +12,7 @@
{{~field name="creationPeriodTo" order='30' type='date' labeli18n="crosswalks.dissemination.html.ech0160.date.to" label="{\"en\": \"Creation period to\",\"de\": \"Entstehung bis\"}" }}
<!-- xpath="//*:date[2]/string()" -->

{{~field name="recordsCreator" order='50' labeli18n="crosswalks.dissemination.html.ech0160.creator" label="{\"en\": \"Records creator\",\"de\": \"Aktenbildende stelle\"}" }}
{{~field name="recordsCreator" order='50' labeli18n="crosswalks.dissemination.html.ech0160.creator" label="{\"en\": \"Records creator *\",\"de\": \"Aktenbildende stelle *\"}" }}
<!-- xpath="//*:creator/string()" -->

{{~field name="systemName" order='60' labeli18n="crosswalks.dissemination.html.ech0160.sysName" label="{\"en\": \"System name\",\"de\": \"System name\"}" }}
Expand All @@ -30,5 +30,5 @@
{{~field name="ptime" order='100' labeli18n="crosswalks.dissemination.html.ech0160.ptime" label="{\"en\": \"Protection time\",\"de\": \"Schutzfrist\"}" }}
<!-- xpath="//*:ptime/string()" -->

<?xml version="1.0"?>
<blank>Metadata xml will be code generated.</blank>
<!-- Metadata xml will be code generated. -->
<blank></blank>

0 comments on commit b9cca57

Please sign in to comment.