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);
});
});
}
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();
}
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);
}
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;
}
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);
}
Aggregations