Skip to content
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
wants to merge 54 commits into
base: dtq-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
380fb45
added provenance metadata for update, remove and add
Paurikova2 Aug 13, 2024
ffe630a
checkstyle violations
Paurikova2 Aug 14, 2024
46335a1
added provenance metadata for update and remove bitstream
Paurikova2 Aug 14, 2024
96158a5
item test json added metadata provenance
Paurikova2 Aug 14, 2024
9d6097f
removed unwanted lines
Paurikova2 Aug 14, 2024
a0c500a
control provenance only by tests of item
Paurikova2 Aug 15, 2024
c79c000
update and remove license
Paurikova2 Aug 19, 2024
c55d418
provenance access control and upload bitstream
Paurikova2 Aug 20, 2024
499aac4
provenance move item to different collection
Paurikova2 Aug 20, 2024
9c361d9
provenance make item non-discoverable
Paurikova2 Aug 20, 2024
9f94913
checkstyle violations and test failures
Paurikova2 Aug 21, 2024
2a0d919
make code more readable
Paurikova2 Aug 21, 2024
1922907
provenance for mapped collection
Paurikova2 Aug 22, 2024
d9dd689
grammer check
Paurikova2 Aug 22, 2024
5cddf35
don't write provenance for bitstream without item
Paurikova2 Aug 22, 2024
4a6072a
move addProvenance to parent class
Paurikova2 Aug 22, 2024
e468c90
refactoring
Paurikova2 Aug 22, 2024
9910c90
checkstyle violations and test failures
Paurikova2 Aug 22, 2024
18607a5
removed unnecessary variables, added logs and checkstyle
Paurikova2 Sep 10, 2024
aae82cc
separated class for provenance
Paurikova2 Sep 25, 2024
0b3c0d7
create class for provenance management
Paurikova2 Sep 27, 2024
64d84a1
added metadata item and bitstream tests
Paurikova2 Oct 1, 2024
7c8f7e5
tests for metadata provenance
Paurikova2 Oct 2, 2024
43c5eb2
problem with access control test
Paurikova2 Oct 2, 2024
b67b4b3
tests do not work
Paurikova2 Oct 2, 2024
d7a270b
better service management:
Paurikova2 Oct 7, 2024
e4da4e1
delete clarin license mapping
Paurikova2 Oct 7, 2024
5b6168c
checkstyle violations
Paurikova2 Oct 7, 2024
a4bc467
checkstyle violations
Paurikova2 Oct 7, 2024
0e4c9a2
checkstyle violations
Paurikova2 Oct 7, 2024
556c3d4
checkstyle violations
Paurikova2 Oct 7, 2024
e7caf0d
checkstyle violations
Paurikova2 Oct 7, 2024
9b7fb5c
added json to resources
Paurikova2 Oct 7, 2024
eba6bbd
modified provenance patch messages
Paurikova2 Oct 7, 2024
a0d5d55
messages bags
Paurikova2 Oct 7, 2024
5282d63
refactoring based on git comparison
Paurikova2 Oct 7, 2024
828769f
checkstyle violations
Paurikova2 Oct 7, 2024
a1b95e6
used correct json
Paurikova2 Oct 8, 2024
8621bcd
checkstyle violations
Paurikova2 Oct 8, 2024
2fdc96e
log exception, replace ! by non conds, added doc comments
Paurikova2 Oct 10, 2024
b026ca0
added logs for replacing mtd
Paurikova2 Oct 17, 2024
64d7eae
removed unused services
Paurikova2 Nov 20, 2024
49cae22
make object from provenance service
Paurikova2 Nov 22, 2024
eb2315e
removed interface prom provenance msg provider
Paurikova2 Nov 22, 2024
876a7f2
checkstyle
Paurikova2 Nov 22, 2024
130d78f
Refactored method `removeReadPolicies` - add provenance after removin…
milanmajchrak Dec 12, 2024
419aff3
The message templates are loaded from the Enum instead of json file.
milanmajchrak Dec 12, 2024
a0abf72
The `getMessage` methods was overloaded.
milanmajchrak Dec 13, 2024
a1324ce
Renamed `getItem` to `findItemByBitstream` to clarify the method's pu…
milanmajchrak Dec 13, 2024
8ff24e0
Do not throw exception when adding to provenance
milanmajchrak Dec 13, 2024
51302fa
The exceptions are caught in the ProvenanceProvider and changed order…
milanmajchrak Dec 13, 2024
46ab18c
Renamed ProvenanceProvider to ProvenanceService and refactored it to …
milanmajchrak Dec 13, 2024
5f63dcd
The ProvenanceService wasn't initialized in the BundleAccessControl
milanmajchrak Dec 16, 2024
fb82e94
Removal of unwanted changes
milanmajchrak Dec 16, 2024
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 @@ -45,6 +45,7 @@
import org.dspace.app.util.DSpaceObjectUtilsImpl;
import org.dspace.app.util.service.DSpaceObjectUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.authorize.factory.AuthorizeServiceFactory;
import org.dspace.authorize.service.ResourcePolicyService;
import org.dspace.content.Bitstream;
Expand All @@ -55,6 +56,7 @@
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.ProvenanceService;
import org.dspace.discovery.DiscoverQuery;
import org.dspace.discovery.SearchService;
import org.dspace.discovery.SearchServiceException;
Expand Down Expand Up @@ -111,6 +113,8 @@ public class BulkAccessControl extends DSpaceRunnable<BulkAccessControlScriptCon

