Skip to content

Commit

Permalink
ufal/be-user-registration-missing (#463)
Browse files Browse the repository at this point in the history
* The user registration is added when the eperson is created by the ui.

* try using newer checkout, same as upstream, since error is with git

---------

Co-authored-by: MajoBerger <88670521+MajoBerger@users.noreply.github.com>
  • Loading branch information
milanmajchrak and MajoBerger committed Dec 1, 2023
1 parent 7d1fdb8 commit 29880ed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
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";

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("createtest@example.com")))
.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("createtestfull@example.com")))
.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

0 comments on commit 29880ed

Please sign in to comment.