use of org.broadinstitute.consent.http.models.User 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.User in project consent by DataBiosphere.
the class InstitutionWithUsersReducer method accumulate.
@Override
public void accumulate(Map<Integer, Institution> map, RowView rowView) {
Institution institution = map.computeIfAbsent(rowView.getColumn("institution_id", Integer.class), id -> rowView.getRow(Institution.class));
User create_user = new User();
if (Objects.nonNull(rowView.getColumn("u_dacuserid", Integer.class))) {
create_user = rowView.getRow(User.class);
}
User update_user = new User();
update_user.setDacUserId(rowView.getColumn("u2_dacuserid", Integer.class));
update_user.setEmail(rowView.getColumn("u2_email", String.class));
update_user.setDisplayName(rowView.getColumn("u2_displayname", String.class));
update_user.setCreateDate(rowView.getColumn("u2_createdate", Timestamp.class));
update_user.setAdditionalEmail(rowView.getColumn("u2_additional_email", String.class));
update_user.setEmailPreference(rowView.getColumn("u2_email_preference", Boolean.class));
update_user.setEraCommonsId(rowView.getColumn("u2_era_commons_id", String.class));
institution.setCreateUser(create_user);
institution.setUpdateUser(update_user);
if (Objects.nonNull(rowView.getColumn("so_dacuserid", Integer.class))) {
SimplifiedUser so_user = new SimplifiedUser();
so_user = rowView.getRow(SimplifiedUser.class);
institution.addSigningOfficial(so_user);
}
}
use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.
the class AdminDarApprovedModel method ownersMapToTemplateList.
private List<DatasetOwnerListModel> ownersMapToTemplateList(Map<User, List<DataSet>> dataOwnersDataSets) {
List<DatasetOwnerListModel> templateList = new ArrayList<>();
Set<User> owners = dataOwnersDataSets.keySet();
for (User owner : owners) {
templateList.addAll(dataOwnersDataSets.get(owner).stream().map(dataSet -> new DatasetOwnerListModel(owner.getDisplayName(), dataSet.getName(), dataSet.getObjectId())).collect(Collectors.toList()));
}
return templateList;
}
use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleVotes.
@Test
public void testUpdateVotesWithValue_MultipleVotes() throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
DataSet dataset = createDataset();
Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
Vote vote1 = createDacVote(user.getDacUserId(), election.getElectionId());
Vote vote2 = createDacVote(user.getDacUserId(), election.getElectionId());
Vote vote3 = createDacVote(user.getDacUserId(), election.getElectionId());
String rationale = "rationale";
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote1, vote2, vote3), true, rationale);
assertNotNull(votes);
assertFalse(votes.isEmpty());
List<Integer> requestVoteIds = Stream.of(vote1, vote2, vote3).map(Vote::getVoteId).collect(Collectors.toList());
votes.forEach(v -> {
assertTrue(v.getVote());
assertEquals(rationale, v.getRationale());
assertTrue(requestVoteIds.contains(v.getVoteId()));
});
}
use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.
the class VoteServiceDAOTest method testUpdateVotesWithValue_RPElectionWithStatus.
private void testUpdateVotesWithValue_RPElectionWithStatus(ElectionStatus status) throws Exception {
User user = createUser();
DataAccessRequest dar = createDataAccessRequestV3();
DataSet dataset = createDataset();
Election election = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
changeElectionStatus(election, status);
Vote vote = createDacVote(user.getDacUserId(), election.getElectionId());
String rationale = "rationale";
initService();
List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote), true, rationale);
assertNotNull(votes);
assertFalse(votes.isEmpty());
assertTrue(votes.get(0).getVote());
assertEquals(rationale, votes.get(0).getRationale());
assertEquals(vote.getVoteId(), votes.get(0).getVoteId());
}
Aggregations