Skip to content

Commit 8f59df8

Browse files
committed
first pass at v2 migration
1 parent ed14836 commit 8f59df8

File tree

11 files changed

+80
-239
lines changed

11 files changed

+80
-239
lines changed

src/main/java/org/broadinstitute/consent/http/configurations/ServicesConfiguration.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class ServicesConfiguration {
1313
public static final String REGISTER_SELF_DIAGNOSTICS_PATH = "register/user/v2/self/diagnostics";
1414
public static final String REGISTER_SELF_PATH = "register/user/v2/self";
1515
public static final String TOS_TEXT_PATH = "tos/text";
16-
public static final String REGISTER_TOS_PATH = "register/user/v1/termsofservice";
16+
public static final String ACCEPT_TOS_PATH = "api/termsOfService/v1/user/self/accept";
17+
public static final String REJECT_TOS_PATH = "api/termsOfService/v1/user/self/reject";
1718
public static final String SAM_V1_USER_EMAIL = "api/users/v1";
1819

1920
@NotNull
@@ -98,8 +99,12 @@ public String getToSTextUrl() {
9899
return getSamUrl() + TOS_TEXT_PATH;
99100
}
100101

101-
public String tosRegistrationUrl() {
102-
return getSamUrl() + REGISTER_TOS_PATH;
102+
public String acceptTosUrl() {
103+
return getSamUrl() + ACCEPT_TOS_PATH;
104+
}
105+
106+
public String rejectTosUrl() {
107+
return getSamUrl() + REJECT_TOS_PATH;
103108
}
104109

105110
public String getV1UserUrl(String email) {

src/main/java/org/broadinstitute/consent/http/db/SamDAO.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.google.api.client.http.HttpRequest;
66
import com.google.api.client.http.HttpResponse;
77
import com.google.api.client.http.HttpStatusCodes;
8-
import com.google.api.client.http.json.JsonHttpContent;
9-
import com.google.api.client.json.gson.GsonFactory;
108
import com.google.common.util.concurrent.FutureCallback;
119
import com.google.common.util.concurrent.Futures;
1210
import com.google.common.util.concurrent.ListenableFuture;
@@ -26,7 +24,6 @@
2624
import org.broadinstitute.consent.http.models.AuthUser;
2725
import org.broadinstitute.consent.http.models.sam.EmailResponse;
2826
import org.broadinstitute.consent.http.models.sam.ResourceType;
29-
import org.broadinstitute.consent.http.models.sam.TosResponse;
3027
import org.broadinstitute.consent.http.models.sam.UserStatus;
3128
import org.broadinstitute.consent.http.models.sam.UserStatusDiagnostics;
3229
import org.broadinstitute.consent.http.models.sam.UserStatusInfo;
@@ -141,31 +138,27 @@ public String getToSText() throws Exception {
141138
return response.parseAsString();
142139
}
143140

144-
public TosResponse postTosAcceptedStatus(AuthUser authUser) throws Exception {
145-
GenericUrl genericUrl = new GenericUrl(configuration.tosRegistrationUrl());
146-
JsonHttpContent content = new JsonHttpContent(new GsonFactory(),
147-
"app.terra.bio/#terms-of-service");
148-
HttpRequest request = clientUtil.buildPostRequest(genericUrl, content, authUser);
141+
public int acceptTosStatus(AuthUser authUser) throws Exception {
142+
GenericUrl genericUrl = new GenericUrl(configuration.acceptTosUrl());
143+
HttpRequest request = clientUtil.buildPutRequest(genericUrl, new EmptyContent(), authUser);
149144
HttpResponse response = clientUtil.handleHttpRequest(request);
150145
if (!response.isSuccessStatusCode()) {
151146
logException("Error accepting Terms of Service through Sam: " + response.getStatusMessage(),
152147
new ServerErrorException(response.getStatusMessage(), response.getStatusCode()));
153148
}
154-
String body = response.parseAsString();
155-
return new Gson().fromJson(body, TosResponse.class);
149+
return response.getStatusCode();
156150
}
157151

158-
public TosResponse removeTosAcceptedStatus(AuthUser authUser) throws Exception {
159-
GenericUrl genericUrl = new GenericUrl(configuration.tosRegistrationUrl());
160-
HttpRequest request = clientUtil.buildDeleteRequest(genericUrl, authUser);
152+
public int rejectTosStatus(AuthUser authUser) throws Exception {
153+
GenericUrl genericUrl = new GenericUrl(configuration.rejectTosUrl());
154+
HttpRequest request = clientUtil.buildPutRequest(genericUrl, new EmptyContent(), authUser);
161155
HttpResponse response = clientUtil.handleHttpRequest(request);
162156
if (!response.isSuccessStatusCode()) {
163157
logException(
164158
"Error removing Terms of Service acceptance through Sam: " + response.getStatusMessage(),
165159
new ServerErrorException(response.getStatusMessage(), response.getStatusCode()));
166160
}
167-
String body = response.parseAsString();
168-
return new Gson().fromJson(body, TosResponse.class);
161+
return response.getStatusCode();
169162
}
170163

171164
public EmailResponse getV1UserByEmail(AuthUser authUser, String email) throws Exception {

src/main/java/org/broadinstitute/consent/http/models/sam/TosResponse.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/main/java/org/broadinstitute/consent/http/resources/SamResource.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.broadinstitute.consent.http.resources;
22

3+
import com.google.api.client.http.HttpStatusCodes;
34
import com.google.inject.Inject;
45
import io.dropwizard.auth.Auth;
56
import jakarta.annotation.security.PermitAll;
@@ -17,7 +18,6 @@
1718
import org.broadinstitute.consent.http.models.AuthUser;
1819
import org.broadinstitute.consent.http.models.User;
1920
import org.broadinstitute.consent.http.models.sam.ResourceType;
20-
import org.broadinstitute.consent.http.models.sam.TosResponse;
2121
import org.broadinstitute.consent.http.models.sam.UserStatus;
2222
import org.broadinstitute.consent.http.models.sam.UserStatusDiagnostics;
2323
import org.broadinstitute.consent.http.models.sam.UserStatusInfo;
@@ -104,8 +104,12 @@ public Response postSelfTos(@Auth AuthUser authUser) {
104104
user.setDisplayName(authUser.getName());
105105
userService.createUser(user);
106106
}
107-
TosResponse tosResponse = samService.postTosAcceptedStatus(authUser);
108-
return Response.ok().entity(tosResponse).build();
107+
int status = samService.postTosAcceptedStatus(authUser);
108+
if (HttpStatusCodes.isSuccess(status)) {
109+
return Response.ok().build();
110+
} else {
111+
return Response.status(status).build();
112+
}
109113
} catch (Exception e) {
110114
return createExceptionResponse(e);
111115
}
@@ -118,8 +122,12 @@ public Response postSelfTos(@Auth AuthUser authUser) {
118122
@PermitAll
119123
public Response removeTos(@Auth AuthUser authUser) {
120124
try {
121-
TosResponse tosResponse = samService.removeTosAcceptedStatus(authUser);
122-
return Response.ok().entity(tosResponse).build();
125+
int status = samService.removeTosAcceptedStatus(authUser);
126+
if (HttpStatusCodes.isSuccess(status)) {
127+
return Response.ok().build();
128+
} else {
129+
return Response.status(status).build();
130+
}
123131
} catch (Exception e) {
124132
return createExceptionResponse(e);
125133
}

src/main/java/org/broadinstitute/consent/http/service/sam/SamService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.broadinstitute.consent.http.db.SamDAO;
66
import org.broadinstitute.consent.http.models.AuthUser;
77
import org.broadinstitute.consent.http.models.sam.ResourceType;
8-
import org.broadinstitute.consent.http.models.sam.TosResponse;
98
import org.broadinstitute.consent.http.models.sam.UserStatus;
109
import org.broadinstitute.consent.http.models.sam.UserStatusDiagnostics;
1110
import org.broadinstitute.consent.http.models.sam.UserStatusInfo;
@@ -43,11 +42,11 @@ public String getToSText() throws Exception {
4342
return samDAO.getToSText();
4443
}
4544

46-
public TosResponse postTosAcceptedStatus(AuthUser authUser) throws Exception {
47-
return samDAO.postTosAcceptedStatus(authUser);
45+
public int postTosAcceptedStatus(AuthUser authUser) throws Exception {
46+
return samDAO.acceptTosStatus(authUser);
4847
}
4948

50-
public TosResponse removeTosAcceptedStatus(AuthUser authUser) throws Exception {
51-
return samDAO.removeTosAcceptedStatus(authUser);
49+
public int removeTosAcceptedStatus(AuthUser authUser) throws Exception {
50+
return samDAO.rejectTosStatus(authUser);
5251
}
5352
}

src/main/java/org/broadinstitute/consent/http/util/HttpClientUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ public HttpRequest buildPostRequest(GenericUrl genericUrl, HttpContent content,
118118
return request;
119119
}
120120

121-
public HttpRequest buildUnAuthedPostRequest(GenericUrl genericUrl, HttpContent content)
121+
public HttpRequest buildPutRequest(GenericUrl genericUrl, HttpContent content, AuthUser authUser)
122122
throws Exception {
123123
HttpTransport transport = new NetHttpTransport();
124-
HttpRequest request = transport.createRequestFactory().buildPostRequest(genericUrl, content);
125-
request.setHeaders(new HttpHeaders().set("X-App-ID", "DUOS"));
124+
HttpRequest request = transport.createRequestFactory().buildPutRequest(genericUrl, content);
125+
request.setHeaders(buildHeaders(authUser));
126126
return request;
127127
}
128128

129-
public HttpRequest buildDeleteRequest(GenericUrl genericUrl, AuthUser authUser)
129+
public HttpRequest buildUnAuthedPostRequest(GenericUrl genericUrl, HttpContent content)
130130
throws Exception {
131131
HttpTransport transport = new NetHttpTransport();
132-
HttpRequest request = transport.createRequestFactory().buildDeleteRequest(genericUrl);
133-
request.setHeaders(buildHeaders(authUser));
132+
HttpRequest request = transport.createRequestFactory().buildPostRequest(genericUrl, content);
133+
request.setHeaders(new HttpHeaders().set("X-App-ID", "DUOS"));
134134
return request;
135135
}
136136

src/main/resources/assets/paths/samRegisterSelfTos.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ post:
66
responses:
77
200:
88
description: Accept ToS
9-
content:
10-
application/json:
11-
schema:
12-
$ref: '../schemas/SamTosResponse.yaml'
139
500:
1410
description: Internal Server Error
1511
delete:
@@ -20,9 +16,5 @@ delete:
2016
responses:
2117
200:
2218
description: Reject ToS
23-
content:
24-
application/json:
25-
schema:
26-
$ref: '../schemas/SamTosResponse.yaml'
2719
500:
2820
description: Internal Server Error

src/main/resources/assets/schemas/SamTosResponse.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/test/java/org/broadinstitute/consent/http/resources/SamResourceTest.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.broadinstitute.consent.http.models.sam.ActionPattern;
2121
import org.broadinstitute.consent.http.models.sam.ResourceType;
2222
import org.broadinstitute.consent.http.models.sam.ResourceTypeRole;
23-
import org.broadinstitute.consent.http.models.sam.TosResponse;
2423
import org.broadinstitute.consent.http.models.sam.UserStatus;
2524
import org.broadinstitute.consent.http.models.sam.UserStatusDiagnostics;
2625
import org.broadinstitute.consent.http.models.sam.UserStatusInfo;
@@ -121,28 +120,16 @@ public void testGetRegistrationInfo() throws Exception {
121120

122121
@Test
123122
public void testPostSelfTos() throws Exception {
124-
TosResponse.Enabled enabled = new TosResponse.Enabled()
125-
.setAdminEnabled(true).setTosAccepted(true).setGoogle(true).setAllUsersGroup(true)
126-
.setLdap(true);
127-
UserStatus.UserInfo info = new UserStatus.UserInfo().setUserEmail("[email protected]")
128-
.setUserSubjectId("subjectId");
129-
TosResponse tosResponse = new TosResponse().setEnabled(enabled).setUserInfo(info);
130-
when(samService.postTosAcceptedStatus(any())).thenReturn(tosResponse);
123+
when(samService.postTosAcceptedStatus(any())).thenReturn(200);
131124
initResource();
132125
Response response = resource.postSelfTos(authUser);
133126
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
134127
}
135128

136129
@Test
137130
public void testPostSelfTos_NoConsentUser() throws Exception {
138-
TosResponse.Enabled enabled = new TosResponse.Enabled()
139-
.setAdminEnabled(true).setTosAccepted(true).setGoogle(true).setAllUsersGroup(true)
140-
.setLdap(true);
141-
UserStatus.UserInfo info = new UserStatus.UserInfo().setUserEmail("[email protected]")
142-
.setUserSubjectId("subjectId");
143-
TosResponse tosResponse = new TosResponse().setEnabled(enabled).setUserInfo(info);
144131
doThrow(new NotFoundException()).when(userService).findUserByEmail(any());
145-
when(samService.postTosAcceptedStatus(any())).thenReturn(tosResponse);
132+
when(samService.postTosAcceptedStatus(any())).thenReturn(200);
146133
initResource();
147134

148135
Response response = resource.postSelfTos(authUser);
@@ -152,14 +139,8 @@ public void testPostSelfTos_NoConsentUser() throws Exception {
152139

153140
@Test
154141
public void testPostSelfTos_ExistingSamUser() throws Exception {
155-
TosResponse.Enabled enabled = new TosResponse.Enabled()
156-
.setAdminEnabled(true).setTosAccepted(true).setGoogle(true).setAllUsersGroup(true)
157-
.setLdap(true);
158-
UserStatus.UserInfo info = new UserStatus.UserInfo().setUserEmail("[email protected]")
159-
.setUserSubjectId("subjectId");
160-
TosResponse tosResponse = new TosResponse().setEnabled(enabled).setUserInfo(info);
161142
doThrow(new ConsentConflictException()).when(samService).postRegistrationInfo(any());
162-
when(samService.postTosAcceptedStatus(any())).thenReturn(tosResponse);
143+
when(samService.postTosAcceptedStatus(any())).thenReturn(409);
163144
initResource();
164145

165146
Response response = resource.postSelfTos(authUser);
@@ -168,13 +149,7 @@ public void testPostSelfTos_ExistingSamUser() throws Exception {
168149

169150
@Test
170151
public void testRemoveSelfTos() throws Exception {
171-
TosResponse.Enabled enabled = new TosResponse.Enabled()
172-
.setAdminEnabled(true).setTosAccepted(false).setGoogle(true).setAllUsersGroup(true)
173-
.setLdap(true);
174-
UserStatus.UserInfo info = new UserStatus.UserInfo().setUserEmail("[email protected]")
175-
.setUserSubjectId("subjectId");
176-
TosResponse tosResponse = new TosResponse().setEnabled(enabled).setUserInfo(info);
177-
when(samService.removeTosAcceptedStatus(any())).thenReturn(tosResponse);
152+
when(samService.removeTosAcceptedStatus(any())).thenReturn(200);
178153
initResource();
179154
Response response = resource.removeTos(authUser);
180155
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());

0 commit comments

Comments
 (0)