DS-3533 Consistency: Return NOT FOUND when resource not found for subresource request

This commit is contained in:
Chris Wilper
2019-12-16 21:40:58 -05:00
parent 17180337d7
commit 10dcd35880
14 changed files with 46 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.BitstreamService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class BitstreamFormatLinkRepository extends AbstractDSpaceRestRepository
try {
Context context = obtainContext();
Bitstream bitstream = bitstreamService.find(context, bitstreamId);
if (bitstream == null || bitstream.getFormat(context) == null) {
if (bitstream == null) {
throw new ResourceNotFoundException("No such bitstream: " + bitstreamId);
}
if (bitstream.getFormat(context) == null) {
return null;
}
return converter.toRest(bitstream.getFormat(context), projection);

View File

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -49,7 +50,7 @@ public class BundleBitstreamLinkRepository extends AbstractDSpaceRestRepository
Context context = obtainContext();
Bundle bundle = bundleService.find(context, bundleId);
if (bundle == null) {
return null;
throw new ResourceNotFoundException("No such bundle: " + bundleId);
}
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
Page<Bitstream> page = utils.getPage(bundle.getBitstreams(), pageable);

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.BundleService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class BundlePrimaryBitstreamLinkRepository extends AbstractDSpaceRestRepo
try {
Context context = obtainContext();
Bundle bundle = bundleService.find(context, bundleId);
if (bundle == null || bundle.getPrimaryBitstream() == null) {
if (bundle == null) {
throw new ResourceNotFoundException("No such bundle: " + bundleId);
}
if (bundle.getPrimaryBitstream() == null) {
return null;
}
return converter.toRest(bundle.getPrimaryBitstream(), projection);

View File

@@ -25,6 +25,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -50,7 +51,7 @@ public class CollectionDefaultAccessConditionLinkRepository extends AbstractDSpa
Context context = obtainContext();
Collection collection = collectionService.find(context, collectionId);
if (collection == null) {
return null;
throw new ResourceNotFoundException("No such collection: " + collectionId);
}
List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, collection,
Constants.DEFAULT_BITSTREAM_READ);

View File

@@ -22,6 +22,7 @@ import org.dspace.core.Context;
import org.dspace.core.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -49,7 +50,7 @@ public class CollectionLicenseLinkRepository extends AbstractDSpaceRestRepositor
Context context = obtainContext();
Collection collection = collectionService.find(context, collectionId);
if (collection == null) {
return null;
throw new ResourceNotFoundException("No such collection: " + collectionId);
}
LicenseRest licenseRest = new LicenseRest();
String text = collection.getLicenseCollection();

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.CollectionService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class CollectionLogoLinkRepository extends AbstractDSpaceRestRepository
try {
Context context = obtainContext();
Collection collection = collectionService.find(context, collectionId);
if (collection == null || collection.getLogo() == null) {
if (collection == null) {
throw new ResourceNotFoundException("No such collection: " + collectionId);
}
if (collection.getLogo() == null) {
return null;
}
return converter.toRest(collection.getLogo(), projection);

View File

@@ -23,6 +23,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -45,7 +46,7 @@ public class CommunityCollectionLinkRepository extends AbstractDSpaceRestReposit
Context context = obtainContext();
Community community = communityService.find(context, communityId);
if (community == null) {
return null;
throw new ResourceNotFoundException("No such community: " + communityId);
}
List<Collection> collections = community.getCollections();
return converter.toRestPage(utils.getPage(collections, optionalPageable), projection);

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.CommunityService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class CommunityLogoLinkRepository extends AbstractDSpaceRestRepository
try {
Context context = obtainContext();
Community community = communityService.find(context, communityId);
if (community == null || community.getLogo() == null) {
if (community == null) {
throw new ResourceNotFoundException("No such community: " + communityId);
}
if (community.getLogo() == null) {
return null;
}
return converter.toRest(community.getLogo(), projection);

View File

@@ -21,6 +21,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -43,7 +44,7 @@ public class CommunitySubcommunityLinkRepository extends AbstractDSpaceRestRepos
Context context = obtainContext();
Community community = communityService.find(context, communityId);
if (community == null) {
return null;
throw new ResourceNotFoundException("No such community: " + communityId);
}
List<Community> subcommunities = community.getSubcommunities();
return converter.toRestPage(utils.getPage(subcommunities, optionalPageable), projection);

View File

@@ -22,6 +22,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -44,7 +45,7 @@ public class ItemBundleLinkRepository extends AbstractDSpaceRestRepository
Context context = obtainContext();
Item item = itemService.find(context, itemId);
if (item == null) {
return null;
throw new ResourceNotFoundException("No such item: " + itemId);
}
Page<Bundle> bundlePage = utils.getPage(item.getBundles(), optionalPageable);
return converter.toRestPage(bundlePage, projection);

View File

@@ -23,6 +23,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -45,7 +46,7 @@ public class ItemMappedCollectionLinkRepository extends AbstractDSpaceRestReposi
Context context = obtainContext();
Item item = itemService.find(context, itemId);
if (item == null) {
return null;
throw new ResourceNotFoundException("No such item: " + itemId);
}
UUID owningCollectionId = item.getOwningCollection() == null ? null : item.getOwningCollection().getID();
Page<Collection> mappedCollectionPage = utils.getPage(item.getCollections().stream()

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class ItemOwningCollectionLinkRepository extends AbstractDSpaceRestReposi
try {
Context context = obtainContext();
Item item = itemService.find(context, itemId);
if (item == null || item.getOwningCollection() == null) {
if (item == null) {
throw new ResourceNotFoundException("No such item: " + itemId);
}
if (item.getOwningCollection() == null) {
return null;
}
return converter.toRest(item.getOwningCollection(), projection);

View File

@@ -24,6 +24,7 @@ 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.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -49,7 +50,7 @@ public class ItemRelationshipLinkRepository extends AbstractDSpaceRestRepository
Context context = obtainContext();
Item item = itemService.find(context, itemId);
if (item == null) {
return null;
throw new ResourceNotFoundException("No such item: " + itemId);
}
int total = relationshipService.countByItem(context, item);
Pageable pageable = utils.getPageable(optionalPageable);

View File

@@ -20,6 +20,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -41,7 +42,10 @@ public class ItemTemplateItemOfLinkRepository extends AbstractDSpaceRestReposito
try {
Context context = obtainContext();
Item item = itemService.find(context, itemId);
if (item == null || item.getTemplateItemOf() == null) {
if (item == null) {
throw new ResourceNotFoundException("No such item: " + itemId);
}
if (item.getTemplateItemOf() == null) {
return null;
}
return converter.toRest(item.getTemplateItemOf(), projection);