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

ufal/be-user-registration-missing #463

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -28,8 +28,12 @@
@Table(name = "user_registration")
public class ClarinUserRegistration implements ReloadableEntity<Integer> {

// Anonymous user
public static final String ANONYMOUS_USER_REGISTRATION = "anonymous";

// Registered user without organization
public static final String UNKNOWN_USER_REGISTRATION = "Unknown";
vidiecan marked this conversation as resolved.
Show resolved Hide resolved

private static Logger log = org.apache.logging.log4j.LogManager.getLogger(ClarinUserRegistration.class);

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.dspace.app.rest.repository;

import static org.dspace.content.clarin.ClarinUserRegistration.UNKNOWN_USER_REGISTRATION;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
Expand Down Expand Up @@ -35,6 +37,8 @@
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.authorize.service.ValidatePasswordService;
import org.dspace.content.clarin.ClarinUserRegistration;
import org.dspace.content.service.clarin.ClarinUserRegistrationService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.EmptyWorkflowGroupException;
Expand Down Expand Up @@ -79,6 +83,9 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
@Autowired
private RegistrationDataService registrationDataService;

@Autowired
ClarinUserRegistrationService clarinUserRegistrationService;

private final EPersonService es;


Expand Down Expand Up @@ -135,6 +142,14 @@ private EPerson createEPersonFromRestObject(Context context, EPersonRest eperson
}
es.update(context, eperson);
metadataConverter.setMetadata(context, eperson, epersonRest.getMetadata());

// Create user registration
ClarinUserRegistration clarinUserRegistration = new ClarinUserRegistration();
clarinUserRegistration.setOrganization(UNKNOWN_USER_REGISTRATION);
clarinUserRegistration.setConfirmation(true);
clarinUserRegistration.setEmail(eperson.getEmail());
clarinUserRegistration.setPersonID(eperson.getID());
clarinUserRegistrationService.create(context, clarinUserRegistration);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.dspace.app.rest.model.patch.ReplaceOperation;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.app.rest.test.MetadataPatchSuite;
import org.dspace.builder.ClarinUserRegistrationBuilder;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EPersonBuilder;
Expand Down Expand Up @@ -120,6 +121,8 @@ public void createTest() throws Exception {

AtomicReference<UUID> idRef = new AtomicReference<UUID>();
AtomicReference<UUID> idRefNoEmbeds = new AtomicReference<UUID>();
AtomicReference<Integer> idRefUserDataReg = new AtomicReference<Integer>();
AtomicReference<Integer> idRefUserDataFullReg = new AtomicReference<Integer>();

String authToken = getAuthToken(admin.getEmail(), password);

Expand Down Expand Up @@ -155,11 +158,51 @@ public void createTest() throws Exception {
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$", HalMatcher.matchNoEmbeds()))
.andDo(result -> idRefNoEmbeds
.set(UUID.fromString(read(result.getResponse().getContentAsString(), "$.id"))));;
.set(UUID.fromString(read(result.getResponse().getContentAsString(), "$.id"))));

// Check that the user registration for test data user has been created
getClient(authToken).perform(get("/api/core/clarinuserregistration/search/byEPerson")
.param("userUUID", String.valueOf(idRef.get()))
.contentType(contentType))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].id", is(not(empty()))))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].email", is("[email protected]")))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].confirmation", is(true)))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].ePersonID", is(idRef.get().toString())))
.andDo(result -> idRefUserDataReg
.set(read(result.getResponse().getContentAsString(),
"$._embedded.clarinuserregistrations[0].id")));

// Check that the user registration for test data full user has been created
getClient(authToken).perform(get("/api/core/clarinuserregistration/search/byEPerson")
.param("userUUID", String.valueOf(idRefNoEmbeds.get()))
.contentType(contentType))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].id", is(not(empty()))))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].email",
is("[email protected]")))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].confirmation", is(true)))
.andExpect(jsonPath(
"$._embedded.clarinuserregistrations[0].ePersonID",
is(idRefNoEmbeds.get().toString())))
.andDo(result -> idRefUserDataFullReg
.set(read(result.getResponse().getContentAsString(),
"$._embedded.clarinuserregistrations[0].id")));

} finally {
EPersonBuilder.deleteEPerson(idRef.get());
EPersonBuilder.deleteEPerson(idRefNoEmbeds.get());
ClarinUserRegistrationBuilder.deleteClarinUserRegistration(idRefUserDataReg.get());
ClarinUserRegistrationBuilder.deleteClarinUserRegistration(idRefUserDataFullReg.get());
}
}

Expand Down
Loading