Search in sources :

Example 1 with DataSetAudit

use of org.broadinstitute.consent.http.models.DataSetAudit in project consent by DataBiosphere.

the class DatasetService method deleteDataset.

public void deleteDataset(Integer datasetId, Integer userId) throws Exception {
    DataSet dataset = datasetDAO.findDataSetById(datasetId);
    if (Objects.nonNull(dataset)) {
        // Some legacy dataset names can be null
        String dsAuditName = Objects.nonNull(dataset.getName()) ? dataset.getName() : dataset.getDatasetIdentifier();
        DataSetAudit dsAudit = new DataSetAudit(datasetId, dataset.getObjectId(), dsAuditName, new Date(), dataset.getActive(), userId, AuditActions.DELETE.getValue().toUpperCase());
        try {
            datasetDAO.useTransaction(h -> {
                try {
                    h.insertDataSetAudit(dsAudit);
                    h.deleteUserAssociationsByDatasetId(datasetId);
                    h.deleteDatasetPropertiesByDatasetId(datasetId);
                    h.deleteConsentAssociationsByDataSetId(datasetId);
                    h.deleteDatasetById(datasetId);
                } catch (Exception e) {
                    h.rollback();
                    throw e;
                }
            });
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw e;
        }
    }
}
Also used : DataSetAudit(org.broadinstitute.consent.http.models.DataSetAudit) DataSet(org.broadinstitute.consent.http.models.DataSet) Date(java.util.Date) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

Date (java.util.Date)1 NotFoundException (javax.ws.rs.NotFoundException)1 DataSet (org.broadinstitute.consent.http.models.DataSet)1 DataSetAudit (org.broadinstitute.consent.http.models.DataSetAudit)1