2

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.

Abdull
  • 26,371
  • 26
  • 130
  • 172
  • 1
    Looks like the docs indicate you are to use `org.dspace.content.service.CollectionService#create(Context, Community)` or `org.dspace.content.service.CollectionService#create(Context, Community, String)` – CollinD May 11 '16 at 13:23

1 Answers1

2

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).

schweerelos
  • 2,189
  • 2
  • 17
  • 25
  • Thank you for your answer. The reasoning you provide also fits well with [DSpace's data model](https://wiki.duraspace.org/display/DSDOC5x/Functional+Overview#FunctionalOverview-DataModel). – Abdull May 12 '16 at 08:53