Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ HealthCheckRegistry providesHealthCheckRegistry() {

@Provides
UseRestrictionConverter providesUseRestrictionConverter() {
return new UseRestrictionConverter(providesClient(), config.getServicesConfiguration());
return new UseRestrictionConverter();
}

@Provides
Expand Down Expand Up @@ -435,9 +435,9 @@ VoteService providesVoteService() {
providesElectionDAO(),
providesEmailService(),
providesElasticSearchService(),
providesUseRestrictionConverter(),
providesVoteDAO(),
providesVoteServiceDAO());
providesVoteServiceDAO(),
providesOntologyService());
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ public class DataAccessReportsParser implements ConsentLogger {

private final DatasetDAO datasetDAO;
private final UseRestrictionConverter useRestrictionConverter;
private final OntologyService ontologyService;

private static final String DEFAULT_SEPARATOR = "\t";

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

public DataAccessReportsParser(
DatasetDAO datasetDAO, UseRestrictionConverter useRestrictionConverter) {
DatasetDAO datasetDAO,
UseRestrictionConverter useRestrictionConverter,
OntologyService ontologyService) {
this.datasetDAO = datasetDAO;
this.useRestrictionConverter = useRestrictionConverter;
this.ontologyService = ontologyService;
}

public void setApprovedDARHeader(FileWriter darWriter) throws IOException {
Expand Down Expand Up @@ -163,8 +167,7 @@ private void addDARLine(
? translatedUseRestriction.replace("\n", " ")
: "";
DataUse dataUse = useRestrictionConverter.parseDataUsePurpose(dar);
String sDAR =
useRestrictionConverter.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
String sDAR = ontologyService.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
String formattedSDAR = sDAR.replace("\n", " ");
darWriter.write(
darCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package org.broadinstitute.consent.http.service;

import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.Objects;
import org.apache.commons.collections4.CollectionUtils;
import org.broadinstitute.consent.http.configurations.ServicesConfiguration;
import org.broadinstitute.consent.http.enumeration.DataUseTranslationType;
import org.broadinstitute.consent.http.models.DataAccessRequest;
import org.broadinstitute.consent.http.models.DataUse;
import org.broadinstitute.consent.http.models.OntologyEntry;
import org.broadinstitute.consent.http.util.ConsentLogger;

public class UseRestrictionConverter implements ConsentLogger {

private final ServicesConfiguration servicesConfiguration;
private final Client client;

public UseRestrictionConverter(Client client, ServicesConfiguration config) {
this.client = client;
this.servicesConfiguration = config;
}
public UseRestrictionConverter() {}

/**
* This method, and its counterpart that processes a map, translates DAR questions to a DataUse
Expand Down Expand Up @@ -130,22 +116,4 @@ public DataUse parseDataUsePurpose(DataAccessRequest dar) {
}
return dataUse;
}

public String translateDataUse(DataUse dataUse, DataUseTranslationType type) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the change. All services that called this method now call the newer version in OntologyService

WebTarget target =
client.target(servicesConfiguration.getOntologyURL() + "translate?for=" + type.getValue());
Response response =
target.request(MediaType.APPLICATION_JSON).post(Entity.json(dataUse.toString()));
if (response.getStatus() == 200) {
try {
return response.readEntity(String.class);
} catch (Exception e) {
logException("Error parsing response from Ontology service", e);
}
}
logException(
"Error response from Ontology service: " + response.readEntity(String.class),
new InternalServerErrorException());
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class VoteService implements ConsentLogger {
private final ElectionDAO electionDAO;
private final EmailService emailService;
private final ElasticSearchService elasticSearchService;
private final UseRestrictionConverter useRestrictionConverter;
private final VoteDAO voteDAO;
private final VoteServiceDAO voteServiceDAO;
private final OntologyService ontologyService;

@Inject
public VoteService(
Expand All @@ -70,19 +70,19 @@ public VoteService(
ElectionDAO electionDAO,
EmailService emailService,
ElasticSearchService elasticSearchService,
UseRestrictionConverter useRestrictionConverter,
VoteDAO voteDAO,
VoteServiceDAO voteServiceDAO) {
VoteServiceDAO voteServiceDAO,
OntologyService ontologyService) {
this.userDAO = userDAO;
this.dacDAO = dacDAO;
this.dataAccessRequestDAO = dataAccessRequestDAO;
this.datasetDAO = datasetDAO;
this.electionDAO = electionDAO;
this.emailService = emailService;
this.elasticSearchService = elasticSearchService;
this.useRestrictionConverter = useRestrictionConverter;
this.voteDAO = voteDAO;
this.voteServiceDAO = voteServiceDAO;
this.ontologyService = ontologyService;
}

/**
Expand Down Expand Up @@ -289,7 +289,7 @@ public void sendDatasetApprovalNotifications(List<Vote> votes, User user) {
approvedDatasetsInDar.stream()
.map(
dataset ->
useRestrictionConverter.translateDataUse(
ontologyService.translateDataUse(
dataset.getDataUse(), DataUseTranslationType.DATASET))
.distinct()
.collect(Collectors.joining(";"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DataAccessReportsParserTest {

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

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

@Test
Expand Down
Loading
Loading