use of org.broadinstitute.consent.http.models.UserProperty in project consent by DataBiosphere.
the class UserWithRolesReducer method accumulate.
@Override
public void accumulate(Map<Integer, User> map, RowView rowView) {
User user = map.computeIfAbsent(rowView.getColumn("dacuserid", Integer.class), id -> rowView.getRow(User.class));
try {
if (Objects.nonNull(rowView.getColumn("user_role_id", Integer.class))) {
UserRole ur = rowView.getRow(UserRole.class);
user.addRole(ur);
}
} catch (MappingException e) {
// Ignore any attempt to map a column that doesn't exist
}
try {
if (Objects.nonNull(rowView.getColumn("i_id", Integer.class))) {
Institution institution = rowView.getRow(Institution.class);
// There are unusual cases where we somehow create an institution with null values
if (Objects.nonNull(institution.getId())) {
user.setInstitution(institution);
}
}
} catch (MappingException e) {
// Ignore institution mapping errors, possible for new users to not have an institution
}
// Below only adds LC if not currently saved on the array
try {
if (Objects.nonNull(rowView.getColumn("lc_id", Integer.class))) {
LibraryCard lc = rowView.getRow(LibraryCard.class);
try {
if (Objects.nonNull(rowView.getColumn("lci_id", Integer.class))) {
Institution institution = rowView.getRow(Institution.class);
// There are unusual cases where we somehow create an institution with null values
if (Objects.nonNull(institution.getId())) {
lc.setInstitution(institution);
}
}
} catch (MappingException e) {
// Ignore institution mapping errors
}
if (Objects.isNull(user.getLibraryCards()) || user.getLibraryCards().stream().noneMatch(card -> card.getId().equals(lc.getId()))) {
user.addLibraryCard(lc);
}
}
} catch (MappingException e) {
// Ignore exceptions here, user may not have a library card issued under this instiution
}
try {
if (Objects.nonNull(rowView.getColumn("up_property_id", Integer.class))) {
UserProperty p = rowView.getRow(UserProperty.class);
user.addProperty(p);
// Note that the completed field is deprecated and will be removed in a future PR.
if (p.getPropertyKey().equalsIgnoreCase(UserFields.COMPLETED.getValue())) {
user.setProfileCompleted(Boolean.valueOf(p.getPropertyValue()));
}
}
} catch (MappingException e) {
// Ignore any attempt to map a column that doesn't exist
}
}
use of org.broadinstitute.consent.http.models.UserProperty in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesWithValidation.
@Test
public void testUpdatePropertiesWithValidation() {
List<UserProperty> props = new ArrayList<>();
Map<String, String> propMap = new HashMap<>();
for (UserFields researcherField : UserFields.values()) {
if (researcherField.getRequired()) {
String val = RandomStringUtils.random(10, true, false);
props.add(new UserProperty(user.getDacUserId(), researcherField.getValue(), val));
propMap.put(researcherField.getValue(), val);
}
}
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(props);
initService();
List<UserProperty> foundProps = service.updateProperties(propMap, authUser, true);
Assert.assertFalse(foundProps.isEmpty());
Assert.assertEquals(props.size(), foundProps.size());
}
use of org.broadinstitute.consent.http.models.UserProperty in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesIncompleteProfile.
@Test
public void testUpdatePropertiesIncompleteProfile() throws Exception {
List<UserProperty> props = new ArrayList<>();
Map<String, String> propMap = new HashMap<>();
for (UserFields researcherField : UserFields.values()) {
if (researcherField.getRequired()) {
String val1 = RandomStringUtils.random(10, true, false);
String val2 = RandomStringUtils.random(10, true, false);
props.add(new UserProperty(user.getDacUserId(), researcherField.getValue(), val1));
propMap.put(researcherField.getValue(), val2);
}
}
props.add(new UserProperty(user.getDacUserId(), UserFields.COMPLETED.getValue(), Boolean.FALSE.toString()));
propMap.put(UserFields.COMPLETED.getValue(), Boolean.FALSE.toString());
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(props);
when(userPropertyDAO.isProfileCompleted(any())).thenReturn(Boolean.FALSE.toString());
doNothing().when(userPropertyDAO).deletePropertiesByUserAndKey(any());
doNothing().when(userPropertyDAO).insertAll(any());
doNothing().when(userPropertyDAO).deleteAllPropertiesByUser(any());
doNothing().when(emailNotifierService).sendNewResearcherCreatedMessage(any(), any());
initService();
List<UserProperty> foundProps = service.updateProperties(propMap, authUser, true);
Assert.assertFalse(foundProps.isEmpty());
Assert.assertEquals(props.size(), foundProps.size());
verify(emailNotifierService, times(0)).sendNewResearcherCreatedMessage(any(), any());
}
use of org.broadinstitute.consent.http.models.UserProperty in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesMissingFields.
@Test(expected = IllegalArgumentException.class)
public void testUpdatePropertiesMissingFields() {
UserProperty prop = new UserProperty(user.getDacUserId(), UserFields.DEPARTMENT.getValue(), RandomStringUtils.random(10, true, false));
Map<String, String> propMap = new HashMap<>();
propMap.put(prop.getPropertyKey(), prop.getPropertyValue());
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
initService();
service.updateProperties(propMap, authUser, true);
}
use of org.broadinstitute.consent.http.models.UserProperty in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesNoValidation.
@Test
public void testUpdatePropertiesNoValidation() {
UserProperty prop = new UserProperty(user.getDacUserId(), UserFields.DEPARTMENT.getValue(), RandomStringUtils.random(10, true, false));
Map<String, String> propMap = new HashMap<>();
propMap.put(prop.getPropertyKey(), prop.getPropertyValue());
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(Collections.singletonList(prop));
initService();
List<UserProperty> props = service.updateProperties(propMap, authUser, false);
Assert.assertFalse(props.isEmpty());
Assert.assertEquals(propMap.size(), props.size());
}
Aggregations