Skip to content

Commit 903b35a

Browse files
Issue #1292 link/unlink items with version relationship (#1304)
* Issue 1292: script to allow link two items into version relationship * implement link and unlink actions * ItemVersionLinkerIT test * improve ItemVersionLinkerIT, fix ScriptRestRepositoryIT * resolve Copilot comments: Part 1 * resolve Copilot comments - part 2 * improve test to be more realistic * improve options description * better call of itemService.clearMetadata() * clear correctly dc.relation.replaces and dc.relation.isreplacedby * use dc.identifier.uri metadata value rather than item.getHandle() to set dc.relation.replaces and dc.relation.isreplacedby * code-cleanup * PR comments * resolve PR comments (O. Kosarko) * add also as a cli script * Use Item.ANY instead of null tested with the production db dump on the items mentions in the issue (11234/1-5537). It was returning: ``` The script has started Item '11234/1-5537' has no handle assigned. ``` because it's dc.identifier.uri.* --------- Co-authored-by: Ondřej Košarko <kosarko@ufal.mff.cuni.cz> Co-authored-by: Ondřej Košarko <ko_ok@centrum.cz>
1 parent 4cc3694 commit 903b35a

File tree

9 files changed

+886
-4
lines changed

9 files changed

+886
-4
lines changed

dspace-api/src/main/java/org/dspace/administer/ItemVersionLinker.java

Lines changed: 383 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.administer;
9+
10+
import org.apache.commons.cli.Options;
11+
import org.dspace.scripts.configuration.ScriptConfiguration;
12+
13+
/**
14+
* The {@link ScriptConfiguration} for the {@link ItemVersionLinker} script.
15+
*
16+
* @author Milan Kuchtiak
17+
*/
18+
public class ItemVersionLinkerConfiguration extends ScriptConfiguration<ItemVersionLinker> {
19+
20+
private Class<ItemVersionLinker> dspaceRunnableClass;
21+
22+
/**
23+
* Generic getter for the dspaceRunnableClass
24+
*
25+
* @return the dspaceRunnableClass value of this ScriptConfiguration
26+
*/
27+
@Override
28+
public Class<ItemVersionLinker> getDspaceRunnableClass() {
29+
return dspaceRunnableClass;
30+
}
31+
32+
/**
33+
* Generic setter for the dspaceRunnableClass
34+
*
35+
* @param dspaceRunnableClass The dspaceRunnableClass to be set for this ScriptConfiguration
36+
*/
37+
@Override
38+
public void setDspaceRunnableClass(Class<ItemVersionLinker> dspaceRunnableClass) {
39+
this.dspaceRunnableClass = dspaceRunnableClass;
40+
}
41+
42+
/**
43+
* The getter for the options of the Script
44+
*
45+
* @return the options value of this ScriptConfiguration
46+
*/
47+
@Override
48+
public Options getOptions() {
49+
if (options == null) {
50+
51+
Options options = new Options();
52+
53+
options.addOption("h", "help", false, "help");
54+
55+
options.addOption("l", "link", false, "link item with the previous item");
56+
57+
options.addOption("u", "unlink", false, "unlink item from the previous item in version history");
58+
59+
options.addOption("p", "previous", true,
60+
"item handle, or UUID, of the previous(left) item that is intended to be linked with the (right)" +
61+
" item (only required for link option)");
62+
63+
options.addOption("i", "item", true,
64+
"item handle, or UUID, of the (right) item that is intended to be linked/unlinked with/from the " +
65+
"previous item (required for both link and unlink options)");
66+
options.getOption("i").setRequired(true);
67+
68+
options.addOption("e", "eperson", true, "ePerson email");
69+
options.getOption("e").setRequired(false);
70+
71+
super.options = options;
72+
}
73+
return options;
74+
}
75+
}

dspace-api/src/main/java/org/dspace/versioning/VersionHistoryServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void update(Context context, List<VersionHistory> versionHistories) throw
7474

7575
@Override
7676
public void delete(Context context, VersionHistory versionHistory) throws SQLException, AuthorizeException {
77-
versionHistoryDAO.delete(context, new VersionHistory());
77+
versionHistoryDAO.delete(context, versionHistory);
7878
}
7979

8080
// LIST order: descending

dspace-api/src/main/java/org/dspace/versioning/VersioningServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,8 @@ public int countVersionsByHistoryWithItem(Context context, VersionHistory versio
266266
return versionDAO.countVersionsByHistoryWithItem(context, versionHistory);
267267
}
268268

269+
@Override
270+
public void deleteVersion(Context c, Version version) throws SQLException {
271+
versionDAO.delete(c, version);
272+
}
269273
}

dspace-api/src/main/java/org/dspace/versioning/service/VersioningService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface VersioningService {
4545
* To keep version numbers stable we do not delete versions, we do only set
4646
* the item, date, summary and eperson null. This methods returns only those
4747
* versions that have an item assigned.
48-
*
48+
*
4949
* @param c The relevant DSpace Context.
5050
* @param vh Version history
5151
* @param offset The position of the first result to return
@@ -79,6 +79,16 @@ List<Version> getVersionsByHistoryWithItems(Context c, VersionHistory vh, int of
7979
Version createNewVersion(Context context, VersionHistory history, Item item, String summary, Date date,
8080
int versionNumber);
8181

82+
/**
83+
* This method deletes the version associated with the item from the versioning history,
84+
* but unlike the {@link #delete} method this doesn't delete the entire item.
85+
*
86+
* @param c context
87+
* @param version version
88+
* @throws SQLException if database error
89+
*/
90+
void deleteVersion(Context c, Version version) throws SQLException;
91+
8292
/**
8393
* Update the Version
8494
*
@@ -94,7 +104,7 @@ Version createNewVersion(Context context, VersionHistory history, Item item, Str
94104
* remove a version we set the item, date, summary and eperson null. This
95105
* method returns only versions that aren't soft deleted and have items
96106
* assigned.
97-
*
107+
*
98108
* @param context The relevant DSpace Context.
99109
* @param versionHistory Version history
100110
* @return Total versions of an version history that have items assigned.

dspace-api/src/test/data/dspaceFolder/config/spring/api/scripts.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<property name="description" value="Retry all failed commits to the OpenURLTracker"/>
4040
<property name="dspaceRunnableClass" value="org.dspace.statistics.export.RetryFailedOpenUrlTracker"/>
4141
</bean>
42-
42+
4343
<bean id="metadata-deletion" class="org.dspace.app.bulkedit.MetadataDeletionCliScriptConfiguration">
4444
<property name="description" value="Delete all the values of the specified metadata field"/>
4545
<property name="dspaceRunnableClass" value="org.dspace.app.bulkedit.MetadataDeletionCli"/>
@@ -106,6 +106,11 @@
106106
<property name="dspaceRunnableClass" value="org.dspace.scripts.filepreview.FilePreview"/>
107107
</bean>
108108

109+
<bean id="item-version-linker" class="org.dspace.administer.ItemVersionLinkerConfiguration" primary="true">
110+
<property name="description" value="Link items into versioning relationship."/>
111+
<property name="dspaceRunnableClass" value="org.dspace.administer.ItemVersionLinker"/>
112+
</bean>
113+
109114
<bean id="report-diff" class="org.dspace.app.reportdiff.ReportDiffScriptConfiguration" primary="true">
110115
<property name="description" value="Compares two health reports and shows the differences between them."/>
111116
<property name="dspaceRunnableClass" value="org.dspace.app.reportdiff.ReportDiff"/>

0 commit comments

Comments
 (0)