Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.NotFoundException;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections4.CollectionUtils;
Comment thread
Copilot marked this conversation as resolved.
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -93,6 +94,9 @@ public class ClarinUserMetadataRestController {
@Autowired
ConfigurationService configurationService;

@Autowired
ObjectMapper objectMapper;

// Enum to distinguish between the two types of the email
enum MailType { ALLZIP, BITSTREAM }

Expand Down Expand Up @@ -129,7 +133,7 @@ public ResponseEntity manageUserMetadataForZIP(@RequestParam("itemUUID") UUID it
ClarinLicense clarinLicense = null;
// Get ClarinUserMetadataRest Array from the request body
ClarinUserMetadataRest[] clarinUserMetadataRestArray =
new ObjectMapper().readValue(request.getInputStream(), ClarinUserMetadataRest[].class);
objectMapper.readValue(request.getInputStream(), ClarinUserMetadataRest[].class);
Comment thread
kuchtiak-ufal marked this conversation as resolved.
Outdated
if (Objects.isNull(clarinUserMetadataRestArray)) {
throw new RuntimeException("The clarinUserMetadataRestArray cannot be null. It could be empty, but" +
" not null");
Expand Down Expand Up @@ -228,12 +232,16 @@ public ResponseEntity manageUserMetadata(@RequestParam("bitstreamUUID") UUID bit
throw new AuthorizeException("Anonymous user is not allowed to get access token");
}

// Get ClarinUserMetadataRest Array from the request body
ClarinUserMetadataRest[] clarinUserMetadataRestArray =
new ObjectMapper().readValue(request.getInputStream(), ClarinUserMetadataRest[].class);
if (Objects.isNull(clarinUserMetadataRestArray)) {
throw new RuntimeException("The clarinUserMetadataRestArray cannot be null. It could be empty, but" +
" not null");
ClarinUserMetadataRest[] clarinUserMetadataRestArray;
Comment thread
kuchtiak-ufal marked this conversation as resolved.
Outdated
try {
clarinUserMetadataRestArray =
objectMapper.readValue(request.getInputStream(), ClarinUserMetadataRest[].class);
if (Objects.isNull(clarinUserMetadataRestArray)) {
throw new RuntimeException("The clarinUserMetadataRestArray cannot be null. It could be empty, but" +
" not null");
}
} catch (JsonMappingException ex) {
Comment thread
kuchtiak-ufal marked this conversation as resolved.
Outdated
throw new DSpaceBadRequestException("Missing or Invalid User Data", ex);
}

// Convert Array to the List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ public void notAuthorizedUser_withAllowingAnonymousLicense_shouldSendEmail() thr
.andExpect(jsonPath("$.page.totalElements", is(1)));
}

@Test
public void notAuthorizedUser_manageUserMetadata_withEmptyMetadata_shouldReturn_400() throws Exception {
this.prepareEnvironment(null, Confirmation.ALLOW_ANONYMOUS);
getClient().perform(post("/api/core/clarinusermetadata/manage?bitstreamUUID=" + bitstream.getID())
.content(new byte[0])
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}

@Test
public void authorizedUserWithoutMetadata_shouldReturnToken() throws Exception {
this.prepareEnvironment("NAME", Confirmation.NOT_REQUIRED);
Expand Down
Loading