forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
metadata-added-provenance #730
Open
Paurikova2
wants to merge
40
commits into
dtq-dev
Choose a base branch
from
metadata-edits-and-provenance
base: dtq-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
380fb45
added provenance metadata for update, remove and add
Paurikova2 ffe630a
checkstyle violations
Paurikova2 46335a1
added provenance metadata for update and remove bitstream
Paurikova2 96158a5
item test json added metadata provenance
Paurikova2 9d6097f
removed unwanted lines
Paurikova2 a0c500a
control provenance only by tests of item
Paurikova2 c79c000
update and remove license
Paurikova2 c55d418
provenance access control and upload bitstream
Paurikova2 499aac4
provenance move item to different collection
Paurikova2 9c361d9
provenance make item non-discoverable
Paurikova2 9f94913
checkstyle violations and test failures
Paurikova2 2a0d919
make code more readable
Paurikova2 1922907
provenance for mapped collection
Paurikova2 d9dd689
grammer check
Paurikova2 5cddf35
don't write provenance for bitstream without item
Paurikova2 4a6072a
move addProvenance to parent class
Paurikova2 e468c90
refactoring
Paurikova2 9910c90
checkstyle violations and test failures
Paurikova2 18607a5
removed unnecessary variables, added logs and checkstyle
Paurikova2 aae82cc
separated class for provenance
Paurikova2 0b3c0d7
create class for provenance management
Paurikova2 64d84a1
added metadata item and bitstream tests
Paurikova2 7c8f7e5
tests for metadata provenance
Paurikova2 43c5eb2
problem with access control test
Paurikova2 b67b4b3
tests do not work
Paurikova2 d7a270b
better service management:
Paurikova2 e4da4e1
delete clarin license mapping
Paurikova2 5b6168c
checkstyle violations
Paurikova2 a4bc467
checkstyle violations
Paurikova2 0e4c9a2
checkstyle violations
Paurikova2 556c3d4
checkstyle violations
Paurikova2 e7caf0d
checkstyle violations
Paurikova2 9b7fb5c
added json to resources
Paurikova2 eba6bbd
modified provenance patch messages
Paurikova2 a0d5d55
messages bags
Paurikova2 5282d63
refactoring based on git comparison
Paurikova2 828769f
checkstyle violations
Paurikova2 a1b95e6
used correct json
Paurikova2 8621bcd
checkstyle violations
Paurikova2 2fdc96e
log exception, replace ! by non conds, added doc comments
Paurikova2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions
35
dspace-api/src/main/java/org/dspace/core/ProvenanceMessageProvider.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,35 @@ | ||
/** | ||
* 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.core; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.ResourcePolicy; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.MetadataField; | ||
|
||
/** | ||
* Interface for providing provenance messages. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public interface ProvenanceMessageProvider { | ||
public String getMessage(Context context, String templateKey, Object... args) | ||
throws SQLException, AuthorizeException; | ||
public String getMessage(Context context, String templateKey, Item item, Object... args) | ||
throws SQLException, AuthorizeException; | ||
public String getMessage(String templateKey, Object... args); | ||
public String addCollectionsToMessage(Item item); | ||
public String getBitstreamMessage(Bitstream bitstream); | ||
public String getResourcePoliciesMessage(List<ResourcePolicy> resPolicies); | ||
public String getMetadata(String oldMtdKey, String oldMtdValue); | ||
public String getMetadataField(MetadataField metadataField); | ||
} |
137 changes: 137 additions & 0 deletions
137
dspace-api/src/main/java/org/dspace/core/ProvenanceMessageProviderImpl.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,137 @@ | ||
/** | ||
* 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.core; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.ResourcePolicy; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Collection; | ||
import org.dspace.content.DCDate; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.MetadataField; | ||
import org.dspace.content.factory.ContentServiceFactory; | ||
import org.dspace.content.service.InstallItemService; | ||
import org.dspace.eperson.EPerson; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc + athor |
||
/** | ||
* The ProvenanceMessageProviderImpl class implements the ProvenanceMessageProvider interface, | ||
* providing methods to generate provenance messages for DSpace items. It loads message templates | ||
* from a JSON file and formats messages based on the context, including user details and timestamps. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public class ProvenanceMessageProviderImpl implements ProvenanceMessageProvider { | ||
private static final String PROVENANCE_MSG_JSON = "provenance_messages.json"; | ||
private static final Logger log = LoggerFactory.getLogger(ProvenanceMessageProviderImpl.class); | ||
private Map<String, String> messageTemplates; | ||
private InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService(); | ||
|
||
public ProvenanceMessageProviderImpl() { | ||
loadMessageTemplates(); | ||
} | ||
|
||
private void loadMessageTemplates() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
String msg; | ||
try (InputStream inputStream = getClass().getResourceAsStream(PROVENANCE_MSG_JSON)) { | ||
if (inputStream == null) { | ||
msg = "Failed to find message templates file."; | ||
log.error(msg); | ||
throw new RuntimeException(msg); | ||
} | ||
messageTemplates = mapper.readValue(inputStream, Map.class); | ||
} catch (IOException e) { | ||
msg = "Failed to load message templates."; | ||
log.error(msg); | ||
throw new RuntimeException(msg, e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getMessage(Context context, String templateKey, Item item, Object... args) | ||
throws SQLException, AuthorizeException { | ||
String msg = getMessage(context, templateKey, args); | ||
msg = msg + "\n" + installItemService.getBitstreamProvenanceMessage(context, item); | ||
return msg; | ||
} | ||
|
||
@Override | ||
public String getMessage(String templateKey, Object... args) { | ||
String template = messageTemplates.get(templateKey); | ||
if (template == null) { | ||
throw new IllegalArgumentException("No message template found for key: " + templateKey); | ||
} | ||
return String.format(template, args); | ||
} | ||
|
||
@Override | ||
public String getMessage(Context context, String templateKey, Object... args) { | ||
EPerson currentUser = context.getCurrentUser(); | ||
String timestamp = DCDate.getCurrent().toString(); | ||
String details = getMessage(templateKey, args); | ||
return String.format("%s by %s (%s) on %s", | ||
details, | ||
currentUser.getFullName(), | ||
currentUser.getEmail(), | ||
timestamp); | ||
} | ||
|
||
@Override | ||
public String addCollectionsToMessage(Item item) { | ||
String msg = "Item was in collections:\n"; | ||
List<Collection> collsList = item.getCollections(); | ||
for (Collection coll : collsList) { | ||
msg = msg + coll.getName() + " (ID: " + coll.getID() + ")\n"; | ||
} | ||
return msg; | ||
} | ||
|
||
@Override | ||
public String getBitstreamMessage(Bitstream bitstream) { | ||
// values of deleted bitstream | ||
String msg = bitstream.getName() + ": " + | ||
bitstream.getSizeBytes() + " bytes, checksum: " + | ||
bitstream.getChecksum() + " (" + | ||
bitstream.getChecksumAlgorithm() + ")\n"; | ||
return msg; | ||
} | ||
|
||
@Override | ||
public String getResourcePoliciesMessage(List<ResourcePolicy> resPolicies) { | ||
return resPolicies.stream() | ||
.filter(rp -> rp.getAction() == Constants.READ) | ||
.map(rp -> String.format("[%s, %s, %d, %s, %s, %s, %s]", | ||
rp.getRpName(), rp.getRpType(), rp.getAction(), | ||
rp.getEPerson() != null ? rp.getEPerson().getEmail() : null, | ||
rp.getGroup() != null ? rp.getGroup().getName() : null, | ||
rp.getStartDate() != null ? rp.getStartDate().toString() : null, | ||
rp.getEndDate() != null ? rp.getEndDate().toString() : null)) | ||
.collect(Collectors.joining(";")); | ||
} | ||
|
||
@Override | ||
public String getMetadata(String oldMtdKey, String oldMtdValue) { | ||
return oldMtdKey + ": " + oldMtdValue; | ||
} | ||
|
||
@Override | ||
public String getMetadataField(MetadataField metadataField) { | ||
return metadataField.toString() | ||
.replace('_', '.'); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
dspace-api/src/main/java/org/dspace/core/ProvenanceService.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,58 @@ | ||
/** | ||
* 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.core; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import org.dspace.app.bulkaccesscontrol.model.BulkAccessControlInput; | ||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Bundle; | ||
import org.dspace.content.Collection; | ||
import org.dspace.content.DSpaceObject; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.MetadataField; | ||
import org.dspace.content.MetadataValue; | ||
|
||
/** | ||
* The ProvenanceService interface defines methods for creating provenance metadata | ||
* for items based on the actions performed. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public interface ProvenanceService { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add doc + author |
||
public void setBitstreamPolicies(Context context, Bitstream bitstream, Item item, | ||
BulkAccessControlInput accessControl) throws SQLException, AuthorizeException; | ||
|
||
public void setItemPolicies(Context context, Item item, BulkAccessControlInput accessControl) | ||
throws SQLException, AuthorizeException; | ||
|
||
public String removedReadPolicies(Context context, DSpaceObject dso, String type) | ||
throws SQLException, AuthorizeException; | ||
public void uploadBitstream(Context context, Bundle bundle) throws SQLException, AuthorizeException; | ||
public void editLicense(Context context, Item item, boolean newLicense) throws SQLException, AuthorizeException; | ||
|
||
public void moveItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException; | ||
public void mappedItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException; | ||
public void deletedItemFromMapped(Context context, Item item, Collection collection) | ||
throws SQLException, AuthorizeException; | ||
public void deleteBitstream(Context context,Bitstream bitstream) throws SQLException, AuthorizeException; | ||
public void addMetadata(Context context, DSpaceObject dso, MetadataField metadataField) | ||
throws SQLException, AuthorizeException; | ||
public void removeMetadata(Context context, DSpaceObject dso, MetadataField metadataField) | ||
throws SQLException, AuthorizeException; | ||
public void removeMetadataAtIndex(Context context, DSpaceObject dso, List<MetadataValue> metadataValues, | ||
int indexInt) throws SQLException, AuthorizeException; | ||
public void replaceMetadata(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal) | ||
throws SQLException, AuthorizeException; | ||
public void replaceMetadataSingle(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal) | ||
throws SQLException, AuthorizeException; | ||
public void makeDiscoverable(Context context, Item item, boolean discoverable) | ||
throws SQLException, AuthorizeException; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with email dspace@dataquest.sk