Skip to content

Commit e6838e7

Browse files
authored
DT-2531: Migrate translate usages from UseRestrictionConverter to OntologyService (#2815)
1 parent 667e608 commit e6838e7

File tree

7 files changed

+39
-166
lines changed

7 files changed

+39
-166
lines changed

src/main/java/org/broadinstitute/consent/http/ConsentModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ HealthCheckRegistry providesHealthCheckRegistry() {
238238

239239
@Provides
240240
UseRestrictionConverter providesUseRestrictionConverter() {
241-
return new UseRestrictionConverter(providesClient(), config.getServicesConfiguration());
241+
return new UseRestrictionConverter();
242242
}
243243

244244
@Provides
@@ -431,9 +431,9 @@ VoteService providesVoteService() {
431431
providesElectionDAO(),
432432
providesEmailService(),
433433
providesElasticSearchService(),
434-
providesUseRestrictionConverter(),
435434
providesVoteDAO(),
436-
providesVoteServiceDAO());
435+
providesVoteServiceDAO(),
436+
providesOntologyService());
437437
}
438438

439439
@Provides

src/main/java/org/broadinstitute/consent/http/service/DataAccessReportsParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ public class DataAccessReportsParser implements ConsentLogger {
2020

2121
private final DatasetDAO datasetDAO;
2222
private final UseRestrictionConverter useRestrictionConverter;
23+
private final OntologyService ontologyService;
2324

2425
private static final String DEFAULT_SEPARATOR = "\t";
2526

2627
private static final String END_OF_LINE = System.lineSeparator();
2728

2829
public DataAccessReportsParser(
29-
DatasetDAO datasetDAO, UseRestrictionConverter useRestrictionConverter) {
30+
DatasetDAO datasetDAO,
31+
UseRestrictionConverter useRestrictionConverter,
32+
OntologyService ontologyService) {
3033
this.datasetDAO = datasetDAO;
3134
this.useRestrictionConverter = useRestrictionConverter;
35+
this.ontologyService = ontologyService;
3236
}
3337

3438
public void setApprovedDARHeader(FileWriter darWriter) throws IOException {
@@ -163,8 +167,7 @@ private void addDARLine(
163167
? translatedUseRestriction.replace("\n", " ")
164168
: "";
165169
DataUse dataUse = useRestrictionConverter.parseDataUsePurpose(dar);
166-
String sDAR =
167-
useRestrictionConverter.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
170+
String sDAR = ontologyService.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
168171
String formattedSDAR = sDAR.replace("\n", " ");
169172
darWriter.write(
170173
darCode

src/main/java/org/broadinstitute/consent/http/service/UseRestrictionConverter.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
package org.broadinstitute.consent.http.service;
22

3-
import jakarta.ws.rs.InternalServerErrorException;
4-
import jakarta.ws.rs.client.Client;
5-
import jakarta.ws.rs.client.Entity;
6-
import jakarta.ws.rs.client.WebTarget;
7-
import jakarta.ws.rs.core.MediaType;
8-
import jakarta.ws.rs.core.Response;
93
import java.util.List;
104
import java.util.Objects;
115
import org.apache.commons.collections4.CollectionUtils;
12-
import org.broadinstitute.consent.http.configurations.ServicesConfiguration;
13-
import org.broadinstitute.consent.http.enumeration.DataUseTranslationType;
146
import org.broadinstitute.consent.http.models.DataAccessRequest;
157
import org.broadinstitute.consent.http.models.DataUse;
168
import org.broadinstitute.consent.http.models.OntologyEntry;
179
import org.broadinstitute.consent.http.util.ConsentLogger;
1810

1911
public class UseRestrictionConverter implements ConsentLogger {
2012

21-
private final ServicesConfiguration servicesConfiguration;
22-
private final Client client;
23-
24-
public UseRestrictionConverter(Client client, ServicesConfiguration config) {
25-
this.client = client;
26-
this.servicesConfiguration = config;
27-
}
13+
public UseRestrictionConverter() {}
2814

2915
/**
3016
* This method, and its counterpart that processes a map, translates DAR questions to a DataUse
@@ -130,22 +116,4 @@ public DataUse parseDataUsePurpose(DataAccessRequest dar) {
130116
}
131117
return dataUse;
132118
}
133-
134-
public String translateDataUse(DataUse dataUse, DataUseTranslationType type) {
135-
WebTarget target =
136-
client.target(servicesConfiguration.getOntologyURL() + "translate?for=" + type.getValue());
137-
Response response =
138-
target.request(MediaType.APPLICATION_JSON).post(Entity.json(dataUse.toString()));
139-
if (response.getStatus() == 200) {
140-
try {
141-
return response.readEntity(String.class);
142-
} catch (Exception e) {
143-
logException("Error parsing response from Ontology service", e);
144-
}
145-
}
146-
logException(
147-
"Error response from Ontology service: " + response.readEntity(String.class),
148-
new InternalServerErrorException());
149-
return null;
150-
}
151119
}

src/main/java/org/broadinstitute/consent/http/service/VoteService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public class VoteService implements ConsentLogger {
5757
private final ElectionDAO electionDAO;
5858
private final EmailService emailService;
5959
private final ElasticSearchService elasticSearchService;
60-
private final UseRestrictionConverter useRestrictionConverter;
6160
private final VoteDAO voteDAO;
6261
private final VoteServiceDAO voteServiceDAO;
62+
private final OntologyService ontologyService;
6363

6464
@Inject
6565
public VoteService(
@@ -70,19 +70,19 @@ public VoteService(
7070
ElectionDAO electionDAO,
7171
EmailService emailService,
7272
ElasticSearchService elasticSearchService,
73-
UseRestrictionConverter useRestrictionConverter,
7473
VoteDAO voteDAO,
75-
VoteServiceDAO voteServiceDAO) {
74+
VoteServiceDAO voteServiceDAO,
75+
OntologyService ontologyService) {
7676
this.userDAO = userDAO;
7777
this.dacDAO = dacDAO;
7878
this.dataAccessRequestDAO = dataAccessRequestDAO;
7979
this.datasetDAO = datasetDAO;
8080
this.electionDAO = electionDAO;
8181
this.emailService = emailService;
8282
this.elasticSearchService = elasticSearchService;
83-
this.useRestrictionConverter = useRestrictionConverter;
8483
this.voteDAO = voteDAO;
8584
this.voteServiceDAO = voteServiceDAO;
85+
this.ontologyService = ontologyService;
8686
}
8787

8888
/**
@@ -289,7 +289,7 @@ public void sendDatasetApprovalNotifications(List<Vote> votes, User user) {
289289
approvedDatasetsInDar.stream()
290290
.map(
291291
dataset ->
292-
useRestrictionConverter.translateDataUse(
292+
ontologyService.translateDataUse(
293293
dataset.getDataUse(), DataUseTranslationType.DATASET))
294294
.distinct()
295295
.collect(Collectors.joining(";"));

src/test/java/org/broadinstitute/consent/http/service/DataAccessReportsParserTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class DataAccessReportsParserTest {
2929

3030
@Mock private DatasetDAO datasetDAO;
3131
@Mock private UseRestrictionConverter useRestrictionConverter;
32+
@Mock private OntologyService ontologyService;
3233
private DataAccessReportsParser parser;
3334
private final String CONSENT_NAME = "ORSP-1903";
3435
private final String NAME = "Test";
@@ -46,7 +47,7 @@ Future use for methods research (analytic/software/technology development) is no
4647
private final String DAR_CODE = "DAR_3";
4748

4849
@BeforeEach
49-
public void setUp() {
50+
void setUp() {
5051
Dataset d = new Dataset();
5152
d.setDatasetId(1); // This translates to an identifier of "DUOS-000001"
5253
d.setAlias(1);
@@ -58,8 +59,8 @@ public void setUp() {
5859
Research is limited to samples restricted for use under the following conditions:
5960
Data is limited for health/medical/biomedical research. [HMB]
6061
""";
61-
when(useRestrictionConverter.translateDataUse(any(), any())).thenReturn(translation);
62-
this.parser = new DataAccessReportsParser(datasetDAO, useRestrictionConverter);
62+
when(ontologyService.translateDataUse(any(), any())).thenReturn(translation);
63+
this.parser = new DataAccessReportsParser(datasetDAO, useRestrictionConverter, ontologyService);
6364
}
6465

6566
@Test

0 commit comments

Comments
 (0)