mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Merge pull request #8417 from 4Science/DS-4415-main
port #2634 CitationPage curation task mess the bitstream policies to the main branch
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.curate;
|
package org.dspace.ctask.general;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -18,6 +18,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
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;
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.Bundle;
|
import org.dspace.content.Bundle;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
@@ -26,6 +29,10 @@ import org.dspace.content.factory.ContentServiceFactory;
|
|||||||
import org.dspace.content.service.BitstreamService;
|
import org.dspace.content.service.BitstreamService;
|
||||||
import org.dspace.content.service.BundleService;
|
import org.dspace.content.service.BundleService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.curate.AbstractCurationTask;
|
||||||
|
import org.dspace.curate.Curator;
|
||||||
|
import org.dspace.curate.Distributive;
|
||||||
|
import org.dspace.curate.Mutative;
|
||||||
import org.dspace.disseminate.factory.DisseminateServiceFactory;
|
import org.dspace.disseminate.factory.DisseminateServiceFactory;
|
||||||
import org.dspace.disseminate.service.CitationDocumentService;
|
import org.dspace.disseminate.service.CitationDocumentService;
|
||||||
|
|
||||||
@@ -67,6 +74,10 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
|
|
||||||
protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
||||||
protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
|
protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
|
||||||
|
protected ResourcePolicyService resourcePolicyService = AuthorizeServiceFactory.getInstance()
|
||||||
|
.getResourcePolicyService();
|
||||||
|
|
||||||
|
private Map<String,Bitstream> displayMap = new HashMap<String,Bitstream>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@@ -95,10 +106,13 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
protected void performItem(Item item) throws SQLException {
|
protected void performItem(Item item) throws SQLException {
|
||||||
//Determine if the DISPLAY bundle exits. If not, create it.
|
//Determine if the DISPLAY bundle exits. If not, create it.
|
||||||
List<Bundle> dBundles = itemService.getBundles(item, CitationPage.DISPLAY_BUNDLE_NAME);
|
List<Bundle> dBundles = itemService.getBundles(item, CitationPage.DISPLAY_BUNDLE_NAME);
|
||||||
|
Bundle original = itemService.getBundles(item, "ORIGINAL").get(0);
|
||||||
Bundle dBundle = null;
|
Bundle dBundle = null;
|
||||||
if (dBundles == null || dBundles.isEmpty()) {
|
if (dBundles == null || dBundles.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
dBundle = bundleService.create(Curator.curationContext(), item, CitationPage.DISPLAY_BUNDLE_NAME);
|
dBundle = bundleService.create(Curator.curationContext(), item, CitationPage.DISPLAY_BUNDLE_NAME);
|
||||||
|
// don't inherit now otherwise they will be copied over the moved bitstreams
|
||||||
|
resourcePolicyService.removeAllPolicies(Curator.curationContext(), dBundle);
|
||||||
} catch (AuthorizeException e) {
|
} catch (AuthorizeException e) {
|
||||||
log.error("User not authroized to create bundle on item \"{}\": {}",
|
log.error("User not authroized to create bundle on item \"{}\": {}",
|
||||||
item::getName, e::getMessage);
|
item::getName, e::getMessage);
|
||||||
@@ -110,7 +124,6 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
|
|
||||||
//Create a map of the bitstreams in the displayBundle. This is used to
|
//Create a map of the bitstreams in the displayBundle. This is used to
|
||||||
//check if the bundle being cited is already in the display bundle.
|
//check if the bundle being cited is already in the display bundle.
|
||||||
Map<String, Bitstream> displayMap = new HashMap<>();
|
|
||||||
for (Bitstream bs : dBundle.getBitstreams()) {
|
for (Bitstream bs : dBundle.getBitstreams()) {
|
||||||
displayMap.put(bs.getName(), bs);
|
displayMap.put(bs.getName(), bs);
|
||||||
}
|
}
|
||||||
@@ -128,6 +141,8 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
pBundle = bundleService.create(Curator.curationContext(), item, CitationPage.PRESERVATION_BUNDLE_NAME);
|
pBundle = bundleService.create(Curator.curationContext(), item, CitationPage.PRESERVATION_BUNDLE_NAME);
|
||||||
|
// don't inherit now otherwise they will be copied over the moved bitstreams
|
||||||
|
resourcePolicyService.removeAllPolicies(Curator.curationContext(), pBundle);
|
||||||
} catch (AuthorizeException e) {
|
} catch (AuthorizeException e) {
|
||||||
log.error("User not authroized to create bundle on item \""
|
log.error("User not authroized to create bundle on item \""
|
||||||
+ item.getName() + "\": " + e.getMessage());
|
+ item.getName() + "\": " + e.getMessage());
|
||||||
@@ -160,7 +175,10 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
citationDocument.makeCitedDocument(Curator.curationContext(), bitstream).getLeft());
|
citationDocument.makeCitedDocument(Curator.curationContext(), bitstream).getLeft());
|
||||||
//Add the cited document to the approiate bundle
|
//Add the cited document to the approiate bundle
|
||||||
this.addCitedPageToItem(citedInputStream, bundle, pBundle,
|
this.addCitedPageToItem(citedInputStream, bundle, pBundle,
|
||||||
dBundle, displayMap, item, bitstream);
|
dBundle, item, bitstream);
|
||||||
|
// now set the policies of the preservation and display bundle
|
||||||
|
clonePolicies(Curator.curationContext(), original, pBundle);
|
||||||
|
clonePolicies(Curator.curationContext(), original, dBundle);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//Could be many things, but nothing that should be
|
//Could be many things, but nothing that should be
|
||||||
//expected.
|
//expected.
|
||||||
@@ -203,8 +221,6 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
* @param pBundle The preservation bundle. The original document should be
|
* @param pBundle The preservation bundle. The original document should be
|
||||||
* put in here if it is not already.
|
* put in here if it is not already.
|
||||||
* @param dBundle The display bundle. The cited document gets put in here.
|
* @param dBundle The display bundle. The cited document gets put in here.
|
||||||
* @param displayMap The map of bitstream names to bitstreams in the display
|
|
||||||
* bundle.
|
|
||||||
* @param item The item containing the bundles being used.
|
* @param item The item containing the bundles being used.
|
||||||
* @param bitstream The original source bitstream.
|
* @param bitstream The original source bitstream.
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
@@ -212,7 +228,7 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
* @throws IOException if IO error
|
* @throws IOException if IO error
|
||||||
*/
|
*/
|
||||||
protected void addCitedPageToItem(InputStream citedDoc, Bundle bundle, Bundle pBundle,
|
protected void addCitedPageToItem(InputStream citedDoc, Bundle bundle, Bundle pBundle,
|
||||||
Bundle dBundle, Map<String,Bitstream> displayMap, Item item,
|
Bundle dBundle, Item item,
|
||||||
Bitstream bitstream) throws SQLException, AuthorizeException, IOException {
|
Bitstream bitstream) throws SQLException, AuthorizeException, IOException {
|
||||||
//If we are modifying a file that is not in the
|
//If we are modifying a file that is not in the
|
||||||
//preservation bundle then we have to move it there.
|
//preservation bundle then we have to move it there.
|
||||||
@@ -240,7 +256,8 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
citedBitstream.setName(context, bitstream.getName());
|
citedBitstream.setName(context, bitstream.getName());
|
||||||
bitstreamService.setFormat(context, citedBitstream, bitstream.getFormat(Curator.curationContext()));
|
bitstreamService.setFormat(context, citedBitstream, bitstream.getFormat(Curator.curationContext()));
|
||||||
citedBitstream.setDescription(context, bitstream.getDescription());
|
citedBitstream.setDescription(context, bitstream.getDescription());
|
||||||
|
displayMap.put(bitstream.getName(), citedBitstream);
|
||||||
|
clonePolicies(context, bitstream, citedBitstream);
|
||||||
this.resBuilder.append(" Added ")
|
this.resBuilder.append(" Added ")
|
||||||
.append(citedBitstream.getName())
|
.append(citedBitstream.getName())
|
||||||
.append(" to the ")
|
.append(" to the ")
|
||||||
@@ -252,4 +269,16 @@ public class CitationPage extends AbstractCurationTask {
|
|||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
this.status = Curator.CURATE_SUCCESS;
|
this.status = Curator.CURATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clonePolicies(Context context, DSpaceObject source,DSpaceObject target)
|
||||||
|
throws SQLException, AuthorizeException {
|
||||||
|
resourcePolicyService.removeAllPolicies(context, target);
|
||||||
|
for (ResourcePolicy rp: source.getResourcePolicies()) {
|
||||||
|
ResourcePolicy newPolicy = resourcePolicyService.clone(context, rp);
|
||||||
|
newPolicy.setdSpaceObject(target);
|
||||||
|
newPolicy.setAction(rp.getAction());
|
||||||
|
resourcePolicyService.update(context, newPolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@@ -15,6 +15,7 @@ plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.RequiredM
|
|||||||
#plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.MicrosoftTranslator = translate
|
#plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.MicrosoftTranslator = translate
|
||||||
plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.MetadataValueLinkChecker = checklinks
|
plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.MetadataValueLinkChecker = checklinks
|
||||||
plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.RegisterDOI = registerdoi
|
plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.RegisterDOI = registerdoi
|
||||||
|
#plugin.named.org.dspace.curate.CurationTask = org.dspace.ctask.general.CitationPage = citationpage
|
||||||
# add new tasks here (or in additional config files)
|
# add new tasks here (or in additional config files)
|
||||||
|
|
||||||
## task queue implementation
|
## task queue implementation
|
||||||
|
Reference in New Issue
Block a user