Search in sources :

Example 96 with EntityProjection

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);
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Address(example.Address) Publisher(example.Publisher) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Book(example.Book) Author(example.Author) Collection(java.util.Collection) Editor(example.Editor) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.jupiter.api.Test)

Example 97 with EntityProjection

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());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) PersistentResourceFetcherTest(com.yahoo.elide.graphql.PersistentResourceFetcherTest) Test(org.junit.jupiter.api.Test)

Example 98 with EntityProjection

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());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) PersistentResourceFetcherTest(com.yahoo.elide.graphql.PersistentResourceFetcherTest) Test(org.junit.jupiter.api.Test)

Example 99 with EntityProjection

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;
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection)

Example 100 with EntityProjection

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;
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) IOException(java.io.IOException)

Aggregations

EntityProjection (com.yahoo.elide.core.request.EntityProjection)108 Test (org.junit.jupiter.api.Test)90 Book (example.Book)41 RequestScope (com.yahoo.elide.core.RequestScope)27 Author (example.Author)27 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)22 Publisher (example.Publisher)22 Relationship (com.yahoo.elide.core.request.Relationship)19 Path (com.yahoo.elide.core.Path)18 TestRequestScope (com.yahoo.elide.core.TestRequestScope)18 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)18 HashMap (java.util.HashMap)18 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)18 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)16 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)15 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)15 Collection (java.util.Collection)15 LinkedHashSet (java.util.LinkedHashSet)14 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)13 Editor (example.Editor)13