Skip to content

Commit

Permalink
Merge pull request 'Release v24.09' (#45) from release_24.09 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Oct 1, 2024
2 parents 41ebe60 + e9a6b5e commit 37c44db
Show file tree
Hide file tree
Showing 21 changed files with 600 additions and 331 deletions.
9 changes: 9 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pipeline {
branch 'master'
branch 'release_*'
branch 'hotfix_release_*'
branch 'sonar_*'
allOf {
branch 'PR-*'
expression { env.CHANGE_BRANCH.startsWith("release_") }
Expand Down Expand Up @@ -55,6 +56,14 @@ pipeline {
sh 'mvn clean verify -U -P release-build'
}
}
stage('build-sonar') {
when {
branch 'sonar_*'
}
steps {
sh 'mvn clean verify -U -P sonar-build'
}
}
stage('sonarcloud') {
when {
allOf {
Expand Down
2 changes: 2 additions & 0 deletions docs/index_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Berechtigung | Erläuterung
`Plugin_Administration_Archive_Management_Inventory_NAME` | Zugriff auf einzelne ausgewählte Bestände, wobei der Suffix NAME durch den Namen des Bestands zu ersetzen ist
`Plugin_Administration_Archive_Management_All_Inventories` | Zugriff auf alle Bestände
`Plugin_Administration_Archive_Management_Delete` | Löschen des ausgewählten Bestandes
`Plugin_Administration_Archive_Management_Process` | Erstellen von Vorgängen


Eine detaillierte Erläuterung über die Bedienung des Plugins bzw. dessen Funktionen findet sich auf dieser Seite:

Expand Down
1 change: 1 addition & 0 deletions docs/index_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Authorisation | Explanation
`Plugin_Administration_Archive_Management_Inventory_NAME` | Access to individual selected inventories, whereby the suffix NAME must be replaced by the name of the inventory
`Plugin_Administration_Archive_Management_All_Inventories` | Access to all inventories
`Plugin_Administration_Archive_Management_Delete` | Delete the selected inventory
`Plugin_Administration_Archive_Management_Process` | Create processes

A detailed explanation of how to use the plugin and its functions can be found on this page:

Expand Down
401 changes: 260 additions & 141 deletions install/plugin_intranda_administration_archive_management.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions module-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<parent>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-administration-archive-management</artifactId>
<version>24.08.1</version>
<version>24.09</version>
</parent>
<artifactId>plugin-administration-archive-management-base</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-administration-archive-management-lib</artifactId>
<version>24.08.1</version>
<version>24.09</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ public class ArchiveManagementAdministrationPlugin implements IArchiveManagement

private boolean readOnlyMode = true;

@Getter
private boolean allowProcessCreation = false;

@Getter
private boolean allowFileUpload = false;

Expand Down Expand Up @@ -347,13 +350,17 @@ public ArchiveManagementAdministrationPlugin() {
// role to edit vocabularies: Plugin_Administration_Archive_Management_Vocabulary
// role to access all: Plugin_Administration_Archive_Management_All_Inventories
// role to access the inventory 'XYZ': Plugin_Administration_Archive_Management_Inventory_XYZ

// role for process creation: Plugin_Administration_Archive_Management_Process
// role to delete inventory: Plugin_Administration_Archive_Management_Delete

if ((user.isSuperAdmin() || user.getAllUserRoles().contains("Plugin_Administration_Archive_Management_Write"))) {
readOnlyMode = false;
}

if (user.isSuperAdmin() || (user.getAllUserRoles().contains("Plugin_Administration_Archive_Management_Process"))) {
allowProcessCreation = true;
}

if (user.isSuperAdmin() || (user.getAllUserRoles().contains("Plugin_Administration_Archive_Management_Upload"))) {
allowFileUpload = true;
}
Expand Down Expand Up @@ -516,28 +523,34 @@ public void createNewDatabase() {
/*
* get root node from ead document
*/
public void parseEadFile(Document document) {
public void parseEadFile(Document document, Integer recordGroupId) {
Element eadElement = null;
Element collection = document.getRootElement();
if ("collection".equals(collection.getName())) {
eadElement = collection.getChild("ead", nameSpaceRead);
} else {
eadElement = collection;
}

rootElement = parseElement(0, 0, eadElement);
rootElement = parseElement(0, 0, eadElement, recordGroupId);
INodeType rootType = new NodeType("root", null, "fa fa-home", 0);
rootElement.setNodeType(rootType);
rootElement.setDisplayChildren(true);

getDuplicationConfiguration();
}

/*
* get root node from ead document
*/
public void parseEadFile(Document document) {
parseEadFile(document, null);
}

/**
* read the metadata for the current xml node. - create an {@link EadEntry} - execute the configured xpaths on the current node - add the metadata
* to one of the 7 levels - check if the node has sub nodes - call the method recursively for all sub nodes
*/
private IEadEntry parseElement(int order, int hierarchy, Element element) {
private IEadEntry parseElement(int order, int hierarchy, Element element, Integer recordGroupId) {
IEadEntry entry = new EadEntry(order, hierarchy);

for (IMetadataField emf : configuredFields) {
Expand Down Expand Up @@ -623,6 +636,30 @@ private IEadEntry parseElement(int order, int hierarchy, Element element) {
if (entry.getNodeType() == null) {
entry.setNodeType(configuredNodes.get(0));
}
// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}

// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}
entry.calculateFingerprint();

if (recordGroupId != null) {
// save current node
ArchiveManagementManager.saveNode(recordGroupId, entry);
// clear saved metadata to reduce memory usage
entry.getIdentityStatementAreaList().clear();
entry.getContextAreaList().clear();
entry.getContentAndStructureAreaAreaList().clear();
entry.getAccessAndUseAreaList().clear();
entry.getAlliedMaterialsAreaList().clear();
entry.getNotesAreaList().clear();
entry.getDescriptionControlAreaList().clear();
}

if (clist == null) {
clist = element.getChildren("c", nameSpaceRead);
}
Expand All @@ -631,18 +668,13 @@ private IEadEntry parseElement(int order, int hierarchy, Element element) {
int subHierarchy = hierarchy + 1;
for (Element c : clist) {

IEadEntry child = parseElement(subOrder, subHierarchy, c);
IEadEntry child = parseElement(subOrder, subHierarchy, c, recordGroupId);
entry.addSubEntry(child);
child.setParentNode(entry);
subOrder++;
}
}

// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}
entry.calculateFingerprint();
return entry;
}

Expand Down Expand Up @@ -794,7 +826,6 @@ public void readConfiguration() {
configuredNodes = new ArrayList<>();

HierarchicalConfiguration config = null;

try {
config = xmlConfig.configurationAt("//config[./archive = '" + databaseName + "']");
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -1113,9 +1144,11 @@ public void upload() {
Helper.setFehlerMeldung("plugin_administration_archive_missing_Data");
return;
}
readConfiguration();

String uploadedFileName = processUploadedFileName(uploadFile);
databaseName = uploadedFileName;
readConfiguration();

// open document, parse it
try (InputStream input = uploadFile.getInputStream()) {
Document document = XmlTools.readDocumentFromStream(input);
Expand All @@ -1131,27 +1164,23 @@ public void upload() {
String message = "plugin_administration_archive_notEadFile";
throw new FileNotFoundException(message);
}

parseEadFile(document);

// check, if uploaded file was used before
recordGroup = ArchiveManagementManager.getRecordGroupByTitle(uploadedFileName);
if (recordGroup == null) {
recordGroup = new RecordGroup();
recordGroup.setTitle(uploadedFileName);
} else {
// replace existing records
ArchiveManagementManager.deleteAllNodes(recordGroup.getId());
}
ArchiveManagementManager.saveRecordGroup(recordGroup);
parseEadFile(document, recordGroup.getId());
}
} catch (IOException e) {
log.error(e);
}
// check, if uploaded file was used before
recordGroup = ArchiveManagementManager.getRecordGroupByTitle(uploadedFileName);
if (recordGroup == null) {
recordGroup = new RecordGroup();
recordGroup.setTitle(uploadedFileName);
} else {
// replace existing records
ArchiveManagementManager.deleteAllNodes(recordGroup.getId());
}

// save nodes
ArchiveManagementManager.saveRecordGroup(recordGroup);
List<IEadEntry> nodes = rootElement.getAllNodes();
ArchiveManagementManager.saveNodes(recordGroup.getId(), nodes);
databaseName = recordGroup.getTitle();
displayMode = "";
// update existing process ids if the uploaded EAD file has an older version
Expand Down Expand Up @@ -1194,7 +1223,7 @@ private String processUploadedFileName(Part file) {
String uploadedFileName = Paths.get(file.getSubmittedFileName()).getFileName().toString(); // MSIE fix.

// filename must end with xml
if (!uploadedFileName.endsWith(".xml")) {
if (!uploadedFileName.toLowerCase().endsWith(".xml")) {
uploadedFileName = uploadedFileName + ".xml";
}
// remove whitespaces from filename
Expand All @@ -1205,6 +1234,27 @@ private String processUploadedFileName(Part file) {

public void addMetadata(Element currentElement, IEadEntry node, Element xmlRootElement, boolean updateHistory) {
boolean isMainElement = false;

Map<String, List<IValue>> metadata = ArchiveManagementManager.convertStringToMap(node.getData());
node.getIdentityStatementAreaList().clear();
node.getContextAreaList().clear();
node.getContentAndStructureAreaAreaList().clear();
node.getAccessAndUseAreaList().clear();
node.getAlliedMaterialsAreaList().clear();
node.getNotesAreaList().clear();
node.getDescriptionControlAreaList().clear();

for (IMetadataField emf : configuredFields) {
List<IValue> values = metadata.get(emf.getName());
if (emf.isGroup()) {
loadGroupMetadata(node, emf, values);

} else {
IMetadataField toAdd = addFieldToEntry(node, emf, values);
addFieldToNode(node, toAdd);
}
}

if ("ead".equals(currentElement.getName())) {
isMainElement = true;
if (updateHistory) {
Expand Down Expand Up @@ -1233,6 +1283,15 @@ public void addMetadata(Element currentElement, IEadEntry node, Element xmlRootE
for (IMetadataField emf : node.getDescriptionControlAreaList()) {
createEadElement(currentElement, isMainElement, emf, xmlRootElement);
}

node.getIdentityStatementAreaList().clear();
node.getContextAreaList().clear();
node.getContentAndStructureAreaAreaList().clear();
node.getAccessAndUseAreaList().clear();
node.getAlliedMaterialsAreaList().clear();
node.getNotesAreaList().clear();
node.getDescriptionControlAreaList().clear();

Element dsc = null;
if (isMainElement) {
if (StringUtils.isNotBlank(node.getId())) {
Expand Down Expand Up @@ -2244,14 +2303,12 @@ public Document createEadFile() {
readConfiguration();
// reload all nodes from db to get every change
rootElement = ArchiveManagementManager.loadRecordGroup(recordGroup.getId());
loadMetadataForAllNodes();

Document document = new Document();

Element eadRoot = new Element("ead", nameSpaceWrite);
document.setRootElement(eadRoot);
addMetadata(eadRoot, rootElement, eadRoot, true);

addMetadata(eadRoot, rootElement, eadRoot, true);
return document;
}

Expand Down Expand Up @@ -2509,7 +2566,9 @@ public void updateGoobiIds() {
selected = rootElement;
}
List<String> lstNodesWithoutIds = removeInvalidProcessIds();

checkGoobiProcessesForArchiveRefs(lstNodesWithoutIds);

setSelectedEntry(selected);
}

Expand Down Expand Up @@ -2545,11 +2604,10 @@ private List<String> removeInvalidProcessIdsForChildren(IEadEntry currentEntry)
if (!currentEntry.isHasChildren() && goobiProcessTitle != null) {
try {
String strProcessTitle = currentEntry.getGoobiProcessTitle();
Process process = ProcessManager.getProcessByTitle(strProcessTitle);
if (process == null) {
if (ProcessManager.countProcessTitle(strProcessTitle, null) == 0) {
currentEntry.setGoobiProcessTitle(null);
lstNodesWithoutIds.add(currentEntry.getId());

ArchiveManagementManager.saveNode(recordGroup.getId(), currentEntry);
Helper.setMeldung("Removing " + strProcessTitle + " from " + currentEntry.getLabel());
}
} catch (Exception e) {
Expand Down Expand Up @@ -2598,9 +2656,7 @@ private List<String> checkGoobiProcessesForArchiveRefs(List<String> lstNodesWith
node.setGoobiProcessTitle(strProcessTitle);
lstNodesWithNewIds.add(node.getLabel());
Helper.setMeldung("Node '" + node.getLabel() + "' has been given Goobi process ID: " + strProcessTitle);
} else {

//perhaps remove the NodeId from the process?
ArchiveManagementManager.saveNode(recordGroup.getId(), node);
}
}

Expand Down Expand Up @@ -3139,9 +3195,12 @@ public boolean isReadOnlyModus() {
public void eadExport() {
List<String> exportFolders = exportConfiguration.get(databaseName);
if (exportFolders == null || exportFolders.isEmpty()) {
Helper.setFehlerMeldung("plugin_administration_archive_eadExportNotConfigured");
databaseName = null;
return;
exportFolders = exportConfiguration.get("*");
if (exportFolders == null || exportFolders.isEmpty()) {
Helper.setFehlerMeldung("plugin_administration_archive_eadExportNotConfigured");
databaseName = null;
return;
}
}

Document document = createEadFile();
Expand Down
Loading

0 comments on commit 37c44db

Please sign in to comment.