Skip to content

Commit 9a56e2d

Browse files
committed
Move linking child processes to a separate, dedidcated dialog in metadata editor
1 parent ec2549b commit 9a56e2d

File tree

14 files changed

+423
-298
lines changed

14 files changed

+423
-298
lines changed

Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddDocStrucTypeDialog.java

Lines changed: 4 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Map.Entry;
2727
import java.util.Objects;
2828
import java.util.Optional;
29-
import java.util.Set;
3029
import java.util.stream.Collectors;
3130

3231
import jakarta.faces.model.SelectItem;
@@ -42,26 +41,21 @@
4241
import org.kitodo.api.dataformat.LogicalDivision;
4342
import org.kitodo.api.dataformat.PhysicalDivision;
4443
import org.kitodo.api.dataformat.View;
45-
import org.kitodo.data.database.beans.Process;
46-
import org.kitodo.data.database.exceptions.DAOException;
4744
import org.kitodo.exceptions.InvalidMetadataValueException;
4845
import org.kitodo.exceptions.NoSuchMetadataFieldException;
4946
import org.kitodo.exceptions.UnknownTreeNodeDataException;
5047
import org.kitodo.production.helper.Helper;
5148
import org.kitodo.production.metadata.InsertionPosition;
5249
import org.kitodo.production.metadata.MetadataEditor;
53-
import org.kitodo.production.services.ServiceManager;
5450
import org.kitodo.production.services.dataeditor.DataEditorService;
55-
import org.primefaces.PrimeFaces;
5651
import org.primefaces.model.TreeNode;
5752

