|
9 | 9 |
|
10 | 10 | import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; |
11 | 11 | import static jakarta.servlet.http.HttpServletResponse.SC_OK; |
| 12 | +import static net.bytebuddy.matcher.ElementMatchers.anyOf; |
12 | 13 | import static org.apache.commons.codec.CharEncoding.UTF_8; |
13 | 14 | import static org.apache.commons.io.IOUtils.toInputStream; |
14 | 15 | import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata; |
@@ -2992,6 +2993,102 @@ public void findShowableByItem() throws Exception { |
2992 | 2993 | ); |
2993 | 2994 | } |
2994 | 2995 |
|
| 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 | + |
2995 | 3092 | @Test |
2996 | 3093 | public void deleteBitstreamsInBulk() throws Exception { |
2997 | 3094 | context.turnOffAuthorisationSystem(); |
|
0 commit comments