mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
added check to avoide creating same versioning
This commit is contained in:
@@ -10,6 +10,7 @@ package org.dspace.versioning;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.dspace.content.DCDate;
|
||||
import org.dspace.content.Item;
|
||||
@@ -196,7 +197,7 @@ public class VersioningServiceImpl implements VersioningService {
|
||||
int versionNumber) {
|
||||
try {
|
||||
Version version = versionDAO.create(context, new Version());
|
||||
if (versionNumber > 0) {
|
||||
if (versionNumber > 0 && !isVersionExist(context, item, versionNumber)) {
|
||||
version.setVersionNumber(versionNumber);
|
||||
} else {
|
||||
version.setVersionNumber(getNextVersionNumer(context, history));
|
||||
@@ -214,6 +215,16 @@ public class VersioningServiceImpl implements VersioningService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isVersionExist(Context context, Item item, int versionNumber) throws SQLException {
|
||||
VersionHistory history = versionHistoryService.findByItem(context, item);
|
||||
if (Objects.isNull(history)) {
|
||||
return false;
|
||||
}
|
||||
return history.getVersions().stream().filter(v -> v.getVersionNumber() == versionNumber)
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Version> getVersionsByHistory(Context c, VersionHistory vh) throws SQLException {
|
||||
List<Version> versions = versionDAO.findVersionsWithItems(c, vh, -1, -1);
|
||||
|
@@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This class extends the {@link ExternalSourceEntryItemUriListHandler} abstract class and implements it specifically
|
||||
* for the List<Item> objects.
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
|
||||
*/
|
||||
|
Reference in New Issue
Block a user