Skip to content

Commit 0433b97

Browse files
authored
Merge pull request #6443 from thomaslow/import-structural-data-from-catalog-fixes-5915
Import catalog metadata from any record in the metadata editor
2 parents a5d79cb + 0f48094 commit 0433b97

26 files changed

Lines changed: 555 additions & 119 deletions

Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,10 @@ private String parentTypeIfForbidden() throws IOException {
505505
* id of project to query from database
506506
* @param referringView
507507
* view the user was coming from
508+
* @param showDialog
509+
* whether to show the appropriate dialog for the default import configuration
508510
*/
509-
public void prepareProcess(int templateId, int projectId, String referringView, Integer parentId) {
511+
public void prepareProcess(int templateId, int projectId, String referringView, Integer parentId, boolean showDialog) {
510512
this.referringView = referringView;
511513
ProcessGenerator processGenerator = new ProcessGenerator();
512514
try {
@@ -544,15 +546,15 @@ public void prepareProcess(int templateId, int projectId, String referringView,
544546
}
545547
}
546548
processDataTab.prepare();
547-
showDialogForImportConfiguration(currentImportConfiguration);
549+
showDialogForImportConfiguration(currentImportConfiguration, showDialog);
548550
}
549551
} catch (ProcessGenerationException | DataException | DAOException | IOException e) {
550552
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
551553
}
552554
}
553555

