Search in sources :

Example 1 with MappingException

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());
    }
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) DataUse(org.broadinstitute.consent.http.models.DataUse) Dac(org.broadinstitute.consent.http.models.Dac) Timestamp(java.sql.Timestamp) MappingException(org.jdbi.v3.core.mapper.MappingException) Date(java.sql.Date) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 2 with MappingException

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
    }
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) Objects(java.util.Objects) Institution(org.broadinstitute.consent.http.models.Institution) UserProperty(org.broadinstitute.consent.http.models.UserProperty) LinkedHashMapRowReducer(org.jdbi.v3.core.result.LinkedHashMapRowReducer) Map(java.util.Map) RowView(org.jdbi.v3.core.result.RowView) UserRole(org.broadinstitute.consent.http.models.UserRole) MappingException(org.jdbi.v3.core.mapper.MappingException) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) User(org.broadinstitute.consent.http.models.User) LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) User(org.broadinstitute.consent.http.models.User) UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserRole(org.broadinstitute.consent.http.models.UserRole) Institution(org.broadinstitute.consent.http.models.Institution) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 3 with MappingException

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);
    }
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) UserProperty(org.broadinstitute.consent.http.models.UserProperty) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Institution(org.broadinstitute.consent.http.models.Institution) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 4 with MappingException

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);
    }
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) Institution(org.broadinstitute.consent.http.models.Institution) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 5 with MappingException

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
    }
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) User(org.broadinstitute.consent.http.models.User) Institution(org.broadinstitute.consent.http.models.Institution) MappingException(org.jdbi.v3.core.mapper.MappingException)

Aggregations

MappingException (org.jdbi.v3.core.mapper.MappingException)5 Institution (org.broadinstitute.consent.http.models.Institution)4 LibraryCard (org.broadinstitute.consent.http.models.LibraryCard)3 User (org.broadinstitute.consent.http.models.User)3 UserProperty (org.broadinstitute.consent.http.models.UserProperty)2 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 Map (java.util.Map)1 Objects (java.util.Objects)1 UserFields (org.broadinstitute.consent.http.enumeration.UserFields)1 Dac (org.broadinstitute.consent.http.models.Dac)1 DarCollection (org.broadinstitute.consent.http.models.DarCollection)1 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)1 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)1 DataUse (org.broadinstitute.consent.http.models.DataUse)1 Election (org.broadinstitute.consent.http.models.Election)1 UserRole (org.broadinstitute.consent.http.models.UserRole)1 Vote (org.broadinstitute.consent.http.models.Vote)1 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)1 LinkedHashMapRowReducer (org.jdbi.v3.core.result.LinkedHashMapRowReducer)1