use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class CanPaginateVisitorTest method testTrueUserOROperationExpression.
@Test
public void testTrueUserOROperationExpression() throws Exception {
@Entity
@Include(rootLevel = false)
class Book {
@Id
private long id;
@ReadPermission(expression = "True User Check OR In Memory Check")
private String title;
}
EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
dictionary.bindEntity(Book.class);
RequestScope scope = mock(RequestScope.class);
assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class PermissionExpressionNormalizationVisitorTest method setUp.
@BeforeAll
public void setUp() {
EntityDictionary dictionary = TestDictionary.getTestDictionary();
ElideSettings elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, null, null, null, UUID.randomUUID(), elideSettings);
permissionExpressionVisitor = new PermissionExpressionVisitor(dictionary, (check -> new CheckExpression(check, null, requestScope, null, null)));
normalizationVisitor = new PermissionExpressionNormalizationVisitor();
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class NotifyTopicLifeCycleHookTest method setup.
@BeforeEach
public void setup() {
EntityDictionary dictionary;
dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
Topic destination = mock(Topic.class);
reset(scope);
reset(connectionFactory);
reset(producer);
when(connectionFactory.createContext()).thenReturn(context);
when(context.createProducer()).thenReturn(producer);
when(context.createTopic(any())).thenReturn(destination);
when(scope.getDictionary()).thenReturn(dictionary);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class SubscriptionScannerTest method testLifeCycleHookBindings.
@Test
public void testLifeCycleHookBindings() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
ClassScanner classScanner = DefaultClassScanner.getInstance();
EntityDictionary dictionary = EntityDictionary.builder().scanner(classScanner).build();
SubscriptionScanner subscriptionScanner = SubscriptionScanner.builder().connectionFactory(connectionFactory).dictionary(dictionary).scanner(classScanner).build();
subscriptionScanner.bindLifecycleHooks();
assertEquals(1, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.CREATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, CLASS_NO_FIELD).size());
assertEquals(0, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.DELETE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, CLASS_NO_FIELD).size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "title").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "genre").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "authors").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "previews").size());
assertEquals(0, dictionary.getTriggers(ClassType.of(Book.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "price").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.CREATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, CLASS_NO_FIELD).size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.DELETE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, CLASS_NO_FIELD).size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "name").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "type").size());
assertEquals(1, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "homeAddress").size());
assertEquals(0, dictionary.getTriggers(ClassType.of(Author.class), LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.POSTCOMMIT, "birthDate").size());
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class PersistentResource method buildIdFilterExpression.
/**
* Build an id filter expression for a particular entity type.
*
* @param ids Ids to include in the filter expression
* @param entityType Type of entity
* @return Filter expression for given ids and type.
*/
private static FilterExpression buildIdFilterExpression(List<String> ids, Type<?> entityType, EntityDictionary dictionary, RequestScope scope) {
Type<?> idType = dictionary.getIdType(entityType);
String idField = dictionary.getIdFieldName(entityType);
List<Object> coercedIds = ids.stream().filter(// these don't exist yet
id -> scope.getObjectById(entityType, id) == null).map(id -> CoerceUtil.coerce(id, idType)).collect(Collectors.toList());
/* construct a new SQL like filter expression, eg: book.id IN [1,2] */
FilterExpression idFilter = new InPredicate(new Path.PathElement(entityType, idType, idField), coercedIds);
return idFilter;
}
Aggregations