Reputation: 27862
I want to write Java code to create a new collection in DSpace 5.4.
There exists a static method org.dspace.content.Collection.create(Context)
, but it is package-private, meaning this method can only be accessed by classes in the same package org.dspace.content
.
Upvotes: 2
Views: 208
Reputation: 2189
CollinD's comment is correct for the methods to use in the current master branch, what will be DSpace 6 eventually. In DSpace 5.4, the method to use is org.dspace.content.Community#createCollection()
(5.x code here) or the other version of this method that takes a handle string as an argument.
The reason is that a collection cannot exist on its own in DSpace. It must always be within a community, so all public API methods for creating a collection must ensure the community is specified.
To use the method I mention above, you will first need to look up the parent community object for your new collection, for example (if you know its handle) via org.dspace.handle.HandleManager#resolveToObject(String)
(5.x code here).
There may be other things you need to do to get proper behaviour (eg metadata such as the title); I would look at what happens in one of the UI options when a collection is created there. See XMLUI here: org.dspace.app.xmlui.aspect.administrative.FlowContainerUtils#createCollection
(5.x code here).
Upvotes: 2