• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DataBiosphere / consent / #5817

02 May 2025 01:06PM UTC coverage: 78.733% (-1.3%) from 80.036%
#5817

push

web-flow
DT-1595 Remove unused endpoints (#2507)

2 of 2 new or added lines in 1 file covered. (100.0%)

159 existing lines in 7 files now uncovered.

10029 of 12738 relevant lines covered (78.73%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/broadinstitute/consent/http/models/DarDecisionMetrics.java
1
package org.broadinstitute.consent.http.models;
2

3
import java.text.SimpleDateFormat;
4
import java.time.Duration;
5
import java.util.Calendar;
6
import java.util.Date;
7
import java.util.Objects;
8

9
/**
10
 * Generate a row of dar decision data in the form of:
11
 *
12
 * <p>DAR ID: DAR-123-A-0 DAC ID: Broad DAC Dataset ID: DS-00001 Date Submitted: 01-01-2020 Date
13
 * Approved: 01-02-2020 Date Denied: 01-02-2020 DAR ToT: 1 day DAC Decision: Yes/No Algorithm
14
 * Decision: Yes/No Structured Research Purpose Decision: Yes/No
15
 */
16
public class DarDecisionMetrics implements DecisionMetrics {
17

UNCOV
18
  private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
×
19
  private static final String YES = "Yes";
20
  private static final String NO = "No";
21
  private String darId;
22
  private String dacName;
23
  private String datasetId;
24
  private Integer countUniqueUser;
25
  private Date dateSubmitted;
26
  private Date dateApproved;
27
  private Date dateDenied;
28
  private Integer turnaroundTime;
29
  private Long turnaroundTimeMillis;
30
  private String dacDecision;
31
  private String algorithmDecision;
32
  private String srpDecision;
33

34
  private static final String JOINER = "\t";
UNCOV
35
  public static final String headerRow = String.join(
×
36
      JOINER,
37
      "DAR ID",
38
      "DAC ID",
39
      "DAC UID",
40
      "Dataset ID",
41
      "Count of Unique Users",
42
      "Date Submitted",
43
      "Date Approved",
44
      "Date Denied",
45
      "DAR ToT",
46
      "Dac Decision",
47
      "Algorithm Decision",
48
      "Agreement Vote",
49
      "Structured Research Purpose Decision",
50
      "\n");
51

52
  public DarDecisionMetrics(
53
      DataAccessRequest dar,
54
      Dac dac,
55
      Dataset dataset,
56
      Election accessElection,
57
      Election rpElection,
58
      Match match,
UNCOV
59
      String darCode) {
×
UNCOV
60
    this.setDarId(darCode);
×
UNCOV
61
    this.setDacName(dac);
×
UNCOV
62
    this.setDatasetId(dataset);
×
UNCOV
63
    this.setCountUniqueUser(dar);
×
UNCOV
64
    this.setDacDecision(accessElection);
×
UNCOV
65
    this.setDateSubmitted(dar);
×
UNCOV
66
    this.setDateApproved(accessElection);
×
UNCOV
67
    this.setDateDenied(accessElection);
×
UNCOV
68
    this.setTurnaroundTime(accessElection);
×
UNCOV
69
    this.setAlgorithmDecision(match);
×
UNCOV
70
    this.setSrpDecision(rpElection);
×
UNCOV
71
  }
×
72

73
  public String toString(String joiner) {
74
    return String.join(
×
75
        joiner,
76
        getValue(this.getDarId()),
×
77
        getValue(getDacName()),
×
78
        getValue(getDacUID(getDacName())),
×
79
        getValue(getDatasetId()),
×
80
        getValue(getCountUniqueUsers()),
×
81
        getValue(getDateSubmitted()),
×
82
        getValue(getDateApproved()),
×
83
        getValue(getDateDenied()),
×
84
        getValue(getTurnaroundTime()),
×
85
        getValue(getDacDecision()),
×
86
        getValue(getAlgorithmDecision()),
×
87
        getValue(getAgreementVote()),
×
88
        getValue(getSrpDecision()),
×
89
        "\n");
90
  }
91

92
  public String getDarId() {
93
    return darId;
×
94
  }
95

96
  private void setDarId(String darCode) {
UNCOV
97
    this.darId = darCode;
×
UNCOV
98
  }
×
99

100
  public String getDacName() {
UNCOV
101
    return dacName;
×
102
  }
103

104
  private void setDacName(Dac dac) {
UNCOV
105
    if (Objects.nonNull(dac)) {
×
106
      this.dacName = dac.getName();
×
107
    }
UNCOV
108
  }
×
109

110
  public String getDatasetId() {
111
    return datasetId;
×
112
  }
113

114
  private void setDatasetId(Dataset dataset) {
UNCOV
115
    if (Objects.nonNull(dataset)) {
×
116
      this.datasetId = dataset.getDatasetIdentifier();
×
117
    }
UNCOV
118
  }
×
119

120
  private void setCountUniqueUser(DataAccessRequest dar) {
UNCOV
121
    this.countUniqueUser =
×
UNCOV
122
        (Objects.nonNull(dar.getData())) ?
×
UNCOV
123
            (int) dar.getData().getLabAndInternalCollaborators().stream()
×
UNCOV
124
                .filter(Objects::nonNull)
×
UNCOV
125
                .map(Collaborator::getEmail)
×
UNCOV
126
                .filter(Objects::nonNull)
×
UNCOV
127
                .map(String::toLowerCase)
×
UNCOV
128
                .distinct()
×
UNCOV
129
                .count()
×
130
            : 0;
×
UNCOV
131
  }
×
132

133
  public Integer getCountUniqueUsers() {
134
    return countUniqueUser;
×
135
  }
136

137
  public Date getDateSubmitted() {
138
    return dateSubmitted;
×
139
  }
140

141
  private void setDateSubmitted(DataAccessRequest dar) {
UNCOV
142
    if (Objects.nonNull(dar)) {
×
UNCOV
143
      this.dateSubmitted = dar.getSubmissionDate();
×
144
    }
UNCOV
145
  }
×
146

147
  public Date getDateApproved() {
148
    return dateApproved;
×
149
  }
150

151
  /**
152
   * Use the update date as a proxy if vote date doesn't exist
153
   *
154
   * <p>TODO: Need a story to track updating the final vote date properly
155
   *
156
   * @param election The election
157
   */
158
  private void setDateApproved(Election election) {
UNCOV
159
    if (Objects.nonNull(election)
×
160
        && Objects.nonNull(election.getFinalAccessVote())
×
161
        && election.getFinalAccessVote()) {
×
162
      if (Objects.nonNull(election.getFinalVoteDate())) {
×
163
        this.dateApproved = election.getFinalVoteDate();
×
164
      } else {
165
        this.dateApproved = election.getLastUpdate();
×
166
      }
167
    }
UNCOV
168
  }
×
169

170
  public Date getDateDenied() {
171
    return dateDenied;
×
172
  }
173

174
  /**
175
   * Use the update date as a proxy if vote date doesn't exist
176
   *
177
   * <p>TODO: Need a story to track updating the final vote date properly
178
   *
179
   * @param election The election
180
   */
181
  private void setDateDenied(Election election) {
UNCOV
182
    if (Objects.nonNull(election)
×
183
        && Objects.nonNull(election.getFinalAccessVote())
×
184
        && !election.getFinalAccessVote()) {
×
185
      if (Objects.nonNull(election.getFinalVoteDate())) {
×
186
        this.dateDenied = election.getFinalVoteDate();
×
187
      } else {
188
        this.dateDenied = election.getLastUpdate();
×
189
      }
190
    }
UNCOV
191
  }
×
192

193
  public Integer getTurnaroundTime() {
194
    return turnaroundTime;
×
195
  }
196

197
  /**
198
   * Use the update date as a proxy if vote date doesn't exist
199
   *
200
   * <p>TODO: Need a story to track updating the final vote date properly
201
   *
202
   * @param election The election
203
   */
204
  private void setTurnaroundTime(Election election) {
UNCOV
205
    if (Objects.nonNull(election)) {
×
206
      Date finalVoteDate =
207
          Objects.nonNull(election.getFinalVoteDate())
×
208
              ? election.getFinalVoteDate()
×
209
              : election.getLastUpdate();
×
210
      if (Objects.nonNull(finalVoteDate)) {
×
211
        Calendar submittedDate = Calendar.getInstance();
×
212
        Calendar finalDate = Calendar.getInstance();
×
213
        submittedDate.setTime(this.getDateSubmitted());
×
214
        finalDate.setTime(finalVoteDate);
×
215
        Duration duration = Duration.between(submittedDate.toInstant(), finalDate.toInstant());
×
216
        this.turnaroundTimeMillis = duration.toMillis();
×
217
        this.turnaroundTime = this.convertMillisToDays(this.turnaroundTimeMillis);
×
218
      }
219
    }
UNCOV
220
  }
×
221

222
  public Long getTurnaroundTimeMillis() {
223
    return turnaroundTimeMillis;
×
224
  }
225

226
  public String getDacDecision() {
227
    return dacDecision;
×
228
  }
229

230
  private void setDacDecision(Election election) {
231
    //NOTE: finalVote is pulled from the associated vote
232
    //Vote records are vastly more reliable than election vote status
UNCOV
233
    if (Objects.nonNull(election) && Objects.nonNull(election.getFinalVote())) {
×
234
      this.dacDecision = election.getFinalVote() ? YES : NO;
×
235
    }
UNCOV
236
  }
×
237

238
  public String getAlgorithmDecision() {
239
    return algorithmDecision;
×
240
  }
241

242
  private void setAlgorithmDecision(Match match) {
UNCOV
243
    if (Objects.nonNull(match) && Objects.nonNull(match.getMatch())) {
×
244
      this.algorithmDecision = match.getMatch() ? YES : NO;
×
245
    }
UNCOV
246
  }
×
247

248
  private String getAgreementVote() {
249
    if (Objects.nonNull(getDacDecision()) && Objects.nonNull(getAlgorithmDecision())) {
×
250
      return getDacDecision().equalsIgnoreCase(getAlgorithmDecision()) ? YES : NO;
×
251
    }
252
    return null;
×
253
  }
254

255
  public String getSrpDecision() {
256
    return srpDecision;
×
257
  }
258

259
  /**
260
   * Use finalAccessVote as a proxy if finalVote is null
261
   *
262
   * <p>TODO: Need a story to track updating the final vote date properly
263
   *
264
   * @param election The election
265
   */
266
  private void setSrpDecision(Election election) {
UNCOV
267
    if (Objects.nonNull(dacDecision) && Objects.nonNull(election)) {
×
268
      Boolean rpVote =
269
          Objects.nonNull(election.getFinalVote())
×
270
              ? election.getFinalVote()
×
271
              : Objects.nonNull(election.getFinalAccessVote())
×
272
                  ? election.getFinalAccessVote()
×
273
                  : null;
×
274
      if (Objects.nonNull(rpVote)) {
×
275
        this.srpDecision = rpVote ? YES : NO;
×
276
      }
277
    }
UNCOV
278
  }
×
279

280
  private String getValue(String str) {
281
    return Objects.nonNull(str) ? str : "";
×
282
  }
283

284
  private String getValue(Integer i) {
285
    return Objects.nonNull(i) ? i.toString() : "";
×
286
  }
287

288
  private String getValue(Date date) {
289
    return Objects.nonNull(date) ? sdf.format(date) : "";
×
290
  }
291
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc