Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

76-BE/import-user-metadata-with-fixed-bitstream #307

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public void doUpdateBitstreamsChecksum(HttpServletRequest request) throws SQLExc
throw new RuntimeException("Context is null!");
}
checksumService.updateMissingBitstreams(context);
context.commit();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.dspace.content.clarin.ClarinLicenseResourceMapping;
import org.dspace.content.clarin.ClarinLicenseResourceUserAllowance;
import org.dspace.content.clarin.ClarinUserMetadata;
import org.dspace.content.clarin.ClarinUserRegistration;
import org.dspace.content.service.clarin.ClarinLicenseResourceUserAllowanceService;
import org.dspace.content.service.clarin.ClarinUserRegistrationService;
import org.dspace.core.Context;
Expand Down Expand Up @@ -89,10 +90,10 @@ public ClarinUserMetadataRest importUserMetadata(HttpServletRequest request) thr
if (Objects.isNull(context)) {
throw new RuntimeException("Context is null!");
}
String epersonUUIDString = request.getParameter("epersonId");
String epersonUUIDString = request.getParameter("epersonUUID");
if (StringUtils.isBlank(epersonUUIDString)) {
log.error("Required parameter eperson_id is null!");
throw new RuntimeException("EpersonId is null!");
log.error("Required parameter eperson id is null!");
throw new RuntimeException("Eperson id is null!");
}
UUID epersonUUID = UUID.fromString(epersonUUIDString);

Expand All @@ -115,25 +116,33 @@ public ClarinUserMetadataRest importUserMetadata(HttpServletRequest request) thr
//we don't control token, because it can be null
String token = request.getParameter("token");

ClarinUserRegistration userRegistration = clarinUserRegistrationService.findByEPersonUUID(context, epersonUUID).get(0);
if (Objects.isNull(userRegistration)) {
log.error("User registration with id: " + userRegistration + " doesn't exist!");
throw new RuntimeException("User registration with id: " + userRegistration + " doesn't exist!");
}

EPerson ePerson = ePersonService.find(context, epersonUUID);
if (Objects.isNull(ePerson)) {
log.error("Eperson with id: " + epersonUUID + " doesn't exist!");
log.error("Eperson with id: " + epersonUUID+ " doesn't exist!");
throw new RuntimeException("Eperson with id: " + epersonUUID + " doesn't exist!");
}

// Get ClarinUserMetadataRest Array from the request body
ClarinUserMetadataRest[] clarinUserMetadataRestArray =
new ObjectMapper().readValue(request.getInputStream(), ClarinUserMetadataRest[].class);
if (ArrayUtils.isEmpty(clarinUserMetadataRestArray)) {
log.error("Cannot get clarinUserMetadataRestArray from request for eperson with id: " + epersonUUID +
log.error("Cannot get clarinUserMetadataRestArray from request for eperson with id: "
+ epersonUUID) +
" and bitstream with id: " + bitstreamUUID);
throw new RuntimeException("Cannot get clarinUserMetadataRestArray from request for eperson with id: "
+ epersonUUID + " and bitstream with id: " + bitstreamUUID);
}
// Convert Array to the List
List<ClarinUserMetadataRest> clarinUserMetadataRestList = Arrays.asList(clarinUserMetadataRestArray);
if (CollectionUtils.isEmpty(clarinUserMetadataRestList)) {
log.error("Cannot convert clarinUserMetadataRestArray to array for eperson with id: " + epersonUUID +
log.error("Cannot convert clarinUserMetadataRestArray to array for eperson with id: "
+ epersonUUID +
" and bitstream id: " + bitstreamUUID);
throw new RuntimeException("Cannot get clarinUserMetadataRestArray from request for eperson with id: "
+ epersonUUID + " and bitstream with id: " + bitstreamUUID);
Expand All @@ -154,8 +163,7 @@ public ClarinUserMetadataRest importUserMetadata(HttpServletRequest request) thr
List<ClarinUserMetadata> newClarinUserMetadataList = clarinUserMetadataRestController.processSignedInUser(
context, ePerson, clarinUserMetadataRestList, clarinLicenseResourceMapping, bitstreamUUID, token);
//set eperson_id (user registration) in user_metadata
newClarinUserMetadataList.get(0).setEperson(clarinUserRegistrationService.findByEPersonUUID(context,
epersonUUID).get(0));
newClarinUserMetadataList.get(0).setEperson(userRegistration);
//set created_on for created license_resource_user_allowance
//created list has to contain minimally one record
ClarinLicenseResourceUserAllowance clarinLicenseResourceUserAllowance =
Expand All @@ -169,9 +177,11 @@ public ClarinUserMetadataRest importUserMetadata(HttpServletRequest request) thr

return clarinUserMetadataRest;
} catch (Exception e) {
log.error("Something is very very very wrong with eperson: " + epersonUUID + " and bitstream: "
log.error("Something is very very very wrong with eperson: " + epersonUUID
+ " and bitstream: "
+ bitstreamUUID + ". Excemption: " + e.getMessage());
throw new RuntimeException("Something is very very very wrong with eperson: " + epersonUUID
throw new RuntimeException("Something is very very very wrong with eperson: "
+ epersonUUID
+ " and bitstream: " + bitstreamUUID + ". Excemption: " + e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void importUserMetadataTest() throws Exception {
getClient(adminToken).perform(post("/api/clarin/import/usermetadata")
.content(mapper.writeValueAsBytes(clarinUserMetadataRestList.toArray()))
.contentType(MediaType.APPLICATION_JSON)
.param("epersonId", admin.getID().toString())
.param("epersonUUID", admin.getID().toString())
.param("bitstreamUUID", bitstream.getID().toString())
.param("createdOn", "2012-09-19T10:30:03.741633")
.param("token", "111"))
Expand Down