public EntityDictionary getDictionary() { return requestScope.getDictionary(); } }
public EntityDictionary getDictionary() { return requestScope.getDictionary(); } }
/** * Get the id of the entity. * @return the optional id */ public Optional<String> getId() { EntityDictionary dictionary = this.requestScope.getDictionary(); String idFieldName = dictionary.getIdFieldName(this.entityClass); return this.attributes.stream() .filter(entry -> idFieldName.equalsIgnoreCase(entry.name)) .map(e -> (String) e.value) .findFirst(); }
@Override public String toString() { EntityDictionary dictionary = ((com.yahoo.elide.core.RequestScope) requestScope).getDictionary(); return String.format("(%s %s)", dictionary.getCheckIdentifier(check.getClass()), result); } }
/** * Get the id of the entity. * @return the optional id */ public Optional<String> getId() { EntityDictionary dictionary = this.requestScope.getDictionary(); String idFieldName = dictionary.getIdFieldName(this.entityClass); return this.attributes.stream() .filter(entry -> idFieldName.equalsIgnoreCase(entry.name)) .map(e -> (String) e.value) .findFirst(); }
@Override public String toString() { EntityDictionary dictionary = ((com.yahoo.elide.core.RequestScope) requestScope).getDictionary(); return String.format("(%s %s)", dictionary.getCheckIdentifier(check.getClass()), result); } }
private static <T> Predicate<T> in(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { Class type = requestScope.getDictionary().getType(entity, field); if (!type.isAssignableFrom(String.class)) { throw new IllegalStateException("Cannot case insensitive compare non-string values"); } String val = transform.apply((String) getFieldValue(entity, field, requestScope)); return val != null && values.stream() .map(v -> transform.apply(CoerceUtil.coerce(v, String.class))) .anyMatch(val::equals); }; }
/** * Set the id of the entity if it doesn't have one already. */ public void setId() { if (!getId().isPresent()) { EntityDictionary dictionary = this.requestScope.getDictionary(); String idFieldName = dictionary.getIdFieldName(this.entityClass); String uuid = UUID.randomUUID().toString(); this.attributes.add(new Attribute(idFieldName, uuid)); } }
/** * Constructor. * * @param verbose True if executor should produce verbose output to caller * @param requestScope Request scope */ public ActivePermissionExecutor(boolean verbose, final RequestScope requestScope) { ExpressionResultCache cache = new ExpressionResultCache(); this.requestScope = requestScope; this.expressionBuilder = new PermissionExpressionBuilder(cache, requestScope.getDictionary()); userPermissionCheckCache = new HashMap<>(); checkStats = new HashMap<>(); this.verbose = verbose; }
/** * Set the id of the entity if it doesn't have one already. */ public void setId() { if (!getId().isPresent()) { EntityDictionary dictionary = this.requestScope.getDictionary(); String idFieldName = dictionary.getIdFieldName(this.entityClass); String uuid = UUID.randomUUID().toString(); this.attributes.add(new Attribute(idFieldName, uuid)); } }
public PersistentResource toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Class<?> cls = requestScope.getDictionary().getEntityClass(type); return PersistentResource.loadRecord(cls, id, requestScope); }
public PersistentResource toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Class<?> cls = requestScope.getDictionary().getEntityClass(type); return PersistentResource.loadRecord(cls, id, requestScope); }
public PersistentResource toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Class<?> cls = requestScope.getDictionary().getEntityClass(type); if (cls == null) { throw new UnknownEntityException(type); } return PersistentResource.loadRecord(cls, id, requestScope); } }
public PersistentResource toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Class<?> cls = requestScope.getDictionary().getEntityClass(type); if (cls == null) { throw new UnknownEntityException(type); } return PersistentResource.loadRecord(cls, id, requestScope); } }
/** * The filter expression is evaluated in memory if it cannot be pushed to the data store by elide for any reason. * * @param object object returned from datastore * @param requestScope Request scope object * @param changeSpec Summary of modifications * @return true if the object pass evaluation against FilterExpression. */ @Override public final boolean ok(T object, RequestScope requestScope, Optional<ChangeSpec> changeSpec) { Class entityClass = coreScope(requestScope).getDictionary().lookupEntityClass(object.getClass()); FilterExpression filterExpression = getFilterExpression(entityClass, requestScope); return filterExpression.accept(new FilterExpressionCheckEvaluationVisitor(object, this, requestScope)); }
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Test (dataProvider = "like_queries_hql") public void testSpecialCharacterLikeQueryHQL(FilterPredicate filterPredicate, int noOfRecords) throws Exception { DataStoreTransaction tx = dataStore.beginReadTransaction(); RequestScope scope = mock(RequestScope.class); EntityDictionary dictionary = new EntityDictionary(new HashMap<>()); dictionary.bindEntity(Book.class); when(scope.getDictionary()).thenReturn(dictionary); Pagination pagination = mock(Pagination.class); when(pagination.isGenerateTotals()).thenReturn(true); tx.loadObjects(Book.class, Optional.of(filterPredicate), Optional.empty(), Optional.of(pagination), scope); tx.commit(scope); tx.close(); verify(pagination).setPageTotals(noOfRecords); }
private PersistentResource<?> entityRecord(StateContext state, EntityContext entity) { String entityName = entity.term().getText(); String id = entity.id().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } return PersistentResource.loadRecord(entityClass, id, state.getRequestScope()); } }
private PersistentResource<?> entityRecord(StateContext state, EntityContext entity) { String entityName = entity.term().getText(); String id = entity.id().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } return PersistentResource.loadRecord(entityClass, id, state.getRequestScope()); } }