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

DataBiosphere / consent / #6006

04 Jun 2025 08:13PM CUT coverage: 78.878%. Remained the same
#6006

push

web-flow
Merge c0b5bd39f into 710d9b6a9

10105 of 12811 relevant lines covered (78.88%)

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

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";
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,
59
      String darCode) {
×
60
    this.setDarId(darCode);
×
61
    this.setDacName(dac);
×
62
    this.setDatasetId(dataset);
×
63
    this.setCountUniqueUser(dar);
×
64
    this.setDacDecision(accessElection);
×
65
    this.setDateSubmitted(dar);
×
66
    this.setDateApproved(accessElection);
×
67
    this.setDateDenied(accessElection);
×
68
    this.setTurnaroundTime(accessElection);
×
69
    this.setAlgorithmDecision(match);
×
70
    this.setSrpDecision(rpElection);
×
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) {
97
    this.darId = darCode;
×
98
  }
×
99

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

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

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

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

120
  private void setCountUniqueUser(DataAccessRequest dar) {
121
    this.countUniqueUser =
×
122
        (Objects.nonNull(dar.getData())) ?
×
123
            (int) dar.getData().getLabAndInternalCollaborators().stream()
×
124
                .filter(Objects::nonNull)
×
125
                .map(Collaborator::getEmail)
×
126
                .filter(Objects::nonNull)
×
127
                .map(String::toLowerCase)
×
128
                .distinct()
×
129
                .count()
×
130
            : 0;
×
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) {
142
    if (Objects.nonNull(dar)) {
×
143
      this.dateSubmitted = dar.getSubmissionDate();
×
144
    }
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) {
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
    }
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) {
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
    }
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) {
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
    }
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
233
    if (Objects.nonNull(election) && Objects.nonNull(election.getFinalVote())) {
×
234
      this.dacDecision = election.getFinalVote() ? YES : NO;
×
235
    }
236
  }
×
237

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

242
  private void setAlgorithmDecision(Match match) {
243
    if (Objects.nonNull(match) && Objects.nonNull(match.getMatch())) {
×
244
      this.algorithmDecision = match.getMatch() ? YES : NO;
×
245
    }
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) {
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
    }
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

© 2025 Coveralls, Inc