Skip to content

Commit 5f52102

Browse files
AdamF42vins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/GLAM-1177 (pull request DSpace#4300)
Task/dspace cris 2024 02 x/GLAM-1177 Approved-by: Vincenzo Mecca
2 parents 60bebb6 + e2c4887 commit 5f52102

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

dspace-api/src/main/java/org/dspace/content/dao/impl/BitstreamDAOImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public Iterator<Bitstream> findShowableByItem(Context context, UUID itemId, Stri
159159
" where mv.dSpaceObject = b and " +
160160
" ms.name = 'bitstream' and " +
161161
" mf.element = 'hide' and " +
162-
" mf.qualifier = null and " +
162+
" mf.qualifier is null and " +
163163
" (mv.value = 'true' or mv.value = 'yes') " +
164164
")" +
165165
" AND (" +

dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestRepositoryIT.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
1111
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
12+
import static net.bytebuddy.matcher.ElementMatchers.anyOf;
1213
import static org.apache.commons.codec.CharEncoding.UTF_8;
1314
import static org.apache.commons.io.IOUtils.toInputStream;
1415
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata;
@@ -2992,6 +2993,102 @@ public void findShowableByItem() throws Exception {
29922993
);
29932994
}
29942995

2996+
@Test
2997+
public void findShowableByItemWithHideMetadata() throws Exception {
2998+
2999+
//Turn off the authorization system, otherwise we can't make the objects
3000+
context.turnOffAuthorisationSystem();
3001+
3002+
//** GIVEN **
3003+
//1. A community-collection structure with one parent community and one collection.
3004+
parentCommunity =
3005+
CommunityBuilder.createCommunity(context)
3006+
.withName("Parent Community")
3007+
.build();
3008+
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build();
3009+
3010+
//2. A public item that is readable by Anonymous
3011+
Item publicItem =
3012+
ItemBuilder.createItem(context, col1)
3013+
.withTitle("Public item with hidden bitstream")
3014+
.withIssueDate("2017-10-17")
3015+
.withAuthor("Smith, Donald")
3016+
.build();
3017+
3018+
// 3. Create visible bitstream in ORIGINAL bundle
3019+
Bitstream visibleBitstream =
3020+
BitstreamBuilder.createBitstream(context, publicItem, toInputStream("visible content", UTF_8))
3021+
.withName("visible-file.txt")
3022+
.withFormat("text/plain")
3023+
.build();
3024+
3025+
// 4. Create hidden bitstream in ORIGINAL bundle with bitstream.hide = true metadata
3026+
Bitstream hiddenBitstream =
3027+
BitstreamBuilder.createBitstream(context, publicItem, toInputStream("hidden content", UTF_8))
3028+
.withName("hidden-file.txt")
3029+
.withMetadata("bitstream", "hide", null, null, "true")
3030+
.withFormat("text/plain")
3031+
.build();
3032+
3033+
// 5. Create another visible bitstream with bitstream.hide = false (should be shown)
3034+
Bitstream explicitlyVisibleBitstream =
3035+
BitstreamBuilder.createBitstream(context, publicItem, toInputStream("explicitly visible", UTF_8))
3036+
.withName("explicitly-visible.txt")
3037+
.withMetadata("bitstream", "hide", null, null, "false")
3038+
.withFormat("text/plain")
3039+
.build();
3040+
3041+
// 6. Create another hidden bitstream with bitstream.hide = yes (should be filtered)
3042+
Bitstream hiddenBitstreamYes =
3043+
BitstreamBuilder.createBitstream(context, publicItem, toInputStream("hidden yes content", UTF_8))
3044+
.withName("hidden-yes-file.txt")
3045+
.withFormat("text/plain")
3046+
.build();
3047+
3048+
// Add bitstream.hide = yes metadata
3049+
bitstreamService.addMetadata(context, hiddenBitstreamYes, "bitstream", "hide", null, null, "yes");
3050+
3051+
context.commit();
3052+
context.restoreAuthSystemState();
3053+
3054+
String token = getAuthToken(admin.getEmail(), password);
3055+
3056+
//** WHEN & THEN **
3057+
// Test 1: Search for bitstreams in ORIGINAL bundle
3058+
// Should return only visible bitstreams (visibleBitstream and explicitlyVisibleBitstream)
3059+
// Should NOT return hidden bitstreams (hiddenBitstream and hiddenBitstreamYes)
3060+
getClient(token).perform(
3061+
get("/api/core/bitstreams/search/showableByItem")
3062+
.param("uuid", publicItem.getID().toString())
3063+
.param("name", Constants.CONTENT_BUNDLE_NAME)
3064+
)
3065+
.andExpect(status().isOk())
3066+
.andExpect(content().contentType(contentType))
3067+
.andExpect(
3068+
jsonPath(
3069+
"$._embedded.bitstreams",
3070+
allOf(
3071+
hasItem(BitstreamMatcher.matchProperties(visibleBitstream)),
3072+
hasItem(BitstreamMatcher.matchProperties(explicitlyVisibleBitstream))
3073+
)
3074+
)
3075+
)
3076+
.andExpect(
3077+
jsonPath("$._embedded.bitstreams", hasSize(2))
3078+
)
3079+
.andExpect(
3080+
jsonPath(
3081+
"$._embedded.bitstreams",
3082+
not(
3083+
anyOf(
3084+
hasItem(BitstreamMatcher.matchProperties(hiddenBitstream)),
3085+
hasItem(BitstreamMatcher.matchProperties(hiddenBitstreamYes))
3086+
)
3087+
)
3088+
)
3089+
);
3090+
}
3091+
29953092
@Test
29963093
public void deleteBitstreamsInBulk() throws Exception {
29973094
context.turnOffAuthorisationSystem();

0 commit comments

Comments
 (0)