Skip to content

Commit

Permalink
Merge pull request DSpace#9448 from DSpace/backport-9271-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] Fix generating versioned identifiers if pre-registration is enabled
  • Loading branch information
tdonohue authored Apr 4, 2024
2 parents a75717f + acfe272 commit a6dd759
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,18 @@ public WorkspaceItem find(Context context, int id) throws SQLException {
@Override
public WorkspaceItem create(Context context, Collection collection, boolean template)
throws AuthorizeException, SQLException {
return create(context, collection, null, template);
return create(context, collection, null, template, false);
}

@Override
public WorkspaceItem create(Context context, Collection collection, UUID uuid, boolean template)
public WorkspaceItem create(Context context, Collection collection, boolean template, boolean isNewVersion)
throws AuthorizeException, SQLException {
return create(context, collection, null, template, isNewVersion);
}

@Override
public WorkspaceItem create(Context context, Collection collection, UUID uuid, boolean template,
boolean isNewVersion)
throws AuthorizeException, SQLException {
// Check the user has permission to ADD to the collection
authorizeService.authorizeAction(context, collection, Constants.ADD);
Expand Down Expand Up @@ -174,8 +181,10 @@ public WorkspaceItem create(Context context, Collection collection, UUID uuid, b

// If configured, register identifiers (eg handle, DOI) now. This is typically used with the Show Identifiers
// submission step which previews minted handles and DOIs during the submission process. Default: false
// Additional check needed: if we are creating a new version of an existing item we skip the identifier
// generation here, as this will be performed when the new version is created in VersioningServiceImpl
if (DSpaceServicesFactory.getInstance().getConfigurationService()
.getBooleanProperty("identifiers.submission.register", false)) {
.getBooleanProperty("identifiers.submission.register", false) && !isNewVersion) {
try {
// Get map of filters to use for identifier types, while the item is in progress
Map<Class<? extends Identifier>, Filter> filters = FilterUtils.getIdentifierFilters(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public static DSpaceObject createDSpaceObject(Context context, DSpaceObject pare
wsi = workspaceItemService.create(context, (Collection)parent, params.useCollectionTemplate());
} else {
wsi = workspaceItemService.create(context, (Collection)parent,
uuid, params.useCollectionTemplate());
uuid, params.useCollectionTemplate(), false);
}

// Please note that we are returning an Item which is *NOT* yet in the Archive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ public interface WorkspaceItemService extends InProgressSubmissionService<Worksp
public WorkspaceItem create(Context context, Collection collection, boolean template)
throws AuthorizeException, SQLException;


/**
* Create a new workspace item, with a new ID. An Item is also created. The
* submitter is the current user in the context.
*
* @param context DSpace context object
* @param collection Collection being submitted to
* @param template if <code>true</code>, the workspace item starts as a copy
* of the collection's template item
* @param isNewVersion whether we are creating a new workspace item version of an existing item
* @return the newly created workspace item
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
*/
public WorkspaceItem create(Context context, Collection collection, boolean template, boolean isNewVersion)
throws AuthorizeException, SQLException;

/**
* Create a new workspace item, with a new ID. An Item is also created. The
* submitter is the current user in the context.
Expand All @@ -65,11 +82,13 @@ public WorkspaceItem create(Context context, Collection collection, boolean temp
* @param uuid the preferred uuid of the new item (used if restoring an item and retaining old uuid)
* @param template if <code>true</code>, the workspace item starts as a copy
* of the collection's template item
* @param isNewVersion whether we are creating a new workspace item version of an existing item
* @return the newly created workspace item
* @throws SQLException if database error
* @throws AuthorizeException if authorization error
*/
public WorkspaceItem create(Context context, Collection collection, UUID uuid, boolean template)
public WorkspaceItem create(Context context, Collection collection, UUID uuid, boolean template,
boolean isNewVersion)
throws AuthorizeException, SQLException;

public WorkspaceItem create(Context c, WorkflowItem wfi) throws SQLException, AuthorizeException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class DefaultItemVersionProvider extends AbstractVersionProvider implemen
@Override
public Item createNewItemAndAddItInWorkspace(Context context, Item nativeItem) {
try {
WorkspaceItem workspaceItem = workspaceItemService.create(context, nativeItem.getOwningCollection(), false);
WorkspaceItem workspaceItem = workspaceItemService.create(context, nativeItem.getOwningCollection(),
false,
true);
Item itemNew = workspaceItem.getItem();
itemService.update(context, itemNew);
return itemNew;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void packagerUUIDAlreadyExistWithoutForceTest() throws Exception {
performExportScript(article.getHandle(), tempFile);
UUID id = article.getID();
itemService.delete(context, article);
WorkspaceItem workspaceItem = workspaceItemService.create(context, col1, id, false);
WorkspaceItem workspaceItem = workspaceItemService.create(context, col1, id, false, false);
installItemService.installItem(context, workspaceItem, "123456789/0100");
performImportNoForceScript(tempFile);
Iterator<Item> items = itemService.findByCollection(context, col1);
Expand Down

0 comments on commit a6dd759

Please sign in to comment.