added check to avoide creating same versioning

This commit is contained in:
Mykhaylo
2021-08-24 15:20:46 +02:00
parent fe4332e2ea
commit 0816473c41
2 changed files with 14 additions and 1 deletions

View File

@@ -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);

View File

@@ -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)
*/