Skip to content

Commit

Permalink
DCJ-570: Add Associated DAA and DAA File info to Get All DACs (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Sep 4, 2024
1 parent d4fda84 commit f73e0ab
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 94 deletions.
88 changes: 62 additions & 26 deletions src/main/java/org/broadinstitute/consent/http/db/DacDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Set;
import org.broadinstitute.consent.http.db.mapper.DacMapper;
import org.broadinstitute.consent.http.db.mapper.DacReducer;
import org.broadinstitute.consent.http.db.mapper.FileStorageObjectMapper;
import org.broadinstitute.consent.http.db.mapper.FileStorageObjectMapperWithFSOPrefix;
import org.broadinstitute.consent.http.db.mapper.RoleMapper;
import org.broadinstitute.consent.http.db.mapper.UserRoleMapper;
import org.broadinstitute.consent.http.db.mapper.UserWithRolesMapper;
Expand All @@ -29,7 +29,7 @@
import org.jdbi.v3.sqlobject.transaction.Transactional;

@RegisterRowMapper(DacMapper.class)
@RegisterRowMapper(FileStorageObjectMapper.class)
@RegisterRowMapper(FileStorageObjectMapperWithFSOPrefix.class)
public interface DacDAO extends Transactional<DacDAO> {

String QUERY_FIELD_SEPARATOR = ", ";
Expand All @@ -39,17 +39,53 @@ public interface DacDAO extends Transactional<DacDAO> {
*
* @return List<Dac>
*/
@RegisterBeanMapper(value = DataAccessAgreement.class, prefix = "daa")
@RegisterBeanMapper(value = FileStorageObjectDAO.class)
@RegisterBeanMapper(value = Dac.class)
@RegisterBeanMapper(value = Dataset.class)
@UseRowReducer(DacReducer.class)
@SqlQuery("""
SELECT dac.dac_id, dac.email, dac.name, dac.description, d.dataset_id, d.name AS dataset_name,
DATE(d.create_date) AS dataset_create_date, d.object_id, d.active, d.needs_approval,
d.alias AS dataset_alias, d.create_user_id, d.update_date AS dataset_update_date,
d.update_user_id, d.data_use AS dataset_data_use, d.sharing_plan_document,
d.sharing_plan_document_name
SELECT
dac.dac_id,
dac.email,
dac.name,
dac.description,
d.dataset_id,
d.name AS dataset_name,
DATE(d.create_date) AS dataset_create_date,
d.object_id,
d.active,
d.needs_approval,
d.alias AS dataset_alias,
d.create_user_id,
d.update_date AS dataset_update_date,
d.update_user_id,
d.data_use AS dataset_data_use,
d.sharing_plan_document,
d.sharing_plan_document_name,
daa.daa_id AS daa_daa_id,
daa.create_user_id AS daa_create_user_id,
daa.create_date AS daa_create_date,
daa.update_user_id AS daa_update_user_id,
daa.update_date AS daa_update_date,
daa.initial_dac_id AS daa_initial_dac_id,
fso.file_storage_object_id AS fso_file_storage_object_id,
fso.entity_id AS fso_entity_id,
fso.file_name AS fso_file_name,
fso.category AS fso_category,
fso.gcs_file_uri AS fso_gcs_file_uri,
fso.media_type AS fso_media_type,
fso.deleted AS fso_deleted,
fso.delete_user_id AS fso_delete_user_id,
fso.create_date AS fso_create_date,
fso.create_user_id AS fso_create_user_id,
fso.update_date AS fso_update_date,
fso.update_user_id AS fso_update_user_id
FROM dac
LEFT OUTER JOIN dataset d ON dac.dac_id = d.dac_id
LEFT JOIN dataset d ON dac.dac_id = d.dac_id
LEFT JOIN dac_daa dd ON dac.dac_id = dd.dac_id
LEFT JOIN data_access_agreement daa ON dd.daa_id = daa.daa_id
LEFT JOIN file_storage_object fso ON daa.daa_id::text = fso.entity_id
""")
List<Dac> findAll();

Expand Down Expand Up @@ -96,24 +132,24 @@ public interface DacDAO extends Transactional<DacDAO> {
@UseRowReducer(DacReducer.class)
@SqlQuery("""
SELECT dac.*,
daa.daa_id as daa_daa_id,
daa.create_user_id as daa_create_user_id,
daa.create_date as daa_create_date,
daa.update_user_id as daa_update_user_id,
daa.update_date as daa_update_date,
daa.initial_dac_id as daa_initial_dac_id,
fso.file_storage_object_id AS file_storage_object_id,
fso.entity_id AS entity_id,
fso.file_name AS file_name,
fso.category AS category,
fso.gcs_file_uri AS gcs_file_uri,
fso.media_type AS media_type,
fso.create_date AS create_date,
fso.create_user_id AS create_user_id,
fso.update_date AS update_date,
fso.update_user_id AS update_user_id,
fso.deleted AS deleted,
fso.delete_user_id AS delete_user_id
daa.daa_id as daa_daa_id,
daa.create_user_id as daa_create_user_id,
daa.create_date as daa_create_date,
daa.update_user_id as daa_update_user_id,
daa.update_date as daa_update_date,
daa.initial_dac_id as daa_initial_dac_id,
fso.file_storage_object_id AS fso_file_storage_object_id,
fso.entity_id AS fso_entity_id,
fso.file_name AS fso_file_name,
fso.category AS fso_category,
fso.gcs_file_uri AS fso_gcs_file_uri,
fso.media_type AS fso_media_type,
fso.deleted AS fso_deleted,
fso.delete_user_id AS fso_delete_user_id,
fso.create_date AS fso_create_date,
fso.create_user_id AS fso_create_user_id,
fso.update_date AS fso_update_date,
fso.update_user_id AS fso_update_user_id
FROM dac
LEFT JOIN dac_daa dd ON dac.dac_id = dd.dac_id
LEFT JOIN data_access_agreement daa ON dd.daa_id = daa.daa_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void accumulate(Map<Integer, Dac> container, RowView rowView) {
daa = rowView.getRow(DataAccessAgreement.class);
}

if (rowView.getColumn("file_storage_object_id", String.class) != null) {
if (hasNonZeroColumn(rowView, "fso_file_storage_object_id")) {
FileStorageObject fso = rowView.getRow(FileStorageObject.class);
daa.setFile(fso);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import java.util.Objects;
import org.broadinstitute.consent.http.enumeration.FileCategory;
import org.broadinstitute.consent.http.models.FileStorageObject;
import org.broadinstitute.consent.http.util.ConsentLogger;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;

public class FileStorageObjectMapper implements RowMapper<FileStorageObject>, RowMapperHelper {
public class FileStorageObjectMapper implements RowMapper<FileStorageObject>, RowMapperHelper,
ConsentLogger {

@Override
public FileStorageObject map(ResultSet r, StatementContext statementContext) throws SQLException {
Expand All @@ -30,17 +32,21 @@ public FileStorageObject map(ResultSet r, StatementContext statementContext) thr
}

if (hasColumn(r, addPrefix("gcs_file_uri"))) {
String value = r.getString(addPrefix("gcs_file_uri"));
try {
file.setBlobId(BlobId.fromGsUtilUri(r.getString(addPrefix("gcs_file_uri"))));
file.setBlobId(BlobId.fromGsUtilUri(value));
} catch (Exception e) {
logException("Error parsing blob id: %s for fso id: %s".formatted(value, file.getFileStorageObjectId()), e);
file.setBlobId(null);
}
}

if (hasColumn(r, addPrefix("category"))) {
String value = r.getString(addPrefix("category"));
try {
file.setCategory(FileCategory.findValue(r.getString(addPrefix("category"))));
file.setCategory(FileCategory.findValue(value));
} catch (Exception e) {
logException("Error parsing file category: %s for fso id: %s".formatted(value, file.getFileStorageObjectId()), e);
file.setCategory(null);
}
}
Expand Down
Loading

0 comments on commit f73e0ab

Please sign in to comment.