mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 12:03:09 +00:00
[DS-2779] Fix versioning due to service api
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.handle.Handle;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
@@ -39,8 +40,12 @@ public abstract class DSpaceObject implements Serializable
|
||||
@OrderBy("metadataField, place")
|
||||
private List<MetadataValue> metadata = new ArrayList<>();
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "dso")
|
||||
private Handle handle;
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "dso")
|
||||
// Order by is here to ensure that the oldest handle is retrieved first,
|
||||
// multiple handles are assigned to the latest version of an item the original handle will have the lowest identifier
|
||||
// This handle is the prefered handle.
|
||||
@OrderBy("handle_id ASC")
|
||||
private List<Handle> handles = new ArrayList<>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "dSpaceObject", cascade={CascadeType.PERSIST}, orphanRemoval = false)
|
||||
private List<ResourcePolicy> resourcePolicies = new ArrayList<>();
|
||||
@@ -118,12 +123,21 @@ public abstract class DSpaceObject implements Serializable
|
||||
*/
|
||||
public String getHandle()
|
||||
{
|
||||
return (handle != null ? handle.getHandle() : null);
|
||||
return (CollectionUtils.isNotEmpty(handles) ? handles.get(0).getHandle() : null);
|
||||
}
|
||||
|
||||
public void setHandle(Handle handle)
|
||||
void setHandle(List<Handle> handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
this.handles = handle;
|
||||
}
|
||||
|
||||
public void addHandle(Handle handle)
|
||||
{
|
||||
this.handles.add(handle);
|
||||
}
|
||||
|
||||
public List<Handle> getHandles() {
|
||||
return handles;
|
||||
}
|
||||
|
||||
protected List<MetadataValue> getMetadata() {
|
||||
|
@@ -29,7 +29,7 @@ public class Handle {
|
||||
@Column(name = "handle", unique = true)
|
||||
private String handle;
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "resource_id")
|
||||
private DSpaceObject dso;
|
||||
|
||||
|
@@ -137,7 +137,7 @@ public class HandleServiceImpl implements HandleService
|
||||
|
||||
handle.setHandle(handleId);
|
||||
handle.setDSpaceObject(dso);
|
||||
dso.setHandle(handle);
|
||||
dso.addHandle(handle);
|
||||
handle.setResourceTypeId(dso.getType());
|
||||
handleDAO.save(context, handle);
|
||||
|
||||
@@ -201,7 +201,7 @@ public class HandleServiceImpl implements HandleService
|
||||
|
||||
handle.setResourceTypeId(dso.getType());
|
||||
handle.setDSpaceObject(dso);
|
||||
dso.setHandle(handle);
|
||||
dso.addHandle(handle);
|
||||
handleDAO.save(context, handle);
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
|
@@ -134,7 +134,7 @@ public class HandleIdentifierProvider extends IdentifierProvider {
|
||||
}
|
||||
|
||||
try{
|
||||
return handleService.createHandle(context, dso, null);
|
||||
return handleService.createHandle(context, dso);
|
||||
}catch (Exception e){
|
||||
log.error(LogManager.getHeader(context, "Error while attempting to create handle", "Item id: " + dso.getID()), e);
|
||||
throw new RuntimeException("Error while attempting to create identifier for Item id: " + dso.getID());
|
||||
|
@@ -111,7 +111,14 @@ public class VersionedHandleIdentifierProvider extends IdentifierProvider {
|
||||
Version previous = versionHistoryService.getPrevious(history, version);
|
||||
if (versionHistoryService.isFirstVersion(history, previous))
|
||||
{
|
||||
modifyHandleMetadata(context, previous.getItem(), (canonical + DOT + 1));
|
||||
try{
|
||||
//If we have a reviewer he/she might not have the rights to edit the metadata of this item, so temporarly grant them.
|
||||
context.turnOffAuthorisationSystem();
|
||||
modifyHandleMetadata(context, previous.getItem(), (canonical + DOT + 1));
|
||||
}finally {
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
|
||||
}
|
||||
// Check if our previous item hasn't got a handle anymore.
|
||||
// This only occurs when a switch has been made from the standard handle identifier provider
|
||||
|
@@ -101,7 +101,7 @@ public abstract class AbstractVersionProvider {
|
||||
}
|
||||
|
||||
|
||||
protected Bitstream createBitstream(Context context, Bitstream nativeBitstream) throws AuthorizeException, SQLException, IOException {
|
||||
protected Bitstream createBitstream(Context context, Bitstream nativeBitstream) throws AuthorizeException, SQLException, IOException {
|
||||
Bitstream newBitstream = bitstreamStorageService.clone(context, nativeBitstream);
|
||||
List<MetadataValue> bitstreamMeta = bitstreamService.getMetadata(nativeBitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||
for (MetadataValue value : bitstreamMeta) {
|
||||
|
@@ -64,7 +64,7 @@ public class VersionHistoryForm extends AbstractDSpaceTransformer {
|
||||
|
||||
public void addBody(Body body) throws WingException, SQLException, AuthorizeException
|
||||
{
|
||||
boolean isItemView=parameters.getParameterAsInteger("itemID",-1) == -1;
|
||||
boolean isItemView=parameters.getParameter("itemID",null) == null;
|
||||
Item item = getItem();
|
||||
|
||||
if(item==null || !authorizeService.isAdmin(this.context, item.getOwningCollection()))
|
||||
@@ -106,7 +106,7 @@ public class VersionHistoryForm extends AbstractDSpaceTransformer {
|
||||
{
|
||||
try
|
||||
{
|
||||
if(parameters.getParameterAsInteger("itemID",-1) == -1)
|
||||
if(parameters.getParameter("itemID",null) == null)
|
||||
{
|
||||
DSpaceObject dso;
|
||||
dso = HandleUtil.obtainHandle(objectModel);
|
||||
|
@@ -88,7 +88,7 @@ public class VersionNoticeTransformer extends AbstractDSpaceTransformer {
|
||||
|
||||
if(history != null){
|
||||
Version latestVersion = retrieveLatestVersion(history, item);
|
||||
if(latestVersion != null && latestVersion.getItem().equals(item))
|
||||
if(latestVersion != null && !latestVersion.getItem().equals(item))
|
||||
{
|
||||
//We have a newer version
|
||||
Item latestVersionItem = latestVersion.getItem();
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
importClass(Packages.java.lang.Class);
|
||||
importClass(Packages.java.lang.ClassLoader);
|
||||
importClass(Packages.java.util.UUID)
|
||||
|
||||
importClass(Packages.org.dspace.app.xmlui.utils.FlowscriptUtils);
|
||||
|
||||
@@ -16,11 +17,9 @@ importClass(Packages.org.dspace.app.xmlui.aspect.administrative.FlowResult);
|
||||
importClass(Packages.org.apache.cocoon.environment.http.HttpEnvironment);
|
||||
importClass(Packages.org.apache.cocoon.servlet.multipart.Part);
|
||||
importClass(Packages.org.dspace.content.Item);
|
||||
importClass(Packages.org.dspace.content.factory.ContentServiceFactory)
|
||||
|
||||
importClass(Packages.org.dspace.handle.HandleManager);
|
||||
importClass(Packages.org.dspace.core.Constants);
|
||||
importClass(Packages.org.dspace.authorize.AuthorizeManager);
|
||||
importClass(Packages.org.dspace.license.CreativeCommons);
|
||||
|
||||
importClass(Packages.org.dspace.app.xmlui.utils.ContextUtil);
|
||||
importClass(Packages.org.dspace.app.xmlui.cocoon.HttpServletRequestCocoonWrapper);
|
||||
@@ -43,6 +42,12 @@ function getObjectModel()
|
||||
return FlowscriptUtils.getObjectModel(cocoon);
|
||||
}
|
||||
|
||||
function getItemService()
|
||||
{
|
||||
return ContentServiceFactory.getInstance().getItemService();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the DSpace context for this request since each HTTP request generates
|
||||
* a new context this object should never be stored and instead always accessed
|
||||
@@ -87,7 +92,7 @@ function getHttpResponse()
|
||||
* Start editing an individual item.
|
||||
*/
|
||||
function startCreateNewVersionItem(){
|
||||
var itemID = cocoon.request.get("itemID");
|
||||
var itemID = UUID.fromString((cocoon.request.get("itemID")));
|
||||
|
||||
assertEditItem(itemID);
|
||||
|
||||
@@ -96,7 +101,7 @@ function startCreateNewVersionItem(){
|
||||
result = doCreateNewVersion(itemID, result);
|
||||
}while(result!=null);
|
||||
|
||||
var item = Item.find(getDSContext(),itemID);
|
||||
var item = getItemService().find(getDSContext(),itemID);
|
||||
|
||||
//Send us back to the item page if we cancel !
|
||||
cocoon.redirectTo(cocoon.request.getContextPath() + "/handle/" + item.getHandle(), true);
|
||||
@@ -139,7 +144,7 @@ function doCreateNewVersion(itemID, result){
|
||||
* Start editing an individual item.
|
||||
*/
|
||||
function startVersionHistoryItem(){
|
||||
var itemID = cocoon.request.get("itemID");
|
||||
var itemID = UUID.fromString((cocoon.request.get("itemID")));
|
||||
|
||||
assertEditItem(itemID);
|
||||
|
||||
@@ -158,7 +163,7 @@ function doVersionHistoryItem(itemID, result){
|
||||
|
||||
if (cocoon.request.get("submit_cancel")){
|
||||
//Pressed the cancel button, redirect us to the item page
|
||||
var item = Item.find(getDSContext(),itemID);
|
||||
var item = getItemService().find(getDSContext(),itemID);
|
||||
|
||||
cocoon.redirectTo(cocoon.request.getContextPath()+"/handle/"+item.getHandle(),true);
|
||||
getDSContext().complete();
|
||||
@@ -183,13 +188,13 @@ function doVersionHistoryItem(itemID, result){
|
||||
}
|
||||
else if (cocoon.request.get("submit_restore") && cocoon.request.get("versionID")){
|
||||
var versionID = cocoon.request.get("versionID");
|
||||
itemID = cocoon.request.get("itemID");
|
||||
itemID = UUID.fromString(cocoon.request.get("itemID"));
|
||||
|
||||
result = doRestoreVersion(itemID, versionID);
|
||||
}
|
||||
else if (cocoon.request.get("submit_update") && cocoon.request.get("versionID")){
|
||||
var versionID = cocoon.request.get("versionID");
|
||||
itemID = cocoon.request.get("itemID");
|
||||
itemID = UUID.fromString((cocoon.request.get("itemID")));
|
||||
result = doUpdateVersion(itemID, versionID);
|
||||
}
|
||||
} while (true)
|
||||
|
Reference in New Issue
Block a user