use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class EntityProjectionMakerTest method testRootEntityWithNestedInclude.
@Test
public void testRootEntityWithNestedInclude() {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.add("include", "books");
queryParams.add("include", "books.publisher,books.editor");
String path = "/author/1";
RequestScope scope = new TestRequestScope(dictionary, path, queryParams);
EntityProjectionMaker maker = new EntityProjectionMaker(dictionary, scope);
EntityProjection expected = EntityProjection.builder().type(Author.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("type").type(Author.AuthorType.class).build()).attribute(Attribute.builder().name("homeAddress").type(Address.class).build()).attribute(Attribute.builder().name("vacationHomes").type(Set.class).build()).attribute(Attribute.builder().name("stuff").type(Map.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).relationship("books", EntityProjection.builder().type(Book.class).attribute(Attribute.builder().name("title").type(String.class).build()).attribute(Attribute.builder().name("awards").type(Collection.class).build()).attribute(Attribute.builder().name("genre").type(String.class).build()).attribute(Attribute.builder().name("language").type(String.class).build()).attribute(Attribute.builder().name("publishDate").type(long.class).build()).attribute(Attribute.builder().name("authorTypes").type(Collection.class).build()).attribute(Attribute.builder().name("price").type(Price.class).build()).relationship("publisher", EntityProjection.builder().type(Publisher.class).attribute(Attribute.builder().name("name").type(String.class).build()).attribute(Attribute.builder().name("updateHookInvoked").type(boolean.class).build()).relationship("books", EntityProjection.builder().type(Book.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).relationship("editor", EntityProjection.builder().type(Editor.class).attribute(Attribute.builder().name("firstName").type(String.class).build()).attribute(Attribute.builder().name("lastName").type(String.class).build()).attribute(Attribute.builder().name("fullName").type(String.class).build()).relationship("editor", EntityProjection.builder().type(Editor.class).build()).build()).relationship("authors", EntityProjection.builder().type(Author.class).build()).build()).build();
EntityProjection actual = maker.parsePath(path);
projectionEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class GraphQLEntityProjectMakerTest method testParameterizedAttributeDefaultValue.
@Test
public void testParameterizedAttributeDefaultValue() {
String graphQLRequest = document(selection(field("parameterizedExample", selections(field("attribute"))))).toQuery();
GraphQLEntityProjectionMaker projectionMaker = new GraphQLEntityProjectionMaker(settings);
GraphQLProjectionInfo projectionInfo = projectionMaker.make(graphQLRequest);
assertEquals(1, projectionInfo.getProjections().size());
EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
// Verify Entity Argument
assertEquals(1, projection.getArguments().size());
Argument entityArgument = projection.getArguments().iterator().next();
assertEquals("entityArgument", entityArgument.getName());
assertEquals(String.class, entityArgument.getType());
assertEquals("defaultArgValue", entityArgument.getValue());
// Verify Attribute Argument
assertEquals(1, projection.getAttributes().size());
Attribute attribute = projection.getAttributes().iterator().next();
assertEquals(1, attribute.getArguments().size());
Argument argument = attribute.getArguments().iterator().next();
assertEquals("argument", argument.getName());
assertEquals(String.class, argument.getType());
assertEquals("defaultValue", argument.getValue());
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class GraphQLEntityProjectMakerTest method testParameterizedAttribute.
@Test
public void testParameterizedAttribute() {
String graphQLRequest = document(selection(field("parameterizedExample", arguments(argument("entityArgument", "xyz", true)), selections(field("attribute", arguments(argument("argument", "abc", true))))))).toQuery();
GraphQLEntityProjectionMaker projectionMaker = new GraphQLEntityProjectionMaker(settings);
GraphQLProjectionInfo projectionInfo = projectionMaker.make(graphQLRequest);
assertEquals(1, projectionInfo.getProjections().size());
EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
// Verify Entity Argument
assertEquals(1, projection.getArguments().size());
Argument entityArgument = projection.getArguments().iterator().next();
assertEquals("entityArgument", entityArgument.getName());
assertEquals(String.class, entityArgument.getType());
assertEquals("xyz", entityArgument.getValue());
// Verify Attribute Argument
assertEquals(1, projection.getAttributes().size());
Attribute attribute = projection.getAttributes().iterator().next();
assertEquals(1, attribute.getArguments().size());
Argument argument = attribute.getArguments().iterator().next();
assertEquals("argument", argument.getName());
assertEquals(String.class, argument.getType());
assertEquals("abc", argument.getValue());
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class DefaultAsyncAPIDAO method deleteAsyncAPIAndResultByFilter.
@Override
@SuppressWarnings("unchecked")
public <T extends AsyncAPI> Iterable<T> deleteAsyncAPIAndResultByFilter(FilterExpression filterExpression, Class<T> type) {
log.debug("deleteAsyncAPIAndResultByFilter");
Iterable<T> asyncAPIList = null;
asyncAPIList = (Iterable<T>) executeInTransaction(dataStore, (tx, scope) -> {
EntityProjection asyncAPIIterable = EntityProjection.builder().type(type).filterExpression(filterExpression).build();
Iterable<Object> loaded = tx.loadObjects(asyncAPIIterable, scope);
Iterator<Object> itr = loaded.iterator();
while (itr.hasNext()) {
T query = (T) itr.next();
if (query != null) {
tx.delete(query, scope);
}
}
return loaded;
});
return asyncAPIList;
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class DefaultAsyncAPIDAO method loadAsyncAPIByFilter.
@Override
@SuppressWarnings("unchecked")
public <T extends AsyncAPI> Iterable<T> loadAsyncAPIByFilter(FilterExpression filterExpression, Class<T> type) {
Iterable<T> asyncAPIList = null;
log.debug("loadAsyncAPIByFilter");
try {
asyncAPIList = (Iterable<T>) executeInTransaction(dataStore, (tx, scope) -> {
EntityProjection asyncAPIIterable = EntityProjection.builder().type(type).filterExpression(filterExpression).build();
return tx.loadObjects(asyncAPIIterable, scope);
});
} catch (Exception e) {
log.error("Exception: {}", e.toString());
throw new IllegalStateException(e);
}
return asyncAPIList;
}
Aggregations