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(" | |