Skip to content

Commit c081ffb

Browse files
author
WANGF
committed
System setting of delete record backup options
1 parent 71bb392 commit c081ffb

7 files changed

Lines changed: 69 additions & 14 deletions

File tree

core/src/main/java/org/fao/geonet/kernel/setting/Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public class Settings {
144144
public static final String METADATA_HISTORY_ENABLED = "metadata/history/enabled";
145145
public static final String METADATA_HISTORY_ACCESS_LEVEL = "metadata/history/accesslevel";
146146
public static final String METADATA_PUBLISHED_DELETE_USERPROFILE = "metadata/delete/profilePublishedMetadata";
147-
public static final String METADATA_DELETE_ENABLEBACKUP = "metadata/delete/enablebackup";
147+
public static final String METADATA_DELETE_BACKUPOPTIONS = "metadata/delete/backupOptions";
148148
public static final String METADATA_PUBLISH_USERPROFILE = "metadata/publication/profilePublishMetadata";
149149
public static final String METADATA_UNPUBLISH_USERPROFILE = "metadata/publication/profileUnpublishMetadata";
150150
public static final String METADATA_BACKUPARCHIVE_ENABLE = "metadata/backuparchive/enable";

core/src/test/resources/org/fao/geonet/api/Messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ api.metadata.share.ErrorUserNotAllowedToPublish=User not allowed to publish the
246246
api.metadata.share.strategy.groupOwnerOnly=You need to be administrator, or reviewer of the metadata group.
247247
api.metadata.share.strategy.reviewerInGroup=You need to be administrator, or reviewer of the metadata group or reviewer with edit privilege on the metadata.
248248
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.
249-
api.metadata.delete.errorWithBackupParamMismatch=The setting metadata/delete/enablebackup: '%s' mismatched the API parameter withBackup '%s'.
249+
api.metadata.delete.errorForceBackup=Cannot force the backup during deletion process because the client specified with backup parameter as: '%s'.
250+
api.metadata.delete.errorForceNoBackup=Cannot force the no-backup during deletion process because the client specified with backup parameter as: '%s'.
250251

251252
feedback_subject_userFeedback=User feedback
252253

services/src/main/java/org/fao/geonet/api/records/MetadataInsertDeleteApi.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,7 @@ public void deleteRecord(
217217
@Parameter(description = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid,
218218
@Parameter(description = API_PARAM_BACKUP_FIRST, required = false) @RequestParam(required = false) Boolean withBackup,
219219
HttpServletRequest request) throws Exception {
220-
boolean isMdDeleteBackupEnable = settingManager.getValueAsBool(Settings.METADATA_DELETE_ENABLEBACKUP);
221-
if (withBackup == null) {
222-
Log.info(LOGGER, String.format("withBackup paramter is missing. Will use setting of metadata/delete/enablebackup '%s' during the deletion process", isMdDeleteBackupEnable));
223-
withBackup = isMdDeleteBackupEnable;
224-
} else if (withBackup != isMdDeleteBackupEnable) {
225-
ResourceBundle messages = ApiUtils.getMessagesResourceBundle(request.getLocales());
226-
throw new IllegalArgumentException(
227-
String.format(messages.getString("api.metadata.delete.errorWithBackupParamMismatch"), isMdDeleteBackupEnable, withBackup));
228-
}
220+
boolean doBackup = withDeleteBackup(withBackup, request);
229221

230222
AbstractMetadata metadata = ApiUtils.canEditRecord(metadataUuid, request);
231223
ServiceContext context = ApiUtils.createServiceContext(request);
@@ -235,7 +227,7 @@ public void deleteRecord(
235227
ApplicationContextHolder.get().publishEvent(preRemoveEvent);
236228

237229
if (metadata.getDataInfo().getType() != MetadataType.SUB_TEMPLATE
238-
&& metadata.getDataInfo().getType() != MetadataType.TEMPLATE_OF_SUB_TEMPLATE && withBackup) {
230+
&& metadata.getDataInfo().getType() != MetadataType.TEMPLATE_OF_SUB_TEMPLATE && doBackup) {
239231
MEFLib.backupRecord(metadata, context);
240232
}
241233

@@ -1036,4 +1028,40 @@ private Pair<Integer, String> loadRecord(MetadataType metadataType, Element xmlE
10361028
return Pair.read(Integer.valueOf(id.get(0)), uuid);
10371029
}
10381030

1031+
/**
1032+
* Determine if the metadata backup is needed during delete API.<br/>
1033+
* 1) The withBackup flag missing from the API, will only overide if setting as ForceNoBackup, otherwise default to true<br/>
1034+
* 2) The withBackup flag designated as true from the API, will throw an error if system setting for ForceNoBackup
1035+
* 3) The withbackup flag designated as false from the API, will throw an error if system setting for ForceBackup
1036+
*
1037+
* @param withBackup API parameter from the client side
1038+
* @param request HTTP Request
1039+
* @return boolean of metadata backup and defaulted to true
1040+
*/
1041+
private boolean withDeleteBackup (Boolean withBackup, HttpServletRequest request) {
1042+
ResourceBundle messages = ApiUtils.getMessagesResourceBundle(request.getLocales());
1043+
String mdDeleteBackupOption = settingManager.getValue(Settings.METADATA_DELETE_BACKUPOPTIONS);
1044+
if (withBackup == null) {
1045+
if (StringUtils.equals(mdDeleteBackupOption, "ForceNoBackup")) {
1046+
return false;
1047+
}
1048+
return true;
1049+
} else if (withBackup == true) {
1050+
if (StringUtils.equals(mdDeleteBackupOption, "ForceNoBackup")) {
1051+
throw new IllegalArgumentException(
1052+
String.format(messages.getString("api.metadata.delete.errorForceBackup"), withBackup));
1053+
}
1054+
return true;
1055+
} else if (withBackup = false) {
1056+
if (StringUtils.equals(mdDeleteBackupOption, "ForceBackup")) {
1057+
throw new IllegalArgumentException(
1058+
String.format(messages.getString("api.metadata.delete.errorForceNoBackup"), withBackup));
1059+
}
1060+
return false;
1061+
}
1062+
1063+
return true;
1064+
1065+
}
1066+
10391067
}

web-ui/src/main/resources/catalog/templates/admin/settings/system.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,31 @@ <h3>{{section2.name | translate}}</h3>
222222
</option>
223223
</select>
224224

225+
<select
226+
data-ng-switch-when="metadata/delete/backupOptions"
227+
class="form-control"
228+
name="{{s.name}}"
229+
>
230+
<option
231+
value="ForceBackup"
232+
ng-selected="'ForceBackup' == s.value"
233+
>
234+
{{'Force backup' | translate}}
235+
</option>
236+
<option
237+
value="ForceNoBackup"
238+
ng-selected="'ForceNoBackup' == s.value"
239+
>
240+
{{'Force no backup' | translate}}
241+
</option>
242+
<option value="Enabled" ng-selected="'Enabled' == s.value">
243+
{{'Enabled' | translate}}
244+
</option>
245+
<option value="Disabled" ng-selected="'Disabled' == s.value">
246+
{{'Disabled' | translate}}
247+
</option>
248+
</select>
249+
225250
<select
226251
data-ng-switch-when="metadata/publication/profilePublishMetadata"
227252
class="form-control"

web/src/main/webapp/WEB-INF/classes/setup/sql/data/data-db-default.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metada
709709
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/history/accesslevel', 'Editor', 0, 12021, 'n');
710710

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

713714
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/publication/profilePublishMetadata', 'Reviewer', 0, 12021, 'n');
714715
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/publication/profileUnpublishMetadata', 'Reviewer', 0, 12022, 'n');

web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v447/migrate-default.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system
66

77
ALTER TABLE Sources ADD COLUMN datahubEnabled BOOLEAN DEFAULT FALSE;
88
ALTER TABLE Sources ADD COLUMN datahubConfiguration TEXT DEFAULT '';
9-
10-
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/enablebackup', 'true', 2, 12012, 'n');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
UPDATE Settings SET value='4.4.8' WHERE name='system/platform/version';
22
UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion';
3+
4+
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/backupOptions', 'Enabled', 0, 12012, 'n');

0 commit comments

Comments
 (0)