use of org.jdbi.v3.core.mapper.MappingException in project consent by DataBiosphere.
the class DacWithDatasetsReducer method accumulate.
@Override
public void accumulate(Map<Integer, Dac> container, RowView rowView) {
try {
Dac dac = container.computeIfAbsent(rowView.getColumn("dac_id", Integer.class), id -> rowView.getRow(Dac.class));
if (Objects.nonNull(rowView.getColumn("datasetid", Integer.class))) {
DatasetDTO dto = rowView.getRow(DatasetDTO.class);
try {
if (Objects.nonNull(rowView.getColumn("dataset_alias", String.class))) {
String dsAlias = rowView.getColumn("dataset_alias", String.class);
try {
dto.setAlias(Integer.parseInt(dsAlias));
} catch (Exception e) {
logger.error("Exception parsing dataset alias: " + dsAlias, e);
}
}
if (Objects.nonNull(rowView.getColumn("dataset_create_date", Date.class))) {
Date createDate = rowView.getColumn("dataset_create_date", Date.class);
dto.setCreateDate(createDate);
}
if (Objects.nonNull(rowView.getColumn("dataset_update_date", Timestamp.class))) {
Timestamp updateDate = rowView.getColumn("dataset_update_date", Timestamp.class);
dto.setUpdateDate(updateDate);
}
} catch (Exception e) {
// no values for these columns
}
if (Objects.nonNull(rowView.getColumn("consent_data_use", String.class))) {
String duStr = rowView.getColumn("consent_data_use", String.class);
Optional<DataUse> du = DataUse.parseDataUse(duStr);
du.ifPresent(dto::setDataUse);
}
if (Objects.nonNull(dto)) {
dac.addDatasetDTO(dto);
}
}
} catch (MappingException e) {
logger.warn(e.getMessage());
}
}
use of org.jdbi.v3.core.mapper.MappingException 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.jdbi.v3.core.mapper.MappingException in project consent by DataBiosphere.
the class DarCollectionReducer method accumulate.
@Override
public void accumulate(Map<Integer, DarCollection> map, RowView rowView) {
DataAccessRequest dar = null;
Election election = null;
Vote vote = null;
User user = null;
UserProperty userProperty = null;
Institution institution = null;
DarCollection collection = map.computeIfAbsent(rowView.getColumn("collection_id", Integer.class), id -> rowView.getRow(DarCollection.class));
if (Objects.nonNull(collection) && Objects.nonNull(collection.getCreateUser())) {
user = collection.getCreateUser();
}
try {
if (Objects.nonNull(rowView.getColumn("up_property_id", Integer.class))) {
userProperty = rowView.getRow(UserProperty.class);
}
if (Objects.isNull(user) && Objects.nonNull(rowView.getColumn("u_dacuserid", Integer.class))) {
user = rowView.getRow(User.class);
}
if (Objects.nonNull(rowView.getColumn("i_id", Integer.class))) {
institution = rowView.getRow(Institution.class);
}
if (Objects.nonNull(collection)) {
if (Objects.nonNull(rowView.getColumn("dar_id", Integer.class))) {
dar = rowView.getRow(DataAccessRequest.class);
String referenceId = dar.getReferenceId();
DataAccessRequest savedDar = collection.getDars().get(referenceId);
if (Objects.isNull(savedDar)) {
DataAccessRequestData data = translate(rowView.getColumn("data", String.class));
dar.setData(data);
} else {
dar = savedDar;
}
}
if (Objects.nonNull(rowView.getColumn("e_election_id", Integer.class))) {
election = rowView.getRow(Election.class);
Integer electionId = election.getElectionId();
Election savedElection = dar.getElections().get(electionId);
if (Objects.nonNull(savedElection)) {
election = savedElection;
}
}
if (Objects.nonNull(rowView.getColumn("v_vote_id", Integer.class))) {
vote = rowView.getRow(Vote.class);
}
}
} catch (MappingException e) {
// ignore any exceptions
}
if (Objects.nonNull(vote)) {
election.addVote(vote);
}
if (Objects.nonNull(election)) {
dar.addElection(election);
}
if (Objects.nonNull(dar)) {
collection.addDar(dar);
}
if (Objects.nonNull(user)) {
if (Objects.nonNull(institution)) {
user.setInstitution(institution);
}
if (Objects.nonNull(userProperty)) {
user.addProperty(userProperty);
}
collection.setCreateUser(user);
}
}
use of org.jdbi.v3.core.mapper.MappingException in project consent by DataBiosphere.
the class LibraryCardReducer method accumulate.
@Override
public void accumulate(Map<Integer, LibraryCard> map, RowView rowView) {
Institution institution = null;
LibraryCard card = map.computeIfAbsent(rowView.getColumn("id", Integer.class), id -> rowView.getRow(LibraryCard.class));
try {
if (Objects.nonNull(card) && Objects.nonNull(rowView.getColumn("i_institution_id", Integer.class))) {
institution = rowView.getRow(Institution.class);
institution.setId(rowView.getColumn("i_institution_id", Integer.class));
}
} catch (MappingException e) {
}
if (Objects.nonNull(institution)) {
card.setInstitution(institution);
}
}
use of org.jdbi.v3.core.mapper.MappingException in project consent by DataBiosphere.
the class UnregisteredUsersWithCardsReducer method accumulate.
@Override
public void accumulate(Map<Integer, User> map, RowView rowView) {
// mapping function will use lc id to map blank user object for unregistered users
User user = map.computeIfAbsent(rowView.getColumn("id", Integer.class), id -> new User());
try {
LibraryCard card = 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())) {
card.setInstitution(institution);
}
}
} catch (MappingException e) {
// Ignore institution mapping errors
}
user.setEmail(card.getUserEmail());
user.addLibraryCard(card);
} catch (MappingException e) {
// Ignore mapping errors
}
}
Aggregations