Add initial class structure for bundles endpoint

This commit is contained in:
Jelle Pelgrims
2019-08-20 10:29:47 +02:00
parent fc31a0cbe3
commit 21116ec7eb
4 changed files with 162 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package org.dspace.app.rest.converter;
import org.dspace.app.rest.model.BundleRest;
import org.dspace.content.Bundle;
import org.springframework.stereotype.Component;
@Component
public class BundleConverter
extends DSpaceObjectConverter<org.dspace.content.Bundle, org.dspace.app.rest.model.BundleRest> {
protected BundleRest newInstance() {
return new BundleRest();
}
protected Class<Bundle> getModelClass() {
return Bundle.class;
}
public BundleRest fromModel(Bundle obj) {
BundleRest bundle = (BundleRest) super.fromModel(obj);
return bundle;
}
public Bundle toModel(BundleRest obj) {
return null;
}
}

View File

@@ -0,0 +1,54 @@
package org.dspace.app.rest.model;
import java.util.List;
import org.dspace.content.Bitstream;
import org.dspace.content.Item;
/**
* The Bundle REST Resource
*
* @author Jelle Pelgrims (jelle.pelgrims at atmire.com)
*/
public class BundleRest extends DSpaceObjectRest {
public static final String NAME = "bundle";
public static final String CATEGORY = RestAddressableModel.CORE;
private Bitstream primaryBitstream;
private List<Bitstream> bitstreams;
private List<Item> items;
public String getCategory() {
return CATEGORY;
}
public String getType() {
return NAME;
}
public Bitstream getPrimaryBitstream() {
return primaryBitstream;
}
public void setPrimaryBitstream(Bitstream primaryBitstream) {
this.primaryBitstream = primaryBitstream;
}
public List<Bitstream> getBitstreams() {
return bitstreams;
}
public void setBitstreams(List<Bitstream> bitstreams) {
this.bitstreams = bitstreams;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}

View File

@@ -0,0 +1,19 @@
package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.BundleRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* Bunde Rest HAL Resource. The HAL Resource wraps the REST Resource
* adding support for the links and embedded resources
*
* @author Jelle Pelgrims (jelle.pelgrims at atmire.com)
*/
@RelNameDSpaceResource(BundleRest.NAME)
public class BundleResource extends DSpaceResource<BundleRest> {
public BundleResource(BundleRest data, Utils utils, String... rels) {
super(data, utils, rels);
}
}

View File

@@ -0,0 +1,61 @@
package org.dspace.app.rest.repository;
import java.sql.SQLException;
import java.util.UUID;
import org.dspace.app.rest.converter.BundleConverter;
import org.dspace.app.rest.model.BundleRest;
import org.dspace.app.rest.model.hateoas.BundleResource;
import org.dspace.app.rest.model.hateoas.DSpaceResource;
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
import org.dspace.content.Bundle;
import org.dspace.content.service.BundleService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository responsible for managing the Bundle Rest object
*
* @author Jelle Pelgrims (jelle.pelgrims at atmire.com)
*/
@Component(BundleRest.CATEGORY + "." + BundleRest.NAME)
public class BundleRestRepository extends DSpaceObjectRestRepository<Bundle, BundleRest> {
@Autowired
private BundleService bundleService;
public BundleRestRepository(BundleService dsoService,
BundleConverter dsoConverter) {
super(dsoService, dsoConverter, new DSpaceObjectPatch<BundleRest>() {});
this.bundleService = dsoService;
}
public BundleRest findOne(Context context, UUID uuid) {
Bundle bundle = null;
try {
bundle = bundleService.find(context, uuid);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (bundle == null) {
return null;
}
return dsoConverter.fromModel(bundle);
}
public Page<BundleRest> findAll(Context context, Pageable pageable) {
return null;
}
public Class<BundleRest> getDomainClass() {
return null;
}
public DSpaceResource<BundleRest> wrapResource(BundleRest model, String... rels) {
return new BundleResource(model, utils, rels);
}
}