2626import java .util .Map .Entry ;
2727import java .util .Objects ;
2828import java .util .Optional ;
29- import java .util .Set ;
3029import java .util .stream .Collectors ;
3130
3231import jakarta .faces .model .SelectItem ;
4241import org .kitodo .api .dataformat .LogicalDivision ;
4342import org .kitodo .api .dataformat .PhysicalDivision ;
4443import org .kitodo .api .dataformat .View ;
45- import org .kitodo .data .database .beans .Process ;
46- import org .kitodo .data .database .exceptions .DAOException ;
4744import org .kitodo .exceptions .InvalidMetadataValueException ;
4845import org .kitodo .exceptions .NoSuchMetadataFieldException ;
4946import org .kitodo .exceptions .UnknownTreeNodeDataException ;
5047import org .kitodo .production .helper .Helper ;
5148import org .kitodo .production .metadata .InsertionPosition ;
5249import org .kitodo .production .metadata .MetadataEditor ;
53- import org .kitodo .production .services .ServiceManager ;
5450import org .kitodo .production .services .dataeditor .DataEditorService ;
55- import org .primefaces .PrimeFaces ;
5651import 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 /**
0 commit comments