-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent duplicate and invalid titles #6326
Draft
BartChris
wants to merge
3
commits into
kitodo:master
Choose a base branch
from
BartChris:fix_duplicate_titles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,65 +75,109 @@ public static void cleanDatabase() throws Exception { | |
MockDatabase.cleanDatabase(); | ||
} | ||
|
||
@Test | ||
public void shouldCreateNewProcess() throws Exception { | ||
CreateProcessForm underTest = new CreateProcessForm(); | ||
underTest.getProcessDataTab().setDocType("Monograph"); | ||
Process newProcess = new Process(); | ||
Workpiece newWorkPiece = new Workpiece(); | ||
TempProcess tempProcess = new TempProcess(newProcess, newWorkPiece); | ||
underTest.setProcesses(new LinkedList<>(Collections.singletonList(tempProcess))); | ||
underTest.getMainProcess().setProject(ServiceManager.getProjectService().getById(1)); | ||
underTest.getMainProcess().setRuleset(ServiceManager.getRulesetService().getById(1)); | ||
underTest.getMainProcess().setTitle("title"); | ||
// Helper to create and initialize a CreateProcessForm with common properties | ||
private CreateProcessForm setupCreateProcessForm(String docType, String title) throws Exception { | ||
CreateProcessForm form = new CreateProcessForm(); | ||
form.getProcessDataTab().setDocType(docType); | ||
|
||
Process process = new Process(); | ||
Workpiece workPiece = new Workpiece(); | ||
TempProcess tempProcess = new TempProcess(process, workPiece); | ||
form.setProcesses(new LinkedList<>(Collections.singletonList(tempProcess))); | ||
|
||
form.getMainProcess().setProject(ServiceManager.getProjectService().getById(1)); | ||
form.getMainProcess().setRuleset(ServiceManager.getRulesetService().getById(1)); | ||
form.getMainProcess().setTitle(title); | ||
|
||
form.updateRulesetAndDocType(tempProcess.getProcess().getRuleset()); | ||
return form; | ||
} | ||
|
||
// Helper to manage script permissions | ||
private void setScriptPermissions(boolean enable) throws Exception { | ||
File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); | ||
if (!SystemUtils.IS_OS_WINDOWS) { | ||
ExecutionPermission.setExecutePermission(script); | ||
if (enable) { | ||
ExecutionPermission.setExecutePermission(script); | ||
} else { | ||
ExecutionPermission.setNoExecutePermission(script); | ||
} | ||
} | ||
} | ||
|
||
// Helper to clean up database and file system | ||
private void cleanUpProcess(Process process) throws Exception { | ||
Integer processId = process.getId(); | ||
processService.remove(processId); | ||
fileService.delete(URI.create(processId.toString())); | ||
} | ||
|
||
@Test | ||
public void shouldCreateNewProcess() throws Exception { | ||
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title"); | ||
|
||
setScriptPermissions(true); | ||
long before = processService.count(); | ||
underTest.createNewProcess(); | ||
if (!SystemUtils.IS_OS_WINDOWS) { | ||
ExecutionPermission.setNoExecutePermission(script); | ||
} | ||
setScriptPermissions(false); | ||
|
||
long after = processService.count(); | ||
assertEquals(before + 1, after, "No process was created!"); | ||
|
||
// clean up database, index and file system | ||
Integer processId = newProcess.getId(); | ||
processService.remove(processId); | ||
fileService.delete(URI.create(processId.toString())); | ||
cleanUpProcess(underTest.getMainProcess()); | ||
} | ||
|
||
/** | ||
* tests creation of processes without workflow. | ||
*/ | ||
@Test | ||
public void shouldCreateNewProcessWithoutWorkflow() throws Exception { | ||
CreateProcessForm underTest = new CreateProcessForm(); | ||
underTest.getProcessDataTab().setDocType("MultiVolumeWork"); | ||
Process newProcess = new Process(); | ||
Workpiece newWorkPiece = new Workpiece(); | ||
TempProcess tempProcess = new TempProcess(newProcess, newWorkPiece); | ||
underTest.setProcesses(new LinkedList<>(Collections.singletonList(tempProcess))); | ||
underTest.getMainProcess().setProject(ServiceManager.getProjectService().getById(1)); | ||
underTest.getMainProcess().setRuleset(ServiceManager.getRulesetService().getById(1)); | ||
underTest.getMainProcess().setTitle("title"); | ||
CreateProcessForm underTest = setupCreateProcessForm("MultiVolumeWork", "title"); | ||
|
||
File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); | ||
ExecutionPermission.setExecutePermission(script); | ||
setScriptPermissions(true); | ||
long before = processService.count(); | ||
underTest.createNewProcess(); | ||
ExecutionPermission.setNoExecutePermission(script); | ||
setScriptPermissions(false); | ||
|
||
long after = processService.count(); | ||
assertEquals(before + 1, after, "No process was created!"); | ||
assertTrue(underTest.getMainProcess().getTasks().isEmpty(), "Process should not have tasks"); | ||
assertNull(underTest.getMainProcess().getSortHelperStatus(), "Process should not have sortHelperStatus"); | ||
|
||
assertTrue(newProcess.getTasks().isEmpty(), "Process should not have tasks"); | ||
assertNull(newProcess.getSortHelperStatus(), "process should not have sortHelperStatus"); | ||
cleanUpProcess(underTest.getMainProcess()); | ||
} | ||
|
||
// clean up database, index and file system | ||
Integer processId = newProcess.getId(); | ||
processService.remove(processId); | ||
fileService.delete(URI.create(processId.toString())); | ||
@Test | ||
public void shouldNotCreateNewProcessWithInvalidTitle() throws Exception { | ||
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title with whitespaces"); | ||
|
||
long before = processService.count(); | ||
underTest.createNewProcess(); | ||
long after = processService.count(); | ||
|
||
assertEquals(before, after, "A process with an invalid title was created!"); | ||
} | ||
|
||
@Test | ||
public void shouldNotAllowDuplicateTitles() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably have to take into account the configuration here. On some systems this is allowed... |
||
// First process creation | ||
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title"); | ||
|
||
setScriptPermissions(true); | ||
long before = processService.count(); | ||
underTest.createNewProcess(); | ||
setScriptPermissions(false); | ||
|
||
long after = processService.count(); | ||
assertEquals(before + 1, after, "First process creation failed. No process was created!"); | ||
|
||
// Second process creation with duplicate title | ||
CreateProcessForm underTestTwo = setupCreateProcessForm("Monograph", "title"); | ||
|
||
long beforeDuplicate = processService.count(); | ||
underTestTwo.createNewProcess(); | ||
long afterDuplicate = processService.count(); | ||
|
||
assertEquals(beforeDuplicate, afterDuplicate, "A duplicate process with the same title was created!"); | ||
|
||
cleanUpProcess(underTest.getMainProcess()); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the new default value not even updated in the
kitodo_config.properties
files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering: This is a hard limitation of the Kitodo software, some titles lead to problems later. Should we allow to change that in the config.properties at all? Or should we hardcode that in the application? Additionally one can think of allowing additional regexes which might be checked on top of the minimal requirements. See #6055
cc @solth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At SLUB we allow even the
.
inside the process title as for historical reasons this was needed to create the processes. Maybe this can be changed now but this should be discussed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more note: the
w
meta character in regular expressions stands fora-z, A-Z, 0-9, including _ (underscore)
. So the expression can be simplified to^[\\w-]+$
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about chosing a new parameter name "validateProcessTitle" which avoids the current "denglisch" (English-German mix)?