Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Oct 30, 2024
1 parent ecd1931 commit 1a678f5
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public abstract class SIARDDKEditFactory implements EditModuleFactory {
private static final Parameter folder = new Parameter().shortName("f").longName(PARAMETER_FOLDER)
.description("Path to SIARDK archive folder").hasArgument(true).setOptionalArgument(false).required(true);

/*
* private static final Parameter regex = new
* Parameter().shortName("regex").longName(PARAMETER_FILE)
* .description("").hasArgument(true).setOptionalArgument(false).required(true);
*/

@Override
public String getModuleName() {
return getEditModuleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.xml.validation.TypeInfoProvider;
import javax.xml.validation.ValidatorHandler;

import com.databasepreservation.modules.siard.validate.common.ZipFileManager;
import org.apache.commons.codec.Charsets;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,33 @@ protected List<TableStructure> getTables(SiardDiark siardArchive) throws ModuleE
if (needsVirtualTable) {
lstTblsDptkl.add(createVirtualTable());
}
lstTblsDptkl.add(createContextDocumentationTable());
TableStructure contextDocumentationTable = createContextDocumentationTable();
if (contextDocumentationTable != null) {
lstTblsDptkl.add(contextDocumentationTable);
}
}
return lstTblsDptkl;
}

private TableStructure createContextDocumentationTable() throws ModuleException {
try {
ContextDocumentationIndex contextDocumentationIndex = loadContextDocumentationTableMetadata();
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;
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))
Expand Down Expand Up @@ -351,12 +358,16 @@ private ContextDocumentationIndex loadContextDocumentationTableMetadata()
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;
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 {
Expand Down Expand Up @@ -475,7 +486,7 @@ private List<ColumnStructure> createContextDocumentsTableColumns() {
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,
Constants.BLOB, "1", true);
"", "1", true);
columnStructureList.add(columnID);
columnStructureList.add(columnTitle);
columnStructureList.add(columnDate);
Expand All @@ -493,7 +504,7 @@ private List<ColumnStructure> createVirtualTableColumns() {
"<information unavailable>", "<information unavailable>", Constants.BINARY_LARGE_OBJECT,
Constants.BINARY_LARGE_OBJECT);
VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, type, true,
Constants.BLOB, "1", true);
"", "1", true);
columnStructureList.add(columnID);
columnStructureList.add(columnLOB);
return columnStructureList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@
*/
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;
Expand All @@ -27,7 +52,6 @@
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.context.ContextDocumentationIndex;
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;
Expand All @@ -37,40 +61,19 @@
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;
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 javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
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;

/**
* @author Thomas Kristensen <tk@bithuset.dk>
Expand Down Expand Up @@ -296,26 +299,33 @@ protected List<TableStructure> getTables(SiardDiark siardArchive) throws ModuleE
if (needsVirtualTable) {
lstTblsDptkl.add(createVirtualTable());
}
lstTblsDptkl.add(createContextDocumentationTable());
TableStructure contextDocumentationTable = createContextDocumentationTable();
if (contextDocumentationTable != null) {
lstTblsDptkl.add(contextDocumentationTable);
}
}
return lstTblsDptkl;
}

private TableStructure createContextDocumentationTable() throws ModuleException {
try {
ContextDocumentationIndex contextDocumentationIndex = loadContextDocumentationTableMetadata();
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;
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))
Expand Down Expand Up @@ -348,11 +358,16 @@ private ContextDocumentationIndex loadContextDocumentationTableMetadata()
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;
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 {
Expand Down Expand Up @@ -470,7 +485,7 @@ private List<ColumnStructure> createContextDocumentsTableColumns() {
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,
Constants.BLOB, "1", true);
"", "1", true);
columnStructureList.add(columnID);
columnStructureList.add(columnTitle);
columnStructureList.add(columnDate);
Expand All @@ -488,7 +503,7 @@ private List<ColumnStructure> createVirtualTableColumns() {
"<information unavailable>", "<information unavailable>", Constants.BINARY_LARGE_OBJECT,
Constants.BINARY_LARGE_OBJECT);
VirtualColumnStructure columnLOB = new VirtualColumnStructure(Constants.BLOB, Constants.BLOB, type, true,
Constants.BLOB, "1", true);
"", "1", true);
columnStructureList.add(columnID);
columnStructureList.add(columnLOB);
return columnStructureList;
Expand Down

0 comments on commit 1a678f5

Please sign in to comment.