Finish GET endpoints

This commit is contained in:
Jelle Pelgrims
2019-08-20 16:21:20 +02:00
parent 48ea95bc15
commit 591f32bfe3
3 changed files with 37 additions and 17 deletions

View File

@@ -1,13 +1,20 @@
package org.dspace.app.rest.converter; package org.dspace.app.rest.converter;
import java.util.stream.Collectors;
import org.dspace.app.rest.model.BitstreamRest;
import org.dspace.app.rest.model.BundleRest; import org.dspace.app.rest.model.BundleRest;
import org.dspace.content.Bundle; import org.dspace.content.Bundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class BundleConverter public class BundleConverter
extends DSpaceObjectConverter<org.dspace.content.Bundle, org.dspace.app.rest.model.BundleRest> { extends DSpaceObjectConverter<org.dspace.content.Bundle, org.dspace.app.rest.model.BundleRest> {
@Autowired
BitstreamConverter bitstreamConverter;
protected BundleRest newInstance() { protected BundleRest newInstance() {
return new BundleRest(); return new BundleRest();
} }
@@ -18,6 +25,17 @@ public class BundleConverter
public BundleRest fromModel(Bundle obj) { public BundleRest fromModel(Bundle obj) {
BundleRest bundle = (BundleRest) super.fromModel(obj); BundleRest bundle = (BundleRest) super.fromModel(obj);
bundle.setBitstreams(obj.getBitstreams()
.stream()
.map(x -> bitstreamConverter.fromModel(x))
.collect(Collectors.toList()));
if (obj.getPrimaryBitstream() != null) {
BitstreamRest primaryBitstreamRest = bitstreamConverter.fromModel(obj.getPrimaryBitstream());
bundle.setPrimaryBitstream(primaryBitstreamRest);
}
return bundle; return bundle;
} }

View File

@@ -2,8 +2,8 @@ package org.dspace.app.rest.model;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.content.Bitstream; import org.dspace.content.Bitstream;
import org.dspace.content.Item;
/** /**
* The Bundle REST Resource * The Bundle REST Resource
@@ -15,9 +15,14 @@ public class BundleRest extends DSpaceObjectRest {
public static final String NAME = "bundle"; public static final String NAME = "bundle";
public static final String CATEGORY = RestAddressableModel.CORE; public static final String CATEGORY = RestAddressableModel.CORE;
private Bitstream primaryBitstream; private BitstreamRest primaryBitstream;
private List<Bitstream> bitstreams; private List<BitstreamRest> bitstreams;
private List<Item> items;
@Override
@JsonIgnore
public String getId() {
return super.getId();
}
public String getCategory() { public String getCategory() {
return CATEGORY; return CATEGORY;
@@ -27,28 +32,25 @@ public class BundleRest extends DSpaceObjectRest {
return NAME; return NAME;
} }
public Bitstream getPrimaryBitstream() {
@JsonIgnore
@LinkRest(linkClass = Bitstream.class)
public BitstreamRest getPrimaryBitstream() {
return primaryBitstream; return primaryBitstream;
} }
public void setPrimaryBitstream(Bitstream primaryBitstream) { public void setPrimaryBitstream(BitstreamRest primaryBitstream) {
this.primaryBitstream = primaryBitstream; this.primaryBitstream = primaryBitstream;
} }
public List<Bitstream> getBitstreams() { @LinkRest(linkClass = Bitstream.class)
@JsonIgnore
public List<BitstreamRest> getBitstreams() {
return bitstreams; return bitstreams;
} }
public void setBitstreams(List<Bitstream> bitstreams) { public void setBitstreams(List<BitstreamRest> bitstreams) {
this.bitstreams = bitstreams; this.bitstreams = bitstreams;
} }
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
} }

View File

@@ -52,7 +52,7 @@ public class BundleRestRepository extends DSpaceObjectRestRepository<Bundle, Bun
} }
public Class<BundleRest> getDomainClass() { public Class<BundleRest> getDomainClass() {
return null; return BundleRest.class;
} }
public DSpaceResource<BundleRest> wrapResource(BundleRest model, String... rels) { public DSpaceResource<BundleRest> wrapResource(BundleRest model, String... rels) {