forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create class for provenance management
- Loading branch information
1 parent
aae82cc
commit 0b3c0d7
Showing
18 changed files
with
647 additions
and
415 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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
/** | ||
* 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 org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.ResourcePolicy; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.MetadataField; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
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) throws SQLException, AuthorizeException; | ||
public String getBitstreamMessage(Bitstream bitstream); | ||
public String getResourcePoliciesMessage(List<ResourcePolicy> resPolicies); | ||
public String getMetadata(String oldMtdKey, String oldMtdValue); | ||
public String getMetadataField(MetadataField metadataField); | ||
} |
122 changes: 122 additions & 0 deletions
122
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,122 @@ | ||
/** | ||
* 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 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.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ProvenanceMessageProviderImpl implements ProvenanceMessageProvider { | ||
private Map<String, String> messageTemplates; | ||
|
||
@Autowired | ||
private InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService(); | ||
|
||
@Autowired | ||
public ProvenanceMessageProviderImpl() { | ||
loadMessageTemplates(); | ||
} | ||
|
||
private void loadMessageTemplates() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
try { | ||
messageTemplates = mapper.readValue(Files.readAllBytes(Paths.get("C:\\workspace\\DSpace\\dspace-api\\src\\main\\java\\org\\dspace\\core\\provenance_messages.json")), Map.class); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to load message templates", 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) throws SQLException, AuthorizeException { | ||
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('_', '.'); | ||
} | ||
} |
28 changes: 27 additions & 1 deletion
28
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 |
---|---|---|
@@ -1,17 +1,43 @@ | ||
/** | ||
* 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 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; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
public interface ProvenanceService { | ||
public void setBitstreaPolicies(Context context, Bitstream bitstream, Item item, BulkAccessControlInput accessControl) throws SQLException, AuthorizeException; | ||
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.