diff --git a/dbptk-bindings/dbptk-bindings-siarddk-1007/pom.xml b/dbptk-bindings/dbptk-bindings-siarddk-1007/pom.xml new file mode 100644 index 000000000..c035bfccf --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-1007/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + dbptk-bindings-siarddk-1007 + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.2 + compile + + + com.databasepreservation + dbptk-bindings-siarddk-1007 + 2.0.0 + + com.databasepreservation + dbptk-bindings + 2.0.0 + .. + + + siard_dk_1007 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + ${version.java} + ${version.java} + UTF-8 + + + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + + + org.jvnet.jaxb + jaxb-maven-plugin + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocIndexType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocIndexType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocIndexType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocIndexType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocumentType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocumentType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocumentType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/DocumentType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/ObjectFactory.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/ObjectFactory.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/ObjectFactory.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/ObjectFactory.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/package-info.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/package-info.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/package-info.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/docindex/package-info.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/FileIndexType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/FileIndexType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/FileIndexType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/FileIndexType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/ObjectFactory.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/ObjectFactory.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/ObjectFactory.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/ObjectFactory.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/package-info.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/package-info.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/package-info.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/fileindex/package-info.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnsType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnsType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnsType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ColumnsType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeyType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeyType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeyType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeyType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeysType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeysType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeysType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ForeignKeysType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/FunctionalDescriptionType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/FunctionalDescriptionType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/FunctionalDescriptionType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/FunctionalDescriptionType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ObjectFactory.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ObjectFactory.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ObjectFactory.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ObjectFactory.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/PrimaryKeyType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/PrimaryKeyType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/PrimaryKeyType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/PrimaryKeyType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ReferenceType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ReferenceType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ReferenceType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ReferenceType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/SiardDiark.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/SiardDiark.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/SiardDiark.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/SiardDiark.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TableType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TableType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TableType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TableType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TablesType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TablesType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TablesType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/TablesType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewsType.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewsType.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewsType.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/ViewsType.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/package-info.java b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/package-info.java similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/package-info.java rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/java/dk/sa/xmlns/diark/_1_0/tableindex/package-info.java diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/XMLSchema.dtd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/XMLSchema.dtd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/XMLSchema.dtd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/XMLSchema.dtd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/XMLSchema.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/XMLSchema.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/XMLSchema.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/XMLSchema.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/archiveIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/archiveIndex.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/archiveIndex.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/archiveIndex.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/contextDocumentationIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/contextDocumentationIndex.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/contextDocumentationIndex.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/contextDocumentationIndex.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/docIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/docIndex.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/docIndex.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/docIndex.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/fileIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/fileIndex.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/fileIndex.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/fileIndex.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/fileIndex_original.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/fileIndex_original.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/fileIndex_original.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/fileIndex_original.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/tableIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/tableIndex.xsd similarity index 100% rename from dbptk-bindings/dbptk-bindings-siarddk/src/main/resources/schema/tableIndex.xsd rename to dbptk-bindings/dbptk-bindings-siarddk-1007/src/main/resources/schema/1007/tableIndex.xsd diff --git a/dbptk-bindings/dbptk-bindings-siarddk/pom.xml b/dbptk-bindings/dbptk-bindings-siarddk-128/pom.xml similarity index 93% rename from dbptk-bindings/dbptk-bindings-siarddk/pom.xml rename to dbptk-bindings/dbptk-bindings-siarddk-128/pom.xml index b2542282b..b79a4d387 100644 --- a/dbptk-bindings/dbptk-bindings-siarddk/pom.xml +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/pom.xml @@ -3,7 +3,7 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - dbptk-bindings-siarddk + dbptk-bindings-siarddk-128 jakarta.xml.bind @@ -13,7 +13,7 @@ com.databasepreservation - dbptk-bindings-siarddk + dbptk-bindings-siarddk-128 2.0.0 com.databasepreservation @@ -22,7 +22,7 @@ .. - siard_dk_2010 + siard_dk_128 diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.dtd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.dtd new file mode 100644 index 000000000..adf2c738b --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.dtd @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.xsd new file mode 100644 index 000000000..2e9a2729e --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/XMLSchema.xsd @@ -0,0 +1,2534 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ]> + + + + Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp + Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp + + + + + + The schema corresponding to this document is normative, + with respect to the syntactic constraints it expresses in the + XML Schema language. The documentation (within <documentation> elements) + below, is not normative, but rather highlights important aspects of + the W3C Recommendation of which this is a part + + + + + The simpleType element and all of its members are defined + towards the end of this schema document + + + + + + Get access to the xml: attribute groups for xml:lang + as declared on 'schema' and 'documentation' below + + + + + + + + This type is extended by almost all schema types + to allow attributes from other namespaces to be + added to user schemas. + + + + + + + + + + + + + This type is extended by all types which allow annotation + other than <schema> itself + + + + + + + + + + + + + + + + This group is for the + elements which occur freely at the top level of schemas. + All of their types are based on the "annotated" type by extension. + + + + + + + + + + + + + This group is for the + elements which can self-redefine (see <redefine> below). + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction} + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction, list, union} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for maxOccurs + + + + + + + + + + + + for all particles + + + + + + + for element, group and attributeGroup, + which both define and reference + + + + + + + + 'complexType' uses this + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This branch is short for + <complexContent> + <restriction base="xs:anyType"> + ... + </restriction> + </complexContent> + + + + + + + + + + + + + + + Will be restricted to required or forbidden + + + + + + Not allowed if simpleContent child is chosen. + May be overriden by setting on complexContent child. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Overrides any setting on complexType parent. + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + No typeDefParticle group reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {substitution, extension, + restriction} + + + + + + + + + + + + + + + + + + + + + + + + + The element element can be used either + at the top level to define an element-type binding globally, + or within a content model to either reference a globally-defined + element or type or declare an element-type binding locally. + The ref form is not allowed at the top level. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for explicit groups, named top-level groups and + group references + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for the three kinds of group + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice with min/max is here to + avoid a pblm with the Elt:All/Choice/Seq + Particle derivation constraint + + + + + + + + + + restricted max/min + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Only elements allowed inside + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + simple type for the value of the 'namespace' attr of + 'any' and 'anyAttribute' + + + + Value is + ##any - - any non-conflicting WFXML/attribute at all + + ##other - - any non-conflicting WFXML/attribute from + namespace other than targetNS + + ##local - - any unqualified non-conflicting WFXML/attribute + + one or - - any non-conflicting WFXML/attribute from + more URI the listed namespaces + references + (space separated) + + ##targetNamespace or ##local may appear in the above list, to + refer to the targetNamespace of the enclosing + schema or an absent targetNamespace respectively + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in selectors + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the following EBNF: + Selector ::= Path ( '|' Path )* + Path ::= ('.//')? Step ( '/' Step )* + Step ::= '.' | NameTest + NameTest ::= QName | '*' | NCName ':' '*' + child:: is also allowed + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in fields + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the same EBNF as for selector, + with the following change: + Path ::= ('.//')? ( Step '/' )* ( Step | '@' NameTest ) + + + + + + + + + + + + + + + + + + + + + + + + + + + The three kinds of identity constraints, all with + type of or derived from 'keybase'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + A public identifier, per ISO 8879 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + notations for use within XML Schema schemas + + + + + + + + + Not the real urType, but as close an approximation as we can + get in the XML representation + + + + + + + + + + First the built-in primitive datatypes. These definitions are for + information only, the real built-in definitions are magic. + + + + For each built-in datatype in this schema (both primitive and + derived) can be uniquely addressed via a URI constructed + as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype + + For example, to address the int datatype, the URI is: + + http://www.w3.org/2001/XMLSchema#int + + Additionally, each facet definition element can be uniquely + addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the facet + + For example, to address the maxInclusive facet, the URI is: + + http://www.w3.org/2001/XMLSchema#maxInclusive + + Additionally, each facet usage in a built-in datatype definition + can be uniquely addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype, followed + by a period (".") followed by the name of the facet + + For example, to address the usage of the maxInclusive facet in + the definition of int, the URI is: + + http://www.w3.org/2001/XMLSchema#int.maxInclusive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOTATION cannot be used directly in a schema; rather a type + must be derived from it by specifying at least one enumeration + facet whose value is the name of a NOTATION declared in the + schema. + + + + + + + + + + Now the derived primitive types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern specifies the content of section 2.12 of XML 1.0e2 + and RFC 3066 (Revised version of RFC 1766). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 7 from the XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 5 from the XML spec + + + + + + + + + + + + + + + pattern matches production 4 from the Namespaces in XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + #all or (possibly empty) subset of {restriction, union, list} + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Can be restricted to required or forbidden + + + + + + + + + + + + + + + + + + Required at the top level + + + + + + + + + + + + + + + + + + + Forbidden when nested + + + + + + + + + + + + + + + + + + + We should use a substitution group for facets, but + that's ruled out because it would allow users to + add their own, which we're not ready for yet. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + base attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + itemType attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + + + memberTypes attribute must be non-empty or there must be + at least one simpleType child + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/archiveIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/archiveIndex.xsd new file mode 100644 index 000000000..74c30d82e --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/archiveIndex.xsd @@ -0,0 +1,448 @@ + + + + + + + + + Information om arkiveringsversionen + Information about the information package + + + + + ArkiveringsversionsID + Entydigt ID som tildeles arkiveringsversionen af Rigsarkivet + ArkiveringsversionsID som defineret i denne bekendtgørelse + Information package ID + + + + + Tidligere aflevering + Entydigt ID på tidligere aflevering fra samme it-system eller datakilde + ArkiveringsversionsID som defineret i denne eller tidligere bekendtgørelse + Previous transfer + + + + + Arkiveringsversions startdato + Startdato for de aflevererede data + År, år-måned, år-måned-dag + Start date for the information package + + + + + Arkiveringsversions slutdato + Slutdato for de aflevererede data + År, år-måned, år-måned-dag + End date for the information package + + + + + + Startdato for dokumenter + År, år-måned, år-måned-dag + Start date for documents in the information package + + + + + Slutdato for dokumenter + Anvendes til angivelse af slutdato for dokumenter + År, år-måned, år-måned-dag + End date for documents in the information package + + + + + + Slutaflevering + Angivelse af, om arkiveringsversionen er en slutaflevering + Boolsk værdi + Final transfer + + + + + + + + Arkivskaber + Den eller de myndigheder, institutioner, organisationer eller personer, der har skabt data. Kan også være organisatoriske enheder inden for en myndighed eller andre bidragydere til arkivaliet. + Fritekst + Archival creator + + + + + Arkivskaber startdato + For hver arkivskaber angives, hvornår arkivskaber er begyndt at tilføje data + År, år-måned, år-måned-dag + Start date for the archival creator + + + + + Arkivskaber slutdato + For hver arkivskaber angives, hvornår arkivskaber er ophørt med at tilføje data + År, år-måned, år-måned-dag + End date for the archival creator + + + + + + + + Arkiveringsversionsperiodetype + Angivelse af, om der er tale om en afsluttet arkivperiode/årgang, eller om der er tale om et øjebliksbillede. True=afsluttet, false=øjebliksbillede + Boolsk værdi + information package period type + + + + + Arkiveringsversioner med lukkede sager + Angiver for it-systemer med dokumenter, at der er tale om et øjebliksbillede af metadata, men kun dokumenter fra lukkede sager. True=der er tale om et øjebliksbillede af metadata, men kun dokumenter fra lukkede sagers + Boolsk værdi + Metadata also exists for cases and documents not submitted in information packagage + + + + + Systemnavn + Det officielle navn på it-systemet eller datakilde, hvor alle forkortelser er opløst + Fritekst + System name or data source + + + + + Alternativt systemnavn + Alternative navne på systemet eller datakilde + Fritekst + Alternative system name + + + + + Systemformål + Beskrivelse af formålet med at indsamle data + Fritekst + System purpose + + + + + Systemindhold + It-systemets centrale population og centrale variabler + Fritekst + System content + + + + + Regionsnumre + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret regionsnumre + Boolsk værdi + Standard identifier. Defines if the information package contains regionsnumre + + + + + Kommunenumre + Standardidentifikatorer. Angivelse af, om der systematisk form er registreret kommunenumre + Boolsk værdi + Standard identifier. Defines if the information package contains kommunenumre + + + + + CPR-numre + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret CPR-nr. + Boolsk værdi + Standard identifier. Defines if the information package contains CPR-nr. + + + + + CVR-numre + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret CVR-nr. + Boolsk værdi + Standard identifier. Defines if the information package contains CVR-nr. + + + + + Matrikelnumre + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret Matrikelnumre + Boolsk værdi + Standard identifier. Defines if the information package contains Matrikelnumre + + + + + BBR-numre + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret BBR-nr. + Boolsk værdi + Standard identifier. Defines if the information package contains BBR-nr. + + + + + WHO-sygdomskoder + Standardidentifikatorer. Angivelse af, om der i systematisk form er registreret WHOs sygdomskoder + Boolsk værdi + Standard identifier. Defines if the information package contains WHOs sygdomskoder + + + + + Datakilde + Det officielle navn på andre datakilder som har leveret data til it-systemet (opslag, overførsel, samkøring osv.) + Fritekst + Data source + + + + + Databrugere + Andre it-systemer som har brugt data fra it-systemet (opslag, overførsel, samkøring osv.) + Fritekst + Data users + + + + + Forgængersystemer + Systemer, der tidligere har varetaget samme funktion. + Fritekst + Predecessor systems + + + + + + + + FORM-version + Angivelse af, hvilken version af FORM kategorisering er hentet fra + Obligatorisk for it-systemer fra offentlige myndigheder. Gyldige FORM-versionsnumre + FORM version + + + + + + + + FORM-klassifikation + Kategorisering af arkiveringsversionen iht. den fællesoffentlige forretningsreferencemodel (FORM) + Obligatorisk for it-systemer fra offentlige myndigheder. Enhver gyldig FORM-reference iht. den angivne version af FORM + FORM class + + + + + FORM-klassifikation klartekst + FORM-klassifikation i klartekst + Obligatorisk for it-systemer fra offentlige myndigheder. Fritekst + FORM Class text + + + + + + + + + + + Digitale dokumenter indeholdt + Bruges til at angive, om der er digitale dokumenter i arkiveringsversionen, udover kontekstdokumentation + Boolsk værdi + Contains digital documents + + + + + GML data indeholdt + Angivelse af, om der er GML data i arkiveringsversionen + Boolsk værdi + Contains geodata + + + + + Forskningsdata indeholdt + Angivelse af, om arkiveringsversionen indeholder forskningsdata + Boolsk værdi + Contains research data + + + + + Forskningsdata afleveret iht. bilag 9 + Angivelse af, om data er afleveret iht. til bilag 9 + Boolsk værdi + Contains research data + + + + + Kassation + Angivelse af, om der er foretaget systematisk kassation af dokumenter inden produktion af arkiveringsversion + Boolsk værdi + Documents disposal + + + + + Søgemiddel til andre sager eller dokumenter + Bruges til at angive, om arkiveringsversionen er et nødvendigt søgemiddel til papirsager/dokumenter eller sager/dokumenter i et andet it-system + Boolsk værdi + Search tool to other files or documents + + + + + Adresserede arkivalier + Henvisning til de arkivalier, som arkiveringsversionen er søgemiddel til + Obligatorisk, hvis der er svaret ja på foregående spørgsmål. Fritekst + Addressed records + + + + + Eksistens af sagsbegreb i it-systemet + Angivelse af, at it-systemet har et sagsbegreb, forstået som en registreret sammenhæng mellem sagligt sammenhørende dokumenter + Kan kun være ja, hvis der er digitale dokumenter i it-systemet. Boolsk værdi + Existence of a file concept in the IT-system + + + + + SOA arkitektur + Angivelse af, om data i arkiveringsversionen er sammensat af data og eventuelt dokumenter fra flere forskellige datakilder i en serviceorienteret arkitektur + Boolsk værdi + SOA Architecture + + + + + Persondata + Angivelse af, om der i arkiveringsversionen findes følsomme personoplysninger iht. Persondatalovenj + Boolsk værdi + Personal data included + + + + + Fristforlængende oplysninger + Angivelse af, om der i arkiveringsversionen findes oplysninger, der kan betinge længere tilgængelighedsfrist i øvrigt + Boolsk værdi + Other access restrictions + + + + + Godkendelsesarkiv + Angivelse af, hvilket offentligt arkiv, der godkender arkiveringsversionen + Identifikation af det pågældende arkiv (2-4 tegn) + Approving archive + + + + + Tilgængelighedsbegrænsninger + Angivelse af nærmere bestemmelser for adgang til materialet. Elementet kan anvendes efter det modtagende arkivs nærmere retningslinjer + Fritekst + Other access restrictions + + + + + + + + type for tekst med en mindstelængde på 1 tegn + type for text with a minimum lenght of 1 character + + + + + + + + datotype + date type + + + + + + dato fra 1700 til 2100 + date from 1700 to 2100 + + + + + + + + + dato og måned fra 1700-01 til 2100-12 + date and month from 1700-01 to 2100-12 + + + + + + + + + dato fra 1700-01-01 til 2100-12-31 + date from 1700-01-01 to 2100-12-31 + + + + + + + + + type for en archiveID + type for an archiveID + + + + + + + + type for en arkiveringsversionsID + type for an information package ID + + + + + + + + type for en arkiveringsversionsID i denne eller tidligere bekendtgørelse + type for an information package ID + + + + + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/contextDocumentationIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/contextDocumentationIndex.xsd new file mode 100644 index 000000000..118c88cc3 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/contextDocumentationIndex.xsd @@ -0,0 +1,388 @@ + + + + + + + + Indeks for alle dokumenter i arkiveringsversionens kontekstdokumentation + Index for all documents in the context documentation of the information package + + + + + + + + DokumentID. Unikt ID på op til 12 cifre + DocumentID. Unique ID with up to 12 digits in total + + + + + Dokumenttitel. Fri tekst + Document title. Free text + + + + + Dokumentbeskrivelse. Fri tekst + Document description. Free text + + + + + Dato. År, år-måned, år-måned-dag + Date. Year, year-month, year-month-day + + + + + + + + Forfatternavn. Fri tekst + Author name. Free text + + + + + Forfatterinstitution. Fri tekst + Author institution. Free text + + + + + + + + Dokumentkategori + Document category + + + + + + + + + + + type for dokumentkategori + type for a document category + + + + + Dokumentation vedrørende administrativ brug af it-systemet + Documentation regarding administrative use of the it system + + + + + Dokumentation vedrørende it-systemets tekniske udformning, drift og udvikling + Documentation regarding the technical design, operation and development of the it system + + + + + Dokumentation vedrørende arkivskabers aflevering af data + Documentation regarding the transfer of data from the archival creator + + + + + Dokumentation vedrørende arkivets modtagelse af data (udfyldes af modtagende arkiv) + Documentation regarding the receipt of data by the archive + + + + + Dokumentation vedrørende arkivets bevaring af arkiveringsversionen (udfyldes at det modtagende arkiv) + Documentation regarding the preservation of the archival version by the archive + + + + + Anden dokumentation + Other documentation + + + + + Dokumentation af forskningsdata + Research documentation + + + + + + + + + It-systemets formål + IT System purpose + + + + + It-systemets lov- og regelgrundlag + Legal and regulatory framework of the it system + + + + + It-systemets indhold, population og særlige begreber + IT System content, population and special concepts + + + + + It-systemets administrative funktioner + Administrative functions of the IT system + + + + + It-systemets præsentationsstruktur + Presentation structure of the IT system + + + + + Tilvejebringelse af data + Provision of data + + + + + Videregivelse af data + Transfer of data + + + + + Data og funktioner fælles med forgænger- og efterfølgersystemer + Data and functions in common with predecessor systems or successor systems + + + + + Myndighedens egen kvalitetskontrol + Quality control of the authority performed by itself + + + + + Publikation af og om data + Publication of and about data + + + + + Andet + Other + + + + + Registreringssystematik + System taxonomy + + + + + Instruks for anvendelse af systemet + instructions for system use + + + + + + + + + Driftsversionens opbygning + Structure of the operational system + + + + + Konvertering hos myndigheden + Transformation at the authority + + + + + Dokumentation af sammensætning af data og eventuelle dokumenter fra flere forskellige systemer i en serviceorienteret arkitektur + Documentation of the combination of data and any documents from several different systems in a service oriented architecture + + + + + Andet + Other + + + + + + + + + Arkivets bestemmelser, herunder afleveringsbestemmelse + Archive regulations, including stipulations about the transfer + + + + + Dokumentation af konvertering fra driftsversion til arkiveringsversion + Documentation of transformation from operational system to information package + + + + + Andet + Other + + + + + + + + + Arkivarnoter + Archivist notes + + + + + Testnoter + Test notes + + + + + Andet + Other + + + + + + + + + Konvertering hos arkivet + Transformations at the archive + + + + + Andet + Other + + + + + + + + + Andet + Other + + + + + + + + + Projektbeskrivelse gældende for de afleverede data + Research project description for the submitted data + + + + + Spørgeskema, interviewguide og/eller registreringsskema anvendt til at indsamle og analysere afleverede data + Questionnaire, interview guide, or registration form used to collect and analyze the submitted data + + + + + Protokoller og metoderapporter + Research protocol + + + + + Publikationer som er udgivet på basis af afleverede data + Publications that stem from the submitted data + + + + + Andet + Other + + + + + + + type for et dokumentID for et dokument i generel dokumentation + A type for a document ID for a document i generel documentation + + + + + + + + datotype for et dokument i kontekstinformation + date type for a document in context information + + + + + + dato fra 1700 til 2100 + date from 1700 to 2100 + + + + + + + + + dato og måned fra 1700-01 til 2100-12 + date and month from 1700-01 to 2100-12 + + + + + + + + + dato fra 1700-01-01 til 2100-12-31 + date from 1700-01-01 to 2100-12-31 + + + + + + + + + type for tekst med en mindstelængde på 1 tegn + type for text with a minimum lenght of 1 character + + + + + + \ No newline at end of file diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/docIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/docIndex.xsd new file mode 100644 index 000000000..9a4b00b55 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/docIndex.xsd @@ -0,0 +1,118 @@ + + + + + + + + Indeks for alle documenter i arkiveringsversionen + Index for all documents in the information package + + + + + + + + type for et dokument + A type for a document + + + + + DocID - ID, som entydigt udpeger det enkelte dokument + DocID - ID that uniquely identifies a document- + + + + + ParentID - ID på overordnet dokument ved indlejrede dokumenter eller dokumenter, der på anden vis indgår i et hierarki + ParentID - ID of the parent document for embedded documents or for documents which are otherwise part of a hierarchy + + + + + MediaID - ID på det lagringsmedie, som dokumentet ligger på + MediaID - ID for the storage media of the the document + + + + + ContainerFolder - Dokumentsamlingsmappe, som dokumentet ligger i. Skal være unikt inden for Documents, men dette krav er ikke indført i dette XML Schema for at lette skabelse og validering + ContainerFolder - document container folder in which the document is residing. Must be unique within Documents, but this requirement is not implemented in this XML Schema in order to ease creation and validation + + + + + OriginalFilename - Angivelse af filens navn inkl. suffix i IT-systemet + OriginalFilename - The original name of the file in the IT-system including its extension + + + + + Angivelse af filens format i arkiveringsversionen + The format of the file in the information package + + + + + For GML filer angives det skema, der skal bruges til validering af den pågældende GML-fil + GML Schema to be used to for validation the GML-file in question + + + + + + + type for et dokumentID + A type for a document ID + + + + + + + + type for et medie ID + A type for a media ID + + + + + + + + Type for en dokumentundermappenavn + Type for a document container folder name + + + + + + + + type for et dokument i arkiveringversionen + type for a document in the information package + Små bogstaver (minuskler) for filtyper (suffix) er krævet i bekendtgørelse, men store bogstaver (versaler) er tilladt i skemaet for at mindske behov for navneændring + Lower case is required, but upper case for the following file type extensions is accepted to reduce the need for renaming--> + + + + + + + + + + + + + + Navn for et gml xml skema + Name for a gml xml schema + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex.xsd new file mode 100644 index 000000000..97004b894 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex.xsd @@ -0,0 +1,83 @@ + + + + + + Dette skema angiver tilladte mappenavne og filnavne, men ikke hvilke filnavne, som er tilladt i hvilke mapper. Denne begrænsning skyldes ønsket om at anvende samme elementnavn 'foN' for alle mappenavne, og XML Schema tillader ikke at samme element kan være af forskellig type (Consistent Declaration Rule) + This Schema defines legal folder names and file names, but not what file names are allowed in what folders. This limitation is due to a desire to use the same element name 'foN' for all folder names, and XML Schema does not allow the same element name to belong to different types (Consistent Declaration Rule) + + + + + Indeks for alle filer i arkiveringsversionen + Index for all files in the information package + + + + + + + + + + + + + + + + Navn for en mappe i arkiveringsversionen + Name for a folder in the information package + + + + + Højst 10.000 docCollection mapper per ContextDocumentation mappe + Maximum of 10.000 docCollection folders per ContextDocumentation folder + + + + + Højst 10.000 docCollection mapper per Documents mappe + Maximum of 10.000 docCollection folders per Documents folder + + + + + + + + + + type for et filnavn i arkiveringversionen + type for a file name in the information package + + + + Små bogstaver (minuskler) for filtyper (suffix) er krævet i bekendtgørelse, men store bogstaver (versaler) er tilladt i Schemaet for at mindske behov for navneændring + Lower case is required, but upper case for the following file type extensions is accepted to reduce the needed for renaming--> + + + + + + + + + + + + + + + + + + Dette er en MD5 kontrolsum med et resultat på 128 bit svarende til 16 bytes repræsenteret som 32 hexadecimale tegn + This is a MD5 checksum with a result of 128 bit equalt to 16 bytes represented as 32 characters in hexadecimal + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex_original.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex_original.xsd new file mode 100644 index 000000000..59b05a4c8 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/fileIndex_original.xsd @@ -0,0 +1,83 @@ + + + + + + Dette skema angiver tilladte mappenavne og filnavne, men ikke hvilke filnavne, som er tilladt i hvilke mapper. Denne begrænsning skyldes ønsket om at anvende samme elementnavn 'foN' for alle mappenavne, og XML Schema tillader ikke at samme element kan være af forskellig type (Consistent Declaration Rule) + This Schema defines legal folder names and file names, but not what file names are allowed in what folders. This limitation is due to a desire to use the same element name 'foN' for all folder names, and XML Schema does not allow the same element name to belong to different types (Consistent Declaration Rule) + + + + + Indeks for alle filer i arkiveringsversionen + Index for all files in the information package + + + + + + + + + + + + + + + + Navn for en mappe i arkiveringsversionen + Name for a folder in the information package + + + + + Højst 10.000 docCollection mapper per ContextDocumentation mappe + Maximum of 10.000 docCollection folders per ContextDocumentation folder + + + + + Højst 10.000 docCollection mapper per Documents mappe + Maximum of 10.000 docCollection folders per Documents folder + + + + + + + + + + type for et filnavn i arkiveringversionen + type for a file name in the information package + + + + Små bogstaver (minuskler) for filtyper (suffix) er krævet i bekendtgørelse, men store bogstaver (versaler) er tilladt i Schemaet for at mindske behov for navneændring + Lower case is required, but upper case for the following file type extensions is accepted to reduce the needed for renaming--> + + + + + + + + + + + + + + + + + + Dette er en MD5 kontrolsum med et resultat på 128 bit svarende til 16 bytes repræsenteret som 32 hexadecimale tegn + This is a MD5 checksum with a result of 128 bit equalt to 16 bytes represented as 32 characters in hexadecimal + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/researchIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/researchIndex.xsd new file mode 100644 index 000000000..9945db157 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/researchIndex.xsd @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/tableIndex.xsd b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/tableIndex.xsd new file mode 100644 index 000000000..451386a12 --- /dev/null +++ b/dbptk-bindings/dbptk-bindings-siarddk-128/src/main/resources/schema/128/tableIndex.xsd @@ -0,0 +1,511 @@ + + + + + + + + + + + + + + + Rodelement for DDL for en siardDiark arkiveringsversion + Root element of DDL for a siardDiark information package + + + + + + + Udgavenr. for dette regelsæt for en siardDiark arkiveringsversion, dette versionsnr. er ikke det samme som versionsnr. for skemaet eller for XML Schema standarden. + Version number for the rules for a siardDiark information package, not for this XML Schema, nor the XML Schema Standard + + + + + Kort navn på databasen + Short database name + + + + + Produktnavn på det anvendte RDBMS> + Name of the RDBMS product used + + + + + Liste over tabeller i databasen + List of the tables in the database + + + + + Liste over views i databasen + List of the views in the database + + + + + + + + + type for a list of tables + type for en tabelliste, bestående af én eller flere tabeller + + + + + + + + + type for et tabelelement kaldet 'table' in siardDiark Archive + type for table element in siardDiark Archive + + + + + tabelnavn + table name + + + + + navn på mappen som indeholder tabellens data og dets tilhørende XML Schema + name of the folder containing the table and its XML Schema + + + + + Beskrivelse af tabellens formål og indhold + Description of the meaning and content of the table + + + + + Liste af kolonner i tabellen + List of the columns in the table + + + + + tabellens primærnøgle + Primary key of the table + + + + + Liste af tabellens fremmednøgler + List of the foreign keys of the table + + + + + Antal rækker i tabellen + Number of rows in the table + + + + + + + + Type for en liste af views + Type for a list of views + + + + + + + + + View element i siardDiark arkiveringsversion + View element in siardDiark Archive + + + + + Navn på view + Name of the view + + + + + Oprindelig SQL forespørgsel som definerer view, eller forespørgsel som er dannet specifikt til arkiveringsversionen + Original query string defining the view + + + + + Beskrivelse af views formål og indhold + Description of the view's meaning and content + + + + + + + + Liste af kolonner + List of columns + + + + + + + + + Kolonneelement i siardDiark arkiveringsversion + Column element in siardDiark Archive + + + + + Kolonnenavn + Column name in the table + + + + + Entydig identifikation af kolonne + Begynder med bogstavet 'c' efterfulgt af nummeret på kolonnens plads i tabellen. Samme rækkefølge skal anvendes i den schemaet for den pågældende tabel. + Column ID + Begins with the letter 'c' followed by the number for the order of the column in the tabe. Same order must be used in the schema for the table + + + + + + + + + + SQL:1999 datatype + SQL:1999 column type + + + + + Original datatype + Original column type + + + + + Kolonnens standardværdi + Column default + + + + + Angivelse af, om kolonnen kan være NULL + Defines if the column can be NULL + + + + + Beskrivelse af kolonnens indhold + The meaning and the content of the column + + + + + Angivelse af særlige information + Defines special information for the column + + + + + + + + Type for en primærnøgle + Type for a Primary key + + + + + Navn på primærnøgle. Navnet skal være unikt inden for arkiveringsversionen og være i overenstemmelse med reglerne for SQL Identifiers i SQL:1999 + Name of the primary key according to SQL:1999 rules for SQL Identifiers + + + + + Liste over navne på kolonner i prinærnøglen + List of names of columns of the primary key + + + + + + + + Liste af fremmednøgler + List of foreign keys + + + + + + + + + fremmednøgle 'foreignKey' element i siardDiark arkiveringsversion + foreignKey element in siardDiark Archive + + + + + Navn på fremmednøgle. Navnet skal være unikt inden for arkiveringsversionen og være i overenstemmelse med reglerne for SQL Identifiers i SQL:1999 + Name of the foreign key according to SQL:1999 rules for SQL Identifiers + + + + + Den tabel som fremmednøglen refererer til. + Table referenced by foreign key + + + + + Reference (liste af kolonner og de kolonner fremmednøglen refererer til + Reference (list of columns and referenced columns) + + + + + + + + Reference element i siardDiark arkiveringsversionen + reference element in siardDiark Archive + + + + + Referende kolonne + Referencing column + + + + + Refereret kolonne + Referenced column + + + + + + + + SQL Identifier i SQL:1999 som skal anvendes til navne for database, tabel, kolonner + SQL Identifier i SQL:1999 to be used for database names, table names, column names + + + + + + + SQL identifiers (except for delimited identifiers) must begin with a letter and may only contain letters, digits and _ unless they are delimited. + + + + + + + + fsNames may only consist of ASCII characters and digits and must start with a non-digit + + + + + + + + + + Uddrag af datatyper fra SQL:1999 data typer + Except of data types from SQL:1999 data types + Max amount of spaces between data type elements is limited + Combinations of upper case/lower case are limited. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Type for særlige informationer - angiver at indholdet af den pågældende kolonne har en særlig funktion/information + special information for a column + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder oplysninger om hvilken myndighed, der har registreret sagen eller dokumentet. + + + + + Bruges til at angive den eller de kolonner i arkiveringsversionen, som beskriver dokumenternes entydige identifikation. + + + + + Bruges til at angive den eller de kolonner i arkiveringsversionen, som beskriver, om dokumentet er lagret elektronisk, på papir eller delvist på papir. Helt eller delvis digitalt = 1, papir = 2, ikke relevant = 3 + + + + + Bruges ved aflevering af øjebliksbilleder m.v. til at angive den eller de kolonner i arkiveringsversionen, som beskriver, om dokumentet allerede er afleveret i en tidligere arkiveringsversion. Tidligere afleveret = 1, ikke tidligere afleveret = 2 + + + + + Den eller de kolonner i arkiveringsversionen, som beskriver sagernes entydige identifikation + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder sagernes titler. + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder dokumenternes titler/beskrivelser. + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder oplysninger om dokumenternes afsendelses- og modtagelsesdatoer. + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder oplysninger om et dokuments afsender eller modtager. + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder oplysninger, der uddraget fra en digital signatur + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder reference til FORM (Den fællesoffentlige forretningsreferencemodel) + + + + + Den eller de kolonner i arkiveringsversionen, som indeholder oplysninger om bevaring og kassation + + + + + diff --git a/dbptk-bindings/pom.xml b/dbptk-bindings/pom.xml index 713d4f5c7..22f2fb561 100644 --- a/dbptk-bindings/pom.xml +++ b/dbptk-bindings/pom.xml @@ -21,7 +21,8 @@ dbptk-bindings-siard1 dbptk-bindings-siard2-0 dbptk-bindings-siard2-1 - dbptk-bindings-siarddk + dbptk-bindings-siarddk-1007 + dbptk-bindings-siarddk-128 @@ -32,6 +33,7 @@ 4.0.0 + generate-siard generate @@ -41,12 +43,6 @@ ${basedir}/src/main/resources/schema - archiveIndex.xsd - docIndex.xsd - - fileIndex.xsd - XMLSchema.xsd - tableIndex.xsd siard2-1-metadata.xsd siard2-0-metadata.xsd siard1-metadata.xsd @@ -60,6 +56,108 @@ ${project.build.directory}/generated-sources/xjc + + com.databasepreservation.modules.siard.bindings.${packagename} + + + + generate-siard-1007-contextDocumentationIndex + + generate + + + false + + + ${basedir}/src/main/resources/schema/1007 + + contextDocumentationIndex.xsd + + + + ${project.build.directory}/generated-sources/xjc-a + + + + + com.databasepreservation.modules.siard.bindings.${packagename}.context + + + + + generate-siard-1007 + + generate + + + false + + + ${basedir}/src/main/resources/schema/1007 + + archiveIndex.xsd + docIndex.xsd + fileIndex.xsd + XMLSchema.xsd + tableIndex.xsd + + true + + ${project.build.directory}/generated-sources/xjc-b + + + + com.databasepreservation.modules.siard.bindings.${packagename} + + + + generate-siard-128-contextDocumentationIndex + + generate + + + false + + + ${basedir}/src/main/resources/schema/128 + + contextDocumentationIndex.xsd + + + + ${project.build.directory}/generated-sources/xjc-a + + + + + com.databasepreservation.modules.siard.bindings.${packagename}.context + + + + + generate-siardk-128 + + generate + + + false + + + ${basedir}/src/main/resources/schema/128 + + archiveIndex.xsd + docIndex.xsd + fileIndex.xsd + researchIndex.xsd + XMLSchema.xsd + tableIndex.xsd + + true + + + ${project.build.directory}/generated-sources/xjc-b + + com.databasepreservation.modules.siard.bindings.${packagename} diff --git a/dbptk-core/pom.xml b/dbptk-core/pom.xml index 23c7c176c..6dc9b929c 100644 --- a/dbptk-core/pom.xml +++ b/dbptk-core/pom.xml @@ -104,7 +104,11 @@ com.databasepreservation - dbptk-bindings-siarddk + dbptk-bindings-siarddk-1007 + + + com.databasepreservation + dbptk-bindings-siarddk-128 diff --git a/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestSIARDDK1007TableIndexFileStrategy.java b/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestSIARDDK1007TableIndexFileStrategy.java new file mode 100644 index 000000000..644e84057 --- /dev/null +++ b/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestSIARDDK1007TableIndexFileStrategy.java @@ -0,0 +1,64 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.out.metadata; + +import static org.testng.AssertJUnit.assertEquals; + +import com.databasepreservation.modules.siard.common.adapters.SIARDDK1007Adapter; +import com.databasepreservation.modules.siard.common.adapters.SIARDDK128Adapter; +import org.testng.annotations.Test; + +/** + * @author Andreas Kring + * + */ +@Test(groups = {"siarddk"}) +public class TestSIARDDK1007TableIndexFileStrategy { + + @Test + public void shouldNotEscapqForNormalWord() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("NormalWord", SIARDDK1007TableIndexFileStrategy.escapeString("NormalWord")); + } + + @Test + public void shouldEscapeWhenSpaceInWord() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("\"normal Word\"", SIARDDK1007TableIndexFileStrategy.escapeString("normal Word")); + } + + @Test + public void shouldEscapeWhenStringBeginsWithNoneLetter() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("\"2NormalWord\"", SIARDDK1007TableIndexFileStrategy.escapeString("2NormalWord")); + } + + @Test + public void shouldNotEscapeWhenUnderscoreInWord() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("Normal_Word", SIARDDK1007TableIndexFileStrategy.escapeString("Normal_Word")); + } + + @Test + public void shouldEscapeWhenDanishLetterInWord() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("\"NormalæWord\"", SIARDDK1007TableIndexFileStrategy.escapeString("NormalæWord")); + } + + @Test + public void shouldEscapeWhenParentesisInWord() { + SIARDDKTableIndexFileStrategy SIARDDK1007TableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(null, + new SIARDDK1007Adapter()); + assertEquals("\"Normal(Word\"", SIARDDK1007TableIndexFileStrategy.escapeString("Normal(Word")); + } +} diff --git a/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestTableIndexFileStrategy.java b/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestTableIndexFileStrategy.java deleted file mode 100644 index 825aab2d1..000000000 --- a/dbptk-core/src/test/java/com/databasepreservation/modules/siard/out/metadata/TestTableIndexFileStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ -package com.databasepreservation.modules.siard.out.metadata; - -import static org.testng.AssertJUnit.assertEquals; - -import org.testng.annotations.Test; - -/** - * @author Andreas Kring - * - */ -@Test(groups = {"siarddk"}) -public class TestTableIndexFileStrategy { - - @Test - public void shouldNotEscapqForNormalWord() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("NormalWord", tableIndexFileStrategy.escapeString("NormalWord")); - } - - @Test - public void shouldEscapeWhenSpaceInWord() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("\"normal Word\"", tableIndexFileStrategy.escapeString("normal Word")); - } - - @Test - public void shouldEscapeWhenStringBeginsWithNoneLetter() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("\"2NormalWord\"", tableIndexFileStrategy.escapeString("2NormalWord")); - } - - @Test - public void shouldNotEscapeWhenUnderscoreInWord() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("Normal_Word", tableIndexFileStrategy.escapeString("Normal_Word")); - } - - @Test - public void shouldEscapeWhenDanishLetterInWord() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("\"NormalæWord\"", tableIndexFileStrategy.escapeString("NormalæWord")); - } - - @Test - public void shouldEscapeWhenParentesisInWord() { - TableIndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(null); - assertEquals("\"Normal(Word\"", tableIndexFileStrategy.escapeString("Normal(Word")); - } -} diff --git a/dbptk-core/src/test/java/com/databasepreservation/siarddk/SIARDDKTestUtil.java b/dbptk-core/src/test/java/com/databasepreservation/siarddk/SIARDDKTestUtil.java index 896298437..b9fd8a6ea 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/siarddk/SIARDDKTestUtil.java +++ b/dbptk-core/src/test/java/com/databasepreservation/siarddk/SIARDDKTestUtil.java @@ -37,8 +37,8 @@ static void assertArchiveFoldersEqualAfterExportImport(Path archiveFldToProcessP FileUtils.deleteDirectory(archFile); } - String[] argumentsToMain = new String[] {"migrate", "--import=siard-dk", "--import-as-schema=public", "--import-folder", - archiveFldToProcessPath.toString(), "--export", "siard-dk", "--export-folder", + String[] argumentsToMain = new String[] {"migrate", "--import=siard-dk-1007", "--import-as-schema=public", "--import-folder", + archiveFldToProcessPath.toString(), "--export", "siard-dk-1007", "--export-folder", archFile.getAbsolutePath().toString()}; assert Main.internalMainUsedOnlyByTestClasses(argumentsToMain) == 0 : "Expected import of siard-dk archive [" diff --git a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestFileIndexFileStrategy.java b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007FileIndexFileStrategy.java similarity index 83% rename from dbptk-core/src/test/java/com/databasepreservation/siarddk/TestFileIndexFileStrategy.java rename to dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007FileIndexFileStrategy.java index 584114ce1..7e3a0cbbe 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestFileIndexFileStrategy.java +++ b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007FileIndexFileStrategy.java @@ -16,6 +16,7 @@ import java.nio.file.FileSystems; import java.nio.file.Path; +import com.databasepreservation.modules.siard.out.metadata.SIARDDK1007FileIndexFileStrategy; import jakarta.xml.bind.DatatypeConverter; import org.apache.commons.io.FileUtils; @@ -25,7 +26,6 @@ import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; import com.databasepreservation.modules.siard.constants.SIARDConstants; -import com.databasepreservation.modules.siard.out.metadata.FileIndexFileStrategy; import com.databasepreservation.modules.siard.out.write.FolderWriteStrategy; import com.databasepreservation.modules.siard.out.write.WriteStrategy; @@ -33,10 +33,10 @@ * @author Andreas Kring * */ -public class TestFileIndexFileStrategy { +public class TestSIARDDK1007FileIndexFileStrategy { private SIARDArchiveContainer mainContainer; - private FileIndexFileStrategy fileIndexFileStrategy; + private SIARDDK1007FileIndexFileStrategy SIARDDK1007FileIndexFileStrategy; private WriteStrategy writeStrategy; @BeforeMethod @@ -50,18 +50,18 @@ public void setUp() throws Exception { mainContainer = new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, rootPath, SIARDArchiveContainer.OutputContainerType.MAIN); writeStrategy = new FolderWriteStrategy(); - fileIndexFileStrategy = new FileIndexFileStrategy(); + SIARDDK1007FileIndexFileStrategy = new SIARDDK1007FileIndexFileStrategy(); } @Test public void shouldCalculateCorrectMd5sumForSingleFile() throws Exception { - OutputStream out = fileIndexFileStrategy.getWriter(mainContainer, "md5sums", writeStrategy); + OutputStream out = SIARDDK1007FileIndexFileStrategy.getWriter(mainContainer, "md5sums", writeStrategy); InputStream in = getClass().getResourceAsStream("/siarddk/text.tif"); IOUtils.copy(in, out); in.close(); out.close(); - byte[] digest = fileIndexFileStrategy.addFile("doesNotMatter"); + byte[] digest = SIARDDK1007FileIndexFileStrategy.addFile("doesNotMatter"); String md5sum = DatatypeConverter.printHexBinary(digest).toLowerCase(); assertEquals("a953767181ab088ee22ec3c4d1c45c87", md5sum); } diff --git a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKImportModule.java b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007ImportModule.java similarity index 98% rename from dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKImportModule.java rename to dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007ImportModule.java index 6fc2ba9e5..ab5c26ac2 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKImportModule.java +++ b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDK1007ImportModule.java @@ -19,7 +19,7 @@ */ @Test(groups = {"siarddk"}) -public class TestSIARDDKImportModule { +public class TestSIARDDK1007ImportModule { private final String ARCHIVE_FLD_NAME_SPLIT_TEST = "AVID.TST.4000.1"; private final String ARCHIVE_FLD_NAME_HEX_TEST = "AVID.HEX.2000.1"; diff --git a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKContentExportPathStrategy.java b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKContentExportPathStrategy.java index e480b1052..1045a3d30 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKContentExportPathStrategy.java +++ b/dbptk-core/src/test/java/com/databasepreservation/siarddk/TestSIARDDKContentExportPathStrategy.java @@ -7,12 +7,12 @@ */ package com.databasepreservation.siarddk; +import com.databasepreservation.modules.siard.out.path.SIARDDKContentPathExportStrategy; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.databasepreservation.modules.siard.out.path.ContentPathExportStrategy; -import com.databasepreservation.modules.siard.out.path.SIARDDKContentPathExportStrategy; public class TestSIARDDKContentExportPathStrategy { diff --git a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/MySqlSIARDDKTest.java b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/MySqlSIARDDKTest.java index 1f82ec05f..2a54e77bb 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/MySqlSIARDDKTest.java +++ b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/MySqlSIARDDKTest.java @@ -63,10 +63,10 @@ public void setup() throws IOException, InterruptedException, URISyntaxException db_target), new String[] {"migrate", "--import=mysql", "--import-hostname=127.0.0.1", "--import-database", db_source, - "--import-username", db_tmp_username, "--import-password", db_tmp_password, "--export=siard-dk", + "--import-username", db_tmp_username, "--import-password", db_tmp_password, "--export=siard-dk-1007", "--export-folder", archiveFullPath}, - new String[] {"migrate", "--import=siard-dk", "--import-as-schema=dpttest", "--import-folder", archiveFullPath, + new String[] {"migrate", "--import=siard-dk-1007", "--import-as-schema=dpttest", "--import-folder", archiveFullPath, "--export=mysql", "--export-hostname=127.0.0.1", "--export-database", db_target, "--export-username", db_tmp_username, "--export-password", db_tmp_password}, diff --git a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/PostgreSqlSIARDDKTest.java b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/PostgreSqlSIARDDKTest.java index ca9647686..93f880e4a 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/PostgreSqlSIARDDKTest.java +++ b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/roundtrip/PostgreSqlSIARDDKTest.java @@ -78,7 +78,7 @@ public void setup() throws IOException, InterruptedException, URISyntaxException "--import-username", db_tmp_username, "--import-password", db_tmp_password, "--import-disable-encryption", "--export=siard-dk", "--export-folder", archiveFullPath}, - new String[] {"migrate", "--import=siard-dk", "--import-as-schema=public", "--import-folder", archiveFullPath, + new String[] {"migrate", "--import=siard-dk-1007", "--import-as-schema=public", "--import-folder", archiveFullPath, "--export=postgresql", "--export-hostname=127.0.0.1", "--export-database", db_target, "--export-username", db_tmp_username, "--export-password", db_tmp_password, "--export-disable-encryption"}, sqlDumpDiffExpectationsPrepQueue, env_var_source, env_var_target); diff --git a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardDKTest.java b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardDKTest.java index 602dcf265..ac73422ff 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardDKTest.java +++ b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardDKTest.java @@ -15,6 +15,7 @@ import java.util.LinkedList; import java.util.List; +import com.databasepreservation.model.structure.virtual.VirtualTableStructure; import org.apache.commons.io.FileUtils; import org.testng.collections.Lists; @@ -146,9 +147,14 @@ protected DatabaseStructure roundTrip(DatabaseStructure orgDbStructure, Path tmp databaseStructure.setArchivalDate(null); // In siard-dk Archival Date is // located in archiveIndex.xml - + int virtualTableCounter = 0; for (SchemaStructure orgSchema : orgDbStructure.getSchemas()) { - assert orgSchema.getTables().size() == databaseStructure.getSchemas().get(0).getTables().size(); + for (TableStructure tableStructure : databaseStructure.getSchemas().get(0).getTables()) { + if (tableStructure instanceof VirtualTableStructure) { + virtualTableCounter++; + } + } + assert orgSchema.getTables().size() == databaseStructure.getSchemas().get(0).getTables().size()-virtualTableCounter; for (int tblIndex = 0; tblIndex < orgSchema.getTables().size(); tblIndex++) { TableStructure orgTable = orgSchema.getTables().get(tblIndex); assert orgTable.getColumns().size() == databaseStructure.getSchemas().get(0).getTables().get(tblIndex) diff --git a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardTest.java b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardTest.java index 758c9eaf7..720be0b56 100644 --- a/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardTest.java +++ b/dbptk-core/src/test/java/com/databasepreservation/testing/integration/siard/SiardTest.java @@ -17,6 +17,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; @@ -28,6 +29,9 @@ import java.util.Map; import java.util.Random; +import com.databasepreservation.model.structure.virtual.VirtualForeignKey; +import com.databasepreservation.model.structure.virtual.VirtualTableStructure; +import com.databasepreservation.modules.siard.in.input.SIARDDK1007ImportModule; import org.joda.time.DateTime; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -70,13 +74,12 @@ import com.databasepreservation.model.structure.type.SimpleTypeBoolean; import com.databasepreservation.model.structure.type.SimpleTypeNumericExact; import com.databasepreservation.model.structure.type.SimpleTypeString; -import com.databasepreservation.modules.siard.SIARDDKModuleFactory; +import com.databasepreservation.modules.siard.SIARDDK1007ModuleFactory; import com.databasepreservation.modules.siard.in.input.SIARD1ImportModule; import com.databasepreservation.modules.siard.in.input.SIARD2ImportModule; -import com.databasepreservation.modules.siard.in.input.SIARDDKImportModule; import com.databasepreservation.modules.siard.out.output.SIARD1ExportModule; import com.databasepreservation.modules.siard.out.output.SIARD2ExportModule; -import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; +import com.databasepreservation.modules.siard.out.output.SIARDDK1007ExportModule; import com.databasepreservation.testing.integration.roundtrip.differences.TextDiff; import com.databasepreservation.utils.JodaUtils; @@ -153,7 +156,21 @@ public void SIARD_RoundTrip(SiardVersion version) } } } - + for (SchemaStructure orgSchema : other.getSchemas()) { + for (TableStructure tableStructure : other.getSchemas().get(0).getTables()) { + if (tableStructure instanceof VirtualTableStructure) { + other.getSchemas().get(0).getTables().remove(tableStructure); + } + } + } + for (SchemaStructure schemaStructure : other.getSchemas()) { + for (TableStructure tableStructure : schemaStructure.getTables()) { + List foreignKeys = tableStructure.getForeignKeys(); + if (foreignKeys != null) { + foreignKeys.removeIf(fk -> fk instanceof VirtualForeignKey); + } + } + } assert original.equals(other) : "The final structure (from SIARD) differs from the original structure"; } @@ -576,10 +593,10 @@ protected DatabaseStructure roundTrip(DatabaseStructure dbStructure, Path tmpFil break; case DK: Map exportModuleArgs = new HashMap<>(); - exportModuleArgs.put(SIARDDKModuleFactory.PARAMETER_FOLDER, tmpFile.toString()); - exportModuleArgs.put(SIARDDKModuleFactory.PARAMETER_LOBS_PER_FOLDER, "10000"); - exportModuleArgs.put(SIARDDKModuleFactory.PARAMETER_LOBS_FOLDER_SIZE, "1000"); - exporter = new SIARDDKExportModule(exportModuleArgs).getDatabaseExportModule(); + exportModuleArgs.put(SIARDDK1007ModuleFactory.PARAMETER_FOLDER, tmpFile.toString()); + exportModuleArgs.put(SIARDDK1007ModuleFactory.PARAMETER_LOBS_PER_FOLDER, "10000"); + exportModuleArgs.put(SIARDDK1007ModuleFactory.PARAMETER_LOBS_FOLDER_SIZE, "1000"); + exporter = new SIARDDK1007ExportModule(exportModuleArgs).getDatabaseExportModule(); break; } @@ -641,7 +658,7 @@ protected DatabaseStructure roundTrip(DatabaseStructure dbStructure, Path tmpFil // Therefore it uses a special 'importAsSchema' parameter, to make it // compatible with the format of the dptkl internal database structure // representation. - importer = new SIARDDKImportModule(tmpFile, dbStructure.getSchemas().get(0).getName()) + importer = new SIARDDK1007ImportModule(tmpFile, dbStructure.getSchemas().get(0).getName()) .getDatabaseImportModule(); break; } diff --git a/dbptk-core/src/test/resources/siarddk/AVID.HEX.1000.1/Indices/fileIndex.xml b/dbptk-core/src/test/resources/siarddk/AVID.HEX.1000.1/Indices/fileIndex.xml index ba8f42029..8f2e79d34 100644 --- a/dbptk-core/src/test/resources/siarddk/AVID.HEX.1000.1/Indices/fileIndex.xml +++ b/dbptk-core/src/test/resources/siarddk/AVID.HEX.1000.1/Indices/fileIndex.xml @@ -1,5 +1,6 @@ - + AVID.HEX.1000.1\Tables\table1 table1.xml diff --git a/dbptk-core/testng.xml b/dbptk-core/testng.xml index f6fe5dcc8..14b4a13fb 100644 --- a/dbptk-core/testng.xml +++ b/dbptk-core/testng.xml @@ -44,19 +44,19 @@ - + - + - + diff --git a/dbptk-model/src/main/java/com/databasepreservation/SIARDEdition.java b/dbptk-model/src/main/java/com/databasepreservation/SIARDEdition.java index 61714d142..c1cb9cc5e 100644 --- a/dbptk-model/src/main/java/com/databasepreservation/SIARDEdition.java +++ b/dbptk-model/src/main/java/com/databasepreservation/SIARDEdition.java @@ -177,6 +177,8 @@ private static HashMap buildImportParameters(HashMap + */ +public class VirtualColumnStructure extends ColumnStructure { + public VirtualColumnStructure() { + super(); + } + + public VirtualColumnStructure(String id, String name, Type type, Boolean nillable, String description, + String defaultValue, Boolean isAutoIncrement) { + super(id, name, type, nillable, description, defaultValue, isAutoIncrement); + } + +} diff --git a/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualForeignKey.java b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualForeignKey.java new file mode 100644 index 000000000..2fca2ef34 --- /dev/null +++ b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualForeignKey.java @@ -0,0 +1,14 @@ +package com.databasepreservation.model.structure.virtual; + +import com.databasepreservation.model.structure.ForeignKey; + +/** + * @author António Lindo + */ +public class VirtualForeignKey extends ForeignKey { + + public VirtualForeignKey() { + super(); + } + +} diff --git a/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualPrimaryKey.java b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualPrimaryKey.java new file mode 100644 index 000000000..5fbcb06c2 --- /dev/null +++ b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualPrimaryKey.java @@ -0,0 +1,19 @@ +package com.databasepreservation.model.structure.virtual; + +import com.databasepreservation.model.structure.PrimaryKey; + +import java.util.List; + +/** + * @author António Lindo + */ +public class VirtualPrimaryKey extends PrimaryKey { + + public VirtualPrimaryKey() { + super(); + } + + public VirtualPrimaryKey(String name, List columns, String description) { + super(name, columns, description); + } +} diff --git a/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualTableStructure.java b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualTableStructure.java new file mode 100644 index 000000000..c4c815d9e --- /dev/null +++ b/dbptk-model/src/main/java/com/databasepreservation/model/structure/virtual/VirtualTableStructure.java @@ -0,0 +1,14 @@ +package com.databasepreservation.model.structure.virtual; + +import com.databasepreservation.model.structure.TableStructure; + +/** + * @author António Lindo + */ +public class VirtualTableStructure extends TableStructure { + + public VirtualTableStructure() { + super(); + } + +} diff --git a/dbptk-modules/dbptk-module-siard/pom.xml b/dbptk-modules/dbptk-module-siard/pom.xml index 3e60ad4e0..cd6bd51dc 100644 --- a/dbptk-modules/dbptk-module-siard/pom.xml +++ b/dbptk-modules/dbptk-module-siard/pom.xml @@ -38,7 +38,11 @@ com.databasepreservation - dbptk-bindings-siarddk + dbptk-bindings-siarddk-1007 + + + com.databasepreservation + dbptk-bindings-siarddk-128 diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007EditFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007EditFactory.java new file mode 100644 index 000000000..0e50b66c5 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007EditFactory.java @@ -0,0 +1,26 @@ +/** + * The contents of this folder are subject to the license and copyright + * detailed in the LICENSE folder at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard; + +import com.databasepreservation.modules.siard.constants.SIARDConstants; + +/** + * @author António Lindo + */ +public class SIARDDK1007EditFactory extends SIARDDKEditFactory { + + @Override + String getEditModuleName() { + return "edit-siard-dk-1007"; + } + + @Override + SIARDConstants.SiardVersion getSIARDVersion() { + return SIARDConstants.SiardVersion.DK_1007; + } +} \ No newline at end of file diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007ModuleFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007ModuleFactory.java new file mode 100644 index 000000000..0d2271285 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK1007ModuleFactory.java @@ -0,0 +1,38 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard; + +import java.nio.file.Path; +import java.util.Map; + +import com.databasepreservation.modules.siard.in.input.SIARDDK1007ImportModule; +import com.databasepreservation.modules.siard.in.input.SIARDDKImportModule; +import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; + +import com.databasepreservation.modules.siard.out.output.SIARDDK1007ExportModule; + +/** + * @author António Lindo + */ +public class SIARDDK1007ModuleFactory extends SIARDDKModuleFactory { + + @Override + String getModuleFactoryName() { + return "siard-dk-1007"; + } + + @Override + SIARDDKImportModule createSIARDDKImportModuleInstance(Path path, String schemaName) { + return new SIARDDK1007ImportModule(path, schemaName); + } + + @Override + SIARDDKExportModule createSIARDDKExportModuleInstance(Map exportModuleArgs) { + return new SIARDDK1007ExportModule(exportModuleArgs); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128EditFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128EditFactory.java new file mode 100644 index 000000000..823e0795e --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128EditFactory.java @@ -0,0 +1,26 @@ +/** + * The contents of this folder are subject to the license and copyright + * detailed in the LICENSE folder at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard; + +import com.databasepreservation.modules.siard.constants.SIARDConstants; + +/** + * @author António Lindo + */ +public class SIARDDK128EditFactory extends SIARDDKEditFactory { + + @Override + String getEditModuleName() { + return "edit-siard-dk-128"; + } + + @Override + SIARDConstants.SiardVersion getSIARDVersion() { + return SIARDConstants.SiardVersion.DK_128; + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128ModuleFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128ModuleFactory.java new file mode 100644 index 000000000..4f9111235 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDK128ModuleFactory.java @@ -0,0 +1,37 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard; + +import com.databasepreservation.modules.siard.in.input.SIARDDK128ImportModule; +import com.databasepreservation.modules.siard.in.input.SIARDDKImportModule; +import com.databasepreservation.modules.siard.out.output.SIARDDK128ExportModule; +import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; + +import java.nio.file.Path; +import java.util.Map; + +/** + * @author António Lindo + */ +public class SIARDDK128ModuleFactory extends SIARDDKModuleFactory { + + @Override + String getModuleFactoryName() { + return "siard-dk-128"; + } + + @Override + SIARDDKImportModule createSIARDDKImportModuleInstance(Path path, String schemaName) { + return new SIARDDK128ImportModule(path, schemaName); + } + + @Override + SIARDDKExportModule createSIARDDKExportModuleInstance(Map exportModuleArgs) { + return new SIARDDK128ExportModule(exportModuleArgs); + } +} \ No newline at end of file diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKEditFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKEditFactory.java new file mode 100644 index 000000000..afc2791ab --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKEditFactory.java @@ -0,0 +1,86 @@ +package com.databasepreservation.modules.siard; + +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.exception.SiardNotFoundException; +import com.databasepreservation.model.modules.edits.EditModule; +import com.databasepreservation.model.modules.edits.EditModuleFactory; +import com.databasepreservation.model.parameters.Parameter; +import com.databasepreservation.model.parameters.Parameters; +import com.databasepreservation.model.reporters.Reporter; +import com.databasepreservation.modules.siard.constants.SIARDConstants; +import com.databasepreservation.modules.siard.update.SIARDEditModule; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @author António Lindo + * + */ + +/** + * Class created for integration with DBPTK-UI. + * SIARDDK edition is not supported. + */ +public abstract class SIARDDKEditFactory implements EditModuleFactory { + + public static final String PARAMETER_FOLDER = "folder"; + + private static final Parameter folder = new Parameter().shortName("f").longName(PARAMETER_FOLDER) + .description("Path to SIARDK archive folder").hasArgument(true).setOptionalArgument(false).required(true); + + @Override + public String getModuleName() { + return getEditModuleName(); + } + + @Override + public boolean isEnabled() { + return false; + } + + @Override + public Parameters getImportParameters() { + return new Parameters(Collections.singletonList(folder), null); + } + + @Override + public Parameters getParameters() { + return null; + } + + @Override + public Map getAllParameters() { + HashMap parameterHashMap = new HashMap<>(); + parameterHashMap.put(folder.longName(), folder); + + return parameterHashMap; + } + + @Override + public Map getSetParameters() { + return null; + } + + @Override + public EditModule buildModule(Map parameters, Reporter reporter) throws ModuleException { + Path pFolder = Paths.get(parameters.get(folder)); + + if (Files.notExists(pFolder)) { + throw new SiardNotFoundException().withPath(pFolder.toAbsolutePath().toString()) + .withMessage("The path to the siard folder appears to be incorrect"); + } + + reporter.importModuleParameters(getModuleName(), PARAMETER_FOLDER, pFolder.normalize().toAbsolutePath().toString()); + + return new SIARDEditModule(pFolder, getSIARDVersion()); + } + + abstract String getEditModuleName(); + + abstract SIARDConstants.SiardVersion getSIARDVersion(); +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKModuleFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKModuleFactory.java index 06ee2986d..e51cf052b 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKModuleFactory.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDDKModuleFactory.java @@ -1,12 +1,6 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -14,18 +8,16 @@ import java.util.List; import java.util.Map; -import com.databasepreservation.model.modules.filters.DatabaseFilterModule; import org.apache.commons.lang3.StringUtils; -import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.exception.LicenseNotAcceptedException; import com.databasepreservation.model.exception.UnsupportedModuleException; import com.databasepreservation.model.modules.DatabaseImportModule; import com.databasepreservation.model.modules.DatabaseModuleFactory; +import com.databasepreservation.model.modules.filters.DatabaseFilterModule; import com.databasepreservation.model.parameters.Parameter; -import com.databasepreservation.model.parameters.Parameter.CATEGORY_TYPE; -import com.databasepreservation.model.parameters.Parameter.INPUT_TYPE; import com.databasepreservation.model.parameters.Parameters; +import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.modules.siard.constants.SIARDDKConstants; import com.databasepreservation.modules.siard.in.input.SIARDDKImportModule; import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; @@ -35,7 +27,7 @@ * @author Thomas Kristensen * */ -public class SIARDDKModuleFactory implements DatabaseModuleFactory { +public abstract class SIARDDKModuleFactory implements DatabaseModuleFactory { public static final String PARAMETER_FOLDER = "folder"; public static final String PARAMETER_ARCHIVE_INDEX = "archiveIndex"; public static final String PARAMETER_CONTEXT_DOCUMENTATION_INDEX = "contextDocumentationIndex"; @@ -102,7 +94,7 @@ public boolean producesExportModules() { @Override public String getModuleName() { - return "siard-dk"; + return getModuleFactoryName(); } @Override @@ -131,7 +123,8 @@ public Map getAllParameters() { @Override public Parameters getConnectionParameters() { return new Parameters( - Arrays.asList(folder.inputType(INPUT_TYPE.FOLDER), importAsSchema.inputType(INPUT_TYPE.TEXT)), null); + Arrays.asList(folder.inputType(Parameter.INPUT_TYPE.FOLDER), importAsSchema.inputType(Parameter.INPUT_TYPE.TEXT)), + null); } @Override @@ -146,14 +139,17 @@ public Parameters getExportModuleParameters() throws UnsupportedModuleException // clobType, clobLength), null); return new Parameters( - Arrays.asList(folder.inputType(INPUT_TYPE.FOLDER).exportOptions(CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), - archiveIndex.inputType(INPUT_TYPE.FILE_OPEN).fileFilter(Parameter.FILE_FILTER_TYPE.XML_EXTENSION) - .exportOptions(CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), - contextDocumentationIndex.inputType(INPUT_TYPE.FILE_OPEN).fileFilter(Parameter.FILE_FILTER_TYPE.XML_EXTENSION) - .exportOptions(CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), - contextDocumentationFolder.inputType(INPUT_TYPE.FOLDER).exportOptions(CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), - lobsPerFolder.inputType(INPUT_TYPE.TEXT).exportOptions(CATEGORY_TYPE.EXTERNAL_LOBS), - lobsFolderSize.inputType(INPUT_TYPE.TEXT).exportOptions(CATEGORY_TYPE.EXTERNAL_LOBS)), + Arrays.asList( + folder.inputType(Parameter.INPUT_TYPE.FOLDER).exportOptions(Parameter.CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), + archiveIndex.inputType(Parameter.INPUT_TYPE.FILE_OPEN).fileFilter(Parameter.FILE_FILTER_TYPE.XML_EXTENSION) + .exportOptions(Parameter.CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), + contextDocumentationIndex.inputType(Parameter.INPUT_TYPE.FILE_OPEN) + .fileFilter(Parameter.FILE_FILTER_TYPE.XML_EXTENSION) + .exportOptions(Parameter.CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), + contextDocumentationFolder.inputType(Parameter.INPUT_TYPE.FOLDER) + .exportOptions(Parameter.CATEGORY_TYPE.SIARD_EXPORT_OPTIONS), + lobsPerFolder.inputType(Parameter.INPUT_TYPE.TEXT).exportOptions(Parameter.CATEGORY_TYPE.EXTERNAL_LOBS), + lobsFolderSize.inputType(Parameter.INPUT_TYPE.TEXT).exportOptions(Parameter.CATEGORY_TYPE.EXTERNAL_LOBS)), null); } @@ -163,7 +159,7 @@ public DatabaseImportModule buildImportModule(Map parameters, reporter.importModuleParameters(getModuleName(), "file", Paths.get(parameters.get(folder)).normalize().toAbsolutePath().toString(), importAsSchema.longName(), parameters.get(importAsSchema)); - return new SIARDDKImportModule(Paths.get(parameters.get(folder)), parameters.get(importAsSchema)) + return createSIARDDKImportModuleInstance(Paths.get(parameters.get(folder)), parameters.get(importAsSchema)) .getDatabaseImportModule(); } @@ -226,6 +222,12 @@ public DatabaseFilterModule buildExportModule(Map parameters, } reporter.exportModuleParameters(getModuleName(), exportModuleParameters.toArray(new String[0])); - return new SIARDDKExportModule(exportModuleArgs).getDatabaseExportModule(); + return createSIARDDKExportModuleInstance(exportModuleArgs).getDatabaseExportModule(); } + + abstract String getModuleFactoryName(); + + abstract SIARDDKImportModule createSIARDDKImportModuleInstance(Path path, String schemaName); + + abstract SIARDDKExportModule createSIARDDKExportModuleInstance(Map exportModuleArgs); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDEditFactory.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDEditFactory.java index 2c46758d3..d9e7f5fd5 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDEditFactory.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/SIARDEditFactory.java @@ -22,6 +22,7 @@ import com.databasepreservation.model.modules.edits.EditModuleFactory; import com.databasepreservation.model.parameters.Parameter; import com.databasepreservation.model.parameters.Parameters; +import com.databasepreservation.modules.siard.constants.SIARDConstants; import com.databasepreservation.modules.siard.update.SIARDEditModule; /** @@ -100,6 +101,6 @@ public EditModule buildModule(Map parameters, Reporter report reporter.importModuleParameters(getModuleName(), PARAMETER_FILE, pFile.normalize().toAbsolutePath().toString()); - return new SIARDEditModule(pFile); + return new SIARDEditModule(pFile, SIARDConstants.SiardVersion.V2_0); } } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK1007Adapter.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK1007Adapter.java new file mode 100644 index 000000000..6717337e1 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK1007Adapter.java @@ -0,0 +1,210 @@ +package com.databasepreservation.modules.siard.common.adapters; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.structure.ColumnStructure; +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.model.structure.ForeignKey; +import com.databasepreservation.model.structure.PrimaryKey; +import com.databasepreservation.model.structure.Reference; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.ArchiveIndex; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQLStandardDatatypeImporter; +import dk.sa.xmlns.diark._1_0.docindex.DocIndexType; +import dk.sa.xmlns.diark._1_0.tableindex.ColumnType; +import dk.sa.xmlns.diark._1_0.tableindex.ColumnsType; +import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeyType; +import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeysType; +import dk.sa.xmlns.diark._1_0.tableindex.FunctionalDescriptionType; +import dk.sa.xmlns.diark._1_0.tableindex.PrimaryKeyType; +import dk.sa.xmlns.diark._1_0.tableindex.ReferenceType; +import dk.sa.xmlns.diark._1_0.tableindex.SiardDiark; +import dk.sa.xmlns.diark._1_0.tableindex.TableType; +import dk.sa.xmlns.diark._1_0.tableindex.TablesType; +import dk.sa.xmlns.diark._1_0.tableindex.ViewType; +import dk.sa.xmlns.diark._1_0.tableindex.ViewsType; +import org.apache.commons.lang3.StringUtils; + +/** + * @author Gabriel Barros + */ +public class SIARDDK1007Adapter implements SIARDDKAdapter { + private SiardDiark siardDiark; + private ArchiveIndex archiveIndex; + private TablesType tablesType; + private TableType tableType; + private ViewsType viewsType; + + public SIARDDK1007Adapter() { + siardDiark = new SiardDiark(); + tablesType = new TablesType(); + + siardDiark.setTables(tablesType); + } + + @Override + public void setSiardDiark(Object siardDiark) { + this.siardDiark = (SiardDiark) siardDiark; + } + + @Override + public void setArchiveIndex(Object archiveIndex) { + this.archiveIndex = (ArchiveIndex) archiveIndex; + } + + @Override + public void setTableType(Object tableType) { + this.tableType = (TableType) tableType; + } + + @Override + public void setVersion(String value) { + siardDiark.setVersion(value); + } + + @Override + public void setDbName(String dbOriginalName) { + siardDiark.setDbName(dbOriginalName); + } + + @Override + public void setDatabaseProduct(String productName) { + siardDiark.setDatabaseProduct(productName); + } + + @Override + public PrimaryKey getPrimaryKey(Object primaryKeyXml) { + PrimaryKey keyDptkl = new PrimaryKey(); + PrimaryKeyType primaryKeyType = (PrimaryKeyType) primaryKeyXml; + keyDptkl.setName(primaryKeyType.getName()); + keyDptkl.setColumnNames(primaryKeyType.getColumn()); + return keyDptkl; + } + + @Override + public String getDatabaseProduct() { + return siardDiark.getDatabaseProduct(); + } + + @Override + public String getDbName() { + return siardDiark.getDbName(); + } + + @Override + public Object getTables() { + return siardDiark.getTables(); + } + + protected List getReferences(List referencesXml) { + List refsDptkld = new LinkedList(); + if (referencesXml != null) { + for (ReferenceType referenceTypeXml : referencesXml) { + Reference refDptkld = new Reference(); + refDptkld.setColumn(referenceTypeXml.getColumn()); + refDptkld.setReferenced(referenceTypeXml.getReferenced()); + refsDptkld.add(refDptkld); + } + } + return refsDptkld; + } + + @Override + public List getTable() { + return Collections.singletonList(siardDiark.getTables().getTable()); + } + + @Override + public void addTable(String tableName, String tableFolder, String tableDescription) { + TableType tableType = new TableType(); + tableType.setName(tableName); + tableType.setFolder(tableFolder); + tableType.setDescription(tableDescription); + tableType.setColumns(new ColumnsType()); + tablesType.getTable().add(tableType); + } + + @Override + public void addColumnForTable(String tableName, String columnName, String columnID, String columType, + String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, + String lobType) { + ColumnType columnType = new ColumnType(); + columnType.setName(columnName); + columnType.setColumnID(columnID); + columnType.setType(columType); + columnType.setTypeOriginal(columnOriginalType); + columnType.setDefaultValue(columnDefaultValue); + columnType.setNullable(columnStructureNillable); + columnType.setDescription(columnDescription); + + if (lobType != null) { + if (lobType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { + FunctionalDescriptionType functionalDescriptionType = FunctionalDescriptionType.DOKUMENTIDENTIFIKATION; + columnType.getFunctionalDescription().add(functionalDescriptionType); + } + } + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get().getColumns() + .getColumn().add(columnType); + } + + @Override + public Object getSIARDDK() { + return siardDiark; + } + + @Override + public void addPrimaryKeyForTable(String tableName, String primaryKeyName, List escapedColumnNames) { + PrimaryKeyType primaryKeyType = new PrimaryKeyType(); + primaryKeyType.setName(primaryKeyName); + primaryKeyType.getColumn().addAll(escapedColumnNames); + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() + .setPrimaryKey(primaryKeyType); + } + + @Override + public void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, + Map escapedReferencedColumns) { + TableType tableType = tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst() + .get(); + if (tableType.getForeignKeys() == null) { + tableType.setForeignKeys(new ForeignKeysType()); + } + ForeignKeyType foreignKeyType = new ForeignKeyType(); + foreignKeyType.setName(foreignKeyName); + foreignKeyType.setReferencedTable(foreignKeyReferencedTable); + escapedReferencedColumns.forEach((column, ref) -> { + ReferenceType referenceType = new ReferenceType(); + referenceType.setColumn(column); + referenceType.setReferenced(ref); + foreignKeyType.getReference().add(referenceType); + }); + tableType.getForeignKeys().getForeignKey().add(foreignKeyType); + } + + @Override + public void setRowsForTable(String tableName, BigInteger bigInteger) { + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() + .setRows(bigInteger); + } + + @Override + public void addView(String viewName, String viewQueryOriginal, String viewDescription) { + if (viewsType == null) { + viewsType = new ViewsType(); + siardDiark.setViews(viewsType); + } + ViewType viewType = new ViewType(); + viewType.setName(viewName); + viewType.setQueryOriginal(viewQueryOriginal); + viewType.setDescription(viewDescription); + viewsType.getView().add(viewType); + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK128Adapter.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK128Adapter.java new file mode 100644 index 000000000..d4a9d4edc --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDK128Adapter.java @@ -0,0 +1,187 @@ +package com.databasepreservation.modules.siard.common.adapters; + +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.model.structure.PrimaryKey; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ArchiveIndex; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnsType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeyType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeysType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.FunctionalDescriptionType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.PrimaryKeyType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ReferenceType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.SiardDiark; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.TableType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.TablesType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ViewType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ViewsType; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +/** + * @author Gabriel Barros + */ +public class SIARDDK128Adapter implements SIARDDKAdapter { + private SiardDiark siardDiark; + private ArchiveIndex archiveIndex; + private final TablesType tablesType; + private TableType tableType; + private ViewsType viewsType; + + public SIARDDK128Adapter() { + siardDiark = new SiardDiark(); + tablesType = new TablesType(); + + siardDiark.setTables(tablesType); + } + + @Override + public void setSiardDiark(Object siardDiark) { + this.siardDiark = (SiardDiark) siardDiark; + } + + @Override + public void setArchiveIndex(Object archiveIndex) { + this.archiveIndex = (ArchiveIndex) archiveIndex; + } + + @Override + public void setVersion(String value) { + siardDiark.setVersion(value); + } + + @Override + public void setTableType(Object tableType) { + this.tableType = (TableType) tableType; + } + + @Override + public void setDbName(String dbOriginalName) { + siardDiark.setDbName(dbOriginalName); + } + + @Override + public void setDatabaseProduct(String productName) { + siardDiark.setDatabaseProduct(productName); + } + + @Override + public String getDatabaseProduct() { + return siardDiark.getDatabaseProduct(); + } + + @Override + public String getDbName() { + return siardDiark.getDbName(); + } + + @Override + public Object getTables() { + return siardDiark.getTables(); + } + + @Override + public PrimaryKey getPrimaryKey(Object primaryKeyXml) { + PrimaryKey keyDptkl = new PrimaryKey(); + PrimaryKeyType primaryKeyType = (PrimaryKeyType) primaryKeyXml; + keyDptkl.setName(primaryKeyType.getName()); + keyDptkl.setColumnNames(primaryKeyType.getColumn()); + return keyDptkl; + } + + @Override + public List getTable() { + return Collections.singletonList(siardDiark.getTables().getTable()); + } + + @Override + public void addTable(String tableName, String tableFolder, String tableDescription) { + TableType tableType = new TableType(); + tableType.setName(tableName); + tableType.setFolder(tableFolder); + tableType.setDescription(tableDescription); + tableType.setColumns(new ColumnsType()); + tablesType.getTable().add(tableType); + } + + @Override + public void addColumnForTable(String tableName, String columnName, String columnID, String columType, + String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, + String lobType) { + ColumnType columnType = new ColumnType(); + columnType.setName(columnName); + columnType.setColumnID(columnID); + columnType.setType(columType); + columnType.setTypeOriginal(columnOriginalType); + columnType.setDefaultValue(columnDefaultValue); + columnType.setNullable(columnStructureNillable); + columnType.setDescription(columnDescription); + + if (lobType != null) { + if (lobType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { + FunctionalDescriptionType functionalDescriptionType = FunctionalDescriptionType.DOKUMENTIDENTIFIKATION; + columnType.getFunctionalDescription().add(functionalDescriptionType); + } + } + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get().getColumns() + .getColumn().add(columnType); + } + + @Override + public Object getSIARDDK() { + return siardDiark; + } + + @Override + public void addPrimaryKeyForTable(String tableName, String primaryKeyName, List escapedColumnNames) { + PrimaryKeyType primaryKeyType = new PrimaryKeyType(); + primaryKeyType.setName(primaryKeyName); + primaryKeyType.getColumn().addAll(escapedColumnNames); + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() + .setPrimaryKey(primaryKeyType); + } + + @Override + public void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, + Map escapedReferencedColumns) { + TableType tableType = tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst() + .get(); + if (tableType.getForeignKeys() == null) { + tableType.setForeignKeys(new ForeignKeysType()); + } + ForeignKeyType foreignKeyType = new ForeignKeyType(); + foreignKeyType.setName(foreignKeyName); + foreignKeyType.setReferencedTable(foreignKeyReferencedTable); + escapedReferencedColumns.forEach((column, ref) -> { + ReferenceType referenceType = new ReferenceType(); + referenceType.setColumn(column); + referenceType.setReferenced(ref); + foreignKeyType.getReference().add(referenceType); + }); + tableType.getForeignKeys().getForeignKey().add(foreignKeyType); + } + + @Override + public void setRowsForTable(String tableName, BigInteger bigInteger) { + tablesType.getTable().stream().filter(table -> table.getName().equals(tableName)).findFirst().get() + .setRows(bigInteger); + } + + @Override + public void addView(String viewName, String viewQueryOriginal, String viewDescription) { + if (viewsType == null) { + viewsType = new ViewsType(); + siardDiark.setViews(viewsType); + } + ViewType viewType = new ViewType(); + viewType.setName(viewName); + viewType.setQueryOriginal(viewQueryOriginal); + viewType.setDescription(viewDescription); + viewsType.getView().add(viewType); + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDKAdapter.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDKAdapter.java new file mode 100644 index 000000000..9518eb47f --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/adapters/SIARDDKAdapter.java @@ -0,0 +1,58 @@ +package com.databasepreservation.modules.siard.common.adapters; + +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.structure.ColumnStructure; +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.model.structure.ForeignKey; +import com.databasepreservation.model.structure.PrimaryKey; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnsType; +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQLStandardDatatypeImporter; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +/** + * @author Gabriel Barros + */ +public interface SIARDDKAdapter { + void setVersion(String value); + + void setDbName(String dbOriginalName); + + void setDatabaseProduct(String productName); + + String getDatabaseProduct(); + + String getDbName(); + + Object getTables(); + + void addTable(String tableName, String tableFolder, String tableDescription); + + void addColumnForTable(String tableName, String columnName, String columnID, String columType, + String columnOriginalType, String columnDefaultValue, Boolean columnStructureNillable, String columnDescription, + String lobType); + + Object getSIARDDK(); + + PrimaryKey getPrimaryKey(Object primaryKeyXml); + + List getTable(); + + void addPrimaryKeyForTable(String tableName, String primaryKeyName, List escapedColumnNames); + + void addForeignKeyForTable(String tableName, String foreignKeyName, String foreignKeyReferencedTable, + Map escapedReferencedColumns); + + void setRowsForTable(String tableName, BigInteger bigInteger); + + void addView(String viewName, String viewQueryOriginal, String viewDescription); + + void setSiardDiark(Object siardDiark); + + void setArchiveIndex(Object archiveIndex); + + void setTableType(Object tableType); + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK1007MetadataPathStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK1007MetadataPathStrategy.java new file mode 100644 index 000000000..dfab40ae1 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK1007MetadataPathStrategy.java @@ -0,0 +1,32 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + *

+ * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.common.path; + +import java.security.InvalidParameterException; + +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +/** + * @author António Lindo + */ +public class SIARDDK1007MetadataPathStrategy extends SIARDDKMetadataPathStrategy { + + @Override + public String getXsdResourcePath(String filename) throws InvalidParameterException { + + if (checkFilename(filename)) { + return new StringBuilder().append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR) + .append(SIARDDKConstants.SCHEMA_RESOURCE_DIR).append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR) + .append(SIARDDKConstants.SIARDDK_1007).append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR).append(filename) + .append(SIARDDKConstants.FILE_EXTENSION_SEPARATOR).append(SIARDDKConstants.XSD_EXTENSION).toString(); + } else { + throw new InvalidParameterException("Invalid filename for metadata file"); + } + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK128MetadataPathStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK128MetadataPathStrategy.java new file mode 100644 index 000000000..b3ecd21d6 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDK128MetadataPathStrategy.java @@ -0,0 +1,32 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + *

+ * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.common.path; + +import java.security.InvalidParameterException; + +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +/** + * @author António Lindo + */ +public class SIARDDK128MetadataPathStrategy extends SIARDDKMetadataPathStrategy { + + @Override + public String getXsdResourcePath(String filename) throws InvalidParameterException { + + if (checkFilename(filename)) { + return new StringBuilder().append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR) + .append(SIARDDKConstants.SCHEMA_RESOURCE_DIR).append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR) + .append(SIARDDKConstants.SIARDDK_128).append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR).append(filename) + .append(SIARDDKConstants.FILE_EXTENSION_SEPARATOR).append(SIARDDKConstants.XSD_EXTENSION).toString(); + } else { + throw new InvalidParameterException("Invalid filename for metadata file"); + } + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDKMetadataPathStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDKMetadataPathStrategy.java index 934c640a6..dcb1180b7 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDKMetadataPathStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/common/path/SIARDDKMetadataPathStrategy.java @@ -1,24 +1,16 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.common.path; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Arrays; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; - /** * @author Andreas Kring * */ -public class SIARDDKMetadataPathStrategy implements MetadataPathStrategy { - +public abstract class SIARDDKMetadataPathStrategy implements MetadataPathStrategy { // Names for directories private static final String INDICES_DIR = "Indices"; private static final String SCHEMA_DIR = "Schemas" + SIARDDKConstants.FILE_SEPARATOR + "standard"; @@ -48,18 +40,9 @@ public String getXsdFilePath(String filename) { } @Override - public String getXsdResourcePath(String filename) throws InvalidParameterException { - - if (checkFilename(filename)) { - return new StringBuilder().append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR) - .append(SIARDDKConstants.SCHEMA_RESOURCE_DIR).append(SIARDDKConstants.RESOURCE_FILE_SEPARATOR).append(filename) - .append(SIARDDKConstants.FILE_EXTENSION_SEPARATOR).append(SIARDDKConstants.XSD_EXTENSION).toString(); - } else { - throw new InvalidParameterException("Invalid filename for metadata file"); - } - } + public abstract String getXsdResourcePath(String filename) throws InvalidParameterException; - private boolean checkFilename(String filename) { + public boolean checkFilename(String filename) { // Valid filenames String[] validFileNames = {SIARDDKConstants.TABLE_INDEX, SIARDDKConstants.ARCHIVE_INDEX, SIARDDKConstants.DOC_INDEX, diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDConstants.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDConstants.java index c6de04bed..dd427ee94 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDConstants.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDConstants.java @@ -35,6 +35,10 @@ public enum SiardVersion { // danish v1.0 fork DK("1.0", "dk"), + DK_1007("1007", "dk-1007"), + + DK_128("128", "dk-128"), + // eCH-0165 v1.0: replaced by 2.0 V1_0("1.0", "1.0", "v1.0"); diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDDKConstants.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDDKConstants.java index 80195fb2f..0141a10d2 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDDKConstants.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/constants/SIARDDKConstants.java @@ -15,6 +15,10 @@ */ public class SIARDDKConstants { + // siardk versions + public static final String SIARDDK_128 = "128"; + public static final String SIARDDK_1007= "1007"; + // System dependent file seperator etc. ("/" on Linux and "\" on Windows) public static final String FILE_SEPARATOR = File.separator; public static final String RESOURCE_FILE_SEPARATOR = "/"; @@ -24,6 +28,7 @@ public class SIARDDKConstants { public static final String XML_EXTENSION = "xml"; public static final String XSD_EXTENSION = "xsd"; public static final String UNKNOWN_MIMETYPE_BLOB_EXTENSION = "bin"; + public static final String BLOB_EXTENSION = "blob"; // Name of the context documentation folder within the archive public static final String CONTEXT_DOCUMENTATION_RELATIVE_PATH = "ContextDocumentation"; @@ -36,6 +41,8 @@ public class SIARDDKConstants { public static final String JAXB_CONTEXT_FILEINDEX = "dk.sa.xmlns.diark._1_0.fileindex"; public static final String JAXB_CONTEXT_DOCINDEX = "dk.sa.xmlns.diark._1_0.docindex"; + public static final String JAXB_CONTEXT_FILEINDEX_128 = "com.databasepreservation.modules.siard.bindings.siard_dk_128.FileIndexType"; + // Key for context documentation folder (given on command line) public static final String CONTEXT_DOCUMENTATION_FOLDER = "contextDocumentationFolder"; @@ -48,6 +55,30 @@ public class SIARDDKConstants { public static final String DOCUMENT_IDENTIFICATION = "documentIdentification"; public static final String XML_SCHEMA = "XMLSchema"; + // Virtual Table + public static final String VIRTUAL_TABLE_NAME = "virtual_table"; + public static final String CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME = "context_documentation"; + public static final String VIRTUAL_TABLE_DESCRIPTION = "A virtual table"; + public static final String CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_DESCRIPTION = "Context documents"; + public static final String VIRTUAL_TABLE_FOREIGN_KEY_NAME = "FK_virtual_table"; + public static final String VIRTUAL_TABLE_PRIMARY_KEY_NAME = "PK_virtual_table"; + public static final String CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_PRIMARY_KEY_NAME = "PK_context_doc"; + public static final String VIRTUAL_TABLE_PRIMARY_KEY_DESCRIPTION = "virtual table primary key"; + + // DocIndex constants + public static final String DID = "dID"; + public static final String DOCUMENT_IDENTIFIER = "Document identifier"; + + // ContexDocumentationIndexConstants + public static final String DOCUMENT_ID = "documentID"; + public static final String DOCUMENT_TITLE = "documentTitle"; + public static final String DOCUMENT_TITLE_DESCRIPTION = "Document title"; + public static final String DOCUMENT_DATE = "documentDate"; + public static final String DOCUMENT_DATE_DESCRIPTION = "Document date"; + + // ArchiveIndex constants + public static final String CREATOR_NAME = "creatorName"; + // Constants for LOBs public static final String BINARY_LARGE_OBJECT = "BINARY LARGE OBJECT"; public static final String CHARACTER_LARGE_OBJECT = "CHARACTER LARGE OBJECT"; @@ -59,4 +90,9 @@ public class SIARDDKConstants { // Digest algorithms public static final String DIGEST_ALGORITHM = "MD5"; + + // Folders + public static final String DOCUMENTS_FOLDER_NAME = "Documents"; + public static final String CONTEXT_DOCUMENTATION_FOLDER_NAME = "ContextDocumentation"; + public static final String DOC_COLLECTION_FOLDER_NAME = "docCollection1"; } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK1007ContentImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK1007ContentImportStrategy.java new file mode 100644 index 000000000..f8eaa3dc7 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK1007ContentImportStrategy.java @@ -0,0 +1,198 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.content; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.context.ContextDocumentationIndex; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.in.path.SIARDDKPathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; + +import dk.sa.xmlns.diark._1_0.docindex.DocIndexType; +import dk.sa.xmlns.diark._1_0.docindex.DocumentType; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; + +/** + * @author António Lindo + */ +public class SIARDDK1007ContentImportStrategy extends + SIARDDKContentImportStrategy { + private static final Logger logger = LoggerFactory.getLogger(SIARDDK1007ContentImportStrategy.class); + + public SIARDDK1007ContentImportStrategy(FolderReadStrategyMD5Sum readStrategy, SIARDDKPathImportStrategy pathStrategy, + String importAsSchema) { + super(readStrategy, pathStrategy, importAsSchema); + } + + DocIndexType loadVirtualTableContent() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(DocIndexType.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.DOC_INDEX)); + JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement.getValue(); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + @Override + ContextDocumentationIndex loadContextDocTableContent() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(ContextDocumentationIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + ContextDocumentationIndex jaxbElement = (ContextDocumentationIndex) unmarshaller + .unmarshal(inputStreamXml); + return jaxbElement; + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + @Override + List getContextDocuments(ContextDocumentationIndex contextDoc) { + return contextDoc.getDocument(); + } + + @Override + List getDocuments(DocIndexType docIndex) { + return docIndex.getDoc(); + } + + @Override + String getDCf(DocumentType doc) { + return doc.getDCf(); + } + + @Override + BigInteger getDID(DocumentType doc) { + return doc.getDID(); + } + + @Override + BigInteger getMID(DocumentType doc) { + return doc.getMID(); + } + + @Override + String getAFt(DocumentType doc) { + return doc.getAFt(); + } + + @Override + String getDocumentID(ContextDocumentationIndex.Document doc) { + return doc.getDocumentID(); + } + + @Override + String getDocumentTitle(ContextDocumentationIndex.Document doc) { + if (doc.getDocumentTitle() != null) { + return doc.getDocumentTitle(); + } else { + return ""; + } + } + + @Override + String getDocumentDate(ContextDocumentationIndex.Document doc) { + if (doc.getDocumentDate() != null) { + return doc.getDocumentDate(); + } else { + return ""; + } + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK128ContentImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK128ContentImportStrategy.java new file mode 100644 index 000000000..1cc6884b3 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDK128ContentImportStrategy.java @@ -0,0 +1,204 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.content; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.context.ContextDocumentationIndex; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.DocIndexType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.DocumentType; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.in.path.SIARDDKPathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; + +/** + * @author António Lindo + */ +public class SIARDDK128ContentImportStrategy extends + SIARDDKContentImportStrategy { + private static final Logger logger = LoggerFactory.getLogger(SIARDDK128ContentImportStrategy.class); + + /** + * @param readStrategy + * @param pathStrategy + * @param importAsSchema + * @author Thomas Kristensen + */ + public SIARDDK128ContentImportStrategy(FolderReadStrategyMD5Sum readStrategy, SIARDDKPathImportStrategy pathStrategy, + String importAsSchema) { + super(readStrategy, pathStrategy, importAsSchema); + } + + DocIndexType loadVirtualTableContent() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(DocIndexType.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.DOC_INDEX)); + JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement.getValue(); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + @Override + ContextDocumentationIndex loadContextDocTableContent() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(ContextDocumentationIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + ContextDocumentationIndex jaxbElement = (ContextDocumentationIndex) unmarshaller + .unmarshal(inputStreamXml); + return jaxbElement; + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + @Override + List getContextDocuments(ContextDocumentationIndex contextDoc) { + return contextDoc.getDocument(); + } + + @Override + List getDocuments(DocIndexType docIndex) { + return docIndex.getDoc(); + } + + @Override + BigInteger getDID(DocumentType doc) { + return doc.getDID(); + } + + @Override + String getDCf(DocumentType doc) { + return doc.getDCf(); + } + + @Override + BigInteger getMID(DocumentType doc) { + return doc.getMID(); + } + + @Override + String getAFt(DocumentType doc) { + return doc.getAFt(); + } + + @Override + String getDocumentID(ContextDocumentationIndex.Document doc) { + return doc.getDocumentID(); + } + + @Override + String getDocumentTitle(ContextDocumentationIndex.Document doc) { + if (doc.getDocumentTitle() != null) { + return doc.getDocumentTitle(); + } else { + return ""; + } + } + + @Override + String getDocumentDate(ContextDocumentationIndex.Document doc) { + if (doc.getDocumentDate() != null) { + return doc.getDocumentDate(); + } else { + return ""; + } + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDKContentImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDKContentImportStrategy.java index 7c68168a9..dd02cb2ab 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDKContentImportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/content/SIARDDKContentImportStrategy.java @@ -2,13 +2,17 @@ * The contents of this file are subject to the license and copyright * detailed in the LICENSE file at the root of the source * tree and available online at - * + *

* https://github.com/keeps/db-preservation-toolkit */ package com.databasepreservation.modules.siard.in.content; +import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.Path; +import java.nio.file.Paths; import java.security.DigestInputStream; import java.util.Arrays; import java.util.HashMap; @@ -18,7 +22,6 @@ import java.util.regex.Pattern; import javax.xml.XMLConstants; -import jakarta.xml.bind.DatatypeConverter; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -29,6 +32,8 @@ import javax.xml.validation.ValidatorHandler; import org.apache.commons.codec.Charsets; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.TypeInfo; @@ -38,6 +43,8 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; +import com.databasepreservation.common.io.providers.DummyInputStreamProvider; +import com.databasepreservation.model.data.BinaryCell; import com.databasepreservation.model.data.Cell; import com.databasepreservation.model.data.NullCell; import com.databasepreservation.model.data.Row; @@ -52,14 +59,21 @@ import com.databasepreservation.model.structure.type.SimpleTypeBinary; import com.databasepreservation.model.structure.type.SimpleTypeString; import com.databasepreservation.model.structure.type.Type; +import com.databasepreservation.model.structure.virtual.VirtualTableStructure; import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; import com.databasepreservation.modules.siard.common.SIARDArchiveContainer.OutputContainerType; import com.databasepreservation.modules.siard.constants.SIARDConstants; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; import com.databasepreservation.modules.siard.in.path.SIARDDKPathImportStrategy; import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; import com.databasepreservation.utils.XMLUtils; -public class SIARDDKContentImportStrategy extends DefaultHandler implements ContentImportStrategy { +import jakarta.xml.bind.DatatypeConverter; + +/** + * @author Thomas Kristensen + */ +public abstract class SIARDDKContentImportStrategy extends DefaultHandler implements ContentImportStrategy { private static final Logger logger = LoggerFactory.getLogger(SIARDDKContentImportStrategy.class); protected final FolderReadStrategyMD5Sum readStrategy; protected final SIARDDKPathImportStrategy pathStrategy; @@ -87,8 +101,10 @@ public class SIARDDKContentImportStrategy extends DefaultHandler implements Cont private DatabaseStructure databaseStructure; /** + * @param readStrategy + * @param pathStrategy + * @param importAsSchema * @author Thomas Kristensen - * */ public SIARDDKContentImportStrategy(FolderReadStrategyMD5Sum readStrategy, SIARDDKPathImportStrategy pathStrategy, String importAsSchema) { @@ -108,7 +124,7 @@ public void importContent(DatabaseExportModule dbExportHandler, SIARDArchiveCont archiveContainerByAbsPath.put(mainFolder.getPath(), mainFolder); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(false); // validation is done using the - // validatorHandler + // validatorHandler saxParserFactory.setNamespaceAware(true); SAXParser saxParser = null; DigestInputStream xsdInputStream = null; @@ -121,76 +137,98 @@ public void importContent(DatabaseExportModule dbExportHandler, SIARDArchiveCont completedTablesInSchema = 0; assert (schema.getName().equals(importAsSchema)); for (TableStructure table : schema.getTables()) { - currentTable = table; - this.dbExportHandler.handleDataOpenTable(table.getId()); - rowIndex = 0; - String xsdFileName = pathStrategy.getTableXSDFilePath(schema.getName(), table.getId()); - String xmlFileName = pathStrategy.getTableXMLFilePath(schema.getName(), table.getId()); - Path archiveFolderLogicalPath = pathStrategy.getArchiveFolderPath(importAsSchema, table.getId()); - - Path archiveFolderActualPath = mainFolder.getPath().resolveSibling(archiveFolderLogicalPath); - if (!archiveContainerByAbsPath.containsKey(archiveFolderActualPath)) { - archiveContainerByAbsPath.put(archiveFolderActualPath, new SIARDArchiveContainer( - SIARDConstants.SiardVersion.DK, archiveFolderActualPath, OutputContainerType.MAIN)); - } - currentFolder = archiveContainerByAbsPath.get(archiveFolderActualPath); - ValidatorHandler validatorHandler = null; - try { - xsdInputStream = readStrategy.createInputStream(currentFolder, xsdFileName, - pathStrategy.getTableXSDFileMD5(schema.getName(), table.getId())); - - SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema xmlSchema = factory.newSchema(new StreamSource(xsdInputStream)); - validatorHandler = xmlSchema.newValidatorHandler(); - typeInfoProvider = validatorHandler.getTypeInfoProvider(); - validatorHandler.setContentHandler(this); - - // saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, - // XMLConstants.W3C_XML_SCHEMA_NS_URI); - // saxParser.setProperty(JAXP_SCHEMA_SOURCE, xsdInputStream); - } catch (SAXException e) { - logger.error("Error validating schema", e); - throw new ModuleException().withMessage("Error reading XSD file: " - + pathStrategy.getTableXSDFilePath(schema.getName(), table.getId()) + " for table:" + table.getId()) - .withCause(e); - } - DigestInputStream currentTableInputStream = readStrategy.createInputStream(currentFolder, xmlFileName, - pathStrategy.getTableXMLFileMD5(schema.getName(), table.getId())); - SAXErrorHandler saxErrorHandler = new SAXErrorHandler(); + if (!(table instanceof VirtualTableStructure)) { + currentTable = table; + this.dbExportHandler.handleDataOpenTable(table.getId()); + rowIndex = 0; + String xsdFileName = pathStrategy.getTableXSDFilePath(schema.getName(), table.getId()); + String xmlFileName = pathStrategy.getTableXMLFilePath(schema.getName(), table.getId()); + Path archiveFolderLogicalPath = pathStrategy.getArchiveFolderPath(importAsSchema, table.getId()); + + Path archiveFolderActualPath = mainFolder.getPath().resolveSibling(archiveFolderLogicalPath); + if (!archiveContainerByAbsPath.containsKey(archiveFolderActualPath)) { + archiveContainerByAbsPath.put(archiveFolderActualPath, new SIARDArchiveContainer( + SIARDConstants.SiardVersion.DK, archiveFolderActualPath, OutputContainerType.MAIN)); + } + currentFolder = archiveContainerByAbsPath.get(archiveFolderActualPath); + ValidatorHandler validatorHandler = null; + try { + xsdInputStream = readStrategy.createInputStream(currentFolder, xsdFileName, + pathStrategy.getTableXSDFileMD5(schema.getName(), table.getId())); + + SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xmlSchema = factory.newSchema(new StreamSource(xsdInputStream)); + validatorHandler = xmlSchema.newValidatorHandler(); + typeInfoProvider = validatorHandler.getTypeInfoProvider(); + validatorHandler.setContentHandler(this); + + // saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, + // XMLConstants.W3C_XML_SCHEMA_NS_URI); + // saxParser.setProperty(JAXP_SCHEMA_SOURCE, xsdInputStream); + } catch (SAXException e) { + logger.error("Error validating schema", e); + throw new ModuleException() + .withMessage("Error reading XSD file: " + + pathStrategy.getTableXSDFilePath(schema.getName(), table.getId()) + " for table:" + table.getId()) + .withCause(e); + } + DigestInputStream currentTableInputStream = readStrategy.createInputStream(currentFolder, xmlFileName, + pathStrategy.getTableXMLFileMD5(schema.getName(), table.getId())); + + SAXErrorHandler saxErrorHandler = new SAXErrorHandler(); + + try { + saxParser = saxParserFactory.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setContentHandler(validatorHandler); + // xmlReader.setErrorHandler(saxErrorHandler); + validatorHandler.setErrorHandler(saxErrorHandler); + logger.debug("begin parse of xml-file:[" + xmlFileName + "], using xsd [" + xsdFileName + "]"); + xmlReader.parse(new InputSource(currentTableInputStream)); + + } catch (SAXException e) { + throw new ModuleException() + .withMessage("A SAX error occurred during processing of XML table file for table:" + table.getId()) + .withCause(e); + } catch (IOException e) { + throw new ModuleException().withMessage("Error while reading XML table file for table:" + table.getId()) + .withCause(e); + } catch (ParserConfigurationException e) { + logger.error("Error creating XML SAXparser", e); + throw new ModuleException().withCause(e); + } - try { - saxParser = saxParserFactory.newSAXParser(); - XMLReader xmlReader = saxParser.getXMLReader(); - xmlReader.setContentHandler(validatorHandler); - // xmlReader.setErrorHandler(saxErrorHandler); - validatorHandler.setErrorHandler(saxErrorHandler); - logger.debug("begin parse of xml-file:[" + xmlFileName + "], using xsd [" + xsdFileName + "]"); - xmlReader.parse(new InputSource(currentTableInputStream)); - - } catch (SAXException e) { - throw new ModuleException() - .withMessage("A SAX error occurred during processing of XML table file for table:" + table.getId()) - .withCause(e); - } catch (IOException e) { - throw new ModuleException().withMessage("Error while reading XML table file for table:" + table.getId()) - .withCause(e); - } catch (ParserConfigurationException e) { - logger.error("Error creating XML SAXparser", e); - throw new ModuleException().withCause(e); - } + if (saxErrorHandler.hasError()) { + throw new ModuleException().withMessage( + "Parsing or validation error occurred while reading XML table file for table:" + table.getId()); - if (saxErrorHandler.hasError()) { - throw new ModuleException().withMessage( - "Parsing or validation error occurred while reading XML table file for table:" + table.getId()); + } + readStrategy.closeAndVerifyMD5Sum(currentTableInputStream); + readStrategy.closeAndVerifyMD5Sum(xsdInputStream); + + completedTablesInSchema++; + this.dbExportHandler.handleDataCloseTable(table.getId()); + } else if (table.getId().contains(SIARDDKConstants.VIRTUAL_TABLE_NAME)) { + try { + populateVirtualTable(table); + } catch (FileNotFoundException e) { + throw new ModuleException() + .withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + } else if (table.getId().contains(SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME)) { + try { + populateContextDocumentationTable(table); + } catch (FileNotFoundException e) { + throw new ModuleException() + .withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } } - - readStrategy.closeAndVerifyMD5Sum(currentTableInputStream); - readStrategy.closeAndVerifyMD5Sum(xsdInputStream); - - completedTablesInSchema++; - this.dbExportHandler.handleDataCloseTable(table.getId()); } completedSchemas++; this.dbExportHandler.handleDataCloseSchema(importAsSchema); @@ -198,6 +236,102 @@ public void importContent(DatabaseExportModule dbExportHandler, SIARDArchiveCont } + void populateContextDocumentationTable(TableStructure table) + throws ModuleException, FileNotFoundException { + F contextDoc = loadContextDocTableContent(); + currentTable = table; + this.dbExportHandler.handleDataOpenTable(table.getId()); + Cell[] cells = new Cell[table.getColumns().size()]; + for (S doc : getContextDocuments(contextDoc)) { + int rowCounter = 0; + int cellCounter = 0; + Row row = new Row(); + row.setIndex(rowCounter); + Cell documentIDCell = new SimpleCell( + SIARDDKConstants.DOCUMENT_ID + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, getDocumentID(doc)); + cells[cellCounter] = documentIDCell; + cellCounter++; + Cell documentTitleCell = new SimpleCell( + SIARDDKConstants.DOCUMENT_TITLE + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, + getDocumentTitle(doc)); + cells[cellCounter] = documentTitleCell; + cellCounter++; + Cell documentDateCell = new SimpleCell( + SIARDDKConstants.DOCUMENT_DATE + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, getDocumentDate(doc)); + cells[cellCounter] = documentDateCell; + cellCounter++; + try { + String docPath = pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + SIARDDKConstants.CONTEXT_DOCUMENTATION_FOLDER_NAME + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + SIARDDKConstants.DOC_COLLECTION_FOLDER_NAME + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + getDocumentID(doc); + String digest = ""; + File docFolder = new File(docPath); + if (docFolder.exists() && docFolder.isDirectory()) { + File[] fileList = docFolder.listFiles(); + if (fileList != null && fileList.length == 1) { + docPath = docPath + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + fileList[0].getName(); + digest = DigestUtils.sha1Hex(FileUtils.readFileToByteArray(Paths.get(docPath).toFile())); + } + } + Cell blobCell = new BinaryCell( + SIARDDKConstants.BLOB_EXTENSION + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, + new DummyInputStreamProvider(), docPath, 0L, digest, DigestUtils.getSha1Digest().toString()); + cells[cellCounter] = blobCell; + cellCounter++; + rowCounter++; + List lstCells = Arrays.asList(cells); + assert !lstCells.contains(null); + row.setCells(lstCells); + this.dbExportHandler.handleDataRow(row); + } catch (ModuleException | IOException e) { + throw new ModuleException().withMessage("Error handling data row index:" + rowCounter).withCause(e); + } + } + this.dbExportHandler.handleDataCloseTable(table.getId()); + } + + void populateVirtualTable(TableStructure table) throws ModuleException, FileNotFoundException { + D docIndex = loadVirtualTableContent(); + currentTable = table; + this.dbExportHandler.handleDataOpenTable(table.getId()); + Cell[] cells = new Cell[table.getColumns().size()]; + for (T doc : getDocuments(docIndex)) { + int rowCounter = 0; + int cellCounter = 0; + Row row = new Row(); + row.setIndex(rowCounter); + Cell dIDCell = new SimpleCell(SIARDDKConstants.DID + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, + getDID(doc).toString()); + cells[cellCounter] = dIDCell; + cellCounter++; + String binPath = pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + SIARDDKConstants.DOCUMENTS_FOLDER_NAME + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + getDCf(doc) + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + getDID(doc) + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + getMID(doc) + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + getAFt(doc); + try { + Cell blobCell = new BinaryCell( + SIARDDKConstants.BLOB_EXTENSION + SIARDDKConstants.FILE_EXTENSION_SEPARATOR + rowCounter, + new DummyInputStreamProvider(), binPath, 0L, + DigestUtils.sha1Hex(FileUtils.readFileToByteArray(Paths.get(binPath).toFile())), + DigestUtils.getSha1Digest().toString()); + cells[cellCounter] = blobCell; + cellCounter++; + rowCounter++; + List lstCells = Arrays.asList(cells); + assert !lstCells.contains(null); + row.setCells(lstCells); + this.dbExportHandler.handleDataRow(row); + } catch (ModuleException | IOException e) { + throw new ModuleException().withMessage("Error handling data row index:" + rowCounter).withCause(e); + } + } + this.dbExportHandler.handleDataCloseTable(table.getId()); + } + + abstract D loadVirtualTableContent() throws ModuleException, FileNotFoundException; + + abstract F loadContextDocTableContent() throws ModuleException, FileNotFoundException; + @Override public void startDocument() throws SAXException { isInTblTag = false; @@ -302,4 +436,21 @@ public void characters(char[] ch, int start, int length) throws SAXException { currentTagContentStrBld.append(ch, start, length); } + abstract List getContextDocuments(F contextDoc); + + abstract List getDocuments(D docIndex); + + abstract BigInteger getDID(T doc); + + abstract String getDCf(T doc); + + abstract BigInteger getMID(T doc); + + abstract String getAFt(T doc); + + abstract String getDocumentID(S doc); + + abstract String getDocumentTitle(S doc); + + abstract String getDocumentDate(S doc); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK1007ImportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK1007ImportModule.java new file mode 100644 index 000000000..3b309ee1a --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK1007ImportModule.java @@ -0,0 +1,60 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.input; + +import java.nio.file.Path; + +import com.databasepreservation.modules.siard.SIARDDK1007ModuleFactory; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.common.path.SIARDDK1007MetadataPathStrategy; +import com.databasepreservation.modules.siard.constants.SIARDConstants; +import com.databasepreservation.modules.siard.in.content.ContentImportStrategy; +import com.databasepreservation.modules.siard.in.content.SIARDDK1007ContentImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.SIARDDK1007MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.path.ResourceFileIndexInputStreamStrategy; +import com.databasepreservation.modules.siard.in.path.SIARDDK1007PathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; + +/** + * @author António Lindo + * + */ +public class SIARDDK1007ImportModule extends SIARDDKImportModule { + private static final String moduleName = "siard-dk-1007"; + + public SIARDDK1007ImportModule(Path siardPackage, String paramImportAsSchema) { + super(moduleName, siardPackage, paramImportAsSchema, + new SIARDDK1007PathImportStrategy( + new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, siardPackage.toAbsolutePath().normalize(), + SIARDArchiveContainer.OutputContainerType.MAIN), + new FolderReadStrategyMD5Sum(new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, + siardPackage.toAbsolutePath().normalize(), SIARDArchiveContainer.OutputContainerType.MAIN)), + new SIARDDK1007MetadataPathStrategy(), paramImportAsSchema, new ResourceFileIndexInputStreamStrategy())); + } + + @Override + protected MetadataImportStrategy createMetadataImportStrategy() { + return new SIARDDK1007MetadataImportStrategy((SIARDDK1007PathImportStrategy) pathStrategy, paramImportAsSchema); + } + + @Override + protected ContentImportStrategy createContentImportStrategy() { + return new SIARDDK1007ContentImportStrategy(readStrategy, pathStrategy, paramImportAsSchema); + } + + @Override + protected String getModuleFactoryParameterFolder() { + return SIARDDK1007ModuleFactory.PARAMETER_FOLDER; + } + + @Override + protected String getModuleFactoryParameterAsSchema() { + return SIARDDK1007ModuleFactory.PARAMETER_AS_SCHEMA; + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK128ImportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK128ImportModule.java new file mode 100644 index 000000000..b5250bba2 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDK128ImportModule.java @@ -0,0 +1,60 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.input; + +import com.databasepreservation.modules.siard.SIARDDK128ModuleFactory; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.common.path.SIARDDK128MetadataPathStrategy; +import com.databasepreservation.modules.siard.constants.SIARDConstants; +import com.databasepreservation.modules.siard.in.content.ContentImportStrategy; +import com.databasepreservation.modules.siard.in.content.SIARDDK128ContentImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.SIARDDK128MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.path.ResourceFileIndexInputStreamStrategy; +import com.databasepreservation.modules.siard.in.path.SIARDDK128PathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; + +import java.nio.file.Path; + +/** + * @author António Lindo + * + */ +public class SIARDDK128ImportModule extends SIARDDKImportModule { + private static final String moduleName = "siard-dk-128"; + + public SIARDDK128ImportModule(Path siardPackage, String paramImportAsSchema) { + super(moduleName, siardPackage, paramImportAsSchema, + new SIARDDK128PathImportStrategy( + new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, siardPackage.toAbsolutePath().normalize(), + SIARDArchiveContainer.OutputContainerType.MAIN), + new FolderReadStrategyMD5Sum(new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, + siardPackage.toAbsolutePath().normalize(), SIARDArchiveContainer.OutputContainerType.MAIN)), + new SIARDDK128MetadataPathStrategy(), paramImportAsSchema, new ResourceFileIndexInputStreamStrategy())); + } + + @Override + protected MetadataImportStrategy createMetadataImportStrategy() { + return new SIARDDK128MetadataImportStrategy((SIARDDK128PathImportStrategy) pathStrategy, paramImportAsSchema); + } + + @Override + protected ContentImportStrategy createContentImportStrategy() { + return new SIARDDK128ContentImportStrategy(readStrategy, pathStrategy, paramImportAsSchema); + } + + @Override + protected String getModuleFactoryParameterFolder() { + return SIARDDK128ModuleFactory.PARAMETER_FOLDER; + } + + @Override + protected String getModuleFactoryParameterAsSchema() { + return SIARDDK128ModuleFactory.PARAMETER_AS_SCHEMA; + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDKImportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDKImportModule.java index eaf86ec0e..1732f6863 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDKImportModule.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/input/SIARDDKImportModule.java @@ -1,70 +1,56 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.in.input; -import java.nio.file.Path; -import java.util.Map; - import com.databasepreservation.model.modules.DatabaseImportModule; -import com.databasepreservation.modules.siard.SIARDDKModuleFactory; import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; -import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; -import com.databasepreservation.modules.siard.common.path.SIARDDKMetadataPathStrategy; import com.databasepreservation.modules.siard.constants.SIARDConstants; import com.databasepreservation.modules.siard.in.content.ContentImportStrategy; -import com.databasepreservation.modules.siard.in.content.SIARDDKContentImportStrategy; import com.databasepreservation.modules.siard.in.metadata.MetadataImportStrategy; -import com.databasepreservation.modules.siard.in.metadata.SIARDDKMetadataImportStrategy; -import com.databasepreservation.modules.siard.in.path.ResourceFileIndexInputStreamStrategy; import com.databasepreservation.modules.siard.in.path.SIARDDKPathImportStrategy; import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; import com.databasepreservation.utils.MapUtils; +import java.nio.file.Path; +import java.util.Map; + /** * @author Thomas Kristensen * */ -public class SIARDDKImportModule { - private static final String moduleName = "siard-dk"; +public abstract class SIARDDKImportModule { protected final FolderReadStrategyMD5Sum readStrategy; protected final SIARDArchiveContainer mainContainer; protected final MetadataImportStrategy metadataStrategy; protected final ContentImportStrategy contentStrategy; + protected final SIARDDKPathImportStrategy pathStrategy; // Adicionado ao construtor + public final String paramImportAsSchema; + private final String moduleName; - private final String paramImportAsSchema; - - public SIARDDKImportModule(Path siardPackage, String paramImportAsSchema) { + public SIARDDKImportModule(String moduleName, Path siardPackage, String paramImportAsSchema, + SIARDDKPathImportStrategy pathStrategy) { + this.moduleName = moduleName; this.paramImportAsSchema = paramImportAsSchema; - mainContainer = new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, siardPackage.toAbsolutePath().normalize(), - SIARDArchiveContainer.OutputContainerType.MAIN); - readStrategy = new FolderReadStrategyMD5Sum(mainContainer); - - MetadataPathStrategy metadataPathStrategy = new SIARDDKMetadataPathStrategy(); - // Please notice, that the MetadataPathStrategy instance is wrapped into - // the SIARDDKPathImportStrategy below. + this.mainContainer = new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK, + siardPackage.toAbsolutePath().normalize(), SIARDArchiveContainer.OutputContainerType.MAIN); + this.readStrategy = new FolderReadStrategyMD5Sum(mainContainer); + this.pathStrategy = pathStrategy; // Inicializa o pathStrategy no construtor - // NOTE: if we need to use the fileIndex.xsd from a given - // "arkiverings version" then change - // the FileIndexInputStreamStrategy to ArchiveFileIndexInputStreamStrategy - SIARDDKPathImportStrategy pathStrategy = new SIARDDKPathImportStrategy(mainContainer, readStrategy, - metadataPathStrategy, paramImportAsSchema, new ResourceFileIndexInputStreamStrategy()); + this.metadataStrategy = createMetadataImportStrategy(); + this.contentStrategy = createContentImportStrategy(); + } - metadataStrategy = new SIARDDKMetadataImportStrategy(pathStrategy, paramImportAsSchema); - contentStrategy = new SIARDDKContentImportStrategy(readStrategy, pathStrategy, paramImportAsSchema); + protected abstract MetadataImportStrategy createMetadataImportStrategy(); - } + protected abstract ContentImportStrategy createContentImportStrategy(); public DatabaseImportModule getDatabaseImportModule() { - final Map properties = MapUtils.buildMapFromObjects(SIARDDKModuleFactory.PARAMETER_FOLDER, - mainContainer.getPath().normalize().toAbsolutePath().toString(), SIARDDKModuleFactory.PARAMETER_AS_SCHEMA, + final Map properties = MapUtils.buildMapFromObjects(getModuleFactoryParameterFolder(), + mainContainer.getPath().normalize().toAbsolutePath().toString(), getModuleFactoryParameterAsSchema(), paramImportAsSchema); return new SIARDImportDefault(moduleName, contentStrategy, mainContainer, readStrategy, metadataStrategy, properties); } + protected abstract String getModuleFactoryParameterFolder(); + + protected abstract String getModuleFactoryParameterAsSchema(); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK1007MetadataImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK1007MetadataImportStrategy.java new file mode 100644 index 000000000..675cd6d00 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK1007MetadataImportStrategy.java @@ -0,0 +1,596 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + *

+ * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.metadata; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.DigestInputStream; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import com.databasepreservation.Constants; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.modules.configuration.ModuleConfiguration; +import com.databasepreservation.model.reporters.Reporter; +import com.databasepreservation.model.structure.ColumnStructure; +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.model.structure.ForeignKey; +import com.databasepreservation.model.structure.PrimaryKey; +import com.databasepreservation.model.structure.Reference; +import com.databasepreservation.model.structure.SchemaStructure; +import com.databasepreservation.model.structure.TableStructure; +import com.databasepreservation.model.structure.ViewStructure; +import com.databasepreservation.model.structure.type.Type; +import com.databasepreservation.model.structure.virtual.VirtualColumnStructure; +import com.databasepreservation.model.structure.virtual.VirtualForeignKey; +import com.databasepreservation.model.structure.virtual.VirtualPrimaryKey; +import com.databasepreservation.model.structure.virtual.VirtualTableStructure; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.ArchiveIndex; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.context.ContextDocumentationIndex; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQL99StandardDatatypeImporter; +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQLStandardDatatypeImporter; +import com.databasepreservation.modules.siard.in.path.SIARDDK1007PathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; +import com.databasepreservation.modules.siard.in.read.ReadStrategy; + +import dk.sa.xmlns.diark._1_0.docindex.DocIndexType; +import dk.sa.xmlns.diark._1_0.tableindex.ColumnType; +import dk.sa.xmlns.diark._1_0.tableindex.ColumnsType; +import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeyType; +import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeysType; +import dk.sa.xmlns.diark._1_0.tableindex.FunctionalDescriptionType; +import dk.sa.xmlns.diark._1_0.tableindex.PrimaryKeyType; +import dk.sa.xmlns.diark._1_0.tableindex.ReferenceType; +import dk.sa.xmlns.diark._1_0.tableindex.SiardDiark; +import dk.sa.xmlns.diark._1_0.tableindex.TableType; +import dk.sa.xmlns.diark._1_0.tableindex.ViewType; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; + +/** + * @author Thomas Kristensen + */ +public class SIARDDK1007MetadataImportStrategy implements MetadataImportStrategy { + + protected final Logger logger = LoggerFactory.getLogger(SIARDDK1007MetadataImportStrategy.class); + + protected final SIARDDK1007PathImportStrategy pathStrategy; + protected DatabaseStructure databaseStructure; + protected final String importAsSchemaName; + private int currentTableIndex = 1; + + private SQLStandardDatatypeImporter sqlStandardDatatypeImporter; + private Reporter reporter; + + public SIARDDK1007MetadataImportStrategy(SIARDDK1007PathImportStrategy pathStrategy, String importAsSchameName) { + this.pathStrategy = pathStrategy; + this.importAsSchemaName = importAsSchameName; + sqlStandardDatatypeImporter = new SQL99StandardDatatypeImporter(); + } + + @Override + public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer container, + ModuleConfiguration moduleConfiguration) throws ModuleException { + FolderReadStrategyMD5Sum readStrategyMD5Sum = null; + if (!(readStrategy instanceof FolderReadStrategyMD5Sum)) { + throw new IllegalArgumentException( + "The current implemenation of SIARDDKMetadataImportStrategy requires relies on the FolderReadStrategyMD5Sum (should be passed to loadMetadata )."); + } + readStrategyMD5Sum = (FolderReadStrategyMD5Sum) readStrategy; + pathStrategy.parseFileIndexMetadata(); + + JAXBContext tableIndexContext; + JAXBContext archiveIndexContext; + try { + tableIndexContext = JAXBContext.newInstance(SiardDiark.class.getPackage().getName()); + archiveIndexContext = JAXBContext.newInstance(ArchiveIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema tableIndexXsdSchema = null; + Schema archiveIndexXsdSchema = null; + InputStream tableIndexXsdInputStream = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)); + InputStream archiveIndexXsdInputStream = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXsdFilePath(SIARDDKConstants.ARCHIVE_INDEX)); + try { + tableIndexXsdSchema = schemaFactory.newSchema(new StreamSource(tableIndexXsdInputStream)); + archiveIndexXsdSchema = schemaFactory.newSchema(new StreamSource(archiveIndexXsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)) + .withCause(e); + } + DigestInputStream tableIndexInputStreamXml = null; + DigestInputStream archiveIndexInputStreamXml = null; + SiardDiark xmlRoot; + ArchiveIndex archiveIndex = null; + Unmarshaller tableIndexUnmarshaller; + Unmarshaller archiveIndexUnmarshaller; + + try { + tableIndexUnmarshaller = tableIndexContext.createUnmarshaller(); + tableIndexUnmarshaller.setSchema(tableIndexXsdSchema); + tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum()); + xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml); + + archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller(); + archiveIndexUnmarshaller.setSchema(archiveIndexXsdSchema); + if (Files.exists(Paths.get(container.getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.ARCHIVE_INDEX)))) { + archiveIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXmlFilePath(SIARDDKConstants.ARCHIVE_INDEX), pathStrategy.getArchiveIndexExpectedMD5Sum()); + archiveIndex = (ArchiveIndex) archiveIndexUnmarshaller.unmarshal(archiveIndexInputStreamXml); + } + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + tableIndexXsdInputStream.close(); + archiveIndexXsdInputStream.close(); + + if (tableIndexInputStreamXml != null) { + readStrategyMD5Sum.closeAndVerifyMD5Sum(tableIndexInputStreamXml); + } + + if (archiveIndexInputStreamXml != null) { + readStrategyMD5Sum.closeAndVerifyMD5Sum(archiveIndexInputStreamXml); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + + databaseStructure = getDatabaseStructure(xmlRoot, archiveIndex); + } + + @Override + public DatabaseStructure getDatabaseStructure() throws ModuleException { + if (databaseStructure != null) { + return databaseStructure; + } else { + throw new ModuleException().withMessage("getDatabaseStructure must not be called before loadMetadata"); + } + } + + @Override + public void setOnceReporter(Reporter reporter) { + this.reporter = reporter; + sqlStandardDatatypeImporter.setOnceReporter(reporter); + } + + protected DatabaseStructure getDatabaseStructure(SiardDiark siardArchive, ArchiveIndex archiveIndex) + throws ModuleException { + DatabaseStructure databaseStructure = new DatabaseStructure(); + databaseStructure.setProductName(siardArchive.getDatabaseProduct()); + databaseStructure.setSchemas(getSchemas(siardArchive)); + if (archiveIndex != null) { + setDatabaseMetadata(siardArchive, databaseStructure, archiveIndex); + } else { + databaseStructure.setName(siardArchive.getDbName()); + } + return databaseStructure; + } + + protected void setDatabaseMetadata(SiardDiark siardArchive, DatabaseStructure databaseStructure, + ArchiveIndex archiveIndex) { + databaseStructure.setDbOriginalName(siardArchive.getDbName()); + String[] informationPackageIdSPlit = archiveIndex.getArchiveInformationPackageID().split("\\."); + String id = informationPackageIdSPlit[informationPackageIdSPlit.length - 1]; + databaseStructure.setName(id + ": " + archiveIndex.getSystemName()); + DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); + DateTime formattedDate = formatter.parseDateTime(archiveIndex.getArchivePeriodEnd()); + databaseStructure.setArchivalDate(formattedDate); + databaseStructure.setDataOriginTimespan(archiveIndex.getArchivePeriodStart() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + archiveIndex.getArchivePeriodEnd()); + StringBuilder creatorsList = new StringBuilder(); + List> creatorListElements = archiveIndex.getArchiveCreatorList() + .getCreatorNameAndCreationPeriodStartAndCreationPeriodEnd(); + for (int i = 0; i < creatorListElements.size(); i++) { + JAXBElement element = creatorListElements.get(i); + if (element.getName().getLocalPart().equals(SIARDDKConstants.CREATOR_NAME)) { + creatorsList.append(element.getValue()); + + boolean isLastCreatorName = true; + for (int j = i + 1; j < creatorListElements.size(); j++) { + if (creatorListElements.get(j).getName().getLocalPart().equals(SIARDDKConstants.CREATOR_NAME)) { + isLastCreatorName = false; + break; + } + } + + if (!isLastCreatorName) { + creatorsList.append("; "); + } + } + } + + databaseStructure.setDataOwner(creatorsList.toString()); + databaseStructure.setDescription(archiveIndex.getSystemPurpose()); + } + + protected List getSchemas(SiardDiark siardArchive) throws ModuleException { + SchemaStructure schemaImportAs = new SchemaStructure(); + schemaImportAs.setName(getImportAsSchemaName()); + schemaImportAs.setTables(getTables(siardArchive)); + schemaImportAs.setViews(getViews(siardArchive)); + List list = new LinkedList(); + list.add(schemaImportAs); + + return list; + + } + + protected List getViews(SiardDiark siardArchive) { + List lstViewsDptkl = new LinkedList(); + if (siardArchive.getViews() != null && siardArchive.getViews().getView() != null) { + for (ViewType viewXml : siardArchive.getViews().getView()) { + ViewStructure viewDptkl = new ViewStructure(); + if (StringUtils.isNotBlank(viewXml.getDescription())) { + viewDptkl.setDescription(viewXml.getDescription()); + } + viewDptkl.setName(viewXml.getName()); + viewDptkl.setQueryOriginal(viewXml.getQueryOriginal()); + // NOTICE: As siard-dk only support defining the query original + // attribute - + // we'll use it for both the query and the query original field in the + // internal representation of the view. + viewDptkl.setQuery(viewXml.getQueryOriginal()); + lstViewsDptkl.add(viewDptkl); + } + } + return lstViewsDptkl; + } + + protected List getTables(SiardDiark siardArchive) throws ModuleException { + List lstTblsDptkl = new LinkedList(); + if (siardArchive.getTables() != null && siardArchive.getTables().getTable() != null) { + boolean needsVirtualTable = false; + for (TableType tblXml : siardArchive.getTables().getTable()) { + TableStructure tblDptkl = new TableStructure(); + tblDptkl.setIndex(currentTableIndex++); + tblDptkl.setSchema(getImportAsSchemaName()); + tblDptkl.setName(tblXml.getName()); + tblDptkl.setId(String.format("%s.%s", tblDptkl.getSchema(), tblDptkl.getName())); + tblDptkl.setDescription(tblXml.getDescription()); + tblDptkl.setPrimaryKey(getPrimaryKey(tblXml.getPrimaryKey())); + tblDptkl.setForeignKeys(getForeignKeys(tblXml.getForeignKeys(), tblDptkl.getId())); + tblDptkl.setRows(getNumberOfTblRows(tblXml.getRows(), tblXml.getName())); + tblDptkl.setColumns(getTblColumns(tblXml.getColumns(), tblDptkl.getId())); + List virtualForeignKeys = getVirtualForeignKeys(tblXml.getColumns(), tblDptkl.getId()); + if (!virtualForeignKeys.isEmpty()) { + tblDptkl.getForeignKeys().addAll(virtualForeignKeys); + needsVirtualTable = true; + } + pathStrategy.associateTableWithFolder(tblDptkl.getId(), tblXml.getFolder()); + lstTblsDptkl.add(tblDptkl); + } + if (needsVirtualTable) { + lstTblsDptkl.add(createVirtualTable()); + } + TableStructure contextDocumentationTable = createContextDocumentationTable(); + if (contextDocumentationTable != null) { + lstTblsDptkl.add(contextDocumentationTable); + } + } + return lstTblsDptkl; + } + + private TableStructure createContextDocumentationTable() throws ModuleException { + try { + ContextDocumentationIndex contextDocumentationIndex = loadContextDocumentationTableMetadata(); + if (contextDocumentationIndex == null) { + return null; + } else { + VirtualTableStructure virtualTable = new VirtualTableStructure(); + virtualTable.setIndex(currentTableIndex++); + virtualTable.setSchema(getImportAsSchemaName()); + virtualTable.setId( + String.format("%s.%s", virtualTable.getSchema(), SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME)); + virtualTable.setName(SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME); + virtualTable.setDescription(SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_DESCRIPTION); + virtualTable.setRows(contextDocumentationIndex.getDocument().size()); + virtualTable.setColumns(createContextDocumentsTableColumns()); + virtualTable.setPrimaryKey(createVirtualPrimaryKey( + SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_PRIMARY_KEY_NAME, SIARDDKConstants.DID)); + return virtualTable; + } + } catch (FileNotFoundException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + } + + private ContextDocumentationIndex loadContextDocumentationTableMetadata() + throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(ContextDocumentationIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + String contextDocumentationIndexFilePath = pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX); + if (Paths.get(contextDocumentationIndexFilePath).toFile().exists()) { + inputStreamXml = new FileInputStream(contextDocumentationIndexFilePath); + ContextDocumentationIndex jaxbElement = (ContextDocumentationIndex) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement; + } else { + return null; + } + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + private DocIndexType loadVirtualTableMetadata() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(DocIndexType.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + pathStrategy.getXmlFilePath(SIARDDKConstants.DOC_INDEX)); + JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement.getValue(); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + private List getVirtualForeignKeys(ColumnsType columns, String tableId) { + List virtualForeignKeys = new ArrayList<>(); + for (ColumnType column : columns.getColumn()) { + if (column.getFunctionalDescription() != null + && column.getFunctionalDescription().contains(FunctionalDescriptionType.DOKUMENTIDENTIFIKATION)) { + VirtualForeignKey virtualForeignKey = new VirtualForeignKey(); + virtualForeignKey.setReferencedSchema(getImportAsSchemaName()); + virtualForeignKey.setName(SIARDDKConstants.VIRTUAL_TABLE_FOREIGN_KEY_NAME); + virtualForeignKey.setReferencedTable(SIARDDKConstants.VIRTUAL_TABLE_NAME); + Reference reference = new Reference(column.getName(), SIARDDKConstants.DID); + List referenceList = new ArrayList<>(); + referenceList.add(reference); + virtualForeignKey.setReferences(referenceList); + virtualForeignKey.setId(String.format("%s.%s", tableId, SIARDDKConstants.VIRTUAL_TABLE_FOREIGN_KEY_NAME)); + virtualForeignKeys.add(virtualForeignKey); + } + } + + return virtualForeignKeys; + } + + private TableStructure createVirtualTable() throws ModuleException { + try { + DocIndexType docIndexType = loadVirtualTableMetadata(); + VirtualTableStructure virtualTable = new VirtualTableStructure(); + virtualTable.setIndex(currentTableIndex++); + virtualTable.setSchema(getImportAsSchemaName()); + virtualTable.setId(String.format("%s.%s", virtualTable.getSchema(), SIARDDKConstants.VIRTUAL_TABLE_NAME)); + virtualTable.setName(SIARDDKConstants.VIRTUAL_TABLE_NAME); + virtualTable.setDescription(SIARDDKConstants.VIRTUAL_TABLE_DESCRIPTION); + virtualTable.setRows(docIndexType.getDoc().size()); + virtualTable.setColumns(createVirtualTableColumns()); + virtualTable + .setPrimaryKey(createVirtualPrimaryKey(SIARDDKConstants.VIRTUAL_TABLE_PRIMARY_KEY_NAME, SIARDDKConstants.DID)); + return virtualTable; + } catch (FileNotFoundException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + } + + private List createContextDocumentsTableColumns() { + List columnStructureList = new ArrayList<>(); + Type typeInt = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "INTEGER", "INTEGER"); + Type typeChar = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "CHARACTER", "CHARACTER"); + Type typeBlob = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", Constants.BINARY_LARGE_OBJECT, + Constants.BINARY_LARGE_OBJECT); + VirtualColumnStructure columnID = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_ID, SIARDDKConstants.DOCUMENT_ID, typeInt, + true, SIARDDKConstants.DOCUMENT_IDENTIFIER, "1", true); + VirtualColumnStructure columnTitle = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_TITLE, SIARDDKConstants.DOCUMENT_TITLE, typeChar, + true, SIARDDKConstants.DOCUMENT_TITLE_DESCRIPTION, "", true); + VirtualColumnStructure columnDate = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_DATE, SIARDDKConstants.DOCUMENT_DATE, typeChar, + true, SIARDDKConstants.DOCUMENT_DATE_DESCRIPTION, "", true); + VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, typeBlob, true, + "", "1", true); + columnStructureList.add(columnID); + columnStructureList.add(columnTitle); + columnStructureList.add(columnDate); + columnStructureList.add(columnLOB); + return columnStructureList; + } + + private List createVirtualTableColumns() { + List columnStructureList = new ArrayList<>(); + Type typeInt = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "INTEGER", "INTEGER"); + VirtualColumnStructure columnID = new VirtualColumnStructure(SIARDDKConstants.DID, SIARDDKConstants.DID, typeInt, + true, SIARDDKConstants.DOCUMENT_IDENTIFIER, "1", true); + Type type = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", Constants.BINARY_LARGE_OBJECT, + Constants.BINARY_LARGE_OBJECT); + VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, type, true, + "", "1", true); + columnStructureList.add(columnID); + columnStructureList.add(columnLOB); + return columnStructureList; + } + + private PrimaryKey createVirtualPrimaryKey(String name, String columnName) { + List columnList = new ArrayList<>(); + columnList.add(columnName); + return new VirtualPrimaryKey(name, columnList, SIARDDKConstants.VIRTUAL_TABLE_PRIMARY_KEY_DESCRIPTION); + } + + protected List getTblColumns(ColumnsType columnsXml, String tableId) throws ModuleException { + List lstColumnsDptkl = new LinkedList(); + if (columnsXml != null && columnsXml.getColumn() != null) { + for (ColumnType columnXml : columnsXml.getColumn()) { + ColumnStructure columnDptkl = new ColumnStructure(); + columnDptkl.setName(columnXml.getName()); + columnDptkl.setId(String.format("%s.%s", tableId, columnDptkl.getName())); + String typeOriginal = StringUtils.isNotBlank(columnXml.getTypeOriginal()) ? columnXml.getTypeOriginal() : null; + columnDptkl + .setType(sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", columnXml.getType(), typeOriginal)); + columnDptkl.setDescription(columnXml.getDescription()); + String defaultValue = StringUtils.isNotBlank(columnXml.getDefaultValue()) ? columnXml.getDefaultValue() : null; + columnDptkl.setDefaultValue(defaultValue); + columnDptkl.setNillable(columnXml.isNullable()); + lstColumnsDptkl.add(columnDptkl); + } + } + return lstColumnsDptkl; + } + + protected Type getType(String type) { + + return null; + } + + protected long getNumberOfTblRows(BigInteger numRows, String tableName) throws ModuleException { + try { + return numRows.longValue(); + } catch (ArithmeticException e) { + throw new ModuleException().withMessage("Unable to import table [" + tableName + "], as the number of rows [" + + numRows + + "] exceeds the max value of the long datatype used to store the number.(Consult the vendor/a programmer for a fix of this problem, if needed)") + .withCause(e); + } + } + + protected PrimaryKey getPrimaryKey(PrimaryKeyType primaryKeyXml) { + PrimaryKey keyDptkl = new PrimaryKey(); + keyDptkl.setName(primaryKeyXml.getName()); + keyDptkl.setColumnNames(primaryKeyXml.getColumn()); + return keyDptkl; + } + + protected List getForeignKeys(ForeignKeysType foreignKeysXml, String tableId) { + List lstForeignKeyDptkl = new LinkedList(); + if (foreignKeysXml != null) { + for (ForeignKeyType foreignKeyXml : foreignKeysXml.getForeignKey()) { + ForeignKey foreignKeyDptkl = new ForeignKey(); + foreignKeyDptkl.setReferencedSchema(getImportAsSchemaName()); + foreignKeyDptkl.setName(foreignKeyXml.getName()); + foreignKeyDptkl.setReferencedTable(foreignKeyXml.getReferencedTable()); + foreignKeyDptkl.setReferences(getReferences(foreignKeyXml.getReference())); + foreignKeyDptkl.setId(String.format("%s.%s", tableId, foreignKeyDptkl.getName())); + lstForeignKeyDptkl.add(foreignKeyDptkl); + } + } + return lstForeignKeyDptkl; + } + + protected List getReferences(List referencesXml) { + List refsDptkld = new LinkedList(); + if (referencesXml != null) { + for (ReferenceType referenceTypeXml : referencesXml) { + Reference refDptkld = new Reference(); + refDptkld.setColumn(referenceTypeXml.getColumn()); + refDptkld.setReferenced(referenceTypeXml.getReferenced()); + refsDptkld.add(refDptkld); + } + } + return refsDptkld; + } + + public String getImportAsSchemaName() { + return importAsSchemaName; + } + +} \ No newline at end of file diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK128MetadataImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK128MetadataImportStrategy.java new file mode 100644 index 000000000..7e596ab00 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK128MetadataImportStrategy.java @@ -0,0 +1,594 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + *

+ * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.metadata; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.DigestInputStream; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import com.databasepreservation.Constants; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.modules.configuration.ModuleConfiguration; +import com.databasepreservation.model.reporters.Reporter; +import com.databasepreservation.model.structure.ColumnStructure; +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.model.structure.ForeignKey; +import com.databasepreservation.model.structure.PrimaryKey; +import com.databasepreservation.model.structure.Reference; +import com.databasepreservation.model.structure.SchemaStructure; +import com.databasepreservation.model.structure.TableStructure; +import com.databasepreservation.model.structure.ViewStructure; +import com.databasepreservation.model.structure.type.Type; +import com.databasepreservation.model.structure.virtual.VirtualColumnStructure; +import com.databasepreservation.model.structure.virtual.VirtualForeignKey; +import com.databasepreservation.model.structure.virtual.VirtualPrimaryKey; +import com.databasepreservation.model.structure.virtual.VirtualTableStructure; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ArchiveIndex; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ColumnsType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.DocIndexType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeyType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ForeignKeysType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.FunctionalDescriptionType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.PrimaryKeyType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ReferenceType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.SiardDiark; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.TableType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.ViewType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.context.ContextDocumentationIndex; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQL99StandardDatatypeImporter; +import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQLStandardDatatypeImporter; +import com.databasepreservation.modules.siard.in.path.SIARDDK128PathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; +import com.databasepreservation.modules.siard.in.read.ReadStrategy; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; + +/** + * @author Thomas Kristensen + */ +public class SIARDDK128MetadataImportStrategy implements MetadataImportStrategy { + + protected final Logger logger = LoggerFactory.getLogger(SIARDDK128MetadataImportStrategy.class); + + protected final SIARDDK128PathImportStrategy pathStrategy; + protected DatabaseStructure databaseStructure; + protected final String importAsSchemaName; + private int currentTableIndex = 1; + + private SQLStandardDatatypeImporter sqlStandardDatatypeImporter; + private Reporter reporter; + + public SIARDDK128MetadataImportStrategy(SIARDDK128PathImportStrategy pathStrategy, String importAsSchameName) { + this.pathStrategy = pathStrategy; + this.importAsSchemaName = importAsSchameName; + sqlStandardDatatypeImporter = new SQL99StandardDatatypeImporter(); + } + + @Override + public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer container, + ModuleConfiguration moduleConfiguration) throws ModuleException { + FolderReadStrategyMD5Sum readStrategyMD5Sum = null; + if (!(readStrategy instanceof FolderReadStrategyMD5Sum)) { + throw new IllegalArgumentException( + "The current implemenation of SIARDDKMetadataImportStrategy requires relies on the FolderReadStrategyMD5Sum (should be passed to loadMetadata )."); + } + readStrategyMD5Sum = (FolderReadStrategyMD5Sum) readStrategy; + pathStrategy.parseFileIndexMetadata(); + + JAXBContext tableIndexContext; + JAXBContext archiveIndexContext; + try { + tableIndexContext = JAXBContext.newInstance(SiardDiark.class.getPackage().getName()); + archiveIndexContext = JAXBContext.newInstance(ArchiveIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema tableIndexXsdSchema = null; + Schema archiveIndexXsdSchema = null; + InputStream tableIndexXsdInputStream = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)); + InputStream archiveIndexXsdInputStream = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXsdFilePath(SIARDDKConstants.ARCHIVE_INDEX)); + try { + tableIndexXsdSchema = schemaFactory.newSchema(new StreamSource(tableIndexXsdInputStream)); + archiveIndexXsdSchema = schemaFactory.newSchema(new StreamSource(archiveIndexXsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)) + .withCause(e); + } + DigestInputStream tableIndexInputStreamXml = null; + DigestInputStream archiveIndexInputStreamXml = null; + SiardDiark xmlRoot; + ArchiveIndex archiveIndex = null; + Unmarshaller tableIndexUnmarshaller; + Unmarshaller archiveIndexUnmarshaller; + + try { + tableIndexUnmarshaller = tableIndexContext.createUnmarshaller(); + tableIndexUnmarshaller.setSchema(tableIndexXsdSchema); + tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum()); + xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml); + + archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller(); + archiveIndexUnmarshaller.setSchema(archiveIndexXsdSchema); + if (Files.exists(Paths.get(container.getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.ARCHIVE_INDEX)))) { + archiveIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container, + pathStrategy.getXmlFilePath(SIARDDKConstants.ARCHIVE_INDEX), pathStrategy.getArchiveIndexExpectedMD5Sum()); + archiveIndex = (ArchiveIndex) archiveIndexUnmarshaller.unmarshal(archiveIndexInputStreamXml); + } + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + tableIndexXsdInputStream.close(); + archiveIndexXsdInputStream.close(); + + if (tableIndexInputStreamXml != null) { + readStrategyMD5Sum.closeAndVerifyMD5Sum(tableIndexInputStreamXml); + } + + if (archiveIndexInputStreamXml != null) { + readStrategyMD5Sum.closeAndVerifyMD5Sum(archiveIndexInputStreamXml); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + + databaseStructure = getDatabaseStructure(xmlRoot, archiveIndex); + } + + @Override + public DatabaseStructure getDatabaseStructure() throws ModuleException { + if (databaseStructure != null) { + return databaseStructure; + } else { + throw new ModuleException().withMessage("getDatabaseStructure must not be called before loadMetadata"); + } + } + + @Override + public void setOnceReporter(Reporter reporter) { + this.reporter = reporter; + sqlStandardDatatypeImporter.setOnceReporter(reporter); + } + + protected DatabaseStructure getDatabaseStructure(SiardDiark siardArchive, ArchiveIndex archiveIndex) + throws ModuleException { + DatabaseStructure databaseStructure = new DatabaseStructure(); + databaseStructure.setProductName(siardArchive.getDatabaseProduct()); + databaseStructure.setSchemas(getSchemas(siardArchive)); + if (archiveIndex != null) { + setDatabaseMetadata(siardArchive, databaseStructure, archiveIndex); + } else { + databaseStructure.setName(siardArchive.getDbName()); + } + return databaseStructure; + } + + protected void setDatabaseMetadata(SiardDiark siardArchive, DatabaseStructure databaseStructure, + ArchiveIndex archiveIndex) { + databaseStructure.setDbOriginalName(siardArchive.getDbName()); + String[] informationPackageIdSPlit = archiveIndex.getArchiveInformationPackageID().split("\\."); + String id = informationPackageIdSPlit[informationPackageIdSPlit.length - 1]; + databaseStructure.setName(id + ": " + archiveIndex.getSystemName()); + DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); + DateTime formattedDate = formatter.parseDateTime(archiveIndex.getArchivePeriodEnd()); + databaseStructure.setArchivalDate(formattedDate); + databaseStructure.setDataOriginTimespan(archiveIndex.getArchivePeriodStart() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + archiveIndex.getArchivePeriodEnd()); + StringBuilder creatorsList = new StringBuilder(); + List> creatorListElements = archiveIndex.getArchiveCreatorList() + .getCreatorNameAndCreationPeriodStartAndCreationPeriodEnd(); + for (int i = 0; i < creatorListElements.size(); i++) { + JAXBElement element = creatorListElements.get(i); + if (element.getName().getLocalPart().equals(SIARDDKConstants.CREATOR_NAME)) { + creatorsList.append(element.getValue()); + + boolean isLastCreatorName = true; + for (int j = i + 1; j < creatorListElements.size(); j++) { + if (creatorListElements.get(j).getName().getLocalPart().equals(SIARDDKConstants.CREATOR_NAME)) { + isLastCreatorName = false; + break; + } + } + + if (!isLastCreatorName) { + creatorsList.append("; "); + } + } + } + + databaseStructure.setDataOwner(creatorsList.toString()); + databaseStructure.setDescription(archiveIndex.getSystemPurpose()); + } + + protected List getSchemas(SiardDiark siardArchive) throws ModuleException { + SchemaStructure schemaImportAs = new SchemaStructure(); + schemaImportAs.setName(getImportAsSchemaName()); + schemaImportAs.setTables(getTables(siardArchive)); + schemaImportAs.setViews(getViews(siardArchive)); + List list = new LinkedList(); + list.add(schemaImportAs); + + return list; + + } + + protected List getViews(SiardDiark siardArchive) { + List lstViewsDptkl = new LinkedList(); + if (siardArchive.getViews() != null && siardArchive.getViews().getView() != null) { + for (ViewType viewXml : siardArchive.getViews().getView()) { + ViewStructure viewDptkl = new ViewStructure(); + if (StringUtils.isNotBlank(viewXml.getDescription())) { + viewDptkl.setDescription(viewXml.getDescription()); + } + viewDptkl.setName(viewXml.getName()); + viewDptkl.setQueryOriginal(viewXml.getQueryOriginal()); + // NOTICE: As siard-dk only support defining the query original + // attribute - + // we'll use it for both the query and the query original field in the + // internal representation of the view. + viewDptkl.setQuery(viewXml.getQueryOriginal()); + lstViewsDptkl.add(viewDptkl); + } + } + return lstViewsDptkl; + } + + protected List getTables(SiardDiark siardArchive) throws ModuleException { + List lstTblsDptkl = new LinkedList(); + if (siardArchive.getTables() != null && siardArchive.getTables().getTable() != null) { + boolean needsVirtualTable = false; + for (TableType tblXml : siardArchive.getTables().getTable()) { + TableStructure tblDptkl = new TableStructure(); + tblDptkl.setIndex(currentTableIndex++); + tblDptkl.setSchema(getImportAsSchemaName()); + tblDptkl.setName(tblXml.getName()); + tblDptkl.setId(String.format("%s.%s", tblDptkl.getSchema(), tblDptkl.getName())); + tblDptkl.setDescription(tblXml.getDescription()); + tblDptkl.setPrimaryKey(getPrimaryKey(tblXml.getPrimaryKey())); + tblDptkl.setForeignKeys(getForeignKeys(tblXml.getForeignKeys(), tblDptkl.getId())); + tblDptkl.setRows(getNumberOfTblRows(tblXml.getRows(), tblXml.getName())); + tblDptkl.setColumns(getTblColumns(tblXml.getColumns(), tblDptkl.getId())); + List virtualForeignKeys = getVirtualForeignKeys(tblXml.getColumns(), tblDptkl.getId()); + if (!virtualForeignKeys.isEmpty()) { + tblDptkl.getForeignKeys().addAll(virtualForeignKeys); + needsVirtualTable = true; + } + pathStrategy.associateTableWithFolder(tblDptkl.getId(), tblXml.getFolder()); + lstTblsDptkl.add(tblDptkl); + } + if (needsVirtualTable) { + lstTblsDptkl.add(createVirtualTable()); + } + TableStructure contextDocumentationTable = createContextDocumentationTable(); + if (contextDocumentationTable != null) { + lstTblsDptkl.add(contextDocumentationTable); + } + } + return lstTblsDptkl; + } + + private TableStructure createContextDocumentationTable() throws ModuleException { + try { + ContextDocumentationIndex contextDocumentationIndex = loadContextDocumentationTableMetadata(); + if (contextDocumentationIndex == null) { + return null; + } else { + VirtualTableStructure virtualTable = new VirtualTableStructure(); + virtualTable.setIndex(currentTableIndex++); + virtualTable.setSchema(getImportAsSchemaName()); + virtualTable.setId( + String.format("%s.%s", virtualTable.getSchema(), SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME)); + virtualTable.setName(SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_NAME); + virtualTable.setDescription(SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_DESCRIPTION); + virtualTable.setRows(contextDocumentationIndex.getDocument().size()); + virtualTable.setColumns(createContextDocumentsTableColumns()); + virtualTable.setPrimaryKey(createVirtualPrimaryKey( + SIARDDKConstants.CONTEXT_DOCUMENTATION_VIRTUAL_TABLE_PRIMARY_KEY_NAME, SIARDDKConstants.DID)); + return virtualTable; + } + } catch (FileNotFoundException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + } + + private ContextDocumentationIndex loadContextDocumentationTableMetadata() + throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(ContextDocumentationIndex.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream( + pathStrategy.getMainFolder().getPath().toString() + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)); + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException().withMessage( + "Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + String contextDocumentationIndexFilePath = pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + + pathStrategy.getXmlFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX); + if (Paths.get(contextDocumentationIndexFilePath).toFile().exists()) { + inputStreamXml = new FileInputStream(contextDocumentationIndexFilePath); + ContextDocumentationIndex jaxbElement = (ContextDocumentationIndex) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement; + } else { + return null; + } + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + private DocIndexType loadVirtualTableMetadata() throws ModuleException, FileNotFoundException { + JAXBContext context; + try { + context = JAXBContext.newInstance(DocIndexType.class.getPackage().getName()); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); + } + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema xsdSchema = null; + InputStream xsdInputStream = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)); + + try { + xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); + } catch (SAXException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + InputStream inputStreamXml = null; + Unmarshaller unmarshaller; + try { + unmarshaller = context.createUnmarshaller(); + unmarshaller.setSchema(xsdSchema); + inputStreamXml = new FileInputStream(pathStrategy.getMainFolder().getPath().toString() + + SIARDDKConstants.RESOURCE_FILE_SEPARATOR + pathStrategy.getXmlFilePath(SIARDDKConstants.DOC_INDEX)); + JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(inputStreamXml); + return jaxbElement.getValue(); + } catch (JAXBException e) { + throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); + } finally { + try { + xsdInputStream.close(); + if (inputStreamXml != null) { + inputStreamXml.close(); + xsdInputStream.close(); + } + } catch (IOException e) { + logger.debug("Could not close xsdStream", e); + } + } + } + + private List getVirtualForeignKeys(ColumnsType columns, String tableId) { + List virtualForeignKeys = new ArrayList<>(); + for (ColumnType column : columns.getColumn()) { + if (column.getFunctionalDescription() != null + && column.getFunctionalDescription().contains(FunctionalDescriptionType.DOKUMENTIDENTIFIKATION)) { + VirtualForeignKey virtualForeignKey = new VirtualForeignKey(); + virtualForeignKey.setReferencedSchema(getImportAsSchemaName()); + virtualForeignKey.setName(SIARDDKConstants.VIRTUAL_TABLE_FOREIGN_KEY_NAME); + virtualForeignKey.setReferencedTable(SIARDDKConstants.VIRTUAL_TABLE_NAME); + Reference reference = new Reference(column.getName(), SIARDDKConstants.DID); + List referenceList = new ArrayList<>(); + referenceList.add(reference); + virtualForeignKey.setReferences(referenceList); + virtualForeignKey.setId(String.format("%s.%s", tableId, SIARDDKConstants.VIRTUAL_TABLE_FOREIGN_KEY_NAME)); + virtualForeignKeys.add(virtualForeignKey); + } + } + + return virtualForeignKeys; + } + + private TableStructure createVirtualTable() throws ModuleException { + try { + DocIndexType docIndexType = loadVirtualTableMetadata(); + VirtualTableStructure virtualTable = new VirtualTableStructure(); + virtualTable.setIndex(currentTableIndex++); + virtualTable.setSchema(getImportAsSchemaName()); + virtualTable.setId(String.format("%s.%s", virtualTable.getSchema(), SIARDDKConstants.VIRTUAL_TABLE_NAME)); + virtualTable.setName(SIARDDKConstants.VIRTUAL_TABLE_NAME); + virtualTable.setDescription(SIARDDKConstants.VIRTUAL_TABLE_DESCRIPTION); + virtualTable.setRows(docIndexType.getDoc().size()); + virtualTable.setColumns(createVirtualTableColumns()); + virtualTable + .setPrimaryKey(createVirtualPrimaryKey(SIARDDKConstants.VIRTUAL_TABLE_PRIMARY_KEY_NAME, SIARDDKConstants.DID)); + return virtualTable; + } catch (FileNotFoundException e) { + throw new ModuleException() + .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.DOC_INDEX)) + .withCause(e); + } + } + + private List createContextDocumentsTableColumns() { + List columnStructureList = new ArrayList<>(); + Type typeInt = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "INTEGER", "INTEGER"); + Type typeChar = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "CHARACTER", "CHARACTER"); + Type typeBlob = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", Constants.BINARY_LARGE_OBJECT, + Constants.BINARY_LARGE_OBJECT); + VirtualColumnStructure columnID = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_ID, + SIARDDKConstants.DOCUMENT_ID, typeInt, true, SIARDDKConstants.DOCUMENT_IDENTIFIER, "1", true); + VirtualColumnStructure columnTitle = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_TITLE, + SIARDDKConstants.DOCUMENT_TITLE, typeChar, true, SIARDDKConstants.DOCUMENT_TITLE_DESCRIPTION, "", true); + VirtualColumnStructure columnDate = new VirtualColumnStructure(SIARDDKConstants.DOCUMENT_DATE, + SIARDDKConstants.DOCUMENT_DATE, typeChar, true, SIARDDKConstants.DOCUMENT_DATE_DESCRIPTION, "", true); + VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, typeBlob, true, + "", "1", true); + columnStructureList.add(columnID); + columnStructureList.add(columnTitle); + columnStructureList.add(columnDate); + columnStructureList.add(columnLOB); + return columnStructureList; + } + + private List createVirtualTableColumns() { + List columnStructureList = new ArrayList<>(); + Type typeInt = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", "INTEGER", "INTEGER"); + VirtualColumnStructure columnID = new VirtualColumnStructure(SIARDDKConstants.DID, SIARDDKConstants.DID, typeInt, + true, SIARDDKConstants.DOCUMENT_IDENTIFIER, "1", true); + Type type = sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", Constants.BINARY_LARGE_OBJECT, + Constants.BINARY_LARGE_OBJECT); + VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, type, true, + "", "1", true); + columnStructureList.add(columnID); + columnStructureList.add(columnLOB); + return columnStructureList; + } + + private PrimaryKey createVirtualPrimaryKey(String name, String columnName) { + List columnList = new ArrayList<>(); + columnList.add(columnName); + return new VirtualPrimaryKey(name, columnList, SIARDDKConstants.VIRTUAL_TABLE_PRIMARY_KEY_DESCRIPTION); + } + + protected List getTblColumns(ColumnsType columnsXml, String tableId) throws ModuleException { + List lstColumnsDptkl = new LinkedList(); + if (columnsXml != null && columnsXml.getColumn() != null) { + for (ColumnType columnXml : columnsXml.getColumn()) { + ColumnStructure columnDptkl = new ColumnStructure(); + columnDptkl.setName(columnXml.getName()); + columnDptkl.setId(String.format("%s.%s", tableId, columnDptkl.getName())); + String typeOriginal = StringUtils.isNotBlank(columnXml.getTypeOriginal()) ? columnXml.getTypeOriginal() : null; + columnDptkl + .setType(sqlStandardDatatypeImporter.getCheckedType("", "", + "", "", columnXml.getType(), typeOriginal)); + columnDptkl.setDescription(columnXml.getDescription()); + String defaultValue = StringUtils.isNotBlank(columnXml.getDefaultValue()) ? columnXml.getDefaultValue() : null; + columnDptkl.setDefaultValue(defaultValue); + columnDptkl.setNillable(columnXml.isNullable()); + lstColumnsDptkl.add(columnDptkl); + } + } + return lstColumnsDptkl; + } + + protected Type getType(String type) { + + return null; + } + + protected long getNumberOfTblRows(BigInteger numRows, String tableName) throws ModuleException { + try { + return numRows.longValue(); + } catch (ArithmeticException e) { + throw new ModuleException().withMessage("Unable to import table [" + tableName + "], as the number of rows [" + + numRows + + "] exceeds the max value of the long datatype used to store the number.(Consult the vendor/a programmer for a fix of this problem, if needed)") + .withCause(e); + } + } + + protected PrimaryKey getPrimaryKey(PrimaryKeyType primaryKeyXml) { + PrimaryKey keyDptkl = new PrimaryKey(); + keyDptkl.setName(primaryKeyXml.getName()); + keyDptkl.setColumnNames(primaryKeyXml.getColumn()); + return keyDptkl; + } + + protected List getForeignKeys(ForeignKeysType foreignKeysXml, String tableId) { + List lstForeignKeyDptkl = new LinkedList(); + if (foreignKeysXml != null) { + for (ForeignKeyType foreignKeyXml : foreignKeysXml.getForeignKey()) { + ForeignKey foreignKeyDptkl = new ForeignKey(); + foreignKeyDptkl.setReferencedSchema(getImportAsSchemaName()); + foreignKeyDptkl.setName(foreignKeyXml.getName()); + foreignKeyDptkl.setReferencedTable(foreignKeyXml.getReferencedTable()); + foreignKeyDptkl.setReferences(getReferences(foreignKeyXml.getReference())); + foreignKeyDptkl.setId(String.format("%s.%s", tableId, foreignKeyDptkl.getName())); + lstForeignKeyDptkl.add(foreignKeyDptkl); + } + } + return lstForeignKeyDptkl; + } + + protected List getReferences(List referencesXml) { + List refsDptkld = new LinkedList(); + if (referencesXml != null) { + for (ReferenceType referenceTypeXml : referencesXml) { + Reference refDptkld = new Reference(); + refDptkld.setColumn(referenceTypeXml.getColumn()); + refDptkld.setReferenced(referenceTypeXml.getReferenced()); + refsDptkld.add(refDptkld); + } + } + return refsDptkld; + } + + public String getImportAsSchemaName() { + return importAsSchemaName; + } +} \ No newline at end of file diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDKMetadataImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDKMetadataImportStrategy.java deleted file mode 100644 index 65ef950ca..000000000 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDKMetadataImportStrategy.java +++ /dev/null @@ -1,295 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ -package com.databasepreservation.modules.siard.in.metadata; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.DigestInputStream; -import java.util.LinkedList; -import java.util.List; - -import javax.xml.XMLConstants; -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; -import jakarta.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xml.sax.SAXException; - -import com.databasepreservation.model.reporters.Reporter; -import com.databasepreservation.model.exception.ModuleException; -import com.databasepreservation.model.modules.configuration.ModuleConfiguration; -import com.databasepreservation.model.structure.ColumnStructure; -import com.databasepreservation.model.structure.DatabaseStructure; -import com.databasepreservation.model.structure.ForeignKey; -import com.databasepreservation.model.structure.PrimaryKey; -import com.databasepreservation.model.structure.Reference; -import com.databasepreservation.model.structure.SchemaStructure; -import com.databasepreservation.model.structure.TableStructure; -import com.databasepreservation.model.structure.ViewStructure; -import com.databasepreservation.model.structure.type.Type; -import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQL99StandardDatatypeImporter; -import com.databasepreservation.modules.siard.in.metadata.typeConverter.SQLStandardDatatypeImporter; -import com.databasepreservation.modules.siard.in.path.SIARDDKPathImportStrategy; -import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; -import com.databasepreservation.modules.siard.in.read.ReadStrategy; - -import dk.sa.xmlns.diark._1_0.tableindex.ColumnType; -import dk.sa.xmlns.diark._1_0.tableindex.ColumnsType; -import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeyType; -import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeysType; -import dk.sa.xmlns.diark._1_0.tableindex.PrimaryKeyType; -import dk.sa.xmlns.diark._1_0.tableindex.ReferenceType; -import dk.sa.xmlns.diark._1_0.tableindex.SiardDiark; -import dk.sa.xmlns.diark._1_0.tableindex.TableType; -import dk.sa.xmlns.diark._1_0.tableindex.ViewType; - -/** - * @author Thomas Kristensen - * - */ -public class SIARDDKMetadataImportStrategy implements MetadataImportStrategy { - - protected final Logger logger = LoggerFactory.getLogger(SIARDDKMetadataImportStrategy.class); - - protected final SIARDDKPathImportStrategy pathStrategy; - protected DatabaseStructure databaseStructure; - protected final String importAsSchemaName; - private int currentTableIndex = 1; - - private SQLStandardDatatypeImporter sqlStandardDatatypeImporter; - private Reporter reporter; - - public SIARDDKMetadataImportStrategy(SIARDDKPathImportStrategy pathStrategy, String importAsSchameName) { - this.pathStrategy = pathStrategy; - this.importAsSchemaName = importAsSchameName; - sqlStandardDatatypeImporter = new SQL99StandardDatatypeImporter(); - } - - @Override - public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer container, - ModuleConfiguration moduleConfiguration) throws ModuleException { - FolderReadStrategyMD5Sum readStrategyMD5Sum = null; - if (!(readStrategy instanceof FolderReadStrategyMD5Sum)) { - throw new IllegalArgumentException( - "The current implemenation of SIARDDKMetadataImportStrategy requires relies on the FolderReadStrategyMD5Sum (should be passed to loadMetadata )."); - } - readStrategyMD5Sum = (FolderReadStrategyMD5Sum) readStrategy; - pathStrategy.parseFileIndexMetadata(); - - JAXBContext context; - try { - context = JAXBContext.newInstance(SiardDiark.class.getPackage().getName()); - } catch (JAXBException e) { - throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); - } - - SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema xsdSchema = null; - InputStream xsdInputStream = readStrategyMD5Sum.createInputStream(container, - pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)); - - try { - xsdSchema = schemaFactory.newSchema(new StreamSource(xsdInputStream)); - } catch (SAXException e) { - throw new ModuleException() - .withMessage("Error reading metadata XSD file: " + pathStrategy.getXsdFilePath(SIARDDKConstants.TABLE_INDEX)) - .withCause(e); - } - DigestInputStream inputStreamXml = null; - SiardDiark xmlRoot; - Unmarshaller unmarshaller; - try { - unmarshaller = context.createUnmarshaller(); - unmarshaller.setSchema(xsdSchema); - inputStreamXml = readStrategyMD5Sum.createInputStream(container, - pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum()); - xmlRoot = (SiardDiark) unmarshaller.unmarshal(inputStreamXml); - } catch (JAXBException e) { - throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); - } finally { - try { - xsdInputStream.close(); - if (inputStreamXml != null) { - readStrategyMD5Sum.closeAndVerifyMD5Sum(inputStreamXml); - } - } catch (IOException e) { - logger.debug("Could not close xsdStream", e); - } - } - - databaseStructure = getDatabaseStructure(xmlRoot); - - } - - @Override - public DatabaseStructure getDatabaseStructure() throws ModuleException { - if (databaseStructure != null) { - return databaseStructure; - } else { - throw new ModuleException().withMessage("getDatabaseStructure must not be called before loadMetadata"); - } - } - - @Override - public void setOnceReporter(Reporter reporter) { - this.reporter = reporter; - sqlStandardDatatypeImporter.setOnceReporter(reporter); - } - - protected DatabaseStructure getDatabaseStructure(SiardDiark siardArchive) throws ModuleException { - DatabaseStructure databaseStructure = new DatabaseStructure(); - databaseStructure.setName(siardArchive.getDbName()); - databaseStructure.setProductName(siardArchive.getDatabaseProduct()); - databaseStructure.setSchemas(getSchemas(siardArchive)); - - return databaseStructure; - - } - - protected List getSchemas(SiardDiark siardArchive) throws ModuleException { - SchemaStructure schemaImportAs = new SchemaStructure(); - schemaImportAs.setName(getImportAsSchemaName()); - schemaImportAs.setTables(getTables(siardArchive)); - schemaImportAs.setViews(getViews(siardArchive)); - List list = new LinkedList(); - list.add(schemaImportAs); - - return list; - - } - - protected List getViews(SiardDiark siardArchive) { - List lstViewsDptkl = new LinkedList(); - if (siardArchive.getViews() != null && siardArchive.getViews().getView() != null) { - for (ViewType viewXml : siardArchive.getViews().getView()) { - ViewStructure viewDptkl = new ViewStructure(); - if (StringUtils.isNotBlank(viewXml.getDescription())) { - viewDptkl.setDescription(viewXml.getDescription()); - } - viewDptkl.setName(viewXml.getName()); - viewDptkl.setQueryOriginal(viewXml.getQueryOriginal()); - // NOTICE: As siard-dk only support defining the query original - // attribute - - // we'll use it for both the query and the query original field in the - // internal representation of the view. - viewDptkl.setQuery(viewXml.getQueryOriginal()); - lstViewsDptkl.add(viewDptkl); - } - } - return lstViewsDptkl; - } - - protected List getTables(SiardDiark siardArchive) throws ModuleException { - List lstTblsDptkl = new LinkedList(); - - if (siardArchive.getTables() != null && siardArchive.getTables().getTable() != null) { - for (TableType tblXml : siardArchive.getTables().getTable()) { - TableStructure tblDptkl = new TableStructure(); - tblDptkl.setIndex(currentTableIndex++); - tblDptkl.setSchema(getImportAsSchemaName()); - tblDptkl.setName(tblXml.getName()); - tblDptkl.setId(String.format("%s.%s", tblDptkl.getSchema(), tblDptkl.getName())); - tblDptkl.setDescription(tblXml.getDescription()); - tblDptkl.setPrimaryKey(getPrimaryKey(tblXml.getPrimaryKey())); - tblDptkl.setForeignKeys(getForeignKeys(tblXml.getForeignKeys(), tblDptkl.getId())); - tblDptkl.setRows(getNumberOfTblRows(tblXml.getRows(), tblXml.getName())); - tblDptkl.setColumns(getTblColumns(tblXml.getColumns(), tblDptkl.getId())); - pathStrategy.associateTableWithFolder(tblDptkl.getId(), tblXml.getFolder()); - lstTblsDptkl.add(tblDptkl); - } - } - return lstTblsDptkl; - } - - protected List getTblColumns(ColumnsType columnsXml, String tableId) throws ModuleException { - List lstColumnsDptkl = new LinkedList(); - if (columnsXml != null && columnsXml.getColumn() != null) { - for (ColumnType columnXml : columnsXml.getColumn()) { - ColumnStructure columnDptkl = new ColumnStructure(); - columnDptkl.setName(columnXml.getName()); - columnDptkl.setId(String.format("%s.%s", tableId, columnDptkl.getName())); - String typeOriginal = StringUtils.isNotBlank(columnXml.getTypeOriginal()) ? columnXml.getTypeOriginal() : null; - columnDptkl - .setType(sqlStandardDatatypeImporter.getCheckedType("", "", - "", "", columnXml.getType(), typeOriginal)); - columnDptkl.setDescription(columnXml.getDescription()); - String defaultValue = StringUtils.isNotBlank(columnXml.getDefaultValue()) ? columnXml.getDefaultValue() : null; - columnDptkl.setDefaultValue(defaultValue); - columnDptkl.setNillable(columnXml.isNullable()); - lstColumnsDptkl.add(columnDptkl); - } - } - return lstColumnsDptkl; - } - - protected Type getType(String type) { - - return null; - } - - protected long getNumberOfTblRows(BigInteger numRows, String tableName) throws ModuleException { - try { - return numRows.longValue(); - } catch (ArithmeticException e) { - throw new ModuleException().withMessage("Unable to import table [" + tableName + "], as the number of rows [" - + numRows - + "] exceeds the max value of the long datatype used to store the number.(Consult the vendor/a programmer for a fix of this problem, if needed)") - .withCause(e); - } - } - - protected PrimaryKey getPrimaryKey(PrimaryKeyType primaryKeyXml) { - PrimaryKey keyDptkl = new PrimaryKey(); - keyDptkl.setName(primaryKeyXml.getName()); - keyDptkl.setColumnNames(primaryKeyXml.getColumn()); - return keyDptkl; - } - - protected List getForeignKeys(ForeignKeysType foreignKeysXml, String tableId) { - List lstForeignKeyDptkl = new LinkedList(); - if (foreignKeysXml != null) { - for (ForeignKeyType foreignKeyXml : foreignKeysXml.getForeignKey()) { - ForeignKey foreignKeyDptkl = new ForeignKey(); - foreignKeyDptkl.setReferencedSchema(getImportAsSchemaName()); - foreignKeyDptkl.setName(foreignKeyXml.getName()); - foreignKeyDptkl.setReferencedTable(foreignKeyXml.getReferencedTable()); - foreignKeyDptkl.setReferences(getReferences(foreignKeyXml.getReference())); - foreignKeyDptkl.setId(String.format("%s.%s", tableId, foreignKeyDptkl.getName())); - lstForeignKeyDptkl.add(foreignKeyDptkl); - } - } - return lstForeignKeyDptkl; - } - - protected List getReferences(List referencesXml) { - List refsDptkld = new LinkedList(); - if (referencesXml != null) { - for (ReferenceType referenceTypeXml : referencesXml) { - Reference refDptkld = new Reference(); - refDptkld.setColumn(referenceTypeXml.getColumn()); - refDptkld.setReferenced(referenceTypeXml.getReferenced()); - refsDptkld.add(refDptkld); - } - } - return refsDptkld; - } - - public String getImportAsSchemaName() { - return importAsSchemaName; - } - -} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/typeConverter/SQLStandardDatatypeImporter.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/typeConverter/SQLStandardDatatypeImporter.java index e22238f5b..e6c64d13b 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/typeConverter/SQLStandardDatatypeImporter.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/typeConverter/SQLStandardDatatypeImporter.java @@ -163,8 +163,13 @@ protected Type getNationalCharType(String typeName, int columnSize, int decimalD @Override protected Type getCharType(String typeName, int columnSize, int decimalDigits, int numPrecRadix) { SimpleTypeString type = new SimpleTypeString(columnSize, false); - type.setSql99TypeName("CHARACTER", columnSize); - type.setSql2008TypeName("CHARACTER", columnSize); + if (columnSize == 0) { + type.setSql99TypeName("CHARACTER"); + type.setSql2008TypeName("CHARACTER"); + } else { + type.setSql99TypeName("CHARACTER", columnSize); + type.setSql2008TypeName("CHARACTER", columnSize); + } return type; } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ArchiveFileIndexInputStreamStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ArchiveFileIndexInputStreamStrategy.java index bd3da9638..0b4836911 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ArchiveFileIndexInputStreamStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ArchiveFileIndexInputStreamStrategy.java @@ -19,7 +19,6 @@ * */ class ArchiveFileIndexInputStreamStrategy implements FileIndexXsdInputStreamStrategy { - /* * (non-Javadoc) * @@ -29,10 +28,10 @@ class ArchiveFileIndexInputStreamStrategy implements FileIndexXsdInputStreamStra * SIARDDKPathImportStrategy) */ @Override - public InputStream getInputStream(SIARDDKPathImportStrategy siarddkPathImportStrategy) throws ModuleException { - ReadStrategy readStrategy = siarddkPathImportStrategy.getReadStrategy(); - SIARDArchiveContainer mainFolder = siarddkPathImportStrategy.getMainFolder(); - String xsdFilePath = siarddkPathImportStrategy.getXsdFilePath(SIARDDKConstants.FILE_INDEX); + public InputStream getInputStream(SIARDDKPathImportStrategy strategy) throws ModuleException { + ReadStrategy readStrategy = strategy.getReadStrategy(); + SIARDArchiveContainer mainFolder = strategy.getMainFolder(); + String xsdFilePath = strategy.getXsdFilePath(SIARDDKConstants.FILE_INDEX); return readStrategy.createInputStream(mainFolder, xsdFilePath); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/FileIndexXsdInputStreamStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/FileIndexXsdInputStreamStrategy.java index cf7cd8167..9b904ff99 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/FileIndexXsdInputStreamStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/FileIndexXsdInputStreamStrategy.java @@ -17,5 +17,5 @@ */ interface FileIndexXsdInputStreamStrategy { - InputStream getInputStream(SIARDDKPathImportStrategy siarddkPathImportStrategy) throws ModuleException; + InputStream getInputStream(SIARDDKPathImportStrategy strategy) throws ModuleException; } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ResourceFileIndexInputStreamStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ResourceFileIndexInputStreamStrategy.java index b2a1a8733..283f7f2c4 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ResourceFileIndexInputStreamStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/ResourceFileIndexInputStreamStrategy.java @@ -25,9 +25,15 @@ public class ResourceFileIndexInputStreamStrategy implements FileIndexXsdInputSt * #getInputStream(com.databasepreservation.modules.siard.in.path. * SIARDDKPathImportStrategy) */ + @Override - public InputStream getInputStream(SIARDDKPathImportStrategy siarddkPathImportStrategy) throws ModuleException { - return this.getClass().getClassLoader().getResourceAsStream("schema/fileIndex.xsd"); + public InputStream getInputStream(SIARDDKPathImportStrategy strategy) throws ModuleException { + if (strategy instanceof SIARDDK1007PathImportStrategy) { + return this.getClass().getClassLoader().getResourceAsStream("schema/1007/fileIndex.xsd"); + } else if (strategy instanceof SIARDDK128PathImportStrategy) { + return this.getClass().getClassLoader().getResourceAsStream("schema/128/fileIndex.xsd"); + } else { + throw new ModuleException(); + } } - } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK1007PathImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK1007PathImportStrategy.java new file mode 100644 index 000000000..20969bcd7 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK1007PathImportStrategy.java @@ -0,0 +1,49 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.path; + +import java.util.List; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType; +import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType.F; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.in.read.ReadStrategy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; + +/** + * @author António Lindo + */ +public class SIARDDK1007PathImportStrategy extends SIARDDKPathImportStrategy { + protected final Logger logger = LoggerFactory.getLogger(ContentPathImportStrategy.class); + + public SIARDDK1007PathImportStrategy(SIARDArchiveContainer mainFolder, ReadStrategy readStrategy, MetadataPathStrategy metadataPathStrategy, String importAsSchema, FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy) { + super(mainFolder, readStrategy, metadataPathStrategy, importAsSchema, fileIndexXsdInputStreamStrategy, FileIndexType.class); + } + + @Override + byte[] getMd5(F fileInfo) { + return fileInfo.getMd5(); + } + + @Override + List getF(FileIndexType fileIndex) { + return fileIndex.getF(); + } + + @Override + String getFoN(F fileInfo) { + return fileInfo.getFoN(); + } + + @Override + String getFiN(F fileInfo) { + return fileInfo.getFiN(); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK128PathImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK128PathImportStrategy.java new file mode 100644 index 000000000..7f768485c --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK128PathImportStrategy.java @@ -0,0 +1,48 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.in.path; + +import com.databasepreservation.modules.siard.bindings.siard_dk_128.FileIndexType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.FileIndexType.F; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; +import com.databasepreservation.modules.siard.in.read.ReadStrategy; + +import java.util.List; + +/** + * @author António Lindo + */ +public class SIARDDK128PathImportStrategy extends SIARDDKPathImportStrategy { + + public SIARDDK128PathImportStrategy(SIARDArchiveContainer mainFolder, ReadStrategy readStrategy, + MetadataPathStrategy metadataPathStrategy, String importAsSchema, + FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy) { + super(mainFolder, readStrategy, metadataPathStrategy, importAsSchema, fileIndexXsdInputStreamStrategy, FileIndexType.class); + } + + @Override + byte[] getMd5(F fileInfo) { + return fileInfo.getMd5(); + } + + @Override + List getF(FileIndexType fileIndex) { + return fileIndex.getF(); + } + + @Override + String getFoN(F fileInfo) { + return fileInfo.getFoN(); + } + + @Override + String getFiN(F fileInfo) { + return fileInfo.getFiN(); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDKPathImportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDKPathImportStrategy.java index ff3200ec5..1c68db878 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDKPathImportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDKPathImportStrategy.java @@ -1,12 +1,23 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.in.path; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.in.read.ReadStrategy; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; import java.io.IOException; import java.io.InputStream; import java.nio.file.FileSystems; @@ -17,45 +28,23 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.XMLConstants; -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBElement; -import jakarta.xml.bind.JAXBException; -import jakarta.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xml.sax.SAXException; - -import com.databasepreservation.model.exception.ModuleException; -import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; -import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.in.read.ReadStrategy; - -import dk.sa.xmlns.diark._1_0.fileindex.FileIndexType; -import dk.sa.xmlns.diark._1_0.fileindex.FileIndexType.F; - /** * @author Thomas Kristensen - * + * * NOTICE: The SIARDDKPathImportStrategy implements both the * ContentPathImportStrategy and the MetadataPathStrategy. Both are * consolidated in one file, as both rely on parsing the fileIndex.xml, * to retrieve md5sums.(The impl. of retrieval of md5sums for the meta * data files are only implemented to the extend that it is needed. ) */ -public class SIARDDKPathImportStrategy implements ContentPathImportStrategy, MetadataPathStrategy { +public abstract class SIARDDKPathImportStrategy implements ContentPathImportStrategy, MetadataPathStrategy { protected final Logger logger = LoggerFactory.getLogger(ContentPathImportStrategy.class); protected final String importAsSchema; protected final SIARDArchiveContainer mainFolder; protected final ReadStrategy readStrategy; protected final MetadataPathStrategy metadataPathStrategy; - protected final Map xmlFilePathLookupByFolderName = new HashMap(); - protected final Map xsdFilePathLookupByFolderName = new HashMap(); + protected final Map xmlFilePathLookupByFolderName = new HashMap(); + protected final Map xsdFilePathLookupByFolderName = new HashMap(); protected final Map folderNameLookupByTableId = new HashMap(); protected final Map archiveFolderLookupByFolderName = new HashMap(); @@ -65,17 +54,20 @@ public class SIARDDKPathImportStrategy implements ContentPathImportStrategy, Met // protected byte[] fileIndexExpectedMD5Sum; --For some reason, no md5sum is // required for fileIndex.xml in the standard protected byte[] tabelIndexExpectedMD5Sum; + protected byte[] archiveIndexExpectedMD5Sum; protected boolean fileIndexIsParsed; + private final Class fileIndexTypeClass; public SIARDDKPathImportStrategy(SIARDArchiveContainer mainFolder, ReadStrategy readStrategy, MetadataPathStrategy metadataPathStrategy, String importAsSchema, - FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy) { + FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy, Class fileIndexTypeClass) { super(); this.mainFolder = mainFolder; this.readStrategy = readStrategy; this.metadataPathStrategy = metadataPathStrategy; this.importAsSchema = importAsSchema; this.fileIndexXsdInputStreamStrategy = fileIndexXsdInputStreamStrategy; + this.fileIndexTypeClass = fileIndexTypeClass; } public void parseFileIndexMetadata() throws ModuleException { @@ -83,7 +75,7 @@ public void parseFileIndexMetadata() throws ModuleException { if (!fileIndexIsParsed) { JAXBContext context; try { - context = JAXBContext.newInstance(FileIndexType.class.getPackage().getName()); + context = JAXBContext.newInstance(fileIndexTypeClass.getPackage().getName()); } catch (JAXBException e) { throw new ModuleException().withMessage("Error loading JAXBContext").withCause(e); } @@ -100,7 +92,7 @@ public void parseFileIndexMetadata() throws ModuleException { .withCause(e); } InputStream reader = null; - FileIndexType xmlFileIndex; + D xmlFileIndex; Unmarshaller unmarshaller; try { unmarshaller = context.createUnmarshaller(); @@ -108,7 +100,7 @@ public void parseFileIndexMetadata() throws ModuleException { reader = readStrategy.createInputStream(mainFolder, metadataPathStrategy.getXmlFilePath(SIARDDKConstants.FILE_INDEX)); @SuppressWarnings("unchecked") - JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(reader); + JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(reader); xmlFileIndex = jaxbElement.getValue(); } catch (JAXBException e) { throw new ModuleException().withMessage("Error while Unmarshalling JAXB").withCause(e); @@ -128,20 +120,20 @@ public void parseFileIndexMetadata() throws ModuleException { Pattern patternIndicesFolder = Pattern.compile("AVID\\.[A-ZÆØÅ]{2,4}\\.[0-9]*\\.1\\\\Indices"); - for (F fileInfo : xmlFileIndex.getF()) { - Matcher mTblFldr = patternTableFolder.matcher(fileInfo.getFoN()); + for (T fileInfo : getF(xmlFileIndex)) { + Matcher mTblFldr = patternTableFolder.matcher(getFoN(fileInfo)); if (mTblFldr.matches()) { String folderName = mTblFldr.group(2); Path archivePath = FileSystems.getDefault().getPath(mTblFldr.group(1)); archiveFolderLookupByFolderName.put(folderName, archivePath); - if (fileInfo.getFiN().toLowerCase().endsWith(SIARDDKConstants.XML_EXTENSION)) { + if (getFiN(fileInfo).toLowerCase().endsWith(SIARDDKConstants.XML_EXTENSION)) { if (xmlFilePathLookupByFolderName.containsKey(folderName)) { throw new ModuleException().withMessage("Inconsistent data in the " + SIARDDKConstants.FILE_INDEX + " for table files. Multiple entries for the xml file for folder [" + folderName + "]."); } xmlFilePathLookupByFolderName.put(folderName, fileInfo); } else { - if (fileInfo.getFiN().toLowerCase().endsWith(SIARDDKConstants.XSD_EXTENSION)) { + if (getFiN(fileInfo).toLowerCase().endsWith(SIARDDKConstants.XSD_EXTENSION)) { if (xsdFilePathLookupByFolderName.containsKey(folderName)) { throw new ModuleException().withMessage("Inconsistent data in the " + SIARDDKConstants.FILE_INDEX + " for table files. Multiple entries for the xsd file for folder [" + folderName + "]."); @@ -150,17 +142,20 @@ public void parseFileIndexMetadata() throws ModuleException { } } } else { - Matcher mIndicesFldr = patternIndicesFolder.matcher(fileInfo.getFoN()); + Matcher mIndicesFldr = patternIndicesFolder.matcher(getFoN(fileInfo)); if (mIndicesFldr.matches()) { // please notice, that this is a rudimentary implementation, only // considering the files relevant for the SIARDDK import module. - if (fileInfo.getFiN().equals(SIARDDKConstants.TABLE_INDEX + "." + SIARDDKConstants.XML_EXTENSION)) { - tabelIndexExpectedMD5Sum = fileInfo.getMd5(); - } /* - * else { if (fileInfo.getFiN().equals(SIARDDKConstants.FILE_INDEX + "." + - * SIARDDKConstants.XML_EXTENSION)) { fileIndexExpectedMD5Sum = - * fileInfo.getMd5(); } - */ + if (getFiN(fileInfo).equals(SIARDDKConstants.TABLE_INDEX + "." + SIARDDKConstants.XML_EXTENSION)) { + tabelIndexExpectedMD5Sum = getMd5(fileInfo); + } else if (getFiN(fileInfo).equals(SIARDDKConstants.ARCHIVE_INDEX + "." + SIARDDKConstants.XML_EXTENSION)) { + archiveIndexExpectedMD5Sum = getMd5(fileInfo); + } + /* + * else { if (fileInfo.getFiN().equals(SIARDDKConstants.FILE_INDEX + "." + + * SIARDDKConstants.XML_EXTENSION)) { fileIndexExpectedMD5Sum = + * fileInfo.getMd5(); } + */ } } @@ -217,7 +212,16 @@ public String getTableXMLFilePath(String schemaName, String tableId) throws Modu } public byte[] getTableXMLFileMD5(String schemaName, String tableId) throws ModuleException { - return getTableXMLFileInfo(schemaName, tableId).getMd5(); + return getMd5(getTableXMLFileInfo(schemaName, tableId)); + } + + public byte[] getArchiveIndexExpectedMD5Sum() throws ModuleException { + if (archiveIndexExpectedMD5Sum == null && fileIndexIsParsed) { + throw new ModuleException() + .withMessage("Parsing of " + SIARDDKConstants.FILE_INDEX + "." + SIARDDKConstants.XML_EXTENSION + + " did not provide a md5sum for " + SIARDDKConstants.ARCHIVE_INDEX + "." + SIARDDKConstants.XML_EXTENSION); + } + return archiveIndexExpectedMD5Sum; } protected void canLookupXSDFilePath(String folderName) throws ModuleException { @@ -228,25 +232,25 @@ protected void canLookupXSDFilePath(String folderName) throws ModuleException { } } - protected F getTableXMLFileInfo(String schemaName, String tableId) throws ModuleException { + protected T getTableXMLFileInfo(String schemaName, String tableId) throws ModuleException { canLookupTable(schemaName, tableId); String folderName = folderNameLookupByTableId.get(tableId); canLookupXMLFilePath(folderName); return xmlFilePathLookupByFolderName.get(folderName); } - protected F getTableXSDFileInfo(String schemaName, String tableId) throws ModuleException { + protected T getTableXSDFileInfo(String schemaName, String tableId) throws ModuleException { canLookupTable(schemaName, tableId); String folderName = folderNameLookupByTableId.get(tableId); canLookupXSDFilePath(folderName); return xsdFilePathLookupByFolderName.get(folderName); } - protected String buildPathSansArchiveFolderName(F fileInfo) { + protected String buildPathSansArchiveFolderName(T fileInfo) { Path pathFolderSperatorNeutral = FileSystems.getDefault().getPath("", - folderSperatorPattern.split(fileInfo.getFoN())); + folderSperatorPattern.split(getFoN(fileInfo))); pathFolderSperatorNeutral = pathFolderSperatorNeutral.subpath(1, pathFolderSperatorNeutral.getNameCount()); - Path pathFolderSperatorNeutralWithFile = pathFolderSperatorNeutral.resolve(fileInfo.getFiN()); + Path pathFolderSperatorNeutralWithFile = pathFolderSperatorNeutral.resolve(getFiN(fileInfo)); return pathFolderSperatorNeutralWithFile.toString(); } @@ -256,7 +260,7 @@ public String getTableXSDFilePath(String schemaName, String tableId) throws Modu } public byte[] getTableXSDFileMD5(String schemaName, String tableId) throws ModuleException { - return getTableXSDFileInfo(schemaName, tableId).getMd5(); + return getMd5(getTableXSDFileInfo(schemaName, tableId)); } public Path getArchiveFolderPath(String schemaName, String tableId) throws ModuleException { @@ -312,4 +316,12 @@ public ReadStrategy getReadStrategy() { public SIARDArchiveContainer getMainFolder() { return mainFolder; } + + abstract byte[] getMd5(T fileInfo); + + abstract List getF(D fileIndex); + + abstract String getFoN(T fileInfo); + + abstract String getFiN(T fileInfo); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/content/SIARDDKContentExportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/content/SIARDDKContentExportStrategy.java index cdcf098f5..1173e90b8 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/content/SIARDDKContentExportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/content/SIARDDKContentExportStrategy.java @@ -1,12 +1,3 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ -// TODO: this class needs some cleaning up - package com.databasepreservation.modules.siard.out.content; import java.io.BufferedInputStream; @@ -27,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.data.BinaryCell; import com.databasepreservation.model.data.Cell; import com.databasepreservation.model.data.ComposedCell; @@ -35,6 +25,7 @@ import com.databasepreservation.model.data.Row; import com.databasepreservation.model.data.SimpleCell; import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.structure.ColumnStructure; import com.databasepreservation.model.structure.SchemaStructure; import com.databasepreservation.model.structure.TableStructure; @@ -42,22 +33,18 @@ import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; import com.databasepreservation.modules.siard.constants.SIARDConstants; import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.out.metadata.DocIndexFileStrategy; -import com.databasepreservation.modules.siard.out.metadata.FileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKDocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKFileIndexFileStrategy; import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; import com.databasepreservation.modules.siard.out.path.ContentPathExportStrategy; import com.databasepreservation.modules.siard.out.write.WriteStrategy; -/** - * @author Andreas Kring - * - */ public class SIARDDKContentExportStrategy implements ContentExportStrategy { private static final String ENCODING = "utf-8"; private static final String TAB = " "; private static final String namespaceBase = "http://www.sa.dk/xmlns/siard/" - + SIARDConstants.SiardVersion.DK.getNamespace() + "/"; + + SIARDConstants.SiardVersion.DK.getNamespace() + "/"; private static final Logger logger = LoggerFactory.getLogger(SIARDDKContentExportStrategy.class); private int tableCounter; @@ -65,8 +52,8 @@ public class SIARDDKContentExportStrategy implements ContentExportStrategy { private boolean foundUnknownMimetype; private final ContentPathExportStrategy contentPathExportStrategy; - private final FileIndexFileStrategy fileIndexFileStrategy; - private final DocIndexFileStrategy docIndexFileStrategy; + private final SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy; + private final SIARDDKDocIndexFileStrategy SIARDDKDocIndexFileStrategy; private final SIARDArchiveContainer baseContainer; private OutputStream tableXmlOutputStream; private OutputStream tableXsdOutputStream; @@ -86,8 +73,8 @@ public SIARDDKContentExportStrategy(SIARDDKExportModule siarddkExportModule) { mimetypeHandler = new SIARDDKMimetypeHandler(); contentPathExportStrategy = siarddkExportModule.getContentPathExportStrategy(); - fileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); - docIndexFileStrategy = siarddkExportModule.getDocIndexFileStrategy(); + SIARDDKFileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); + SIARDDKDocIndexFileStrategy = siarddkExportModule.getDocIndexFileStrategy(); baseContainer = siarddkExportModule.getMainContainer(); writeStrategy = siarddkExportModule.getWriteStrategy(); lobsTracker = siarddkExportModule.getLobsTracker(); @@ -108,8 +95,8 @@ public void closeSchema(SchemaStructure schema) throws ModuleException { @Override public void openTable(TableStructure tableStructure) throws ModuleException { - tableXmlOutputStream = fileIndexFileStrategy.getWriter(baseContainer, - contentPathExportStrategy.getTableXmlFilePath(0, tableCounter), writeStrategy); + tableXmlOutputStream = SIARDDKFileIndexFileStrategy.getWriter(baseContainer, + contentPathExportStrategy.getTableXmlFilePath(0, tableCounter), writeStrategy); try { tableXmlWriter = new BufferedWriter(new OutputStreamWriter(tableXmlOutputStream, ENCODING)); @@ -123,11 +110,11 @@ public void openTable(TableStructure tableStructure) throws ModuleException { StringBuilder builder = new StringBuilder(); builder.append("\n") - .append("").append("\n"); + .append("
").append("\n"); try { tableXmlWriter.write(builder.toString()); @@ -140,14 +127,14 @@ public void openTable(TableStructure tableStructure) throws ModuleException { // Set namespaces for schema Namespace defaultNamespace = Namespace - .getNamespace(contentPathExportStrategy.getTableXsdNamespace(namespaceBase, 0, tableCounter)); + .getNamespace(contentPathExportStrategy.getTableXsdNamespace(namespaceBase, 0, tableCounter)); Namespace xs = Namespace.getNamespace("xs", "http://www.w3.org/2001/XMLSchema"); // Create root element Element schema = new Element("schema", xs); schema.addNamespaceDeclaration(defaultNamespace); schema.setAttribute("targetNamespace", - contentPathExportStrategy.getTableXsdNamespace(namespaceBase, 0, tableCounter)); + contentPathExportStrategy.getTableXsdNamespace(namespaceBase, 0, tableCounter)); schema.setAttribute("elementFormDefault", "qualified"); schema.setAttribute("attributeFormDefault", "unqualified"); @@ -185,15 +172,15 @@ public void openTable(TableStructure tableStructure) throws ModuleException { // Register LOB in the LOBsTracker if (SIARDDKConstants.BINARY_LARGE_OBJECT.equals(sql99Type) - || SIARDDKConstants.CHARACTER_LARGE_OBJECT.equals(sql99Type)) { + || SIARDDKConstants.CHARACTER_LARGE_OBJECT.equals(sql99Type)) { lobsTracker.addLOBLocationAndType(tableCounter, columnIndex, sql99Type); } String xsdType = SIARDDKsql99ToXsdType.convert(sql99Type); if (xsdType == null) { throw new ModuleException().withMessage( - "Unable to export column [" + columnStructure.getName() + "] in table [" + tableStructure.getName() - + "], as siard-dk doesn't support the normalized SQL data type of the column: [" + sql99Type + "] "); + "Unable to export column [" + columnStructure.getName() + "] in table [" + tableStructure.getName() + + "], as siard-dk doesn't support the normalized SQL data type of the column: [" + sql99Type + "] "); } c.setAttribute("type", xsdType); @@ -212,8 +199,8 @@ public void openTable(TableStructure tableStructure) throws ModuleException { // TO-DO: unfortunate name below: getLOBWriter (change the // FileIndexFileStrategy) - tableXsdOutputStream = fileIndexFileStrategy.getLOBWriter(baseContainer, - contentPathExportStrategy.getTableXsdFilePath(0, tableCounter), writeStrategy); + tableXsdOutputStream = SIARDDKFileIndexFileStrategy.getLOBWriter(baseContainer, + contentPathExportStrategy.getTableXsdFilePath(0, tableCounter), writeStrategy); BufferedWriter xsdWriter = new BufferedWriter(new OutputStreamWriter(tableXsdOutputStream)); Document d = new Document(schema); @@ -223,7 +210,7 @@ public void openTable(TableStructure tableStructure) throws ModuleException { outputter.output(d, xsdWriter); xsdWriter.close(); - fileIndexFileStrategy.addFile(contentPathExportStrategy.getTableXsdFilePath(0, tableCounter)); + SIARDDKFileIndexFileStrategy.addFile(contentPathExportStrategy.getTableXsdFilePath(0, tableCounter)); } catch (IOException e) { throw new ModuleException().withMessage("Could not write table" + tableCounter + " to disk").withCause(e); @@ -237,7 +224,7 @@ public void closeTable(TableStructure tableStructure) throws ModuleException { tableXmlWriter.write("
"); tableXmlWriter.close(); - fileIndexFileStrategy.addFile(contentPathExportStrategy.getTableXmlFilePath(0, tableCounter)); + SIARDDKFileIndexFileStrategy.addFile(contentPathExportStrategy.getTableXmlFilePath(0, tableCounter)); if (foundClob) { logger.info("CLOB(s) found in table " + tableCounter + ". Archived as string"); @@ -251,7 +238,7 @@ public void closeTable(TableStructure tableStructure) throws ModuleException { if (foundUnknownMimetype) { String warning = new StringBuilder().append("Found BLOB(s) with unknown mimetype(s) in table '") - .append(tableStructure.getName()).append("'. ").append("File(s) archived with extension '.bin'").toString(); + .append(tableStructure.getName()).append("'. ").append("File(s) archived with extension '.bin'").toString(); logger.warn(warning); } } @@ -280,21 +267,21 @@ public Row tableRow(Row row) throws ModuleException { // System.out.println("SimpleData = " + // simpleCell.getSimpleData()); tableXmlWriter.append(TAB).append(TAB).append("") - .append(encodeText(simpleCell.getSimpleData())).append("\n"); + .append(encodeText(simpleCell.getSimpleData())).append("\n"); } else if (cell instanceof BinaryCell) { BinaryCell binaryCell = (BinaryCell) cell; InputStream in = binaryCell.createInputStream(); tableXmlWriter.append(TAB).append(TAB).append("") - .append(Hex.encodeHexString(IOUtils.toByteArray(in))).append("\n"); + .append(Hex.encodeHexString(IOUtils.toByteArray(in))).append("\n"); in.close(); binaryCell.cleanResources(); } } else { tableXmlWriter.append(TAB).append(TAB).append("").append("\n"); + .append(" xsi:nil=\"true\"/>").append("\n"); } } else { @@ -302,7 +289,7 @@ public Row tableRow(Row row) throws ModuleException { if (cell instanceof NullCell) { tableXmlWriter.append(TAB).append(TAB).append("").append("\n"); + .append(" xsi:nil=\"true\"/>").append("\n"); } else if (cell instanceof SimpleCell) { // CLOB is not NULL @@ -318,7 +305,7 @@ public Row tableRow(Row row) throws ModuleException { // lobsTracker.addLOB(); // Only if LOB not NULL tableXmlWriter.append(TAB).append(TAB).append("") - .append(encodeText(clobsData)).append("\n"); + .append(encodeText(clobsData)).append("\n"); } else if (cell instanceof BinaryCell) { @@ -344,8 +331,8 @@ public Row tableRow(Row row) throws ModuleException { // SIARDDK tableXmlWriter.append(TAB).append(TAB).append("") - .append(Integer.toString(lobsTracker.getLOBsCount())).append("\n"); + .append(Integer.toString(lobsTracker.getLOBsCount())).append("\n"); String path = contentPathExportStrategy.getBlobFilePath(-1, -1, -1, -1); String fileExtension; @@ -363,7 +350,7 @@ public Row tableRow(Row row) throws ModuleException { // Create new FileIndexFileStrategy // Write the BLOB - OutputStream out = fileIndexFileStrategy.getLOBWriter(baseContainer, blob.getOutputPath(), writeStrategy); + OutputStream out = SIARDDKFileIndexFileStrategy.getLOBWriter(baseContainer, blob.getOutputPath(), writeStrategy); InputStream in = blob.getInputStreamProvider().createInputStream(); IOUtils.copy(in, out); IOUtils.closeQuietly(in); @@ -374,11 +361,11 @@ public Row tableRow(Row row) throws ModuleException { // are dealing with metadata) // TO-DO: obtain (how?) hardcoded values - docIndexFileStrategy.addDoc(lobsTracker.getLOBsCount(), 0, 1, lobsTracker.getDocCollectionCount(), - "originalFilename", fileExtension, null); + SIARDDKDocIndexFileStrategy.addDoc(lobsTracker.getLOBsCount(), 0, 1, lobsTracker.getDocCollectionCount(), + "originalFilename", fileExtension, null); // Add file to fileIndex - fileIndexFileStrategy.addFile(blob.getOutputPath()); + SIARDDKFileIndexFileStrategy.addFile(blob.getOutputPath()); } else { // never happens diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARD21MetadataExportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARD21MetadataExportStrategy.java index deaaaa5a4..f876f2a21 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARD21MetadataExportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARD21MetadataExportStrategy.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.math.BigInteger; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -183,6 +184,7 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine .withCause(e); } + removeViewsWithoutColumns(dbStructure); SiardArchive xmlroot = jaxbSiardArchive(dbStructure); Marshaller m; try { @@ -333,6 +335,20 @@ private SiardArchive jaxbSiardArchive(DatabaseStructure dbStructure) throws Modu return siardArchive; } + private void removeViewsWithoutColumns(DatabaseStructure databaseStructure) { + for (SchemaStructure s : databaseStructure.getSchemas()) { + List list = new ArrayList<>(); + for (ViewStructure v : s.getViews()) { + if (v.getColumns() != null) { + list.add(v); + } else { + reporter.viewWithNullColumns(v.getName(), s.getName()); + } + } + s.setViews(list); + } + } + private PrivilegesType jaxbPrivilegesType(List privileges) throws ModuleException { if (privileges != null && !privileges.isEmpty()) { PrivilegesType privilegesType = new PrivilegesType(); diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007DocIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007DocIndexFileStrategy.java new file mode 100644 index 000000000..ae10da9ae --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007DocIndexFileStrategy.java @@ -0,0 +1,71 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.out.metadata; + +import java.math.BigInteger; +import java.util.List; + +import dk.sa.xmlns.diark._1_0.docindex.DocIndexType; +import dk.sa.xmlns.diark._1_0.docindex.DocumentType; + +/** + * @author António Lindo + * + */ +public class SIARDDK1007DocIndexFileStrategy extends SIARDDKDocIndexFileStrategy { + + public SIARDDK1007DocIndexFileStrategy() { + super(); + } + + @Override + DocIndexType createDocIndexTypeInstance() { + return new DocIndexType(); + } + + @Override + DocumentType createDocumentTypeInstance() { + return new DocumentType(); + } + + @Override + void setDID(DocumentType doc, BigInteger value) { + doc.setDID(value); + } + + @Override + void setMID(DocumentType doc, BigInteger value) { + doc.setMID(value); + } + + @Override + void setDCf(DocumentType doc, String dCf) { + doc.setDCf(dCf); + } + + @Override + void setOFn(DocumentType doc, String oFn) { + doc.setOFn(oFn); + } + + @Override + void setAFt(DocumentType doc, String aFt) { + doc.setAFt(aFt); + } + + @Override + void setGmlXsd(DocumentType doc, String gmlXsd) { + doc.setGmlXsd(gmlXsd); + } + + @Override + List getDoc(DocIndexType docIndex) { + return docIndex.getDoc(); + } + +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007FileIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007FileIndexFileStrategy.java new file mode 100644 index 000000000..a80f8276f --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK1007FileIndexFileStrategy.java @@ -0,0 +1,68 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +/** + * The methods should be called in this order from the SIARDDKMetadataExportStrategy + * 1) getWriter + * 2) addFile (should not be called until writer obtained from getWriter is closed) + * 3) generateXML + * + * TO-DO: + * NOTE: this class should be rewritten: the getLOBwriter part should be made smarter (more generic) + */ +package com.databasepreservation.modules.siard.out.metadata; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import dk.sa.xmlns.diark._1_0.fileindex.FileIndexType; +import dk.sa.xmlns.diark._1_0.fileindex.FileIndexType.F; + +/** + * @author António Lindo + * + */ +public class SIARDDK1007FileIndexFileStrategy extends SIARDDKFileIndexFileStrategy { + + private static final Logger LOGGER = LoggerFactory.getLogger(SIARDDK1007FileIndexFileStrategy.class); + + public SIARDDK1007FileIndexFileStrategy() { + super(); + } + + @Override + FileIndexType createFileIndexTypeInstance() { + return new FileIndexType(); + } + + @Override + F createFileIndexTypeFInstance() { + return new FileIndexType.F(); + } + + @Override + List getF(FileIndexType fileIndexType) { + return fileIndexType.getF(); + } + + @Override + void setFoN(F file, String foN) { + file.setFoN(foN); + } + + @Override + void setFiN(F file, String fiN) { + file.setFiN(fiN); + } + + @Override + void setMd5(F file, byte[] value) { + file.setMd5(value); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128DocIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128DocIndexFileStrategy.java new file mode 100644 index 000000000..c57ae786c --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128DocIndexFileStrategy.java @@ -0,0 +1,70 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.out.metadata; + +import com.databasepreservation.modules.siard.bindings.siard_dk_128.DocIndexType; +import com.databasepreservation.modules.siard.bindings.siard_dk_128.DocumentType; + +import java.math.BigInteger; +import java.util.List; + +/** + * @author António Lindo + * + */ +public class SIARDDK128DocIndexFileStrategy extends SIARDDKDocIndexFileStrategy { + + public SIARDDK128DocIndexFileStrategy() { + super(); + } + + @Override + DocIndexType createDocIndexTypeInstance() { + return new DocIndexType(); + } + + @Override + DocumentType createDocumentTypeInstance() { + return new DocumentType(); + } + + @Override + void setDID(DocumentType doc, BigInteger value) { + doc.setDID(value); + } + + @Override + void setMID(DocumentType doc, BigInteger value) { + doc.setMID(value); + } + + @Override + void setDCf(DocumentType doc, String dCf) { + doc.setDCf(dCf); + } + + @Override + void setOFn(DocumentType doc, String oFn) { + doc.setOFn(oFn); + } + + @Override + void setAFt(DocumentType doc, String aFt) { + doc.setAFt(aFt); + } + + @Override + void setGmlXsd(DocumentType doc, String gmlXsd) { + doc.setGmlXsd(gmlXsd); + } + + @Override + List getDoc(DocIndexType docIndex) { + return docIndex.getDoc(); + } +} \ No newline at end of file diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128FileIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128FileIndexFileStrategy.java new file mode 100644 index 000000000..d17924986 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDK128FileIndexFileStrategy.java @@ -0,0 +1,65 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +/** + * The methods should be called in this order from the SIARDDKMetadataExportStrategy + * 1) getWriter + * 2) addFile (should not be called until writer obtained from getWriter is closed) + * 3) generateXML + * + * TO-DO: + * NOTE: this class should be rewritten: the getLOBwriter part should be made smarter (more generic) + */ +package com.databasepreservation.modules.siard.out.metadata; + +import com.databasepreservation.modules.siard.bindings.siard_dk_128.FileIndexType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** + * @author António Lindo + * + */ +public class SIARDDK128FileIndexFileStrategy extends SIARDDKFileIndexFileStrategy { + private static final Logger LOGGER = LoggerFactory.getLogger(SIARDDK128FileIndexFileStrategy.class); + + public SIARDDK128FileIndexFileStrategy() { + super(); + } + + @Override + FileIndexType createFileIndexTypeInstance() { + return new FileIndexType(); + } + + @Override + FileIndexType.F createFileIndexTypeFInstance() { + return new FileIndexType.F(); + } + + @Override + List getF(FileIndexType fileIndexType) { + return fileIndexType.getF(); + } + + @Override + void setFoN(FileIndexType.F file, String foN) { + file.setFoN(foN); + } + + @Override + void setFiN(FileIndexType.F file, String fiN) { + file.setFiN(fiN); + } + + @Override + void setMd5(FileIndexType.F file, byte[] value) { + file.setMd5(value); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/ContextDocumentationWriter.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKContextDocumentationWriter.java similarity index 78% rename from dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/ContextDocumentationWriter.java rename to dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKContextDocumentationWriter.java index 82174f03e..61bb77bcd 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/ContextDocumentationWriter.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKContextDocumentationWriter.java @@ -1,12 +1,11 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.out.metadata; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.out.write.WriteStrategy; +import org.apache.commons.io.IOUtils; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -16,32 +15,24 @@ import java.nio.file.Path; import java.util.Map; -import org.apache.commons.io.IOUtils; - -import com.databasepreservation.model.exception.ModuleException; -import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.out.write.WriteStrategy; - /** * @author Andreas Kring * */ -public class ContextDocumentationWriter { - +public class SIARDDKContextDocumentationWriter { private Map exportModuleArgs; private SIARDArchiveContainer mainContainer; - private FileIndexFileStrategy fileIndexFileStrategy; + private SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy; private WriteStrategy writeStrategy; private Path mainContainerPath; - public ContextDocumentationWriter(SIARDArchiveContainer mainContainer, WriteStrategy writeStrategy, - FileIndexFileStrategy fileIndexFileStrategy, Map exportModuleArgs) { + public SIARDDKContextDocumentationWriter(SIARDArchiveContainer mainContainer, WriteStrategy writeStrategy, + SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy, Map exportModuleArgs) { this.mainContainer = mainContainer; this.writeStrategy = writeStrategy; - this.fileIndexFileStrategy = fileIndexFileStrategy; + this.SIARDDKFileIndexFileStrategy = SIARDDKFileIndexFileStrategy; this.exportModuleArgs = exportModuleArgs; } @@ -61,7 +52,7 @@ public void writeContextDocumentation() throws ModuleException { } /** - * + * * @param files * List context documentation files to write to the archive * @param path @@ -84,12 +75,12 @@ private void writeFile(File[] files, Path path) throws ModuleException { try { fis = new FileInputStream(file); - fos = fileIndexFileStrategy.getWriter(mainContainer, pathRelativeToMainContainerPath.toString(), + fos = SIARDDKFileIndexFileStrategy.getWriter(mainContainer, pathRelativeToMainContainerPath.toString(), writeStrategy); try { IOUtils.copy(fis, fos); - fileIndexFileStrategy.addFile(pathRelativeToMainContainerPath.toString()); + SIARDDKFileIndexFileStrategy.addFile(pathRelativeToMainContainerPath.toString()); } catch (IOException e) { throw new ModuleException().withMessage("There was an error writing " + path).withCause(e); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/DocIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKDocIndexFileStrategy.java similarity index 52% rename from dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/DocIndexFileStrategy.java rename to dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKDocIndexFileStrategy.java index 413ace963..747b61d39 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/DocIndexFileStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKDocIndexFileStrategy.java @@ -1,35 +1,26 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.out.metadata; -import java.math.BigInteger; - import com.databasepreservation.model.exception.ModuleException; import com.databasepreservation.model.structure.DatabaseStructure; -import dk.sa.xmlns.diark._1_0.docindex.DocIndexType; -import dk.sa.xmlns.diark._1_0.docindex.DocumentType; +import java.math.BigInteger; +import java.util.List; /** * @author Andreas Kring * */ -public class DocIndexFileStrategy implements IndexFileStrategy { +public abstract class SIARDDKDocIndexFileStrategy implements IndexFileStrategy { - private DocIndexType docIndex; + private T docIndex; - public DocIndexFileStrategy() { - docIndex = new DocIndexType(); + public SIARDDKDocIndexFileStrategy() { + docIndex = createDocIndexTypeInstance(); } /* * (non-Javadoc) - * + * * @see com.databasepreservation.modules.siard.out.metadata.IndexFileStrategy# * generateXML(com.databasepreservation.model.structure.DatabaseStructure) */ @@ -40,7 +31,7 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException /** * Adds a doc element to the docIndex - * + * * @param dID * value of the dID * @param pID @@ -57,25 +48,43 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException * ... * @return the doc element containing the given data */ - public DocumentType addDoc(int dID, int pID, int mID, int docCollectionNumber, String oFn, String aFt, - String gmlXsd) { - DocumentType doc = new DocumentType(); + public D addDoc(int dID, int pID, int mID, int docCollectionNumber, String oFn, String aFt, + String gmlXsd) { + D doc = createDocumentTypeInstance(); - doc.setDID(BigInteger.valueOf(dID)); + setDID(doc, BigInteger.valueOf(dID)); if (pID > 0) { // TO-DO: set pID } - doc.setMID(BigInteger.valueOf(mID)); - doc.setDCf("docCollection" + docCollectionNumber); - doc.setOFn(oFn); - doc.setAFt(aFt); + setMID(doc, BigInteger.valueOf(mID)); + setDCf(doc, "docCollection" + docCollectionNumber); + setOFn(doc, oFn); + setAFt(doc, aFt); if (gmlXsd != null) { - doc.setGmlXsd(gmlXsd); + setGmlXsd(doc, gmlXsd); } - docIndex.getDoc().add(doc); + getDoc(docIndex).add(doc); return doc; } + abstract T createDocIndexTypeInstance(); + + abstract D createDocumentTypeInstance(); + + abstract void setDID(D doc, BigInteger value); + + abstract void setMID(D doc, BigInteger value); + + abstract void setDCf(D doc, String dCf); + + abstract void setOFn(D doc, String oFn); + + abstract void setAFt(D doc, String aFt); + + abstract void setGmlXsd(D doc, String gmlXsd); + + abstract List getDoc(T docIndex); } + diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/FileIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKFileIndexFileStrategy.java similarity index 80% rename from dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/FileIndexFileStrategy.java rename to dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKFileIndexFileStrategy.java index 82c131c48..51ec1beef 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/FileIndexFileStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKFileIndexFileStrategy.java @@ -1,22 +1,13 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ -/** - * The methods should be called in this order from the SIARDDKMetadataExportStrategy - * 1) getWriter - * 2) addFile (should not be called until writer obtained from getWriter is closed) - * 3) generateXML - * - * TO-DO: - * NOTE: this class should be rewritten: the getLOBwriter part should be made smarter (more generic) - */ package com.databasepreservation.modules.siard.out.metadata; -import java.io.IOException; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.structure.DatabaseStructure; +import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.out.write.WriteStrategy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.OutputStream; import java.nio.file.Path; import java.security.DigestOutputStream; @@ -28,23 +19,12 @@ import java.util.TreeMap; import java.util.regex.Pattern; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.databasepreservation.model.exception.ModuleException; -import com.databasepreservation.model.structure.DatabaseStructure; -import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.out.write.WriteStrategy; - -import dk.sa.xmlns.diark._1_0.fileindex.FileIndexType; - /** * @author Andreas Kring * */ -public class FileIndexFileStrategy implements IndexFileStrategy { - private static final Logger LOGGER = LoggerFactory.getLogger(FileIndexFileStrategy.class); +public abstract class SIARDDKFileIndexFileStrategy implements IndexFileStrategy { + private static final Logger LOGGER = LoggerFactory.getLogger(SIARDDK1007FileIndexFileStrategy.class); // This is determined by the fileIndex schema private static final String SIARDDK_FILE_SEPERATOR = "\\"; @@ -55,7 +35,7 @@ public class FileIndexFileStrategy implements IndexFileStrategy { private SortedMap md5sums; private SIARDArchiveContainer outputContainer; - public FileIndexFileStrategy() { + public SIARDDKFileIndexFileStrategy() { md5sums = new TreeMap(); outputContainer = null; currentlyDigestingLOB = false; @@ -67,10 +47,10 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException Path baseContainer = outputContainer.getPath(); int count = baseContainer.getNameCount(); String foNbase = baseContainer.getName(count - 1).toString(); // e.g. - // AVID.SA.19000.1 + // AVID.SA.19000.1 - FileIndexType fileIndexType = new FileIndexType(); - List fList = fileIndexType.getF(); + T fileIndexType = createFileIndexTypeInstance(); + List fList = getF(fileIndexType); for (Map.Entry entry : md5sums.entrySet()) { @@ -90,10 +70,10 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException String foN = pathBuilder.toString(); // System.out.println(foN); - FileIndexType.F f = new FileIndexType.F(); - f.setFoN(foN); - f.setFiN(fiN); - f.setMd5(entry.getValue()); + D f = createFileIndexTypeFInstance(); + setFoN(f, foN); + setFiN(f, fiN); + setMd5(f, entry.getValue()); fList.add(f); } @@ -126,7 +106,7 @@ private OutputStream getWriter(SIARDArchiveContainer outputContainer, String pat /** * Writer to be used when not writing LOBs - * + * * @param outputContainer * @param path * @param writeStrategy @@ -140,7 +120,7 @@ public OutputStream getWriter(SIARDArchiveContainer outputContainer, String path /** * Write to be used when writing LOBs - * + * * @param outputContainer * @param path * @param writeStrategy @@ -154,7 +134,7 @@ public OutputStream getLOBWriter(SIARDArchiveContainer outputContainer, String p /** * Adds file to archive. - * + * * @param path * The path in the outputContainer (already has the correct format, * since this method gets it from the MetadataPathStrategy) @@ -180,4 +160,17 @@ public byte[] addFile(String path) { return digest; } + + abstract T createFileIndexTypeInstance(); + + abstract D createFileIndexTypeFInstance(); + + abstract List getF(T fileIndexType); + + abstract void setFoN(D file, String foN); + + abstract void setFiN(D file, String fiN); + + abstract void setMd5(D file, byte[] value); + } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKMetadataExportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKMetadataExportStrategy.java index 37d49205a..7715bd5ae 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKMetadataExportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKMetadataExportStrategy.java @@ -1,33 +1,26 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.out.metadata; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.structure.DatabaseStructure; import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; +import com.databasepreservation.modules.siard.common.adapters.SIARDDKAdapter; import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; import com.databasepreservation.modules.siard.constants.SIARDDKConstants; import com.databasepreservation.modules.siard.out.content.LOBsTracker; import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; import com.databasepreservation.modules.siard.out.write.WriteStrategy; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; /** * @author Andreas Kring @@ -38,20 +31,22 @@ public class SIARDDKMetadataExportStrategy implements MetadataExportStrategy { private SIARDMarshaller siardMarshaller; private MetadataPathStrategy metadataPathStrategy; - private FileIndexFileStrategy fileIndexFileStrategy; - private DocIndexFileStrategy docIndexFileStrategy; + private SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy; + private SIARDDKDocIndexFileStrategy SIARDDKDocIndexFileStrategy; private Map exportModuleArgs; private LOBsTracker lobsTracker; + private SIARDDKAdapter siarddkAdapter; private Reporter reporter; - public SIARDDKMetadataExportStrategy(SIARDDKExportModule siarddkExportModule) { + public SIARDDKMetadataExportStrategy(SIARDDKExportModule siarddkExportModule, SIARDDKAdapter siarddkAdapter) { siardMarshaller = siarddkExportModule.getSiardMarshaller(); - fileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); - docIndexFileStrategy = siarddkExportModule.getDocIndexFileStrategy(); + SIARDDKFileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); + SIARDDKDocIndexFileStrategy = siarddkExportModule.getDocIndexFileStrategy(); metadataPathStrategy = siarddkExportModule.getMetadataPathStrategy(); exportModuleArgs = siarddkExportModule.getExportModuleArgs(); lobsTracker = siarddkExportModule.getLobsTracker(); + this.siarddkAdapter = siarddkAdapter; } @Override @@ -64,9 +59,9 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine // Generate tableIndex.xml try { - IndexFileStrategy tableIndexFileStrategy = new TableIndexFileStrategy(lobsTracker); + IndexFileStrategy tableIndexFileStrategy = new SIARDDKTableIndexFileStrategy(lobsTracker, siarddkAdapter); String path = metadataPathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX); - OutputStream writer = fileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); + OutputStream writer = SIARDDKFileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); siardMarshaller.marshal(SIARDDKConstants.JAXB_CONTEXT_TABLEINDEX, metadataPathStrategy.getXsdResourcePath(SIARDDKConstants.TABLE_INDEX), @@ -75,7 +70,7 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine writer.close(); - fileIndexFileStrategy.addFile(path); + SIARDDKFileIndexFileStrategy.addFile(path); } catch (IOException e) { throw new ModuleException().withMessage("Error writing tableIndex.xml to the archive.").withCause(e); @@ -86,13 +81,13 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine if (exportModuleArgs.get(SIARDDKConstants.ARCHIVE_INDEX) != null) { try { String path = metadataPathStrategy.getXmlFilePath(SIARDDKConstants.ARCHIVE_INDEX); - OutputStream writer = fileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); + OutputStream writer = SIARDDKFileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); IndexFileStrategy archiveIndexFileStrategy = new CommandLineIndexFileStrategy(SIARDDKConstants.ARCHIVE_INDEX, exportModuleArgs, writer, metadataPathStrategy); archiveIndexFileStrategy.generateXML(null); writer.close(); - fileIndexFileStrategy.addFile(path); + SIARDDKFileIndexFileStrategy.addFile(path); } catch (IOException e) { throw new ModuleException().withMessage("Error writing archiveIndex.xml to the archive").withCause(e); @@ -105,13 +100,13 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine try { String path = metadataPathStrategy.getXmlFilePath(SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX); - OutputStream writer = fileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); + OutputStream writer = SIARDDKFileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); IndexFileStrategy contextDocumentationIndexFileStrategy = new CommandLineIndexFileStrategy( SIARDDKConstants.CONTEXT_DOCUMENTATION_INDEX, exportModuleArgs, writer, metadataPathStrategy); contextDocumentationIndexFileStrategy.generateXML(null); writer.close(); - fileIndexFileStrategy.addFile(path); + SIARDDKFileIndexFileStrategy.addFile(path); } catch (IOException e) { throw new ModuleException().withMessage("Error writing contextDocumentationIndex.xml to the archive") @@ -122,16 +117,16 @@ public void writeMetadataXML(DatabaseStructure dbStructure, SIARDArchiveContaine if (lobsTracker.getLOBsCount() > 0) { try { String path = metadataPathStrategy.getXmlFilePath(SIARDDKConstants.DOC_INDEX); - OutputStream writer = fileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); + OutputStream writer = SIARDDKFileIndexFileStrategy.getWriter(outputContainer, path, writeStrategy); siardMarshaller.marshal(SIARDDKConstants.JAXB_CONTEXT_DOCINDEX, metadataPathStrategy.getXsdResourcePath(SIARDDKConstants.DOC_INDEX), "http://www.sa.dk/xmlns/diark/1.0 ../Schemas/standard/docIndex.xsd", writer, - docIndexFileStrategy.generateXML(dbStructure)); + SIARDDKDocIndexFileStrategy.generateXML(dbStructure)); writer.close(); - fileIndexFileStrategy.addFile(path); + SIARDDKFileIndexFileStrategy.addFile(path); } catch (IOException e) { throw new ModuleException().withMessage("Error writing docIndex.xml to the archive.").withCause(e); @@ -179,7 +174,7 @@ private void writeSchemaFile(SIARDArchiveContainer container, String indexFile, // System.out.println(path); } - OutputStream outputStream = fileIndexFileStrategy.getWriter(container, path, writeStrategy); + OutputStream outputStream = SIARDDKFileIndexFileStrategy.getWriter(container, path, writeStrategy); try { if (inputStream != null) { @@ -188,7 +183,7 @@ private void writeSchemaFile(SIARDArchiveContainer container, String indexFile, outputStream.close(); } - fileIndexFileStrategy.addFile(path); + SIARDDKFileIndexFileStrategy.addFile(path); } catch (IOException e) { throw new ModuleException().withMessage("There was an error writing " + indexFile + ".xsd").withCause(e); @@ -205,4 +200,5 @@ private void createLocalSharedFolder(SIARDArchiveContainer container) { LOGGER.error("Could not create directories", e); } } + } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/TableIndexFileStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKTableIndexFileStrategy.java similarity index 56% rename from dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/TableIndexFileStrategy.java rename to dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKTableIndexFileStrategy.java index 29488f1e0..07217ab04 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/TableIndexFileStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/metadata/SIARDDKTableIndexFileStrategy.java @@ -9,7 +9,9 @@ import java.math.BigInteger; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -25,58 +27,49 @@ import com.databasepreservation.model.structure.TableStructure; import com.databasepreservation.model.structure.ViewStructure; import com.databasepreservation.model.structure.type.Type; +import com.databasepreservation.modules.siard.common.adapters.SIARDDKAdapter; import com.databasepreservation.modules.siard.constants.SIARDDKConstants; import com.databasepreservation.modules.siard.out.content.LOBsTracker; -import dk.sa.xmlns.diark._1_0.tableindex.ColumnType; -import dk.sa.xmlns.diark._1_0.tableindex.ColumnsType; -import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeyType; -import dk.sa.xmlns.diark._1_0.tableindex.ForeignKeysType; -import dk.sa.xmlns.diark._1_0.tableindex.FunctionalDescriptionType; -import dk.sa.xmlns.diark._1_0.tableindex.PrimaryKeyType; -import dk.sa.xmlns.diark._1_0.tableindex.ReferenceType; -import dk.sa.xmlns.diark._1_0.tableindex.SiardDiark; -import dk.sa.xmlns.diark._1_0.tableindex.TableType; -import dk.sa.xmlns.diark._1_0.tableindex.TablesType; -import dk.sa.xmlns.diark._1_0.tableindex.ViewType; -import dk.sa.xmlns.diark._1_0.tableindex.ViewsType; - /** * @author Andreas Kring * */ -public class TableIndexFileStrategy implements IndexFileStrategy { +public class SIARDDKTableIndexFileStrategy implements IndexFileStrategy { // LOBsTracker used to get the locations of functionalDescriptions private LOBsTracker lobsTracker; private String regex; + private SIARDDKAdapter siarddkBinding; - public TableIndexFileStrategy(LOBsTracker lobsTracker) { + public SIARDDKTableIndexFileStrategy(LOBsTracker lobsTracker, SIARDDKAdapter siarddkAdapter) { this.lobsTracker = lobsTracker; + this.siarddkBinding = siarddkAdapter; regex = "(\\p{L}(_|\\w)*)|(\".*\")"; } - private static final Logger logger = LoggerFactory.getLogger(TableIndexFileStrategy.class); + private static final Logger logger = LoggerFactory.getLogger(SIARDDKTableIndexFileStrategy.class); @Override public Object generateXML(DatabaseStructure dbStructure) throws ModuleException { // Set version - mandatory - SiardDiark siardDiark = new SiardDiark(); - siardDiark.setVersion("1.0"); + siarddkBinding.setVersion("1.0"); // Set dbName - mandatory - siardDiark.setDbName(dbStructure.getName()); + if (dbStructure.getDbOriginalName() != null) { + siarddkBinding.setDbName(dbStructure.getDbOriginalName()); + } else { + siarddkBinding.setDbName(dbStructure.getName()); + } // Set databaseProduct if (StringUtils.isNotBlank(dbStructure.getProductName())) { - siardDiark.setDatabaseProduct(dbStructure.getProductName()); + siarddkBinding.setDatabaseProduct(dbStructure.getProductName()); } // Set tables - mandatory int tableCounter = 1; - TablesType tablesType = new TablesType(); - List schemas = dbStructure.getSchemas(); // System.out.println(schemas.get(0)); @@ -106,51 +99,44 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException continue; } else { for (TableStructure tableStructure : schemaStructure.getTables()) { - - // Set table - mandatory - - TableType tableType = new TableType(); - // Set name - mandatory - tableType.setName(escapeString(tableStructure.getName())); + String tableName = escapeString(tableStructure.getName()); // Set folder - mandatory - tableType.setFolder("table" + Integer.toString(tableCounter)); + String tableFolder = "table" + Integer.toString(tableCounter); // Set description + String tableDescription = "Description should be entered manually"; if (tableStructure.getDescription() != null && !tableStructure.getDescription().trim().isEmpty()) { - tableType.setDescription(tableStructure.getDescription().trim()); - } else { - tableType.setDescription("Description should be entered manually"); + tableDescription = tableStructure.getDescription().trim(); } + siarddkBinding.addTable(tableName, tableFolder, tableDescription); // Set columns - mandatory int columnCounter = 1; - ColumnsType columns = new ColumnsType(); for (ColumnStructure columnStructure : tableStructure.getColumns()) { // Set column - mandatory - - ColumnType column = new ColumnType(); Type type = columnStructure.getType(); // Set column name - mandatory - column.setName(escapeString(columnStructure.getName())); + String columnName = escapeString(columnStructure.getName()); // Set columnID - mandatory - column.setColumnID("c" + Integer.toString(columnCounter)); + String columnID = "c" + Integer.toString(columnCounter); // Set type - mandatory String sql99DataType = type.getSql99TypeName(); + String columType = type.getSql99TypeName(); if (sql99DataType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { - column.setType("INTEGER"); + columType = "INTEGER"; } else if (sql99DataType.equals(SIARDDKConstants.CHARACTER_LARGE_OBJECT)) { if (lobsTracker.getMaxClobLength(tableCounter, columnCounter) > 0) { - column.setType(SIARDDKConstants.DEFAULT_CLOB_TYPE + "(" - + lobsTracker.getMaxClobLength(tableCounter, columnCounter) + ")"); + columType = SIARDDKConstants.DEFAULT_CLOB_TYPE + "(" + + lobsTracker.getMaxClobLength(tableCounter, columnCounter) + ")"; } else { - column.setType(SIARDDKConstants.DEFAULT_CLOB_TYPE + "(1)"); + columType = SIARDDKConstants.DEFAULT_CLOB_TYPE + "(1)"; } } else if (sql99DataType.startsWith("BIT VARYING") || sql99DataType.startsWith("BINARY VARYING")) { @@ -158,99 +144,81 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException String length = sql99DataType.split("\\(")[1].trim(); length = length.substring(0, length.length() - 1); - column.setType("CHARACTER VARYING(" + length + ")"); + columType = "CHARACTER VARYING(" + length + ")"; - } else { - column.setType(type.getSql99TypeName()); } // Set typeOriginal - if (StringUtils.isNotBlank(type.getOriginalTypeName())) { - column.setTypeOriginal(type.getOriginalTypeName()); - } + String columnOriginalType = StringUtils.isNotBlank(type.getOriginalTypeName()) ? type.getOriginalTypeName() + : null; // Set defaultValue - if (StringUtils.isNotBlank(columnStructure.getDefaultValue())) { - column.setDefaultValue(columnStructure.getDefaultValue()); - } + String columnDefaultValue = StringUtils.isNotBlank(columnStructure.getDefaultValue()) + ? columnStructure.getDefaultValue() + : null; // Set nullable - column.setNullable(columnStructure.isNillable()); + Boolean columnStructureNillable = columnStructure.isNillable(); // Set description + String columnDescription = "Description should be set"; if (columnStructure.getDescription() != null && !columnStructure.getDescription().trim().isEmpty()) { - column.setDescription(columnStructure.getDescription().trim()); - } else { - column.setDescription("Description should be set"); + columnDescription = columnStructure.getDescription().trim(); } // Set functionalDescription String lobType = lobsTracker.getLOBsType(tableCounter, columnCounter); - if (lobType != null) { - if (lobType.equals(SIARDDKConstants.BINARY_LARGE_OBJECT)) { - FunctionalDescriptionType functionalDescriptionType = FunctionalDescriptionType.DOKUMENTIDENTIFIKATION; - column.getFunctionalDescription().add(functionalDescriptionType); - } - } - columns.getColumn().add(column); + siarddkBinding.addColumnForTable(tableName, columnName, columnID, columType, columnOriginalType, + columnDefaultValue, columnStructureNillable, columnDescription, lobType); columnCounter += 1; } - tableType.setColumns(columns); // Set primary key - mandatory - PrimaryKeyType primaryKeyType = new PrimaryKeyType(); // JAXB PrimaryKey primaryKey = tableStructure.getPrimaryKey(); if (primaryKey == null) { - primaryKeyType.setName("MISSING"); - primaryKeyType.getColumn().add("MISSING"); + siarddkBinding.addPrimaryKeyForTable(tableName, "MISSING", List.of("MISSING")); } else { - primaryKeyType.setName(escapeString(primaryKey.getName())); + String primaryKeyName = escapeString(primaryKey.getName()); List columnNames = primaryKey.getColumnNames(); + List escapedColumnNames = new ArrayList<>(); for (String columnName : columnNames) { - // Set column names for primary key - - primaryKeyType.getColumn().add(escapeString(columnName)); + escapedColumnNames.add(escapeString(columnName)); } + + siarddkBinding.addPrimaryKeyForTable(tableName, primaryKeyName, escapedColumnNames); } - tableType.setPrimaryKey(primaryKeyType); // Set foreignKeys - ForeignKeysType foreignKeysType = new ForeignKeysType(); List foreignKeys = tableStructure.getForeignKeys(); if (foreignKeys != null && foreignKeys.size() > 0) { for (ForeignKey key : foreignKeys) { - ForeignKeyType foreignKeyType = new ForeignKeyType(); - // Set key name - mandatory - foreignKeyType.setName(escapeString(key.getName())); + String foreignKeyName = escapeString(key.getName()); // Set referenced table - mandatory - foreignKeyType.setReferencedTable(escapeString(key.getReferencedTable())); + String foreignKeyReferencedTable = escapeString(key.getReferencedTable()); // Set reference - mandatory + Map escapedReferencedColumns = new LinkedHashMap<>(); for (Reference ref : key.getReferences()) { - ReferenceType referenceType = new ReferenceType(); - referenceType.setColumn(escapeString(ref.getColumn())); - referenceType.setReferenced(escapeString(ref.getReferenced())); - foreignKeyType.getReference().add(referenceType); + escapedReferencedColumns.put(escapeString(ref.getColumn()), escapeString(ref.getReferenced())); } - foreignKeysType.getForeignKey().add(foreignKeyType); + + siarddkBinding.addForeignKeyForTable(tableName, foreignKeyName, foreignKeyReferencedTable, + escapedReferencedColumns); } - tableType.setForeignKeys(foreignKeysType); } // Set rows if (tableStructure.getRows() >= 0) { - tableType.setRows(BigInteger.valueOf(tableStructure.getRows())); + siarddkBinding.setRowsForTable(tableName, BigInteger.valueOf(tableStructure.getRows())); } else { throw new ModuleException() .withMessage("Error while exporting table structure: number of table rows not set"); } - tablesType.getTable().add(tableType); - tableCounter += 1; } @@ -258,36 +226,28 @@ public Object generateXML(DatabaseStructure dbStructure) throws ModuleException List viewStructures = schemaStructure.getViews(); if (viewStructures != null && viewStructures.size() > 0) { - ViewsType viewsType = new ViewsType(); for (ViewStructure viewStructure : viewStructures) { - - // Set view - mandatory - ViewType viewType = new ViewType(); - // Set view name - mandatory - viewType.setName(escapeString(viewStructure.getName())); + String viewName = escapeString(viewStructure.getName()); // Set queryOriginal - mandatory + String viewQueryOriginal = "unknown"; if (StringUtils.isNotBlank(viewStructure.getQueryOriginal())) { - viewType.setQueryOriginal(viewStructure.getQueryOriginal()); - } else { - viewType.setQueryOriginal("unknown"); + viewQueryOriginal = viewStructure.getQueryOriginal(); } // Set description - if (StringUtils.isNotBlank(viewStructure.getDescription())) { - viewType.setDescription(viewStructure.getDescription()); - } + String viewDescription = StringUtils.isNotBlank(viewStructure.getDescription()) + ? viewStructure.getDescription() + : null; - viewsType.getView().add(viewType); + siarddkBinding.addView(viewName, viewQueryOriginal, viewDescription); } - siardDiark.setViews(viewsType); } } } - siardDiark.setTables(tablesType); - return siardDiark; + return siarddkBinding.getSIARDDK(); } String escapeString(String s) { diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007DatabaseExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007DatabaseExportModule.java new file mode 100644 index 000000000..d251c3570 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007DatabaseExportModule.java @@ -0,0 +1,26 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.out.output; + +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +/** + * @author António Lindo + * + */ +public class SIARDDK1007DatabaseExportModule extends SIARDDKDatabaseExportModule { + + public SIARDDK1007DatabaseExportModule(SIARDDKExportModule siarddkExportModule) { + super(siarddkExportModule); + } + + @Override + String getJAXBContext() { + return SIARDDKConstants.JAXB_CONTEXT_FILEINDEX; + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007ExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007ExportModule.java new file mode 100644 index 000000000..3b3f7b7ac --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK1007ExportModule.java @@ -0,0 +1,62 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +/** + * Factory for setting up SIARDDK strategies + * + * @author Andreas Kring + * + */ + +package com.databasepreservation.modules.siard.out.output; + +import java.util.Map; + +import com.databasepreservation.modules.siard.common.adapters.SIARDDK1007Adapter; +import com.databasepreservation.modules.siard.common.path.SIARDDK1007MetadataPathStrategy; +import com.databasepreservation.modules.siard.common.path.SIARDDKMetadataPathStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDK1007FileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDK1007DocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKDocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKFileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKMetadataExportStrategy; + +/** + * @author António Lindo + * + */ +public class SIARDDK1007ExportModule extends SIARDDKExportModule { + + public SIARDDK1007ExportModule(Map exportModuleArgs) { + super(exportModuleArgs); + } + + @Override + SIARDDKFileIndexFileStrategy createSIARDDKFileIndexFileStrategyInstance() { + return new SIARDDK1007FileIndexFileStrategy(); + } + + @Override + SIARDDKDocIndexFileStrategy createSIARDDKDocIndexFileStrategyInstance() { + return new SIARDDK1007DocIndexFileStrategy(); + } + + @Override + SIARDDKMetadataPathStrategy createSIARDDKMetadataPathStrategyInstance() { + return new SIARDDK1007MetadataPathStrategy(); + } + + @Override + SIARDDKMetadataExportStrategy createSIARDDKMetadataExportStrategyInstance() { + return new SIARDDKMetadataExportStrategy(this, new SIARDDK1007Adapter()); + } + + @Override + SIARDDKDatabaseExportModule createSIARDDKDatabaseExportModule() { + return new SIARDDK1007DatabaseExportModule(this); + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128DatabaseExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128DatabaseExportModule.java new file mode 100644 index 000000000..334aa2017 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128DatabaseExportModule.java @@ -0,0 +1,26 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +package com.databasepreservation.modules.siard.out.output; + +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; + +/** + * @author António Lindo + * + */ +public class SIARDDK128DatabaseExportModule extends SIARDDKDatabaseExportModule { + + public SIARDDK128DatabaseExportModule(SIARDDKExportModule siarddkExportModule) { + super(siarddkExportModule); + } + + @Override + String getJAXBContext() { + return SIARDDKConstants.JAXB_CONTEXT_FILEINDEX_128; + } +} diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128ExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128ExportModule.java new file mode 100644 index 000000000..0c70f2856 --- /dev/null +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDK128ExportModule.java @@ -0,0 +1,62 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE file at the root of the source + * tree and available online at + * + * https://github.com/keeps/db-preservation-toolkit + */ +/** + * Factory for setting up SIARDDK strategies + * + * @author Andreas Kring + * + */ + +package com.databasepreservation.modules.siard.out.output; + +import com.databasepreservation.modules.siard.common.adapters.SIARDDK128Adapter; +import com.databasepreservation.modules.siard.common.path.SIARDDK128MetadataPathStrategy; +import com.databasepreservation.modules.siard.common.path.SIARDDKMetadataPathStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDK128DocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDK128FileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKDocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKFileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKMetadataExportStrategy; +import java.util.Map; + +/** + * @author António Lindo + * + */ +public class SIARDDK128ExportModule extends SIARDDKExportModule { + + public SIARDDK128ExportModule(Map exportModuleArgs) { + super(exportModuleArgs); + } + + @Override + SIARDDKFileIndexFileStrategy createSIARDDKFileIndexFileStrategyInstance() { + return new SIARDDK128FileIndexFileStrategy(); + } + + @Override + SIARDDKDocIndexFileStrategy createSIARDDKDocIndexFileStrategyInstance() { + return new SIARDDK128DocIndexFileStrategy(); + } + + @Override + SIARDDKMetadataPathStrategy createSIARDDKMetadataPathStrategyInstance() { + return new SIARDDK128MetadataPathStrategy(); + } + + @Override + SIARDDKMetadataExportStrategy createSIARDDKMetadataExportStrategyInstance() { + return new SIARDDKMetadataExportStrategy(this, new SIARDDK128Adapter()); + } + + @Override + SIARDDKDatabaseExportModule createSIARDDKDatabaseExportModule() { + return new SIARDDK128DatabaseExportModule(this); + } +} + diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKDatabaseExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKDatabaseExportModule.java index 2e0eda660..66dfaee3f 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKDatabaseExportModule.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKDatabaseExportModule.java @@ -1,12 +1,15 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.out.output; +import com.databasepreservation.model.exception.ModuleException; +import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; +import com.databasepreservation.modules.siard.constants.SIARDDKConstants; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKContextDocumentationWriter; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKFileIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDMarshaller; +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -15,22 +18,11 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.databasepreservation.model.exception.ModuleException; -import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; -import com.databasepreservation.modules.siard.constants.SIARDDKConstants; -import com.databasepreservation.modules.siard.out.metadata.ContextDocumentationWriter; -import com.databasepreservation.modules.siard.out.metadata.FileIndexFileStrategy; -import com.databasepreservation.modules.siard.out.metadata.SIARDMarshaller; - /** * @author Andreas Kring * */ -public class SIARDDKDatabaseExportModule extends SIARDExportDefault { +public abstract class SIARDDKDatabaseExportModule extends SIARDExportDefault { private SIARDDKExportModule siarddkExportModule; private static final Logger logger = LoggerFactory.getLogger(SIARDDKDatabaseExportModule.class); @@ -69,7 +61,7 @@ public void initDatabase() throws ModuleException { // Get the creation time of the old archive folder BasicFileAttributes basicFileAttributes = Files.readAttributes(pathToArchive, BasicFileAttributes.class); String creationTimeStamp = basicFileAttributes.creationTime().toString(); - + String name = pathToArchive.toString() + "_backup_" + creationTimeStamp; // Rename the old folder @@ -86,21 +78,20 @@ public void initDatabase() throws ModuleException { @Override public void finishDatabase() throws ModuleException { super.finishDatabase(); - // Write ContextDocumentation to archive Map exportModuleArgs = siarddkExportModule.getExportModuleArgs(); - FileIndexFileStrategy fileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); + SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy = siarddkExportModule.getFileIndexFileStrategy(); MetadataPathStrategy metadataPathStrategy = siarddkExportModule.getMetadataPathStrategy(); SIARDMarshaller siardMarshaller = siarddkExportModule.getSiardMarshaller(); if (exportModuleArgs.get(SIARDDKConstants.CONTEXT_DOCUMENTATION_FOLDER) != null) { - ContextDocumentationWriter contextDocumentationWriter = new ContextDocumentationWriter( - siarddkExportModule.getMainContainer(), siarddkExportModule.getWriteStrategy(), fileIndexFileStrategy, + SIARDDKContextDocumentationWriter SIARDDKContextDocumentationWriter = new SIARDDKContextDocumentationWriter( + siarddkExportModule.getMainContainer(), siarddkExportModule.getWriteStrategy(), SIARDDKFileIndexFileStrategy, siarddkExportModule.getExportModuleArgs()); - contextDocumentationWriter.writeContextDocumentation(); + SIARDDKContextDocumentationWriter.writeContextDocumentation(); } // Create fileIndex.xml @@ -109,20 +100,19 @@ public void finishDatabase() throws ModuleException { // the MetadataExportStrategy) try { - fileIndexFileStrategy.generateXML(null); + SIARDDKFileIndexFileStrategy.generateXML(null); } catch (ModuleException e) { throw new ModuleException().withMessage("Error writing fileIndex.xml").withCause(e); } try { String path = metadataPathStrategy.getXmlFilePath(SIARDDKConstants.FILE_INDEX); - OutputStream writer = fileIndexFileStrategy.getWriter(siarddkExportModule.getMainContainer(), path, + OutputStream writer = SIARDDKFileIndexFileStrategy.getWriter(siarddkExportModule.getMainContainer(), path, siarddkExportModule.getWriteStrategy()); - siardMarshaller.marshal(SIARDDKConstants.JAXB_CONTEXT_FILEINDEX, - metadataPathStrategy.getXsdResourcePath(SIARDDKConstants.FILE_INDEX), + siardMarshaller.marshal(getJAXBContext(), metadataPathStrategy.getXsdResourcePath(SIARDDKConstants.FILE_INDEX), "http://www.sa.dk/xmlns/diark/1.0 ../Schemas/standard/fileIndex.xsd", writer, - fileIndexFileStrategy.generateXML(null)); + SIARDDKFileIndexFileStrategy.generateXML(null)); writer.close(); } catch (IOException e) { @@ -130,4 +120,6 @@ public void finishDatabase() throws ModuleException { } } + + abstract String getJAXBContext(); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKExportModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKExportModule.java index 3b814507a..e8f162602 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKExportModule.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/output/SIARDDKExportModule.java @@ -1,24 +1,5 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ -/** - * Factory for setting up SIARDDK strategies - * - * @author Andreas Kring - * - */ - package com.databasepreservation.modules.siard.out.output; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.util.Map; - -import com.databasepreservation.model.modules.DatabaseExportModule; import com.databasepreservation.model.modules.filters.DatabaseFilterModule; import com.databasepreservation.modules.siard.common.SIARDArchiveContainer; import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; @@ -27,9 +8,9 @@ import com.databasepreservation.modules.siard.out.content.ContentExportStrategy; import com.databasepreservation.modules.siard.out.content.LOBsTracker; import com.databasepreservation.modules.siard.out.content.SIARDDKContentExportStrategy; -import com.databasepreservation.modules.siard.out.metadata.DocIndexFileStrategy; -import com.databasepreservation.modules.siard.out.metadata.FileIndexFileStrategy; import com.databasepreservation.modules.siard.out.metadata.MetadataExportStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKDocIndexFileStrategy; +import com.databasepreservation.modules.siard.out.metadata.SIARDDKFileIndexFileStrategy; import com.databasepreservation.modules.siard.out.metadata.SIARDDKMetadataExportStrategy; import com.databasepreservation.modules.siard.out.metadata.SIARDMarshaller; import com.databasepreservation.modules.siard.out.metadata.StandardSIARDMarshaller; @@ -38,12 +19,15 @@ import com.databasepreservation.modules.siard.out.write.FolderWriteStrategy; import com.databasepreservation.modules.siard.out.write.WriteStrategy; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.Map; + /** * @author Andreas Kring * */ -public class SIARDDKExportModule { - +public abstract class SIARDDKExportModule { private MetadataExportStrategy metadataExportStrategy; private SIARDArchiveContainer mainContainer; private ContentExportStrategy contentExportStrategy; @@ -54,8 +38,8 @@ public class SIARDDKExportModule { private LOBsTracker lobsTracker; private Map exportModuleArgs; - private FileIndexFileStrategy fileIndexFileStrategy; - private DocIndexFileStrategy docIndexFileStrategy; + private SIARDDKFileIndexFileStrategy SIARDDKFileIndexFileStrategy; + private SIARDDKDocIndexFileStrategy SIARDDKDocIndexFileStrategy; public SIARDDKExportModule(Map exportModuleArgs) { this.exportModuleArgs = exportModuleArgs; @@ -66,18 +50,18 @@ public SIARDDKExportModule(Map exportModuleArgs) { SIARDArchiveContainer.OutputContainerType.MAIN); writeStrategy = new FolderWriteStrategy(); siardMarshaller = new StandardSIARDMarshaller(); - fileIndexFileStrategy = new FileIndexFileStrategy(); - docIndexFileStrategy = new DocIndexFileStrategy(); + SIARDDKFileIndexFileStrategy = createSIARDDKFileIndexFileStrategyInstance(); + SIARDDKDocIndexFileStrategy = createSIARDDKDocIndexFileStrategyInstance(); lobsTracker = new LOBsTracker(Integer.parseInt(exportModuleArgs.get("lobs-per-folder")), Integer.parseInt(exportModuleArgs.get("lobs-folder-size"))); contentPathExportStrategy = new SIARDDKContentPathExportStrategy(this); - metadataPathStrategy = new SIARDDKMetadataPathStrategy(); - metadataExportStrategy = new SIARDDKMetadataExportStrategy(this); + metadataPathStrategy = createSIARDDKMetadataPathStrategyInstance(); + metadataExportStrategy = createSIARDDKMetadataExportStrategyInstance(); contentExportStrategy = new SIARDDKContentExportStrategy(this); } public DatabaseFilterModule getDatabaseExportModule() { - return new SIARDDKDatabaseExportModule(this); + return createSIARDDKDatabaseExportModule(); } public Map getExportModuleArgs() { @@ -88,15 +72,15 @@ public WriteStrategy getWriteStrategy() { return writeStrategy; } - public FileIndexFileStrategy getFileIndexFileStrategy() { - return fileIndexFileStrategy; + public SIARDDKFileIndexFileStrategy getFileIndexFileStrategy() { + return SIARDDKFileIndexFileStrategy; } /** * @return the docIndexFileStrategy */ - public DocIndexFileStrategy getDocIndexFileStrategy() { - return docIndexFileStrategy; + public SIARDDKDocIndexFileStrategy getDocIndexFileStrategy() { + return SIARDDKDocIndexFileStrategy; } public SIARDMarshaller getSiardMarshaller() { @@ -129,4 +113,14 @@ public SIARDArchiveContainer getMainContainer() { public LOBsTracker getLobsTracker() { return lobsTracker; } + + abstract SIARDDKFileIndexFileStrategy createSIARDDKFileIndexFileStrategyInstance(); + + abstract SIARDDKDocIndexFileStrategy createSIARDDKDocIndexFileStrategyInstance(); + + abstract SIARDDKMetadataPathStrategy createSIARDDKMetadataPathStrategyInstance(); + + abstract SIARDDKMetadataExportStrategy createSIARDDKMetadataExportStrategyInstance(); + + abstract SIARDDKDatabaseExportModule createSIARDDKDatabaseExportModule(); } diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/path/SIARDDKContentPathExportStrategy.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/path/SIARDDKContentPathExportStrategy.java index a1cf0e553..3d6f5fc73 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/path/SIARDDKContentPathExportStrategy.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/out/path/SIARDDKContentPathExportStrategy.java @@ -1,17 +1,9 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE file at the root of the source - * tree and available online at - * - * https://github.com/keeps/db-preservation-toolkit - */ package com.databasepreservation.modules.siard.out.path; -import org.apache.commons.lang3.NotImplementedException; - import com.databasepreservation.modules.siard.constants.SIARDDKConstants; import com.databasepreservation.modules.siard.out.content.LOBsTracker; import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule; +import org.apache.commons.lang3.NotImplementedException; /** * @author Andreas Kring diff --git a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/update/SIARDEditModule.java b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/update/SIARDEditModule.java index 734447538..61ae7f994 100644 --- a/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/update/SIARDEditModule.java +++ b/dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/update/SIARDEditModule.java @@ -7,35 +7,11 @@ */ package com.databasepreservation.modules.siard.update; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.exception.ModuleException; import com.databasepreservation.model.metadata.SIARDDatabaseMetadata; import com.databasepreservation.model.modules.configuration.ModuleConfiguration; import com.databasepreservation.model.modules.edits.EditModule; +import com.databasepreservation.model.reporters.Reporter; import com.databasepreservation.model.structure.DatabaseStructure; import com.databasepreservation.model.structure.PrivilegeStructure; import com.databasepreservation.modules.DefaultExceptionNormalizer; @@ -43,14 +19,22 @@ import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy; import com.databasepreservation.modules.siard.common.path.SIARD1MetadataPathStrategy; import com.databasepreservation.modules.siard.common.path.SIARD2MetadataPathStrategy; +import com.databasepreservation.modules.siard.common.path.SIARDDK1007MetadataPathStrategy; +import com.databasepreservation.modules.siard.common.path.SIARDDK128MetadataPathStrategy; import com.databasepreservation.modules.siard.constants.SIARDConstants; import com.databasepreservation.modules.siard.in.metadata.MetadataImportStrategy; import com.databasepreservation.modules.siard.in.metadata.SIARD1MetadataImportStrategy; import com.databasepreservation.modules.siard.in.metadata.SIARD20MetadataImportStrategy; import com.databasepreservation.modules.siard.in.metadata.SIARD21MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.SIARDDK1007MetadataImportStrategy; +import com.databasepreservation.modules.siard.in.metadata.SIARDDK128MetadataImportStrategy; import com.databasepreservation.modules.siard.in.path.ContentPathImportStrategy; +import com.databasepreservation.modules.siard.in.path.ResourceFileIndexInputStreamStrategy; import com.databasepreservation.modules.siard.in.path.SIARD1ContentPathImportStrategy; import com.databasepreservation.modules.siard.in.path.SIARD2ContentPathImportStrategy; +import com.databasepreservation.modules.siard.in.path.SIARDDK1007PathImportStrategy; +import com.databasepreservation.modules.siard.in.path.SIARDDK128PathImportStrategy; +import com.databasepreservation.modules.siard.in.read.FolderReadStrategyMD5Sum; import com.databasepreservation.modules.siard.in.read.ReadStrategy; import com.databasepreservation.modules.siard.in.read.ZipAndFolderReadStrategy; import com.databasepreservation.modules.siard.in.read.ZipReadStrategy; @@ -62,6 +46,28 @@ import com.databasepreservation.modules.siard.out.update.MetadataUpdateStrategy; import com.databasepreservation.modules.siard.out.update.UpdateStrategy; import com.databasepreservation.utils.ModuleConfigurationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * @author Miguel Guimarães @@ -83,36 +89,59 @@ public class SIARDEditModule implements EditModule { * @param siardPackagePath * Path to the main SIARD file (file with extension .siard) */ - public SIARDEditModule(Path siardPackagePath) { + public SIARDEditModule(Path siardPackagePath, SIARDConstants.SiardVersion version) { Path siardPackageNormalizedPath = siardPackagePath.toAbsolutePath().normalize(); - mainContainer = new SIARDArchiveContainer(siardPackageNormalizedPath, - SIARDArchiveContainer.OutputContainerType.MAIN); - readStrategy = new ZipAndFolderReadStrategy(mainContainer); - - // identify version before creating metadata import strategy instance - try { - readStrategy.setup(mainContainer); - } catch (ModuleException e) { - LOGGER.debug("Problem setting up container", e); - } + String paramImportAsSchema = "public"; + if (version.equals(SIARDConstants.SiardVersion.DK_1007)) { + mainContainer = new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK_1007, siardPackageNormalizedPath, + SIARDArchiveContainer.OutputContainerType.MAIN); + readStrategy = new FolderReadStrategyMD5Sum(mainContainer); + + MetadataPathStrategy metadataPathStrategy = new SIARDDK1007MetadataPathStrategy(); + SIARDDK1007PathImportStrategy pathStrategy = new SIARDDK1007PathImportStrategy(mainContainer, readStrategy, + metadataPathStrategy, paramImportAsSchema, new ResourceFileIndexInputStreamStrategy()); + + metadataImportStrategy = new SIARDDK1007MetadataImportStrategy(pathStrategy, paramImportAsSchema); + } else if (version.equals(SIARDConstants.SiardVersion.DK_128)) { + mainContainer = new SIARDArchiveContainer(SIARDConstants.SiardVersion.DK_128, siardPackageNormalizedPath, + SIARDArchiveContainer.OutputContainerType.MAIN); + readStrategy = new FolderReadStrategyMD5Sum(mainContainer); + + MetadataPathStrategy metadataPathStrategy = new SIARDDK128MetadataPathStrategy(); + SIARDDK128PathImportStrategy pathStrategy = new SIARDDK128PathImportStrategy(mainContainer, readStrategy, + metadataPathStrategy, paramImportAsSchema, new ResourceFileIndexInputStreamStrategy()); + + metadataImportStrategy = new SIARDDK128MetadataImportStrategy(pathStrategy, paramImportAsSchema); + } else { + mainContainer = new SIARDArchiveContainer(siardPackageNormalizedPath, + SIARDArchiveContainer.OutputContainerType.MAIN); + readStrategy = new ZipAndFolderReadStrategy(mainContainer); + + // identify version before creating metadata import strategy instance + try { + readStrategy.setup(mainContainer); + } catch (ModuleException e) { + LOGGER.debug("Problem setting up container", e); + } - MetadataPathStrategy metadataPathStrategy = new SIARD2MetadataPathStrategy(); - ContentPathImportStrategy contentPathStrategy = new SIARD2ContentPathImportStrategy(); + MetadataPathStrategy metadataPathStrategy = new SIARD2MetadataPathStrategy(); + ContentPathImportStrategy contentPathStrategy = new SIARD2ContentPathImportStrategy(); + + switch (mainContainer.getVersion()) { + case V2_0: + metadataImportStrategy = new SIARD20MetadataImportStrategy(metadataPathStrategy, contentPathStrategy); + break; + case V2_1: + metadataImportStrategy = new SIARD21MetadataImportStrategy(metadataPathStrategy, contentPathStrategy); + break; + case V1_0: + metadataImportStrategy = new SIARD1MetadataImportStrategy(new SIARD1MetadataPathStrategy(), + new SIARD1ContentPathImportStrategy()); + break; + default: + metadataImportStrategy = null; + } - switch (mainContainer.getVersion()) { - case V2_0: - metadataImportStrategy = new SIARD20MetadataImportStrategy(metadataPathStrategy, contentPathStrategy); - break; - case V2_1: - metadataImportStrategy = new SIARD21MetadataImportStrategy(metadataPathStrategy, contentPathStrategy); - break; - case V1_0: - metadataImportStrategy = new SIARD1MetadataImportStrategy(new SIARD1MetadataPathStrategy(), - new SIARD1ContentPathImportStrategy()); - break; - case DK: - default: - metadataImportStrategy = null; } } diff --git a/pom.xml b/pom.xml index a721cb25a..f3c57b52b 100644 --- a/pom.xml +++ b/pom.xml @@ -317,7 +317,13 @@ com.databasepreservation - dbptk-bindings-siarddk + dbptk-bindings-siarddk-1007 + 2.0.0 + + + + com.databasepreservation + dbptk-bindings-siarddk-128 2.0.0