Skip to content
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

Enable manipulation of child process links in metadata editor #5507

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public ProcessFieldedMetadata getPhysicalMetadataTable() {
}

void showLogical(Optional<LogicalDivision> optionalStructure) {
if (optionalStructure.isPresent()) {
if (optionalStructure.isPresent() && Objects.isNull(optionalStructure.get().getLink())) {
logicalMetadataTable = createProcessFieldedMetadata(optionalStructure.get());
dataEditorForm.getAddMetadataDialog().prepareAddableMetadataForStructure(
getLogicalMetadataRows().getChildren());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,16 +1363,17 @@ private void checkLogicalDragDrop(StructureTreeNode dragNode, StructureTreeNode
dropStructure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());

LinkedList<LogicalDivision> dragParents;
if (divisionView.getAllowedSubstructuralElements().containsKey(dragStructure.getType())) {
if (divisionView.getAllowedSubstructuralElements().containsKey(dragStructure.getType())
|| Objects.nonNull(dragStructure.getLink())) {
dragParents = MetadataEditor.getAncestorsOfLogicalDivision(dragStructure,
dataEditor.getWorkpiece().getLogicalStructure());
if (!dragParents.isEmpty()) {
LogicalDivision parentStructure = dragParents.get(dragParents.size() - 1);
if (parentStructure.getChildren().contains(dragStructure)) {
if (!this.logicalStructureTreeContainsMedia()) {
preserveLogical();
} else {
if (logicalStructureTreeContainsMedia()) {
preserveLogicalAndPhysical();
} else {
preserveLogical();
}
this.dataEditor.getGalleryPanel().updateStripes();
this.dataEditor.getPaginationPanel().show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static void addLink(LogicalDivision parentLogicalDivision, int index,
* Remove link to process with ID 'childProcessId' from workpiece of Process 'parentProcess'.
*
* @param parentProcess Process from which link is removed
* @param childProcessId ID of process whose link will be remove from workpiece of parent process
* @param childProcessId ID of process whose link will be removed from workpiece of parent process
* @throws IOException thrown if meta.xml could not be loaded
*/
public static void removeLink(Process parentProcess, int childProcessId) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ public static List<SelectItem> getAddableMetadataForStructureElement(DataEditorF
Collection<String> additionalFields = isLogicalStructure ? dataEditor.getMetadataPanel()
.getLogicalMetadataTable().getAdditionallySelectedFields() : dataEditor.getMetadataPanel()
.getPhysicalMetadataTable().getAdditionallySelectedFields();
addableMetadata = getAddableMetadataForStructureElement(structureView, existingMetadata,
additionalFields, dataEditor.getProcess().getRuleset());
if (Objects.nonNull(structureView)) {
addableMetadata = getAddableMetadataForStructureElement(structureView, existingMetadata,
additionalFields, dataEditor.getProcess().getRuleset());
}
} catch (InvalidMetadataValueException e) {
Helper.setErrorMessage(e);
}
Expand Down Expand Up @@ -245,22 +247,46 @@ public static StructuralElementViewInterface getStructuralElementView(DataEditor
.getStructuralElementView(
selectedStructure.get().getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
} else {
TreeNode selectedLogicalNode = dataEditor.getStructurePanel().getSelectedLogicalNode();
if (Objects.nonNull(selectedLogicalNode)
&& selectedLogicalNode.getData() instanceof StructureTreeNode) {
StructureTreeNode structureTreeNode = (StructureTreeNode) selectedLogicalNode.getData();
if (structureTreeNode.getDataObject() instanceof View) {
View view = (View) structureTreeNode.getDataObject();
if (Objects.nonNull(view.getPhysicalDivision())) {
return dataEditor.getRulesetManagement().getStructuralElementView(
view.getPhysicalDivision().getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
}
}
}

TreeNode selectedLogicalNode = dataEditor.getStructurePanel().getSelectedLogicalNode();

if (Objects.isNull(selectedLogicalNode)) {
throw new IllegalStateException("No logical node selected!");
}

if (!(selectedLogicalNode.getData() instanceof StructureTreeNode)) {
String nodeClass = "unknown";
if (Objects.nonNull(selectedLogicalNode.getData())) {
nodeClass = selectedLogicalNode.getData().getClass().getName();
}
throw new IllegalStateException("Selected logical node data has wrong type '" + nodeClass
+ "'! ('StructureTreeNode' expected)");
}
StructureTreeNode structureTreeNode = (StructureTreeNode) selectedLogicalNode.getData();

Object dataObject = structureTreeNode.getDataObject();

// data object is null for structures inside parent processes
if (Objects.isNull(dataObject)) {
return null;
}

if (dataObject instanceof View) {
View view = (View) dataObject;
if (Objects.isNull(view.getPhysicalDivision())) {
throw new IllegalStateException("View has no physical division assigned!");
}
return dataEditor.getRulesetManagement().getStructuralElementView(
view.getPhysicalDivision().getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
}

// data object is a sibling process
if (dataObject instanceof Process) {
return null;
}
throw new IllegalStateException();
throw new IllegalStateException("Data object has unknown type '" + dataObject.getClass().getName() + "'!");
}

/**
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ unassignTasks=Aufgaben zur\u00FCcksetzen
unit=Einheit
uncounted=unnummeriert
unknown=Unbekannt
unlinkProcess=Prozessverkn\u00FCpfung aufheben
unlocked=Entsperrt
up=hoch
updateFileReferences=Aktualisierung der Dateireferenzen
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ unassignTasks=Unassign Tasks
unit=unit
uncounted=uncounted
unknown=Unknown
unlinkProcess=Unlink process
unlocked=Unlocked
up=up
updateFileReferences=Update file references
Expand Down
5 changes: 0 additions & 5 deletions Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -2545,11 +2545,6 @@ Column content

.ui-tree .ui-treenode.linked {
background: transparent;
cursor: not-allowed;
}

.ui-tree .ui-treenode.linked span {
pointer-events: none;
}

.ui-tree .ui-treenode.undefined .ui-treenode-label span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
rendered="#{not readOnly}">
<p:row>
<h:panelGroup id="addMetadataButtonWrapper"
rendered="#{not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
title="#{DataEditorForm.metadataPanel.metadataAddableToStructureElement() ? msgs['dataEditor.addMetadata.newMetadata'] : msgs['dataEditor.addMetadata.noMetadataAddable']}">
<p:commandButton id="addMetadataButton"
icon="fa fa-plus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</p:tree>
<p:contextMenu for="logicalTree" id="contextMenuLogicalTree" widgetVar="contextMenuLogicalTree">
<p:menuitem value="#{msgs.addElement}"
rendered="#{DataEditorForm.selectedMedia.size() lt 1}"
rendered="#{DataEditorForm.selectedMedia.size() lt 1 and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
icon="fa fa-plus fa-sm"
styleClass="plain"
disabled="#{readOnly}"
Expand All @@ -115,7 +115,7 @@
<f:actionListener binding="#{DataEditorForm.addDocStrucTypeDialog.preparePreselectedViews()}"/>
</p:menuitem>
<p:menuitem value="#{DataEditorForm.consecutivePagesSelected() ? msgs.addElement.concat(' ').concat(msgs.assignMedia) : msgs['dataEditor.removeElement.noConsecutivePagesSelected']}"
rendered="#{DataEditorForm.selectedMedia.size() ge 1}"
rendered="#{DataEditorForm.selectedMedia.size() ge 1 and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
icon="fa fa-plus fa-sm"
styleClass="plain"
disabled="#{readOnly or not DataEditorForm.consecutivePagesSelected()}"
Expand All @@ -126,7 +126,7 @@
<f:actionListener binding="#{DataEditorForm.addDocStrucTypeDialog.preparePreselectedViews()}"/>
</p:menuitem>
<p:menuitem value="#{msgs.changeDocstructType}"
rendered="#{DataEditorForm.structurePanel.selectedLogicalNode.data.dataObject['class'].simpleName ne 'View'}"
rendered="#{DataEditorForm.structurePanel.selectedLogicalNode.data.dataObject['class'].simpleName ne 'View' and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
icon="fa fa-pencil fa-sm"
styleClass="plain"
disabled="#{readOnly}"
Expand All @@ -138,7 +138,7 @@
icon="fa fa-link fa-sm"
styleClass="plain"
disabled="#{readOnly}"
rendered="#{DataEditorForm.structurePanel.assignableSeveralTimes}"
rendered="#{DataEditorForm.structurePanel.assignableSeveralTimes and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
action="#{DataEditorForm.structurePanel.assign}"
process="@this"
oncomplete="$('#loadingScreen').hide()"
Expand All @@ -151,7 +151,7 @@
icon="fa fa-chain-broken fa-sm"
styleClass="plain"
disabled="#{readOnly}"
rendered="#{DataEditorForm.structurePanel.assignedSeveralTimes}"
rendered="#{DataEditorForm.structurePanel.assignedSeveralTimes and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
action="#{DataEditorForm.structurePanel.unassign}"
process="@this"
oncomplete="$('#loadingScreen').hide()"
Expand All @@ -162,14 +162,14 @@
imagePreviewForm:mediaContextMenu"/>
<p:menuitem value="#{msgs.uploadMedia}"
action="#{DataEditorForm.uploadFileDialog.prepare}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.isFolderConfigurationComplete()}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.isFolderConfigurationComplete() and not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
icon="fa fa-download fa-sm"
styleClass="plain"
update = "uploadFileDialog"
disabled="#{readOnly}"
process="@this"/>
<p:menuitem value="#{msgs.removeElement}"
rendered="#{DataEditorForm.structurePanel.selectedLogicalNode.data.dataObject['class'].simpleName ne 'View'}"
<p:menuitem value="#{DataEditorForm.structurePanel.selectedLogicalNode.data.linked ? msgs.unlinkProcess : msgs.removeElement}"
rendered="#{DataEditorForm.structurePanel.selectedLogicalNode.data.dataObject ne null and DataEditorForm.structurePanel.selectedLogicalNode.data.dataObject['class'].simpleName ne 'View'}"
icon="fa fa-trash fa-sm"
styleClass="plain"
disabled="#{readOnly}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
rendered="#{not readOnly}">
<p:row>
<h:panelGroup id="addMetadataButtonWrapper"
rendered="#{not DataEditorForm.structurePanel.selectedLogicalNode.data.linked}"
title="#{DataEditorForm.metadataPanel.metadataAddableToMediaUnit() ? msgs['dataEditor.addMetadata.newMetadata'] : msgs['dataEditor.addMetadata.noMetadataAddable']}">
<p:commandButton id="addMetadataButton"
icon="fa fa-plus"
Expand Down
42 changes: 42 additions & 0 deletions Kitodo/src/test/java/org/kitodo/MockDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,21 @@ private static void insertProcesses() throws DAOException, DataException {
ServiceManager.getProcessService().save(thirdProcess);
}

/**
* The folders up to and including number 9 in the metadata folder are
* already in use, so here we insert placeholder processes so that the
* newspaper’s overall process gets the number 10.
* @param startId ID of first placeholder process to add
* @param endId ID of last placeholder process to add
*/
public static void insertPlaceholderProcesses(int startId, int endId) throws DataException {
for (int processNumber = startId; processNumber <= endId; processNumber++) {
Process nthProcess = new Process();
nthProcess.setTitle("Placeholder process number ".concat(Integer.toString(processNumber)));
ServiceManager.getProcessService().save(nthProcess);
}
}

public static void insertProcessesForHierarchyTests() throws DAOException, DataException {
Process fourthProcess = new Process();
fourthProcess.setProject(ServiceManager.getProjectService().getById(1));
Expand Down Expand Up @@ -1989,4 +2004,31 @@ public static ImportConfiguration getK10PlusImportConfiguration() throws DAOExce
public static ImportConfiguration getCustomTypeImportConfiguration() throws DAOException {
return ServiceManager.getImportConfigurationService().getById(CUSTOM_CONFIGURATION_ID);
}

/**
* Add process with title 'processTitle' to MockDatabase.
*
* @param processTitle title of process
* @param projectId ID of project to add to new process
* @param templateId ID of template to add to new process
* @return new process
* @throws DAOException when retrieving entities from database fails
* @throws DataException when saving new process to database fails
*/
public static Process addProcess(String processTitle, int projectId, int templateId)
throws DAOException, DataException {
Project projectOne = ServiceManager.getProjectService().getById(projectId);
Template template = ServiceManager.getTemplateService().getById(templateId);
LocalDate localDate = LocalDate.of(2023, 1, 3);
Process process = new Process();
process.setTitle(processTitle);
process.setCreationDate(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
process.setSortHelperImages(30);
process.setDocket(template.getDocket());
process.setProject(projectOne);
process.setRuleset(template.getRuleset());
process.setTemplate(template);
ServiceManager.getProcessService().save(process);
return process;
}
}
Loading