forked from geonetwork/core-geonetwork
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abed63e
commit 73f8e48
Showing
22 changed files
with
280 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.auditable; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
@@ -39,11 +38,13 @@ | |
import java.util.*; | ||
|
||
public abstract class BaseAuditableService<U> { | ||
protected static final String LINE_SEPARATOR = System.getProperty("line.separator"); | ||
protected static final String LINE_SEPARATOR = System.lineSeparator(); | ||
|
||
protected BaseAuditableRepository<U> repository; | ||
protected SettingManager settingManager; | ||
|
||
public abstract String getEntityType(); | ||
|
||
public void auditSave(U auditableEntity) { | ||
if (!isAuditableEnabled()) return; | ||
|
||
|
@@ -72,7 +73,6 @@ public List<RevisionInfo> getEntityHistory(Integer entityIdentifier) { | |
return retrieveRevisionHistory(revisions); | ||
} | ||
|
||
public abstract String getEntityType(); | ||
|
||
protected String retrieveRevisionHistoryAsString(Revisions<Integer, U> revisions, ResourceBundle messages) { | ||
List<RevisionInfo> revisionInfoList = retrieveRevisionHistory(revisions); | ||
|
@@ -123,7 +123,7 @@ protected List<RevisionInfo> retrieveRevisionHistory(Revisions<Integer, U> revis | |
|
||
// Initial revision | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
Map<String, Object> revisionMap = objectMapper.convertValue(initialRevision.getEntity(), Map.class); | ||
Map<String, Object> revisionMap = objectMapper.convertValue(initialRevision.getEntity(), Map.class); | ||
// Remove empty values and id | ||
revisionMap.values().removeAll(Arrays.asList("", null)); | ||
revisionMap.remove(idFieldName); | ||
|
@@ -136,13 +136,13 @@ protected List<RevisionInfo> retrieveRevisionHistory(Revisions<Integer, U> revis | |
revisionInfoList.add(initialRevisionInfo); | ||
|
||
int i = 0; | ||
while (i+1 < numRevisions) { | ||
while (i + 1 < numRevisions) { | ||
Revision<Integer, U> revision1 = revisionList.get(i); | ||
Revision<Integer, U> revision2 = revisionList.get(i+1); | ||
Revision<Integer, U> revision2 = revisionList.get(i + 1); | ||
|
||
Map<String, Object> revision1Map = objectMapper.convertValue(revision1.getEntity(), Map.class); | ||
Map<String, Object> revision1Map = objectMapper.convertValue(revision1.getEntity(), Map.class); | ||
revision1Map.remove(idFieldName); | ||
Map<String, Object> revision2Map = objectMapper.convertValue(revision2.getEntity(), Map.class); | ||
Map<String, Object> revision2Map = objectMapper.convertValue(revision2.getEntity(), Map.class); | ||
revision2Map.remove(idFieldName); | ||
|
||
MapDifference<String, Object> diff = Maps.difference(revision1Map, revision2Map); | ||
|
@@ -162,7 +162,6 @@ protected List<RevisionInfo> retrieveRevisionHistory(Revisions<Integer, U> revis | |
RevisionFieldChange revisionFieldChange = new RevisionFieldChange(key, oldValueAsString, newValueAsString); | ||
|
||
revisionInfo.addChange(revisionFieldChange); | ||
|
||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 29 additions & 4 deletions
33
auditable/src/main/java/org/fao/geonet/auditable/model/RevisionFieldChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
/* | ||
* Copyright (C) 2001-2024 Food and Agriculture Organization of the | ||
* United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
* and United Nations Environment Programme (UNEP) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
* | ||
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
package org.fao.geonet.auditable.model; | ||
|
||
/** | ||
* This class represents a change in an entity field. It stores the field name, | ||
* the previous and the new value. | ||
*/ | ||
public class RevisionFieldChange { | ||
private String name; | ||
private String oldValue; | ||
|
||
private String newValue; | ||
private final String name; | ||
private final String oldValue; | ||
private final String newValue; | ||
|
||
public RevisionFieldChange(String name, String oldValue, String newValue) { | ||
this.name = name; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,23 +20,20 @@ | |
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.auditable.model; | ||
|
||
import org.fao.geonet.domain.ISODate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.List; | ||
import org.fao.geonet.domain.ISODate; | ||
|
||
public class RevisionInfo { | ||
private int revisionNumber; | ||
private String user; | ||
private String date; | ||
|
||
private String value; | ||
|
||
private List<RevisionFieldChange> changes; | ||
private final int revisionNumber; | ||
private final String user; | ||
private final String date; | ||
private final String value; | ||
private final List<RevisionFieldChange> changes; | ||
|
||
public RevisionInfo(int revisionNumber, String user, Date date, String value) { | ||
this.revisionNumber = revisionNumber; | ||
|
@@ -62,8 +59,11 @@ public String getValue() { | |
return value; | ||
} | ||
|
||
/** | ||
* @return an unmodifiable view of the list of changes. | ||
*/ | ||
public List<RevisionFieldChange> getChanges() { | ||
return changes; | ||
return Collections.unmodifiableList(changes); | ||
} | ||
|
||
public void addChange(RevisionFieldChange change) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,11 @@ | |
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.auditable.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import org.fao.geonet.domain.Group; | ||
import org.fao.geonet.domain.Profile; | ||
import org.fao.geonet.domain.User; | ||
|
@@ -31,21 +33,16 @@ | |
import org.junit.Test; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class UserAuditableTest { | ||
|
||
@Test | ||
public void testBuildUserAuditable() { | ||
Group group = new Group() | ||
.setId(1) | ||
.setName("sample"); | ||
Group group = new Group().setId(1).setName("sample"); | ||
Group group2 = new Group().setId(2).setName("sampleGroup2"); | ||
|
||
|
||
User user = new User() | ||
|
@@ -54,7 +51,7 @@ public void testBuildUserAuditable() { | |
.setSurname("surname") | ||
.setUsername("username") | ||
.setEnabled(true) | ||
.setEmailAddresses(new HashSet<>(Arrays.asList("[email protected]"))) | ||
.setEmailAddresses(new HashSet<>(List.of("[email protected]"))) | ||
.setProfile(Profile.Reviewer); | ||
|
||
|
||
|
@@ -65,7 +62,7 @@ public void testBuildUserAuditable() { | |
.setProfile(Profile.Editor); | ||
|
||
UserGroup userGroup2 = new UserGroup() | ||
.setGroup(group) | ||
.setGroup(group2) | ||
.setUser(user) | ||
.setProfile(Profile.Reviewer); | ||
|
||
|
@@ -81,12 +78,12 @@ public void testBuildUserAuditable() { | |
assertEquals(user.getUsername(), userAuditable.getUsername()); | ||
assertEquals(user.getEmailAddresses().toArray()[0], userAuditable.getEmailAddress()); | ||
assertEquals(user.getProfile().toString(), userAuditable.getProfile()); | ||
assertTrue(!StringUtils.hasLength(userAuditable.getGroupsRegisteredUser())); | ||
assertFalse(StringUtils.hasLength(userAuditable.getGroupsRegisteredUser())); | ||
assertTrue(userAuditable.getGroupsEditor().contains(group.getName())); | ||
assertTrue(userAuditable.getGroupsReviewer().contains(group.getName())); | ||
assertTrue(!StringUtils.hasLength(userAuditable.getGroupsUserAdmin())); | ||
assertTrue(userAuditable.getGroupsReviewer().contains(group2.getName())); | ||
assertFalse(StringUtils.hasLength(userAuditable.getGroupsUserAdmin())); | ||
|
||
assertEquals(group.getName(), userAuditable.getGroupsEditor()); | ||
assertEquals(group.getName(), userAuditable.getGroupsReviewer()); | ||
assertEquals(group2.getName(), userAuditable.getGroupsReviewer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# | ||
# Copyright (C) 2001-2016 Food and Agriculture Organization of the | ||
# Copyright (C) 2001-2024 Food and Agriculture Organization of the | ||
# United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
# and United Nations Environment Programme (UNEP) | ||
# | ||
|
@@ -20,7 +20,6 @@ | |
# Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
# Rome - Italy. email: [email protected] | ||
# | ||
|
||
mail_error=Failed to send email. | ||
mail_config_test_subject=%s / Test / Mail configuration | ||
mail_config_test_message=Test message from %s\n\ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
# Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
# Rome - Italy. email: [email protected] | ||
# | ||
|
||
mail_error=Erreur lors de l'envoi du mail. | ||
mail_config_test_subject=%s / Test / Configuration serveur de mail | ||
mail_config_test_message=Message de test de %s\n\ | ||
|
@@ -237,8 +236,8 @@ api.metadata.status.errorSetStatusNotAllowed=Seul le propri\u00E9taire des m\u00 | |
|
||
feedback_subject_userFeedback=Commentaire de l'utilisateur | ||
|
||
audit.revision=Updated by %s on %s:\n\ | ||
audit.revision=Mise \u00E0 jour par %s le %s:\n\ | ||
%s | ||
audit.revision.field.set=- Field '%s' set to '%s' | ||
audit.revision.field.unset=- Field '%s' unset | ||
audit.revision.field.updated=- Field '%s' changed from '%s' to '%s' | ||
audit.revision.field.set=- Champ '%s' d\u00E9fini \u00E0 '%s' | ||
audit.revision.field.unset=- Champ '%s' d\u00E9sactiv\u00E9 | ||
audit.revision.field.updated=- Champ '%s' modifi\u00E9 de '%s' \u00E0 '%s' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,14 @@ | |
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.auditable; | ||
|
||
import java.util.Optional; | ||
import org.fao.geonet.domain.User; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Extracts the current user used, to store the information in the auditable entities. | ||
*/ | ||
|
26 changes: 26 additions & 0 deletions
26
domain/src/main/java/org/fao/geonet/auditable/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2001-2024 Food and Agriculture Organization of the | ||
* United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
* and United Nations Environment Programme (UNEP) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
* | ||
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
@NonNullApi | ||
package org.fao.geonet.auditable; | ||
|
||
import org.springframework.lang.NonNullApi; |
Oops, something went wrong.