Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -144,6 +144,7 @@ public class Settings {
public static final String METADATA_HISTORY_ENABLED = "metadata/history/enabled";
public static final String METADATA_HISTORY_ACCESS_LEVEL = "metadata/history/accesslevel";
public static final String METADATA_PUBLISHED_DELETE_USERPROFILE = "metadata/delete/profilePublishedMetadata";
public static final String METADATA_DELETE_BACKUPOPTIONS = "metadata/delete/backupOptions";
public static final String METADATA_PUBLISH_USERPROFILE = "metadata/publication/profilePublishMetadata";
public static final String METADATA_UNPUBLISH_USERPROFILE = "metadata/publication/profileUnpublishMetadata";
public static final String METADATA_BACKUPARCHIVE_ENABLE = "metadata/backuparchive/enable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ api.metadata.share.ErrorUserNotAllowedToPublish=User not allowed to publish the
api.metadata.share.strategy.groupOwnerOnly=You need to be administrator, or reviewer of the metadata group.
api.metadata.share.strategy.reviewerInGroup=You need to be administrator, or reviewer of the metadata group or reviewer with edit privilege on the metadata.
api.metadata.status.errorSetStatusNotAllowed=Only the owner of the metadata can set the status of this record. User is not the owner of the metadata.
api.metadata.delete.errorForceBackup=Cannot force the backup during deletion process because the client specified with backup parameter as: '%s'.
api.metadata.delete.errorForceNoBackup=Cannot force the no-backup during deletion process because the client specified with backup parameter as: '%s'.

feedback_subject_userFeedback=User feedback

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ public class MetadataInsertDeleteApi {
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteRecord(
@Parameter(description = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid,
@Parameter(description = API_PARAM_BACKUP_FIRST, required = false) @RequestParam(required = false, defaultValue = "true") boolean withBackup,
@Parameter(description = API_PARAM_BACKUP_FIRST, required = false) @RequestParam(required = false) Boolean withBackup,
HttpServletRequest request) throws Exception {
boolean doBackup = withDeleteBackup(withBackup, request);

AbstractMetadata metadata = ApiUtils.canEditRecord(metadataUuid, request);
ServiceContext context = ApiUtils.createServiceContext(request);
Store store = context.getBean("resourceStore", Store.class);
Expand All @@ -225,7 +227,7 @@ public void deleteRecord(
ApplicationContextHolder.get().publishEvent(preRemoveEvent);

if (metadata.getDataInfo().getType() != MetadataType.SUB_TEMPLATE
&& metadata.getDataInfo().getType() != MetadataType.TEMPLATE_OF_SUB_TEMPLATE && withBackup) {
&& metadata.getDataInfo().getType() != MetadataType.TEMPLATE_OF_SUB_TEMPLATE && doBackup) {
MEFLib.backupRecord(metadata, context);
}

Expand Down Expand Up @@ -1026,4 +1028,41 @@ private Pair<Integer, String> loadRecord(MetadataType metadataType, Element xmlE
return Pair.read(Integer.valueOf(id.get(0)), uuid);
}

/**
* Determine if the metadata backup is needed during delete API.<br/>
* 1) The withBackup flag missing from the API, will only overide if setting as ForceNoBackup, otherwise default to true<br/>
* 2) The withBackup flag designated as true from the API, will throw an error if system setting for ForceNoBackup
* 3) The withbackup flag designated as false from the API, will throw an error if system setting for ForceBackup
*
* @param withBackup API parameter from the client side
* @param request HTTP Request
* @return boolean of metadata backup and defaulted to true
*/
private boolean withDeleteBackup (Boolean withBackup, HttpServletRequest request) {
ResourceBundle messages = ApiUtils.getMessagesResourceBundle(request.getLocales());
String mdDeleteBackupOption = settingManager.getValue(Settings.METADATA_DELETE_BACKUPOPTIONS);
if (withBackup == null) {
if (StringUtils.equals(mdDeleteBackupOption, "ForceNoBackup")) {
return false;
}
// Will default to true if setting set to UseAPIParameter, ForceBackup or empty
return true;
} else if (withBackup == true) {
if (StringUtils.equals(mdDeleteBackupOption, "ForceNoBackup")) {
throw new IllegalArgumentException(
String.format(messages.getString("api.metadata.delete.errorForceBackup"), withBackup));
}
return true;
} else if (withBackup = false) {
if (StringUtils.equals(mdDeleteBackupOption, "ForceBackup")) {
throw new IllegalArgumentException(
String.format(messages.getString("api.metadata.delete.errorForceNoBackup"), withBackup));
}
return false;
}

return true;

}

}
4 changes: 4 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@
"metadata/delete": "Metadata delete",
"metadata/delete/profilePublishedMetadata": "Minimum user profile allowed to delete published metadata",
"metadata/delete/profilePublishedMetadata-help": "Minimum user profile allowed to delete published metadata (Editor, Reviewer or Administrator). The default value is Editor.",
"metadata/delete/enablebackup": "Enable Backup",
"metadata/delete/enablebackup-help": "Backup metadata on the server before deleting process.",
"metadata/delete/backupOptions": "Backup Options",
"metadata/delete/backupOptions-help": "Set to override backup option from the API client parameter during deletion process. Force backup: always makes a backup. Ignores the API parameter; Force no backup: never makes a backup. Ignores the API parameter; Use API parameter: If provided, uses the value provided. If not provided, it makes a backup (current default behaviour).",
"metadata/batchediting": "Metadata Batch Editing",
"metadata/batchediting/accesslevel": "Select the minimum user profile allowed to access batch editing",
"metadata/batchediting/accesslevel-help": "Select the minimum user profile allowed to access batch editing (Editor, Reviewer or Administrator). The default value is Editor.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,28 @@ <h3>{{section2.name | translate}}</h3>
</option>
</select>

<select
data-ng-switch-when="metadata/delete/backupOptions"
class="form-control"
name="{{s.name}}"
>
<option
value="ForceBackup"
ng-selected="'ForceBackup' == s.value"
>
{{'Force backup' | translate}}
</option>
<option
value="ForceNoBackup"
ng-selected="'ForceNoBackup' == s.value"
>
{{'Force no backup' | translate}}
</option>
<option value="UseAPIParameter" ng-selected="'UseAPIParameter' == s.value">
{{'UseAPIParameter' | translate}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add translation keys for these values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the translation in en-admin.json. Please check

</option>
</select>

<select
data-ng-switch-when="metadata/publication/profilePublishMetadata"
class="form-control"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metada
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/history/accesslevel', 'Editor', 0, 12021, 'n');

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/profilePublishedMetadata', 'Editor', 0, 12011, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/backupOptions', 'UseAPIParameter', 0, 12012, 'n');

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/publication/profilePublishMetadata', 'Reviewer', 0, 12021, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/publication/profileUnpublishMetadata', 'Reviewer', 0, 12022, 'n');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
UPDATE Settings SET value='4.4.8' WHERE name='system/platform/version';
UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion';

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/backupOptions', 'UseAPIParameter', 0, 12012, 'n');