5853
/**
5954
* Backing bean for the add doc struc type dialog of the metadata editor.
6055
*/
61-
public class AddDocStrucTypeDialog {
56+
public class AddDocStrucTypeDialog extends AddNodeDialog {
6257
private static final Logger logger = LogManager.getLogger(AddDocStrucTypeDialog.class);
6358

64-
private final DataEditorForm dataEditor;
6559
private List<SelectItem> selectionItemsForChildren;
6660
private List<SelectItem> selectionItemsForParent;
6761
private List<SelectItem> selectionItemsForSiblings;
@@ -77,10 +71,6 @@ public class AddDocStrucTypeDialog {
7771
private String selectLastPageOnAddNode;
7872
private List<SelectItem> selectPageOnAddNodeItems;
7973
private List<View> preselectedViews;
80-
private String processNumber = "";
81-
private Process selectedProcess = null;
82-
private List<Process> processes = Collections.emptyList();
83-
private boolean linkSubDialogVisible = false;
8474
private static final String PREVIEW_MODE = "preview";
8575
private static final String LIST_MODE = "list";
8676
private TreeNode previouslySelectedLogicalNode;
@@ -91,25 +81,7 @@ public class AddDocStrucTypeDialog {
9181
* @see "WEB-INF/templates/includes/metadataEditor/dialogs/addDocStrucType.xhtml"
9282
*/
9383
AddDocStrucTypeDialog(DataEditorForm dataEditor) {
94-
this.dataEditor = dataEditor;
95-
}
96-
97-
/**
98-
* Check and return if sub dialog is visible.
99-
*
100-
* @return sub dialog visibility
101-
*/
102-
public boolean isLinkSubDialogVisible() {
103-
return this.linkSubDialogVisible;
104-
}
105-
106-
/**
107-
* Set sub dialog visibility.
108-
*
109-
* @param visible whether sub dialog is visible or not
110-
*/
111-
public void setLinkSubDialogVisible(boolean visible) {
112-
this.linkSubDialogVisible = visible;
84+
super(dataEditor);
11385
}
11486

11587
/**
@@ -431,37 +403,6 @@ public void prepare() {
431403
}
432404
}
433405

434-
/**
435-
* Determines the logical parent division that can be used as a basis for the dialog.
436-
*
437-
* <p>In case physical divisions are selected, the parent logical division is returned.</p>
438-
*
439-
* <p>In case a single logical division is selected, the logical division itself is returned.</p>
440-
*
441-
* <p>In case multiple divisions are selected, or physical divisions have multiple different parents, nothing is returned.</p>
442-
*/
443-
private Optional<LogicalDivision> getTargetLogicalDivisionFromNodeSelection() {
444-
Set<LogicalDivision> logicalDivisionSet = dataEditor.getStructurePanel().getSelectedLogicalNodes().stream()
445-
.map(StructureTreeOperations::getTreeNodeLogicalParentOrSelf)
446-
.map(StructureTreeOperations::getLogicalDivisionFromTreeNode)
447-
.collect(Collectors.toSet());
448-
449-
if (logicalDivisionSet.isEmpty()) {
450-
// determine logical parent division for selection of media (in case of gallery selection)
451-
logicalDivisionSet.addAll(
452-
dataEditor.getSelectedMedia().stream()
453-
.map(Pair::getRight)
454-
.collect(Collectors.toSet())
455-
);
456-
}
457-
458-
if (logicalDivisionSet.size() == 1) {
459-
LogicalDivision logicalDivision = logicalDivisionSet.iterator().next();
460-
return Optional.of(logicalDivision);
461-
}
462-
return Optional.empty();
463-
}
464-
465406
/**
466407
* Update lists of available doc struct types that can be added to the currently selected structure element in the
467408
* currently selected position.
@@ -600,9 +541,6 @@ public void preparePreselectedViews() {
600541
*/
601542
public void resetValues() {
602543
preselectedViews = Collections.emptyList();
603-
processNumber = "";
604-
processes = Collections.emptyList();
605-
linkSubDialogVisible = false;
606544
inputMetaDataValue = "";
607545
elementsToAddSpinnerValue = 1;
608546
selectFirstPageOnAddNode = null;
@@ -613,97 +551,6 @@ public void resetValues() {
613551
}
614552
}
615553

616-
/**
617-
* Returns the process number. The process number is an input field where
618-
* the user can enter the process number or the process title, and then it
619-
* is searched for. But search is only when the button is clicked (too much
620-
* load otherwise).
621-
*
622-
* @return the process number
623-
*/
624-
public String getProcessNumber() {
625-
return processNumber;
626-
}
627-
628-
/**
629-
* Sets the process number when the user entered it.
630-
*
631-
* @param processNumber
632-
* process number to set
633-
*/
634-
public void setProcessNumber(String processNumber) {
635-
this.processNumber = processNumber;
636-
}
637-
638-
/**
639-
* Function for the button for the search. Looks for suitable processes. If
640-
* the process number is a number and the process exists, it is already
641-
* found. Otherwise it must be searched for, excluding the wrong ruleset or
642-
* the wrong client.
643-
*/
644-
public void search() {
645-
if (processNumber.trim().isEmpty()) {
646-
alert(Helper.getTranslation("dialogAddDocStrucType.searchButtonClick.empty"));
647-
return;
648-
}
649-
try {
650-
Set<String> allowedSubstructuralElements = DataEditorService.getStructuralElementView(this.dataEditor)
651-
.getAllowedSubstructuralElements().keySet();
652-
List<Integer> ids = ServiceManager.getProcessService().findLinkableChildProcesses(processNumber,
653-
dataEditor.getProcess().getRuleset().getId(), allowedSubstructuralElements)
654-
.stream().map(Process::getId).collect(Collectors.toList());
655-
if (ids.isEmpty()) {
656-
alert(Helper.getTranslation("dialogAddDocStrucType.searchButtonClick.noHits"));
657-
}
658-
processes = new LinkedList<>();
659-
for (int processId : ids) {
660-
processes.add(ServiceManager.getProcessService().getById(processId));
661-
}
662-
} catch (DAOException e) {
663-
logger.catching(e);
664-
alert(Helper.getTranslation("dialogAddDocStrucType.searchButtonClick.error", e.getMessage()));
665-
}
666-
}
667-
668-
/**
669-
* Displays a dialog box with a message to the user.
670-
*
671-
* @param message
672-
* message to show
673-
*/
674-
private void alert(String message) {
675-
PrimeFaces.current().executeScript("alert('" + message + "');");
676-
}
677-
678-
/**
679-
* Returns the process selected by the user in the drop-down list.
680-
*
681-
* @return the selected process
682-
*/
683-
public Process getSelectedProcess() {
684-
return selectedProcess;
685-
}
686-
687-
/**
688-
* Sets the number of the process selected by the user.
689-
*
690-
* @param selectedProcess
691-
* selected process
692-
*/
693-
public void setSelectedProcess(Process selectedProcess) {
694-
this.selectedProcess = selectedProcess;
695-
}
696-
697-
/**
698-
* Returns the list of items to populate the drop-down list to select a
699-
* process.
700-
*
701-
* @return the list of processes
702-
*/
703-
public List<Process> getProcesses() {
704-
return processes;
705-
}
706-
707554
/**
708555
* Get preselectedViews.
709556
*
@@ -713,19 +560,6 @@ public List<View> getPreselectedViews() {
713560
return preselectedViews;
714561
}
715562

716-
/**
717-
* Adds the link when the user clicks OK.
718-
*/
719-
public void addProcessLink() {
720-
dataEditor.getCurrentChildren().add(selectedProcess);
721-
MetadataEditor.addLink(getTargetLogicalDivisionFromNodeSelection().orElseThrow(IllegalStateException::new),
722-
selectedProcess.getId());
723-
dataEditor.getStructurePanel().show(true);
724-
dataEditor.getPaginationPanel().show();
725-
selectedProcess = null;
726-
processes = Collections.emptyList();
727-
}
728-
729563
/**
730564
* Return the label of the currently selected structure.
731565
*
@@ -744,9 +578,8 @@ public String getCurrentStructureLabel() {
744578
}
745579

746580
private StructuralElementViewInterface getDivisionViewOfStructure(String structure) {
747-
StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement()
748-
.getStructuralElementView(structure, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
749-
return divisionView;
581+
return dataEditor.getRulesetManagement().getStructuralElementView(structure, dataEditor.getAcquisitionStage(),
582+
dataEditor.getPriorityList());
750583
}
751584

752585
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org>
3+
*
4+
* This file is part of the Kitodo project.
5+
*
6+
* It is licensed under GNU General Public License version 3 or later.
7+
*
8+
* For the full copyright and license information, please read the
9+
* GPL3-License.txt file that was distributed with this source code.
10+
*/
11+
12+
package org.kitodo.production.forms.dataeditor;
13+
14+
import java.util.Optional;
15+
import java.util.Set;
16+
import java.util.stream.Collectors;
17+
18+
import org.apache.commons.lang3.tuple.Pair;
19+
import org.kitodo.api.dataformat.LogicalDivision;
20+
21+
public class AddNodeDialog {
22+
23+
protected final DataEditorForm dataEditor;
24+
25+
AddNodeDialog(DataEditorForm dataEditor) {
26+
this.dataEditor = dataEditor;
27+
}
28+
29+
/**
30+
* Determines the logical parent division that can be used as a basis for the dialog.
31+
*
32+
* <p>In case physical divisions are selected, the parent logical division is returned.</p>
33+
*
34+
* <p>In case a single logical division is selected, the logical division itself is returned.</p>
35+
*
36+
* <p>In case multiple divisions are selected, or physical divisions have multiple different parents, nothing is returned.</p>
37+
*/
38+
protected Optional<LogicalDivision> getTargetLogicalDivisionFromNodeSelection() {
39+
Set<LogicalDivision> logicalDivisionSet = dataEditor.getStructurePanel().getSelectedLogicalNodes().stream()
40+
.map(StructureTreeOperations::getTreeNodeLogicalParentOrSelf)
41+
.map(StructureTreeOperations::getLogicalDivisionFromTreeNode)
42+
.collect(Collectors.toSet());
43+
44+
if (logicalDivisionSet.isEmpty()) {
45+
// determine logical parent division for selection of media (in case of gallery selection)
46+
logicalDivisionSet.addAll(
47+
dataEditor.getSelectedMedia().stream()
48+
.map(Pair::getRight)
49+
.collect(Collectors.toSet())
50+
);
51+
}
52+
53+
if (logicalDivisionSet.size() == 1) {
54+
LogicalDivision logicalDivision = logicalDivisionSet.iterator().next();
55+
return Optional.of(logicalDivision);
56+
}
57+
return Optional.empty();
58+
}
59+
60+
}

Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public class DataEditorForm extends ValidatableForm implements MetadataTreeTable
110110
*/
111111
private final ChangeDocStrucTypeDialog changeDocStrucTypeDialog;
112112

113+
private final LinkProcessDialog linkProcessDialog;
114+
113115
/**
114116
* Backing bean for the edit pages dialog.
115117
*/
@@ -250,6 +252,7 @@ public DataEditorForm() {
250252
this.changeDocStrucTypeDialog = new ChangeDocStrucTypeDialog(this);
251253
this.editPagesDialog = new EditPagesDialog(this);
252254
this.uploadFileDialog = new UploadFileDialog(this);
255+
this.linkProcessDialog = new LinkProcessDialog(this);
253256
}
254257

255258
/**
@@ -697,6 +700,10 @@ public ChangeDocStrucTypeDialog getChangeDocStrucTypeDialog() {
697700
return changeDocStrucTypeDialog;
698701
}
699702

703+
public LinkProcessDialog getLinkProcessDialog() {
704+
return linkProcessDialog;
705+
}
706+
700707
/**
701708
* Returns the backing bean for the edit pages dialog. This function is used
702709
* by PrimeFaces to access the elements of the edit pages dialog.

0 commit comments

Comments
 (0)