554-
private void showDialogForImportConfiguration(ImportConfiguration importConfiguration) {
555-
if (Objects.nonNull(importConfiguration)) {
556+
private void showDialogForImportConfiguration(ImportConfiguration importConfiguration, boolean showDialog) {
557+
if (Objects.nonNull(importConfiguration) && showDialog) {
556558
if (ImportConfigurationType.OPAC_SEARCH.name().equals(importConfiguration.getConfigurationType())) {
557559
PrimeFaces.current().executeScript("PF('catalogSearchDialog').show();");
558560
} else if (ImportConfigurationType.PROCESS_TEMPLATE.name().equals(importConfiguration.getConfigurationType())) {

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ public class DataEditorForm implements MetadataTreeTableInterface, RulesetSetupI
9797
*/
9898
private final AddMetadataDialog addMetadataDialog;
9999

100-
private final UpdateMetadataDialog updateMetadataDialog;
101-
102100
/**
103101
* Backing bean for the add PhysicalDivision dialog.
104102
*/
@@ -240,7 +238,6 @@ public DataEditorForm() {
240238
this.paginationPanel = new PaginationPanel(this);
241239
this.addDocStrucTypeDialog = new AddDocStrucTypeDialog(this);
242240
this.addMetadataDialog = new AddMetadataDialog(this);
243-
this.updateMetadataDialog = new UpdateMetadataDialog(this);
244241
this.addPhysicalDivisionDialog = new AddPhysicalDivisionDialog(this);
245242
this.changeDocStrucTypeDialog = new ChangeDocStrucTypeDialog(this);
246243
this.editPagesDialog = new EditPagesDialog(this);
@@ -670,16 +667,6 @@ public AddMetadataDialog getAddMetadataDialog() {
670667
return addMetadataDialog;
671668
}
672669

673-
/**
674-
* Get updateMetadataDialog.
675-
*
676-
* @return value of updateMetadataDialog
677-
*/
678-
public UpdateMetadataDialog getUpdateMetadataDialog() {
679-
return updateMetadataDialog;
680-
}
681-
682-
683670
/**
684671
* Returns the backing bean for the add media dialog. This function is used
685672
* by PrimeFaces to access the elements of the add media dialog.
@@ -1295,28 +1282,6 @@ public String getMetadataFileLoadingError() {
12951282
return metadataFileLoadingError;
12961283
}
12971284

1298-
/**
1299-
* Check and return whether conditions for metadata update are met or not.
1300-
*
1301-
* @return whether metadata of process can be updated
1302-
*/
1303-
public boolean canUpdateMetadata() {
1304-
try {
1305-
return DataEditorService.canUpdateCatalogMetadata(process, workpiece, structurePanel.getSelectedLogicalNodeIfSingle());
1306-
} catch (IOException e) {
1307-
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
1308-
return false;
1309-
}
1310-
}
1311-
1312-
/**
1313-
* Perform metadata update for current process.
1314-
*/
1315-
public void applyMetadataUpdate() {
1316-
DataEditorService.updateMetadataWithNewValues(workpiece, updateMetadataDialog.getMetadataComparisons());
1317-
metadataPanel.update();
1318-
}
1319-
13201285
/**
13211286
* Retrieve and return value of metadata configured as functional metadata 'recordIdentifier'.
13221287
*

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

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@
1111

1212
package org.kitodo.production.forms.dataeditor;
1313

14+
import java.io.IOException;
15+
import java.io.Serializable;
1416
import java.util.HashSet;
1517
import java.util.LinkedList;
1618
import java.util.List;
19+
import java.util.Objects;
1720

21+
import javax.faces.view.ViewScoped;
22+
import javax.inject.Inject;
23+
import javax.inject.Named;
24+
25+
import org.apache.logging.log4j.LogManager;
26+
import org.apache.logging.log4j.Logger;
1827
import org.kitodo.api.Metadata;
28+
import org.kitodo.api.dataformat.Division;
29+
import org.kitodo.api.dataformat.LogicalDivision;
1930
import org.kitodo.exceptions.InvalidMetadataValueException;
2031
import org.kitodo.production.forms.createprocess.ProcessDetail;
2132
import org.kitodo.production.helper.Helper;
@@ -24,15 +35,25 @@
2435
import org.primefaces.PrimeFaces;
2536
import org.primefaces.model.TreeNode;
2637

27-
public class UpdateMetadataDialog {
38+
/**
39+
* Manages the dialog when a user clicks on the update metadata button.
40+
*
41+
* <p>Re-imports the catalog record for a known record identifier and import configuration
42+
* and visualizes the differences between the current metadata and re-imported metadata of the
43+
* catalog.</p>
44+
*/
45+
@Named("UpdateMetadataDialog")
46+
@ViewScoped
47+
public class UpdateMetadataDialog implements Serializable {
48+
49+
private static final Logger logger = LogManager.getLogger(UpdateMetadataDialog.class);
2850

29-
private final DataEditorForm dataEditor;
51+
@Inject
52+
private DataEditorForm dataEditor;
3053

3154
private List<MetadataComparison> metadataComparisons = new LinkedList<>();
3255

33-
UpdateMetadataDialog(DataEditorForm dataEditor) {
34-
this.dataEditor = dataEditor;
35-
}
56+
private String recordIdentifier = "";
3657

3758
/**
3859
* Get list of metadata comparisons displayed in 'UpdateMetadataDialog'.
@@ -43,11 +64,73 @@ public List<MetadataComparison> getMetadataComparisons() {
4364
return metadataComparisons;
4465
}
4566

67+
/**
68+
* Return catalog identifier of record whose metadata is imported.
69+
*
70+
* <p>The record identifier is shown to the user in the metadata comparison dialog.</p>
71+
*
72+
* @return the record identifier
73+
*/
74+
public String getRecordIdentifier() {
75+
return this.recordIdentifier;
76+
}
77+
78+
/**
79+
* Set record identifier of record whose metadata is imported.
80+
*
81+
* <p>The record identifier is shown to the user in the metadata comparison dialog.</p>
82+
*
83+
* @param recordIdentifier the record identifier
84+
*/
85+
public void setRecordIdentifier(String recordIdentifier) {
86+
this.recordIdentifier = recordIdentifier;
87+
}
88+
89+
/**
90+
* Perform metadata update for current process.
91+
*/
92+
public void applyMetadataUpdate() {
93+
Division<?> division = dataEditor.getMetadataPanel().getLogicalMetadataTable().getDivision();
94+
if (Objects.nonNull(division) && division instanceof LogicalDivision) {
95+
DataEditorService.updateMetadataWithNewValues((LogicalDivision) division, getMetadataComparisons());
96+
dataEditor.getMetadataPanel().update();
97+
} else {
98+
Helper.setErrorMessage("cannot update metadata of non-logical division");
99+
}
100+
}
101+
102+
/**
103+
* Check and return whether conditions for metadata update are met or not.
104+
*
105+
* @return whether metadata of process can be updated
106+
*/
107+
public boolean canUpdateMetadata() {
108+
try {
109+
return DataEditorService.canUpdateCatalogMetadata(
110+
dataEditor.getProcess(), dataEditor.getWorkpiece(), dataEditor.getStructurePanel().getSelectedLogicalNodeIfSingle()
111+
);
112+
} catch (IOException e) {
113+
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
114+
return false;
115+
}
116+
}
117+
118+
/**
119+
* Is called when a user clicks on the update metadata button of the logical metadata panel.
120+
*/
121+
public void onUpdateCatalogMetadataClick() {
122+
if (canUpdateMetadata()) {
123+
// update metadata from catalog using existing record identifier and import configuration
124+
updateCatalogMetadata();
125+
}
126+
}
127+
46128
/**
47129
* Trigger re-import of metadata of current process.
48130
*/
49131
public void updateCatalogMetadata() {
50132
if (dataEditor.getSelectedStructure().isPresent()) {
133+
setRecordIdentifier(dataEditor.getProcessRecordIdentifier());
51134
try {
52135
HashSet<Metadata> existingMetadata = getMetadata(dataEditor.getMetadataPanel().getLogicalMetadataRows());
53136
metadataComparisons = DataEditorService.reimportCatalogMetadata(dataEditor.getProcess(),

0 commit comments

Comments
 (0)