Skip to content

Commit

Permalink
refactor: removes the negotiation column from the request table
Browse files Browse the repository at this point in the history
  • Loading branch information
svituz committed Sep 25, 2024
1 parent 76c708c commit 9175cfc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,9 @@ private static void initializeStateForNewResources(
}

private Negotiation getNegotiation(String negotiationId) {
Negotiation negotiation =
negotiationRepository
.findById(negotiationId)
.orElseThrow(() -> new EntityNotFoundException(negotiationId));
return negotiation;
}

private Request getRequest(String negotiationId) {
Request request =
requestRepository
.findByNegotiation_Id(negotiationId)
.orElseThrow(() -> new EntityNotFoundException(negotiationId));
return request;
return negotiationRepository
.findById(negotiationId)
.orElseThrow(() -> new EntityNotFoundException(negotiationId));

Check warning on line 170 in src/main/java/eu/bbmri_eric/negotiator/governance/resource/ResourceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/eu/bbmri_eric/negotiator/governance/resource/ResourceServiceImpl.java#L168-L170

Added lines #L168 - L170 were not covered by tests
}

private boolean userIsntAuthorized(String negotiationId, Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ public void addMappings() {
mapper ->
mapper.using(requestToRedirectUrl).map(Request::getId, RequestDTO::setRedirectUrl));

Converter<Negotiation, String> negotiationToNegotiationId =
q -> convertNegotiationToNegotiationId(q.getSource());
typeMap.addMappings(
mapper ->
mapper
.using(negotiationToNegotiationId)
.map(Request::getNegotiation, RequestDTO::setNegotiationId));

///////////////////////////////////////////
// Mapper from v2 Request to V3 Request
TypeMap<QueryCreateV2DTO, RequestCreateDTO> v2ToV3Map =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public class Request {
@NotNull
private Set<Resource> resources;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "negotiation_id")
@Exclude
private Negotiation negotiation;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "discovery_service_id")
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ public interface RequestRepository extends JpaRepository<Request, String> {

@EntityGraph(value = "request-with-detailed-resources")
Optional<Request> findDetailedById(String id);

Optional<Request> findByNegotiation_Id(String negotiationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ set human_readable = (
insert into negotiation_resources_link (negotiation_id, resource_id)
select r.negotiation_id, rrl.resource_id from request_resources_link rrl join request r on rrl.request_id = r.id;

delete from request where negotiation_id is null;
delete from request where negotiation_id is null;

alter table request drop column negotiation_id;
16 changes: 8 additions & 8 deletions src/main/resources/db/test/migration/R__Initial_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ values (101, '2024-03-11', 101, '2024-03-31', 'REPRESENTATIVE_CONTACTED', 'negot
(101, '2024-03-11', 101, '2024-03-31', 'REPRESENTATIVE_CONTACTED', 'negotiation-3', 5),
(101, '2024-03-11', 101, '2024-03-31', 'RESOURCE_AVAILABLE', 'negotiation-3', 5);

insert into request (id, url, human_readable, discovery_service_id, negotiation_id)
values ('request-1', 'http://discoveryservice.dev', '#1: No filters used', 1, 'negotiation-1'),
('request-2', 'http://discoveryservice.dev', '#1: DNA Samples', 1, null),
('request-5', 'http://discoveryservice.dev', '#1: DNA Samples', 1, 'negotiation-5'),
('request-v2', 'http://discoveryservice.dev', '#1: Blood Samples', 1, 'negotiation-v2'),
('request-3', 'http://discoveryservice.dev', '#1: Blood Samples', 1, 'negotiation-3'),
('request-4', 'http://discoveryservice.dev', '#1: Blood Samples', 1, 'negotiation-4'),
('request-unassigned', 'http://discoveryservice.dev', '#1: Blood Samples', 1, null);
insert into request (id, url, human_readable, discovery_service_id)
values ('request-1', 'http://discoveryservice.dev', '#1: No filters used', 1),
('request-2', 'http://discoveryservice.dev', '#1: DNA Samples', 1),
('request-5', 'http://discoveryservice.dev', '#1: DNA Samples', 1),
('request-v2', 'http://discoveryservice.dev', '#1: Blood Samples', 1),
('request-3', 'http://discoveryservice.dev', '#1: Blood Samples', 1),
('request-4', 'http://discoveryservice.dev', '#1: Blood Samples', 1),
('request-unassigned', 'http://discoveryservice.dev', '#1: Blood Samples', 1);

insert into request_resources_link (request_id, resource_id)
values ('request-1', 4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public void testGetAll_Ok_whenNoNegotiationIsAssigned() throws Exception {
assertEquals(repository.count(), previousCount);
}

@Disabled
@Test
@WithMockUser
public void testGetAll_Ok_whenNegotiationIsAssigned() throws Exception {
Expand All @@ -226,8 +227,6 @@ public void testGetAll_Ok_whenNegotiationIsAssigned() throws Exception {
@WithUserDetails("researcher")
public void testGetById_Ok_whenNoNegotiationIsAssigned() throws Exception {
RequestDTO r = requestService.create(TestUtils.createRequest(false));
long previousCount = repository.count();

mockMvc
.perform(
MockMvcRequestBuilders.get("%s/%s".formatted(ENDPOINT, r.getId()))
Expand All @@ -236,9 +235,7 @@ public void testGetById_Ok_whenNoNegotiationIsAssigned() throws Exception {
.andExpect(jsonPath("$.id").isString())
.andExpect(jsonPath("$.url", is("http://discoveryservice.dev")))
.andExpect(jsonPath("$.redirectUrl", containsString("http://localhost/request")))
.andExpect(jsonPath("$.negotiationId").doesNotExist())
.andExpect(jsonPath("$.resources[0].id", is("biobank:1:collection:1")));
assertEquals(repository.count(), previousCount);
}

// This is no longer possible since when the negotiation is assigned the request is removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ private Negotiation saveNegotiation(Person author) {
.payload(payload)
.build();
negotiation.setCreatedBy(author);
request.setNegotiation(negotiation);
negotiationRepository.save(negotiation);
return negotiation;
}
Expand Down

0 comments on commit 9175cfc

Please sign in to comment.