Skip to content

Commit

Permalink
Cleaned prompts and disassociation logic for disposal holds (#3235)
Browse files Browse the repository at this point in the history
Signed-off-by: sugarylump <[email protected]>
  • Loading branch information
SugaryLump authored Jul 5, 2024
1 parent 2ecdda7 commit 75b9c0a
Show file tree
Hide file tree
Showing 18 changed files with 504 additions and 284 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.roda.core.data.v2.ip.disposalhold;

/**
* @author Miguel Guimarães <[email protected]>
*/

import java.io.Serial;
import java.io.Serializable;

import org.roda.core.data.v2.generics.select.SelectedItemsRequest;

public class DisassociateDisposalHoldRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1324253414733503493L;

private SelectedItemsRequest selectedItems;
private String details;
private boolean clear;

public DisassociateDisposalHoldRequest() {
// empty constructor
}

public SelectedItemsRequest getSelectedItems() {
return selectedItems;
}

public void setSelectedItems(SelectedItemsRequest selectedItems) {
this.selectedItems = selectedItems;
}

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}

public boolean getClear() {
return clear;
}

public void setClear(boolean clear) {
this.clear = clear;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.roda.core.data.v2.ip.disposalhold;

/**
* @author Miguel Guimarães <[email protected]>
*/

import java.io.Serial;
import java.io.Serializable;

import org.roda.core.data.v2.generics.select.SelectedItemsRequest;

public class LiftDisposalHoldRequest implements Serializable {

@Serial
private static final long serialVersionUID = -6983980156805237858L;

private SelectedItemsRequest selectedItems;
private String details;

public LiftDisposalHoldRequest() {
// empty constructor
}

public SelectedItemsRequest getSelectedItems() {
return selectedItems;
}

public void setSelectedItems(SelectedItemsRequest selectedItems) {
this.selectedItems = selectedItems;
}

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.roda.core.data.v2.ip.disposalhold;

/**
* @author Miguel Guimarães <[email protected]>
*/

import java.io.Serial;
import java.io.Serializable;

import org.roda.core.data.v2.disposal.hold.DisposalHold;

public class UpdateDisposalHoldRequest implements Serializable {

@Serial
private static final long serialVersionUID = 3125581525913041977L;

private DisposalHold disposalHold;
private String details;

public UpdateDisposalHoldRequest() {
// empty constructor
}

public DisposalHold getDisposalHold() {
return disposalHold;
}

public void setDisposalHold(DisposalHold disposalHold) {
this.disposalHold = disposalHold;
}

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3747,16 +3747,17 @@ public DisposalHold createDisposalHold(DisposalHold disposalHold, String created
public DisposalHold updateDisposalHoldFirstUseDate(DisposalHold disposalHold, String updatedBy)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, IllegalOperationException,
GenericException {
return updateDisposalHold(disposalHold, updatedBy, true);
return updateDisposalHold(disposalHold, updatedBy, true, null);
}

public DisposalHold updateDisposalHold(DisposalHold disposalHold, String updatedBy)
public DisposalHold updateDisposalHold(DisposalHold disposalHold, String updatedBy, String details)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, IllegalOperationException,
GenericException {
return updateDisposalHold(disposalHold, updatedBy, false);
return updateDisposalHold(disposalHold, updatedBy, false, details);
}

public DisposalHold updateDisposalHold(DisposalHold disposalHold, String updatedBy, boolean updateFirstUseDate)
public DisposalHold updateDisposalHold(DisposalHold disposalHold, String updatedBy, boolean updateFirstUseDate,
String details)
throws RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException,
IllegalOperationException {
RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType);
Expand Down Expand Up @@ -3787,6 +3788,9 @@ public DisposalHold updateDisposalHold(DisposalHold disposalHold, String updated

storage.updateBinaryContent(disposalHoldPath, new StringContentPayload(disposalHoldAsJson), false, true);

createRepositoryEvent(PreservationEventType.UPDATE, "Update disposal hold", PluginState.SUCCESS, "", details, "",
true);

return currentDisposalHold;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.roda.core.data.common.RodaConstants;
import org.roda.core.data.exceptions.AlreadyExistsException;
import org.roda.core.data.exceptions.AuthorizationDeniedException;
import org.roda.core.data.exceptions.GenericException;
import org.roda.core.data.exceptions.IllegalOperationException;
import org.roda.core.data.exceptions.InvalidParameterException;
import org.roda.core.data.exceptions.NotFoundException;
import org.roda.core.data.exceptions.RequestNotValidException;
import org.roda.core.data.v2.LiteOptionalWithCause;
import org.roda.core.data.v2.common.Pair;
import org.roda.core.data.v2.disposal.hold.DisposalHold;
import org.roda.core.data.v2.disposal.hold.DisposalHoldState;
import org.roda.core.data.v2.disposal.metadata.DisposalHoldAIPMetadata;
import org.roda.core.data.v2.ip.AIP;
import org.roda.core.data.v2.ip.IndexedAIP;
import org.roda.core.data.v2.jobs.Job;
Expand Down Expand Up @@ -65,10 +62,16 @@ public class DisassociateDisposalHoldFromAIPPlugin extends AbstractPlugin<AIP> {
"Disassociate all holds", PluginParameter.PluginParameterType.BOOLEAN).withDefaultValue("false")
.isMandatory(true).isReadOnly(false).withDescription("Disassociate all disposal holds associated to AIP")
.build());

pluginParameters.put(RodaConstants.PLUGIN_PARAMS_DETAILS,
PluginParameter
.getBuilder(RodaConstants.PLUGIN_PARAMS_DETAILS, "Details", PluginParameter.PluginParameterType.STRING)
.isMandatory(false).withDescription("Details that will be used when creating event").build());
}

private String disposalHoldId;
private boolean clearAll;
private String details;

public static String getStaticName() {
return "Disassociate disposal hold from AIP";
Expand All @@ -83,6 +86,7 @@ public List<PluginParameter> getParameters() {
ArrayList<PluginParameter> parameters = new ArrayList<>();
parameters.add(pluginParameters.get(RodaConstants.PLUGIN_PARAMS_DISPOSAL_HOLD_ID));
parameters.add(pluginParameters.get(RodaConstants.PLUGIN_PARAMS_DISPOSAL_HOLD_DISASSOCIATE_ALL));
parameters.add(pluginParameters.get(RodaConstants.PLUGIN_PARAMS_DETAILS));
return parameters;
}

Expand All @@ -97,6 +101,10 @@ public void setParameterValues(Map<String, String> parameters) throws InvalidPar
if (parameters.containsKey(RodaConstants.PLUGIN_PARAMS_DISPOSAL_HOLD_DISASSOCIATE_ALL)) {
clearAll = Boolean.parseBoolean(parameters.get(RodaConstants.PLUGIN_PARAMS_DISPOSAL_HOLD_DISASSOCIATE_ALL));
}

if (parameters.containsKey(RodaConstants.PLUGIN_PARAMS_DETAILS)) {
details = parameters.get(RodaConstants.PLUGIN_PARAMS_DETAILS);
}
}

@Override
Expand Down Expand Up @@ -184,6 +192,8 @@ public void process(IndexService index, ModelService model, StorageService stora

private void processAIP(IndexService index, ModelService model, Report report, Job cachedJob,
JobPluginInfo jobPluginInfo, List<AIP> aips) {
report.addPluginDetails(details);

for (AIP aip : aips) {
String outcomeText;
PluginState state = PluginState.SUCCESS;
Expand All @@ -195,12 +205,12 @@ private void processAIP(IndexService index, ModelService model, Report report, J
try {
// lift disposal holds
if (aip.getHolds() != null && !aip.getHolds().isEmpty()) {
List<DisposalHoldAIPMetadata> holds = new ArrayList<>(aip.getHolds());
outcomeText = "Cannot found any active direct disposal hold for disassociate from AIP : " + aip.getId();
boolean hasAtLeastOneDirectHold = false;
for (DisposalHold hold : model.retrieveDirectActiveDisposalHolds(aip.getId())) {
hasAtLeastOneDirectHold = true;
outcomeText = DisposalHoldPluginUtils.disassociateDisposalHoldFromAIP(hold.getId(), aip, reportItem);
outcomeText = DisposalHoldPluginUtils.disassociateDisposalHoldFromAIP(hold.getId(), aip, reportItem)
.getSecond();
processTransitiveAIP(model, index, cachedJob, aip, hold.getId(), jobPluginInfo, report);
}

Expand Down Expand Up @@ -233,10 +243,17 @@ private void processAIP(IndexService index, ModelService model, Report report, J
}
} else {
try {
outcomeText = DisposalHoldPluginUtils.liftDisposalHoldFromAIP(aip, disposalHoldId, reportItem);
Pair<Boolean, String> outcome = DisposalHoldPluginUtils.disassociateDisposalHoldFromAIP(disposalHoldId, aip,
reportItem);
boolean lifted = outcome.getFirst();
outcomeText = outcome.getSecond();
processTransitiveAIP(model, index, cachedJob, aip, disposalHoldId, jobPluginInfo, report);
model.updateAIP(aip, cachedJob.getUsername());
jobPluginInfo.incrementObjectsProcessedWithSuccess();
if (lifted) {
jobPluginInfo.incrementObjectsProcessedWithSuccess();
} else {
jobPluginInfo.incrementObjectsProcessedWithSkipped();
}
reportItem.setPluginState(state);
} catch (GenericException | NotFoundException | RequestNotValidException | AuthorizationDeniedException e) {
outcomeText = "Error lifting disposal hold" + disposalHoldId + " from AIP " + aip.getId();
Expand All @@ -260,17 +277,6 @@ private void processAIP(IndexService index, ModelService model, Report report, J
LOGGER.error("Error creating event: {}", e.getMessage(), e);
}
}

if (StringUtils.isNotBlank(disposalHoldId)) {
try {
DisposalHold disposalHold = model.retrieveDisposalHold(disposalHoldId);
disposalHold.setState(DisposalHoldState.LIFTED);
model.updateDisposalHold(disposalHold, cachedJob.getUsername());
} catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException
| IllegalOperationException e) {
LOGGER.error("Unable to update disposal hold {}: {}", disposalHoldId, e.getMessage(), e);
}
}
}

private void processTransitiveAIP(ModelService model, IndexService index, Job cachedJob, AIP aip, String holdId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import org.roda.core.data.exceptions.GenericException;
import org.roda.core.data.exceptions.NotFoundException;
import org.roda.core.data.exceptions.RequestNotValidException;
import org.roda.core.data.v2.common.Pair;
import org.roda.core.data.v2.disposal.hold.DisposalHold;
import org.roda.core.data.v2.disposal.hold.DisposalHoldState;
import org.roda.core.data.v2.disposal.metadata.DisposalAIPMetadata;
import org.roda.core.data.v2.disposal.metadata.DisposalHoldAIPMetadata;
import org.roda.core.data.v2.disposal.metadata.DisposalTransitiveHoldAIPMetadata;
import org.roda.core.data.v2.disposal.hold.DisposalHold;
import org.roda.core.data.v2.disposal.hold.DisposalHoldState;
import org.roda.core.data.v2.index.filter.Filter;
import org.roda.core.data.v2.index.filter.FilterParameter;
import org.roda.core.data.v2.index.filter.OrFiltersParameters;
Expand Down Expand Up @@ -80,21 +81,6 @@ public static void addTransitiveDisposalHoldAIPMetadata(AIP aip, String disposal
disposalTransitiveHoldAIPMetadata.addFromAip(fromAIP);
}

public static String liftDisposalHoldFromAIP(AIP aip, String disposalHoldId, Report reportItem) {
String outcomeLiftText = "Cannot find disposal hold " + disposalHoldId + " on AIP " + aip.getId();
DisposalAIPMetadata disposal = aip.getDisposal();
if (disposal != null) {
List<DisposalHoldAIPMetadata> holds = disposal.getHolds();
for (DisposalHoldAIPMetadata hold : new ArrayList<>(holds)) {
if (disposalHoldId.equals(hold.getId())) {
outcomeLiftText = liftHold(hold, disposal, aip.getId(), reportItem);
break;
}
}
}
return outcomeLiftText;
}

public static String liftTransitiveDisposalHoldFromAIP(AIP aip, String disposalHoldId, Report reportItem) {
DisposalAIPMetadata disposal = aip.getDisposal();
String outcomeLiftText = "Cannot find transitive disposal hold " + disposalHoldId + " on AIP " + aip.getId();
Expand All @@ -115,21 +101,26 @@ public static void disassociateAllDisposalHoldsFromAIP(ModelService model, Plugi
DisposalAIPMetadata disposal = aip.getDisposal();
if (disposal != null) {
for (DisposalHoldAIPMetadata disposalHoldAIPMetadata : new ArrayList<>(disposal.getHolds())) {
String outcomeLiftText = disassociateDisposalHoldFromAIP(disposalHoldAIPMetadata.getId(), aip, reportItem);
String outcomeLiftText = disassociateDisposalHoldFromAIP(disposalHoldAIPMetadata.getId(), aip, reportItem)
.getSecond();
model.createEvent(aip.getId(), null, null, null, POLICY_ASSIGNMENT, LiftDisposalHoldPlugin.getStaticName(),
null, null, state, outcomeLiftText, "", cachedJob.getUsername(), true);
}
}
}

public static String disassociateDisposalHoldFromAIP(String disposalHoldAIPMetadataID, AIP aip, Report reportItem) {
public static Pair<Boolean, String> disassociateDisposalHoldFromAIP(String disposalHoldAIPMetadataID, AIP aip,
Report reportItem) {
boolean lifted;
String outcomeLiftText;
DisposalHold disposalHold = RodaCoreFactory.getDisposalHold(disposalHoldAIPMetadataID);
if (disposalHold.getState().equals(DisposalHoldState.LIFTED)) {
if (disposalHold != null && disposalHold.getState().equals(DisposalHoldState.LIFTED)) {
lifted = false;
outcomeLiftText = "Disposal hold '" + disposalHoldAIPMetadataID
+ "' is lifted and cannot be disassociated from aip '" + aip.getId() + "'";
} else {
aip.removeDisposalHold(disposalHoldAIPMetadataID);
lifted = true;
if (disposalHold == null) {
outcomeLiftText = "Disposal hold '" + disposalHoldAIPMetadataID + "' was successfully disassociated from AIP '"
+ aip.getId() + "'";
Expand All @@ -142,7 +133,7 @@ public static String disassociateDisposalHoldFromAIP(String disposalHoldAIPMetad
+ ") was successfully disassociated from AIP\n");
}
}
return outcomeLiftText;
return new Pair<>(lifted, outcomeLiftText);
}

public static String disassociateTransitiveDisposalHoldFromAIP(String disposalHoldAIPMetadataID, AIP aip,
Expand Down Expand Up @@ -188,26 +179,6 @@ private static String liftTransitiveHold(DisposalTransitiveHoldAIPMetadata trans
return outcomeLiftText;
}

private static String liftHold(DisposalHoldAIPMetadata disposalHold, DisposalAIPMetadata disposal, String aipId,
Report reportItem) {

// disposal.getHolds().remove(disposalHold);
DisposalHold liftedHold = RodaCoreFactory.getDisposalHold(disposalHold.getId());
String outcomeLiftText;
if (liftedHold == null) {
outcomeLiftText = "Disposal hold '" + disposalHold.getId() + "' was successfully lifted from AIP '" + aipId + "'";
reportItem.addPluginDetails(
"Disposal hold '" + disposalHold.getId() + "' was successfully lifted from AIP '" + aipId + "'");
} else {
outcomeLiftText = "Disposal hold '" + liftedHold.getTitle() + "' (" + liftedHold.getId()
+ ") was successfully lifted from AIP '" + aipId + "'";
reportItem.addPluginDetails("Disposal hold '" + liftedHold.getTitle() + "' (" + liftedHold.getId()
+ ") was successfully lifted from AIP '" + aipId + "'");
}

return outcomeLiftText;
}

public static IterableIndexResult<IndexedAIP> getTransitivesHoldsAIPs(IndexService index, String aipId)
throws NotFoundException, GenericException, RequestNotValidException {
final IndexedAIP indexedAip = index.retrieve(IndexedAIP.class, aipId, new ArrayList<>());
Expand Down
Loading

0 comments on commit 75b9c0a

Please sign in to comment.