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

DataBiosphere / consent / #5334

30 Aug 2024 03:14PM UTC coverage: 78.034% (-0.008%) from 78.042%
#5334

push

web-flow
DCJ-644: Minor test refactor to increase stability (#2395)

10025 of 12847 relevant lines covered (78.03%)

0.78 hits per line

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

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

3
import com.google.common.collect.Streams;
4
import java.text.SimpleDateFormat;
5
import java.time.Duration;
6
import java.util.Calendar;
7
import java.util.Date;
8
import java.util.Objects;
9

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

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

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

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

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

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

97
  private void setDarId(String darCode) {
98
    this.darId = darCode;
1✔
99
  }
1✔
100

101
  public String getDacName() {
102
    return dacName;
1✔
103
  }
104

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

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

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

121
  private void setCountUniqueUser(DataAccessRequest dar) {
122
    this.countUniqueUser =
1✔
123
        (Objects.nonNull(dar.getData())) ?
1✔
124
            (int) Streams
1✔
125
                .concat(
1✔
126
                    dar.getData().getLabCollaborators().stream(),
1✔
127
                    dar.getData().getInternalCollaborators().stream())
1✔
128
                .filter(Objects::nonNull)
1✔
129
                .map(Collaborator::getEmail)
1✔
130
                .filter(Objects::nonNull)
1✔
131
                .map(String::toLowerCase)
1✔
132
                .distinct()
1✔
133
                .count()
1✔
134
            : 0;
×
135
  }
1✔
136

137
  public Integer getCountUniqueUsers() {
138
    return countUniqueUser;
×
139
  }
140

141
  public Date getDateSubmitted() {
142
    return dateSubmitted;
×
143
  }
144

145
  private void setDateSubmitted(DataAccessRequest dar) {
146
    if (Objects.nonNull(dar)) {
1✔
147
      this.dateSubmitted = dar.getSubmissionDate();
1✔
148
    }
149
  }
1✔
150

151
  public Date getDateApproved() {
152
    return dateApproved;
×
153
  }
154

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

174
  public Date getDateDenied() {
175
    return dateDenied;
×
176
  }
177

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

197
  public Integer getTurnaroundTime() {
198
    return turnaroundTime;
×
199
  }
200

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

226
  public Long getTurnaroundTimeMillis() {
227
    return turnaroundTimeMillis;
×
228
  }
229

230
  public String getDacDecision() {
231
    return dacDecision;
×
232
  }
233

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

242
  public String getAlgorithmDecision() {
243
    return algorithmDecision;
×
244
  }
245

246
  private void setAlgorithmDecision(Match match) {
247
    if (Objects.nonNull(match) && Objects.nonNull(match.getMatch())) {
1✔
248
      this.algorithmDecision = match.getMatch() ? YES : NO;
×
249
    }
250
  }
1✔
251

252
  private String getAgreementVote() {
253
    if (Objects.nonNull(getDacDecision()) && Objects.nonNull(getAlgorithmDecision())) {
×
254
      return getDacDecision().equalsIgnoreCase(getAlgorithmDecision()) ? YES : NO;
×
255
    }
256
    return null;
×
257
  }
258

259
  public String getSrpDecision() {
260
    return srpDecision;
×
261
  }
262

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

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

288
  private String getValue(Integer i) {
289
    return Objects.nonNull(i) ? i.toString() : "";
×
290
  }
291

292
  private String getValue(Date date) {
293
    return Objects.nonNull(date) ? sdf.format(date) : "";
×
294
  }
295
}
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