Merge pull request #2051 from Georgetown-University-Libraries/ds3650

[DS-3650] Add subcommunities link to community object
This commit is contained in:
Andrea Bollini
2018-05-14 15:52:34 +02:00
committed by GitHub
3 changed files with 40 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ import org.dspace.app.rest.model.CollectionRest;
import org.dspace.app.rest.model.CommunityRest;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -45,14 +46,25 @@ public class CommunityConverter
com.setLogo(bitstreamConverter.convert(logo));
}
List<Collection> collections = obj.getCollections();
List<CollectionRest> collectionsRest = new ArrayList<CollectionRest>();
if (collections != null) {
List<CollectionRest> collectionsRest = new ArrayList<CollectionRest>();
for (Collection col : collections) {
CollectionRest colrest = collectionConverter.fromModel(col);
collectionsRest.add(colrest);
}
com.setCollections(collectionsRest);
}
com.setCollections(collectionsRest);
List<Community> subCommunities = obj.getSubcommunities();
List<CommunityRest> communityRest = new ArrayList<CommunityRest>();
if (subCommunities != null) {
for (Community scom : subCommunities) {
CommunityRest scomrest = this.fromModel(scom);
communityRest.add(scomrest);
}
}
com.setSubCommunities(communityRest);
return com;
}

View File

@@ -23,7 +23,6 @@ public class CommunityRest extends DSpaceObjectRest {
@JsonIgnore
private BitstreamRest logo;
private List<CollectionRest> collections;
@LinkRest(linkClass = CollectionRest.class)
@@ -36,6 +35,18 @@ public class CommunityRest extends DSpaceObjectRest {
this.collections = collections;
}
private List<CommunityRest> subcommunities;
@LinkRest(linkClass = CommunityRest.class)
@JsonIgnore
public List<CommunityRest> getSubcommunities() {
return subcommunities;
}
public void setSubCommunities(List<CommunityRest> subcommunities) {
this.subcommunities = subcommunities;
}
public BitstreamRest getLogo() {
return logo;
}

View File

@@ -178,6 +178,9 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
.containsString("/api/core/communities/" + parentCommunity.getID().toString() + "/logo")))
.andExpect(jsonPath("$._links.collections.href", Matchers
.containsString("/api/core/communities/" + parentCommunity.getID().toString() + "/collections")))
.andExpect(jsonPath("$._links.subcommunities.href", Matchers
.containsString("/api/core/communities/" + parentCommunity.getID().toString() +
"/subcommunities")))
;
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString() + "/logo"))
@@ -187,12 +190,23 @@ public class CommunityRestRepositoryIT extends AbstractControllerIntegrationTest
getClient().perform(get("/api/core/communities/" + child1.getID().toString() + "/logo"))
.andExpect(status().isOk());
//Main community has no collections, therefore contentType is not set
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString() + "/collections"))
.andExpect(status().isOk());
//.andExpect(status().isNoContent()); //TODO After DS-3808 is implemented
getClient().perform(get("/api/core/communities/" + child1.getID().toString() + "/collections"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType));
getClient().perform(get("/api/core/communities/" + parentCommunity.getID().toString() + "/subcommunities"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType));
//child1 subcommunity has no subcommunities, therefore contentType is not set
getClient().perform(get("/api/core/communities/" + child1.getID().toString() + "/subcommunities"))
.andExpect(status().isOk());
//.andExpect(status().isNoContent()); //TODO After DS-3808 is implemented
}