Search in sources :

Example 71 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class IncludedProcessor method addIncludedResources.

/**
 * Adds the requested relation resources to the included block of the JsonApiDocument.
 */
private void addIncludedResources(JsonApiDocument jsonApiDocument, PersistentResource rec, List<String> requestedRelationPaths) {
    EntityProjectionMaker maker = new EntityProjectionMaker(rec.getDictionary(), rec.getRequestScope());
    EntityProjection projection = maker.parseInclude(rec.getResourceType());
    // Process each include relation path
    requestedRelationPaths.forEach(pathParam -> {
        List<String> pathList = Arrays.asList(pathParam.split(RELATION_PATH_SEPARATOR));
        pathList.forEach(requestedRelationPath -> {
            List<String> relationPath = Lists.newArrayList(requestedRelationPath.split(RELATION_PATH_DELIMITER));
            addResourcesForPath(jsonApiDocument, rec, relationPath, projection);
        });
    });
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) EntityProjectionMaker(com.yahoo.elide.jsonapi.EntityProjectionMaker)

Example 72 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class EntityProjectionMaker method visitIncludePath.

public EntityProjection visitIncludePath(Path path) {
    Path.PathElement pathElement = path.getPathElements().get(0);
    int size = path.getPathElements().size();
    Type<?> entityClass = pathElement.getFieldType();
    if (size > 1) {
        Path nextPath = new Path(path.getPathElements().subList(1, size));
        EntityProjection relationshipProjection = visitIncludePath(nextPath);
        return EntityProjection.builder().relationships(toRelationshipSet(getSparseRelationships(entityClass))).relationship(nextPath.getPathElements().get(0).getFieldName(), relationshipProjection).attributes(getSparseAttributes(entityClass)).filterExpression(scope.getFilterExpressionByType(entityClass).orElse(null)).type(entityClass).arguments(getDefaultEntityArguments(entityClass)).build();
    }
    return EntityProjection.builder().relationships(toRelationshipSet(getSparseRelationships(entityClass))).attributes(getSparseAttributes(entityClass)).type(entityClass).arguments(getDefaultEntityArguments(entityClass)).filterExpression(scope.getFilterExpressionByType(entityClass).orElse(null)).build();
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection)

Example 73 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class Resource method toPersistentResource.

public PersistentResource<?> toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException {
    EntityDictionary dictionary = requestScope.getDictionary();
    Type<?> cls = dictionary.getEntityClass(type, requestScope.getApiVersion());
    if (cls == null) {
        throw new UnknownEntityException(type);
    }
    if (id == null) {
        throw new InvalidObjectIdentifierException(id, type);
    }
    EntityProjection projection = EntityProjection.builder().type(cls).build();
    return PersistentResource.loadRecord(projection, id, requestScope);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) UnknownEntityException(com.yahoo.elide.core.exceptions.UnknownEntityException) InvalidObjectIdentifierException(com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 74 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class AbstractHQLQueryBuilderTest method getMockEntityProjection.

private static EntityProjection getMockEntityProjection() {
    EntityProjection entityProjection = mock(EntityProjection.class);
    when(entityProjection.getIncludedRelationsName()).thenReturn(new HashSet<>());
    return entityProjection;
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection)

Example 75 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class RootCollectionFetchQueryBuilderTest method testRootFetch.

@Test
public void testRootFetch() {
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Book AS example_Book";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

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