forked from DSpace/dspace-replicate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveToTrashSingleAIP.java
More file actions
105 lines (93 loc) · 3.68 KB
/
Copy pathMoveToTrashSingleAIP.java
File metadata and controls
105 lines (93 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.ctask.replicate;
import java.io.IOException;
import java.sql.SQLException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator;
import org.dspace.curate.Distributive;
/**
* MoveToTrashSingleAIP task moves a single AIP from one group (folder) in external
* storage to another group (folder). Currently, it always moves content
* from the 'group.aip.name' store to the 'group.delete.name' store, essentially
* moving the content into a "trash" folder.
* <P>
* This task is primarily used by the ReplicateConsumer to move the AIP for a
* deleted DSpace Object off to a "trash" folder / temporary location. This
* allows the AIP to remain in external storage for a period, just in case the
* deleted object needs to be restored to DSpace.
* <P>
* This task only moves a single AIP at at time (it inhibits iteration when
* invoked on a container object).
*
* @author tdonohue
*/
@Distributive
public class MoveToTrashSingleAIP extends AbstractCurationTask {
// Source and destination group where AIP will be moved to
private String srcGroupName;
private String destGroupName;
private String archFmt;
@Override
public void init(Curator curator, String taskId) throws IOException {
super.init(curator, taskId);
srcGroupName = configurationService.getProperty("replicate.group.aip.name");
destGroupName = configurationService.getProperty("replicate.group.delete.name");
archFmt = configurationService.getProperty("replicate.packer.archfmt");
}
/**
* Perform 'Move To Trash Single AIP' task
* <p>
* Actually generates the AIP and transmits it to the replica ObjectStore
* @param dso DSpace Object to perform on
* @return integer which represents Curator return status
* @throws IOException if I/O error
*/
@Override
public int perform(DSpaceObject dso) throws IOException {
if (dso != null) {
try {
return perform(Curator.curationContext(), dso.getHandle());
} catch (SQLException e) {
throw new IOException(e);
}
} else {
String result = "DSpace Object not specified!";
report(result);
setResult(result);
return Curator.CURATE_FAIL;
}
}
/**
* Perform 'Move AIP' task
* <p>
* Moves an existing AIP from the 'group.aip.name' store to the 'group.delete.name' store
* @param ctx DSpace Context
* @param id ID of object whose AIP should be moved
* @return integer which represents Curator return status
* @throws IOException if I/O error
*/
@Override
public int perform(Context ctx, String id) throws IOException {
ReplicaManager repMan = ReplicaManager.instance();
String objId = repMan.storageId(ctx, id, archFmt);
boolean success = repMan.moveObject(srcGroupName, destGroupName, objId);
String result = "AIP for object: " + id + " could NOT be moved from: " + srcGroupName + " to : "
+ destGroupName + ".";
if (success) {
result = "AIP for object: " + id + " moved from: " + srcGroupName + " to : " + destGroupName + ".";
}
report(result);
setResult(result);
return success ? Curator.CURATE_SUCCESS : Curator.CURATE_FAIL;
}
}