コード例 #1
0
ファイル: RecordState.java プロジェクト: jkusa/elide
 @Override
 public void handle(StateContext state, SubCollectionReadCollectionContext ctx) {
   String subCollection = ctx.term().getText();
   EntityDictionary dictionary = state.getRequestScope().getDictionary();
   try {
     Set<PersistentResource> collection = resource.getRelation(subCollection); // Check if exists.
     String entityName =
         dictionary.getBinding(
             dictionary.getParameterizedType(resource.getObject(), subCollection));
     Class<?> entityClass = dictionary.getBinding(entityName);
     if (entityClass == null) {
       throw new IllegalArgumentException("Unknown type " + entityName);
     }
     final BaseState nextState;
     if (collection instanceof SingleElementSet) {
       PersistentResource record = collection.iterator().next();
       nextState = new RecordTerminalState(subCollection, record);
     } else {
       nextState =
           new CollectionTerminalState(
               entityClass, Optional.of(resource), Optional.of(subCollection));
     }
     state.setState(nextState);
   } catch (InvalidAttributeException e) {
     throw new InvalidCollectionException(subCollection);
   }
 }
コード例 #2
0
  @Override
  public ExpressionResult evaluate() {
    PersistentResource resource = condition.getResource().get();
    EntityDictionary dictionary =
        ((com.yahoo.elide.core.PersistentResource) resource).getDictionary();

    if (!dictionary.isShareable(resource.getResourceClass()) || !entityExpression.isPresent()) {
      return FAIL;
    }

    return entityExpression.get().evaluate();
  }
コード例 #3
0
  @BeforeMethod
  public void setUp() throws Exception {
    includedProcessor = new IncludedProcessor();

    EntityDictionary dictionary = new EntityDictionary();
    dictionary.bindEntity(Child.class);
    dictionary.bindEntity(Parent.class);

    RequestScope goodUserScope =
        new RequestScope(
            new JsonApiDocument(), null, new User(1), dictionary, null, new TestLogger());

    // Create objects
    Parent parent1 = newParent(1);
    Parent parent2 = newParent(2);
    Parent parent3 = newParent(3);

    Child child1 = newChild(2);
    Child child2 = newChild(3);
    Child child3 = newChild(4);
    Child child4 = newChild(5);

    // Form relationships
    parent1.setSpouses(new HashSet<>(Collections.singletonList(parent2)));
    parent1.setChildren(new HashSet<>(Collections.singletonList(child1)));
    parent2.setChildren(new HashSet<>(Collections.singletonList(child2)));
    child1.setFriends(new HashSet<>(Collections.singletonList(child2)));

    // Parent with multiple children each with a friend
    parent3.setChildren(new HashSet<>(Arrays.asList(child3, child4)));
    child3.setFriends(new HashSet<>(Collections.singletonList(child1)));
    child4.setFriends(new HashSet<>(Collections.singletonList(child2)));

    // Create Persistent Resources
    parentRecord1 = new PersistentResource<>(parent1, goodUserScope);
    parentRecord2 = new PersistentResource<>(parent2, goodUserScope);
    parentRecord3 = new PersistentResource<>(parent3, goodUserScope);
    childRecord1 = new PersistentResource<>(child1, goodUserScope);
    childRecord2 = new PersistentResource<>(child2, goodUserScope);
    childRecord3 = new PersistentResource<>(child3, goodUserScope);
    childRecord4 = new PersistentResource<>(child4, goodUserScope);
  }
コード例 #4
0
ファイル: PersistenceStore.java プロジェクト: leixu/elide
 @Override
 public void populateEntityDictionary(EntityDictionary dictionary) {
   for (EntityType entity : entityManagerFactory.getMetamodel().getEntities()) {
     dictionary.bindEntity(entity.getBindableJavaType());
   }
 }