protected String eperson = null;

protected ProvenanceService provenanceService = ContentServiceFactory.getInstance().getProvenanceService();

@Override
@SuppressWarnings("unchecked")
public void setup() throws ParseException {
Expand Down Expand Up @@ -465,6 +469,7 @@ private void setItemPolicies(Item item, BulkAccessControlInput accessControl)
itemAccessConditions.get(accessCondition.getName())));

itemService.adjustItemPolicies(context, item, item.getOwningCollection(), false);
provenanceService.setItemPolicies(context, item, accessControl);
}

/**
Expand Down Expand Up @@ -552,7 +557,10 @@ private void updateBitstreamPolicies(Bitstream bitstream, Item item, BulkAccessC
*/
private void removeReadPolicies(DSpaceObject dso, String type) {
try {
// Get all read policies of the dso before removing them
List<ResourcePolicy> resPolicies = resourcePolicyService.find(context, dso, type);
resourcePolicyService.removePolicies(context, dso, type, Constants.READ);
provenanceService.removeReadPolicies(context, dso, resPolicies);
} catch (SQLException | AuthorizeException e) {
throw new BulkAccessControlException(e);
}
Expand Down Expand Up @@ -580,6 +588,7 @@ private void setBitstreamPolicies(Bitstream bitstream, Item item, BulkAccessCont

itemService.adjustBitstreamPolicies(context, item, item.getOwningCollection(), bitstream);
mediaFilterService.updatePoliciesOfDerivativeBitstreams(context, item, bitstream);
provenanceService.setBitstreamPolicies(context, bitstream, item, accessControl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.content.service.SiteService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.ProvenanceService;
import org.dspace.eperson.service.SubscribeService;
import org.dspace.handle.service.HandleClarinService;
import org.dspace.services.factory.DSpaceServicesFactory;
Expand Down Expand Up @@ -77,6 +78,7 @@ public abstract class ContentServiceFactory {
public abstract SiteService getSiteService();

public abstract SubscribeService getSubscribeService();

public abstract PreviewContentService getPreviewContentService();

/**
Expand Down Expand Up @@ -123,6 +125,13 @@ public abstract class ContentServiceFactory {
*/
public abstract HandleClarinService getHandleClarinService();

/**
* Return the implementation of the ProvenanceService interface
*
* @return the ProvenanceService
*/
public abstract ProvenanceService getProvenanceService();

public InProgressSubmissionService getInProgressSubmissionService(InProgressSubmission inProgressSubmission) {
if (inProgressSubmission instanceof WorkspaceItem) {
return getWorkspaceItemService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.content.service.SiteService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.ProvenanceService;
import org.dspace.eperson.service.SubscribeService;
import org.dspace.handle.service.HandleClarinService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -93,6 +94,9 @@ public class ContentServiceFactoryImpl extends ContentServiceFactory {
@Autowired(required = true)
private HandleClarinService handleClarinService;

@Autowired(required = true)
private ProvenanceService provenanceService;

@Override
public List<DSpaceObjectService<? extends DSpaceObject>> getDSpaceObjectServices() {
return dSpaceObjectServices;
Expand Down Expand Up @@ -173,6 +177,11 @@ public PreviewContentService getPreviewContentService() {
return previewContentService;
}

@Override
public ProvenanceService getProvenanceService() {
return provenanceService;
}

@Override
public RelationshipTypeService getRelationshipTypeService() {
return relationshipTypeService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* 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 java.util.stream.Collectors;

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;

/**
* The ProvenanceMessageProvider 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 ProvenanceMessageFormatter {
private InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();

public ProvenanceMessageFormatter() {}

public String getMessage(Context context, String messageTemplate, Item item, Object... args)
throws SQLException, AuthorizeException {
String msg = getMessage(context, messageTemplate, args);
msg = msg + "\n" + installItemService.getBitstreamProvenanceMessage(context, item);
return msg;
}

public String getMessage(Context context, String messageTemplate, Object... args) {
EPerson currentUser = context.getCurrentUser();
String timestamp = DCDate.getCurrent().toString();
String details = validateMessageTemplate(messageTemplate, args);
return String.format("%s by %s (%s) on %s",
details,
currentUser.getFullName(),
currentUser.getEmail(),
timestamp);
}

public String getMessage(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;
}

public String getMessage(Bitstream bitstream) {
// values of deleted bitstream
String msg = bitstream.getName() + ": " +
bitstream.getSizeBytes() + " bytes, checksum: " +
bitstream.getChecksum() + " (" +
bitstream.getChecksumAlgorithm() + ")\n";
return msg;
}

public String getMessage(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(";"));
}

public String getMetadata(String oldMtdKey, String oldMtdValue) {
return oldMtdKey + ": " + oldMtdValue;
}

public String getMetadataField(MetadataField metadataField) {
return metadataField.toString()
.replace('_', '.');
}

private String validateMessageTemplate(String messageTemplate, Object... args) {
if (messageTemplate == null) {
throw new IllegalArgumentException("The provenance message template is null!");
}
return String.format(messageTemplate, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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;

/**
* The ProvenanceMessageTemplates enum provides message templates for provenance messages.
*
* @author Michaela Paurikova (dspace at dataquest.sk)
*/
public enum ProvenanceMessageTemplates {
ACCESS_CONDITION("Access condition (%s) was added to %s (%s)"),
RESOURCE_POLICIES_REMOVED("Resource policies (%s) of %s (%s) were removed"),
BUNDLE_ADDED("Item was added bitstream to bundle (%s)"),
EDIT_LICENSE("License (%s) was %s"),
MOVE_ITEM("Item was moved from collection (%s) to different collection"),
MAPPED_ITEM("Item was mapped to collection (%s)"),
DELETED_ITEM_FROM_MAPPED("Item was deleted from mapped collection (%s)"),
EDIT_BITSTREAM("Item (%s) was deleted bitstream (%s)"),
ITEM_METADATA("Item metadata (%s) was %s"),
BITSTREAM_METADATA("Item metadata (%s) was %s bitstream (%s)"),
ITEM_REPLACE_SINGLE_METADATA("Item bitstream (%s) metadata (%s) was updated"),
DISCOVERABLE("Item was made %sdiscoverable");

private final String template;

ProvenanceMessageTemplates(String template) {
this.template = template;
}

public String getTemplate() {
return template;
}
}
Loading
Loading