From d8e0625399a182f5a535a4b57e0cc8983b244185 Mon Sep 17 00:00:00 2001 From: Valentin Schulte Date: Wed, 17 May 2023 11:18:29 +0200 Subject: [PATCH 1/3] =?UTF-8?q?proposal=20for=20a=20start=20of=20a=20more?= =?UTF-8?q?=20controlled=20handling=20of=20"alien=20objects"=20in=20data?= =?UTF-8?q?=20directory=20=E2=80=93=20fixes=20metadata=20rebuild=20command?= =?UTF-8?q?=20while=20arbitrary=20files=20present=20in=20data=20dirs=20(pr?= =?UTF-8?q?oject/type)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/MCRDefaultXMLMetadataManager.java | 78 +++++++++++++++++-- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java index af045bee3b..c34bfc43cb 100644 --- a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java +++ b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java @@ -563,12 +563,18 @@ public List listIDsOfType(String type) { public List listIDs() { try (Stream streamBasePath = list(basePath)) { return streamBasePath.flatMap(projectPath -> { - final String project = projectPath.getFileName().toString(); - return list(projectPath).flatMap(typePath -> { - final String type = typePath.getFileName().toString(); - final String base = getStoryKey(project, type); - return listIDsForBase(base).stream(); - }); + if (isProjectDirSane(projectPath)) { + final String project = projectPath.getFileName().toString(); + return list(projectPath).flatMap(typePath -> { + if (isTypeDirSane(typePath)) { + final String type = typePath.getFileName().toString(); + final String base = getStoryKey(project, type); + return listIDsForBase(base).stream(); + } + return Stream.empty(); + }); + } + return Stream.empty(); }).collect(Collectors.toList()); } } @@ -592,7 +598,65 @@ public Collection getObjectBaseIds() { .collect(Collectors.toSet()); } } - + + /** + * + * @param path + * @return true when usable project + */ + private boolean isProjectDirSane(Object path) { + return projectDirStatus(path) > 0; + } + + /** + * + * @param path + * @return: 0 - not usable / no project + * 1 - clean + * 2 - dirty + * + */ + //TODO: consider sanity checks like getObjectTypes() does. (performance penalty?) + private int projectDirStatus(Object path) { + File p = new File(path.toString()); + if (!p.isDirectory()) { + LOGGER.warn( + "File '{}' spotted in data-directory where only subdirectories are expected.", + p.getAbsolutePath() + ); + return 0; + } + return 1; + } + + /** + * + * @param path + * @return true when usable type directory (inside project) + */ + private boolean isTypeDirSane(Object path) { + return typeDirStatus(path) > 0; + } + + /** + * + * @param path + * @return: 0 - not usable / no type dir + * 1 - clean + * 2 - dirty + */ + private int typeDirStatus(Object path) { + File p = new File(path.toString()); + if (!p.isDirectory()) { + LOGGER.warn( + "File '{}' spotted in data-directory where only subdirectories are expected.", + p.getAbsolutePath() + ); + return 0; + } + return 1; + } + /** * Returns the entries of the given path. Throws a MCRException if an I/O-Exceptions occur. * From 2093e13ab1ee99d2c11757c2693986c14a897eb4 Mon Sep 17 00:00:00 2001 From: Valentin Schulte Date: Wed, 28 Jun 2023 16:26:34 +0200 Subject: [PATCH 2/3] reduced approach of MCR-2885 - but with ProjectDirState enum --- .../common/MCRDefaultXMLMetadataManager.java | 47 +++++-------------- .../datamodel/common/ProjectDirState.java | 7 +++ 2 files changed, 20 insertions(+), 34 deletions(-) create mode 100644 mycore-base/src/main/java/org/mycore/datamodel/common/ProjectDirState.java diff --git a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java index c34bfc43cb..8ce7583ee5 100644 --- a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java +++ b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java @@ -600,61 +600,40 @@ public Collection getObjectBaseIds() { } /** - * + * check if we can enter the project directory * @param path - * @return true when usable project + * @return true when usable project directory */ - private boolean isProjectDirSane(Object path) { - return projectDirStatus(path) > 0; - } - - /** - * - * @param path - * @return: 0 - not usable / no project - * 1 - clean - * 2 - dirty - * - */ - //TODO: consider sanity checks like getObjectTypes() does. (performance penalty?) - private int projectDirStatus(Object path) { - File p = new File(path.toString()); - if (!p.isDirectory()) { - LOGGER.warn( - "File '{}' spotted in data-directory where only subdirectories are expected.", - p.getAbsolutePath() - ); - return 0; - } - return 1; + private boolean isProjectDirSane(Path path) { + return projectDirStatus(path) != ProjectDirState.UNUSABLE; } /** - * + * check if we can enter the project-type directory * @param path * @return true when usable type directory (inside project) */ - private boolean isTypeDirSane(Object path) { - return typeDirStatus(path) > 0; + private boolean isTypeDirSane(Path path) { + //currently just the same simple check as project-dir... + return isProjectDirSane(path); } /** * * @param path - * @return: 0 - not usable / no type dir - * 1 - clean - * 2 - dirty + * @return: CLEAN or UNUSABLE */ - private int typeDirStatus(Object path) { + //TODO: consider sanity checks like getObjectTypes() does. (performance penalty?) + private ProjectDirState projectDirStatus(Path path) { File p = new File(path.toString()); if (!p.isDirectory()) { LOGGER.warn( "File '{}' spotted in data-directory where only subdirectories are expected.", p.getAbsolutePath() ); - return 0; + return ProjectDirState.UNUSABLE; } - return 1; + return ProjectDirState.CLEAN; } /** diff --git a/mycore-base/src/main/java/org/mycore/datamodel/common/ProjectDirState.java b/mycore-base/src/main/java/org/mycore/datamodel/common/ProjectDirState.java new file mode 100644 index 0000000000..9f5cb8dd4d --- /dev/null +++ b/mycore-base/src/main/java/org/mycore/datamodel/common/ProjectDirState.java @@ -0,0 +1,7 @@ +package org.mycore.datamodel.common; + +public enum ProjectDirState { + CLEAN, + //DIRTY + UNUSABLE +} From d357e7498cefb0ae72f811c4835d9bc7e0f061ec Mon Sep 17 00:00:00 2001 From: Valentin Schulte Date: Tue, 4 Jul 2023 16:37:42 +0200 Subject: [PATCH 3/3] MCR-2885 - humbly not using stone-age file api anymore --- .../datamodel/common/MCRDefaultXMLMetadataManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java index 8ce7583ee5..dda7e9e0c9 100644 --- a/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java +++ b/mycore-base/src/main/java/org/mycore/datamodel/common/MCRDefaultXMLMetadataManager.java @@ -625,11 +625,10 @@ private boolean isTypeDirSane(Path path) { */ //TODO: consider sanity checks like getObjectTypes() does. (performance penalty?) private ProjectDirState projectDirStatus(Path path) { - File p = new File(path.toString()); - if (!p.isDirectory()) { + if (Files.isDirectory(path)) { LOGGER.warn( "File '{}' spotted in data-directory where only subdirectories are expected.", - p.getAbsolutePath() + path.toAbsolutePath() ); return ProjectDirState.UNUSABLE; }