Skip to content

Commit

Permalink
Finished rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Klish committed Aug 8, 2020
1 parent ba5c153 commit 6296e23
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ protected AsyncQueryResult processQuery() throws URISyntaxException, NoHttpRespo
if (queryObj.getQueryType().equals(QueryType.JSONAPI_V1_0)) {
MultivaluedMap<String, String> queryParams = getQueryParams(queryObj.getQuery());
log.debug("Extracted QueryParams from AsyncQuery Object: {}", queryParams);
response = elide.get(getPath(queryObj.getQuery()), queryParams, user, apiVersion, requestId);

//TODO - we need to add the baseUrlEndpoint to the queryObject.
response = elide.get("", getPath(queryObj.getQuery()), queryParams, user, apiVersion, requestId);
log.debug("JSONAPI_V1_0 getResponseCode: {}, JSONAPI_V1_0 getBody: {}",
response.getResponseCode(), response.getBody());
}
else if (queryObj.getQueryType().equals(QueryType.GRAPHQL_V1_0)) {
response = runner.run(queryObj.getQuery(), user, requestId);
//TODO - we need to add the baseUrlEndpoint to the queryObject.

response = runner.run("", queryObj.getQuery(), user, requestId);
log.debug("GRAPHQL_V1_0 getResponseCode: {}, GRAPHQL_V1_0 getBody: {}",
response.getResponseCode(), response.getBody());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected Object executeInTransaction(DataStore dataStore, Transactional action)
try (DataStoreTransaction tx = dataStore.beginTransaction()) {
JsonApiDocument jsonApiDoc = new JsonApiDocument();
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
RequestScope scope = new RequestScope("query", NO_VERSION, jsonApiDoc,
RequestScope scope = new RequestScope("", "query", NO_VERSION, jsonApiDoc,
tx, null, queryParams, UUID.randomUUID(), elide.getElideSettings());
result = action.execute(tx, scope);
tx.flush(scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testProcessQueryJsonApi() throws NoHttpResponseException, URISyntaxE
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
when(elide.get(anyString(), any(), any(), anyString(), any())).thenReturn(response);
when(elide.get(anyString(), anyString(), any(), any(), anyString(), any())).thenReturn(response);
AsyncQueryThread queryThread = new AsyncQueryThread(queryObj, user, elide, runner, asyncQueryDao, "v1");
queryResultObj = queryThread.processQuery();
assertEquals(queryResultObj.getResponseBody(), "ResponseBody");
Expand All @@ -69,7 +69,7 @@ public void testProcessQueryGraphQl() throws NoHttpResponseException, URISyntaxE
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
when(runner.run(eq(query), eq(user), any())).thenReturn(response);
when(runner.run(anyString(), eq(query), eq(user), any())).thenReturn(response);
AsyncQueryThread queryThread = new AsyncQueryThread(queryObj, user, elide, runner, asyncQueryDao, "v1");
queryResultObj = queryThread.processQuery();
assertEquals(queryResultObj.getResponseBody(), "ResponseBody");
Expand Down
9 changes: 5 additions & 4 deletions elide-core/src/main/java/com/yahoo/elide/Elide.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public ElideResponse get(String baseUrlEndPoint, String path, MultivaluedMap<Str
* @param apiVersion the API version
* @return Elide response object
*/
public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDocument,
public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDocument,
User opaqueUser, String apiVersion) {
return post(baseUrlEndPoint, path, jsonApiDocument, null, opaqueUser, apiVersion, UUID.randomUUID());
}
Expand All @@ -222,7 +222,8 @@ public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDoc
* @param requestId the request ID
* @return Elide response object
*/
public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDocument, MultivaluedMap<String, String> queryParams,
public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDocument,
MultivaluedMap<String, String> queryParams,
User opaqueUser, String apiVersion, UUID requestId) {
return handleRequest(false, opaqueUser, dataStore::beginTransaction, requestId, (tx, user) -> {
JsonApiDocument jsonApiDoc = mapper.readJsonApiDocument(jsonApiDocument);
Expand Down Expand Up @@ -250,7 +251,7 @@ public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDoc
public ElideResponse patch(String baseUrlEndPoint, String contentType, String accept,
String path, String jsonApiDocument,
User opaqueUser, String apiVersion) {
return patch(baseUrlEndPoint, contentType, accept, path, jsonApiDocument,
return patch(baseUrlEndPoint, contentType, accept, path, jsonApiDocument,
null, opaqueUser, apiVersion, UUID.randomUUID());
}

Expand Down Expand Up @@ -328,7 +329,7 @@ public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiD
* @param requestId the request ID
* @return Elide response object
*/
public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiDocument,
public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiDocument,
MultivaluedMap<String, String> queryParams,
User opaqueUser, String apiVersion, UUID requestId) {
return handleRequest(false, opaqueUser, dataStore::beginTransaction, requestId, (tx, user) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ElideSettings build() {
defaultMaxPageSize,
defaultPageSize,
updateStatusCode,
serdes,
serdes,
enableJsonLinks);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Response post(
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion;
User user = new SecurityContextUser(securityContext);
return build(elide.post(uriInfo.getBaseUri().toString(), path, jsonapiDocument,
return build(elide.post(uriInfo.getBaseUri().toString(), path, jsonapiDocument,
queryParams, user, safeApiVersion, UUID.randomUUID()));
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public Response patch(

String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion;
User user = new SecurityContextUser(securityContext);
return build(elide.patch(uriInfo.getBaseUri().toString(), contentType, accept, path,
return build(elide.patch(uriInfo.getBaseUri().toString(), contentType, accept, path,
jsonapiDocument, queryParams, user, safeApiVersion, UUID.randomUUID()));
}

Expand All @@ -147,7 +147,8 @@ public Response delete(
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion;
User user = new SecurityContextUser(securityContext);
return build(elide.delete(uriInfo.getBaseUri(), path, jsonApiDocument, queryParams, user, safeApiVersion, UUID.randomUUID()));
return build(elide.delete(uriInfo.getBaseUri().toString(), path, jsonApiDocument, queryParams,
user, safeApiVersion, UUID.randomUUID()));
}

private static Response build(ElideResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public void execute(LifeCycleHookBinding.Operation operation,
}
}

private final String baseUrl = "http://localhost:8080/api/v1";
static class ClassPreCommitHook implements LifeCycleHook<FieldTestModel> {
@Override
public void execute(LifeCycleHookBinding.Operation operation,
Expand Down Expand Up @@ -298,6 +297,7 @@ public void relationCallback(LifeCycleHookBinding.Operation operation,
*/
public class LifeCycleTest {

private final String baseUrl = "http://localhost:8080/api/v1";
private static final AuditLogger MOCK_AUDIT_LOGGER = mock(AuditLogger.class);
private EntityDictionary dictionary;

Expand Down Expand Up @@ -492,7 +492,7 @@ public void testElideGetRelationship() throws Exception {
when(tx.loadObject(isA(EntityProjection.class), any(), isA(RequestScope.class))).thenReturn(mockModel);

MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
ElideResponse response = elide.get("/testModel/1/relationships/models", headers, null, NO_VERSION);
ElideResponse response = elide.get(baseUrl, "/testModel/1/relationships/models", headers, null, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());

verify(mockModel, never()).classAllFieldsCallback(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ public class TestRequestScope extends RequestScope {

private MultivaluedMap queryParamOverrides = null;

public TestRequestScope(String baseURL,
DataStoreTransaction transaction,
User user,
EntityDictionary dictionary) {
super(baseURL, null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(),
new ElideSettingsBuilder(null)
.withEntityDictionary(dictionary)
.withJSONApiLinks(new DefaultJSONApiLinks())
.build());
}

public TestRequestScope(DataStoreTransaction transaction,
User user,
EntityDictionary dictionary) {
super(null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(),
super(null, null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(),
new ElideSettingsBuilder(null)
.withEntityDictionary(dictionary)
.build());
Expand All @@ -34,7 +45,7 @@ public TestRequestScope(DataStoreTransaction transaction,
public TestRequestScope(EntityDictionary dictionary,
String path,
MultivaluedMap<String, String> queryParams) {
super(path, NO_VERSION, new JsonApiDocument(), null, null, queryParams, UUID.randomUUID(),
super(null, path, NO_VERSION, new JsonApiDocument(), null, null, queryParams, UUID.randomUUID(),
new ElideSettingsBuilder(null)
.withEntityDictionary(dictionary)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static org.mockito.Mockito.mock;

import com.yahoo.elide.core.DataStoreTransaction;
import com.yahoo.elide.core.DefaultJSONApiLinks;
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.core.PersistentResource;
import com.yahoo.elide.core.RequestScope;
Expand Down Expand Up @@ -50,6 +49,7 @@
public class JsonApiTest {
private JsonApiMapper mapper;
private User user = new TestUser("0");
private static String BASE_URL = "http://localhost:8080/json/";

private EntityDictionary dictionary;
private DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
Expand All @@ -67,7 +67,7 @@ public void writeSingleNoAttributesNoRel() throws JsonProcessingException {
Parent parent = new Parent();
parent.setId(123L);

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

JsonApiDocument jsonApiDocument = new JsonApiDocument();
jsonApiDocument.setData(new Data<>(new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope).toResource()));
Expand Down Expand Up @@ -104,7 +104,7 @@ public void writeSingle() throws JsonProcessingException {
child.setParents(Collections.singleton(parent));
child.setFriends(new HashSet<>());

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

JsonApiDocument jsonApiDocument = new JsonApiDocument();
jsonApiDocument.setData(new Data<>(new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope).toResource()));
Expand Down Expand Up @@ -141,7 +141,7 @@ public void writeSingleIncluded() throws JsonProcessingException {
child.setParents(Collections.singleton(parent));
child.setFriends(new HashSet<>());

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

PersistentResource<Parent> pRec = new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope);

Expand Down Expand Up @@ -195,7 +195,7 @@ public void writeList() throws JsonProcessingException {
parent.setFirstName("bob");
child.setFriends(new HashSet<>());

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

JsonApiDocument jsonApiDocument = new JsonApiDocument();
jsonApiDocument.setData(
Expand Down Expand Up @@ -233,7 +233,7 @@ public void writeListIncluded() throws JsonProcessingException {
parent.setFirstName("bob");
child.setFriends(new HashSet<>());

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

PersistentResource<Parent> pRec = new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope);

Expand Down Expand Up @@ -475,7 +475,7 @@ public void compareOrder() throws JsonProcessingException {
Parent parent2 = new Parent();
parent2.setId(456L);

RequestScope userScope = new TestRequestScope(tx, user, dictionary);
RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary);

PersistentResource<Parent> pRec1 = new PersistentResource<>(parent1, null, userScope.getUUIDFor(parent1), userScope);
PersistentResource<Parent> pRec2 = new PersistentResource<>(parent2, null, userScope.getUUIDFor(parent2), userScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Iterable<Object> loadObjects(

if (pagination != null) {
//Issue #1429
if (pagination.returnPageTotals() && (!results.isEmpty() || p.getLimit() == 0)) {
if (pagination.returnPageTotals() && (!results.isEmpty() || pagination.getLimit() == 0)) {
pagination.setPageTotals(getTotalRecords(entityClass,
Optional.ofNullable(filterExpression), scope.getDictionary()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Response post(
if (runner == null) {
response = buildErrorResponse(elide, new InvalidOperationException("Invalid API Version"), false);
} else {
response = runner.run(graphQLDocument, user);
response = runner.run(uriInfo.getBaseUri().toString(), graphQLDocument, user);
}
return Response.status(response.getResponseCode()).entity(response.getBody()).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public GraphQLRequestScope(
// we should have a GraphQLRequestScope and a JSONAPIRequestScope.
// TODO: What should mutate multiple entity value be? There is a problem with this setting in practice.
// Namely, we don't filter or paginate in the data store.
super(baseUrlEndPoint, "/", apiVersion, null, transaction, user, new MultivaluedHashMap<>(), requestId, elideSettings);
super(baseUrlEndpoint, "/", apiVersion, null, transaction, user,
new MultivaluedHashMap<>(), requestId, elideSettings);
this.projectionInfo = projectionInfo;

// Entity Projection is retrieved from projectionInfo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public QueryRunner(Elide elide, String apiVersion) {
* @return The response.
*/
public ElideResponse run(String baseUrlEndPoint, String graphQLDocument, User user) {
return run(graphQLDocument, user, UUID.randomUUID());
return run(baseUrlEndPoint, graphQLDocument, user, UUID.randomUUID());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void testCrypticErrorOnUpsert() throws IOException, JSONException {
)
).toQuery();

Response response = endpoint.post(uriInfo, user2, graphQLRequestToJSON(graphQLRequest));
Response response = endpoint.post(uriInfo, NO_VERSION, user2, graphQLRequestToJSON(graphQLRequest));
JsonNode node = extract200Response(response);
Iterator<JsonNode> errors = node.get("errors").elements();
assertTrue(errors.hasNext());
Expand Down Expand Up @@ -876,7 +876,7 @@ public void testMultipleRoot() throws JSONException {
).toResponse();


Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest));
Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, graphQLResponse);
}

Expand Down Expand Up @@ -942,7 +942,7 @@ public void testMultipleQueryWithAlias() throws JSONException {
).toResponse();


Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest));
Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest));
assert200EqualBody(response, graphQLResponse);
}

Expand Down Expand Up @@ -1026,7 +1026,7 @@ public void testMultipleQueryWithAliasAndArguments() throws JSONException {
variables.put("author1", "1");
variables.put("author2", "2");

Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest, variables));
Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest, variables));
assert200EqualBody(response, graphQLResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ protected void assertParsingFails(String graphQLRequest) {
protected ExecutionResult runGraphQLRequest(String graphQLRequest, Map<String, Object> variables) {
DataStoreTransaction tx = inMemoryDataStore.beginTransaction();
GraphQLProjectionInfo projectionInfo = new GraphQLEntityProjectionMaker(settings).make(graphQLRequest);
GraphQLRequestScope requestScope = new GraphQLRequestScope(tx, null, NO_VERSION, settings, projectionInfo, UUID.randomUUID());
GraphQLRequestScope requestScope = new GraphQLRequestScope(baseUrl, tx, null, NO_VERSION, settings,
projectionInfo, UUID.randomUUID());

return api.execute(graphQLRequest, requestScope, variables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,16 +724,17 @@ public String getAuthenticationScheme() {
}
});

String baseUrl = "/";
// Principal is Owner
response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());

// Principal has Admin Role
response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());

// Principal without Admin Role
response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION);
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_FORBIDDEN, response.getResponseCode());
}

Expand Down
Loading

0 comments on commit 6296e23

Please sign in to comment.