Search in sources :

Example 6 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class AsyncAPICleanerRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    dateUtil = mock(DateUtil.class);
    cleanerThread = new AsyncAPICleanerRunnable(7, elide, 7, asyncAPIDao, dateUtil);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) DateUtil(com.yahoo.elide.async.service.DateUtil) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class TestBinder method configure.

@Override
protected void configure() {
    EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).build();
    dictionary.scanForSecurityChecks();
    bind(dictionary).to(EntityDictionary.class);
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(EMBEDDED_JMS_URL);
    bind(connectionFactory).to(ConnectionFactory.class);
    // Primary Elide instance for CRUD endpoints.
    bindFactory(new Factory<Elide>() {

        @Override
        public Elide provide() {
            HashMapDataStore inMemoryStore = new HashMapDataStore(Set.of(Book.class, Author.class, Publisher.class, ChatBot.class));
            Elide elide = buildElide(inMemoryStore, dictionary);
            elide.doScans();
            SubscriptionScanner subscriptionScanner = SubscriptionScanner.builder().connectionFactory(connectionFactory).dictionary(elide.getElideSettings().getDictionary()).scanner(elide.getScanner()).build();
            subscriptionScanner.bindLifecycleHooks();
            return elide;
        }

        @Override
        public void dispose(Elide elide) {
        }
    }).to(Elide.class).named("elide");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) SubscriptionScanner(com.yahoo.elide.graphql.subscriptions.hooks.SubscriptionScanner) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 8 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class MetaDataStore method addMetaData.

/**
 * Add a meta data object into this data store, check for duplication.
 *
 * @param object a meta data object
 */
private void addMetaData(Object object, String version) {
    HashMapDataStore hashMapDataStore = hashMapDataStores.computeIfAbsent(version, SERVER_ERROR);
    EntityDictionary dictionary = hashMapDataStore.getDictionary();
    Type<?> cls = dictionary.lookupBoundClass(EntityDictionary.getType(object));
    String id = dictionary.getId(object);
    if (hashMapDataStore.get(cls).containsKey(id)) {
        if (!hashMapDataStore.get(cls).get(id).equals(object)) {
            throw new DuplicateMappingException("Duplicated " + cls.getSimpleName() + " metadata " + id);
        }
    } else {
        hashMapDataStore.get(cls).put(id, object);
    }
}
Also used : HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 9 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class PersistentResourceFetcherTest method initializeQueryRunner.

@BeforeAll
public void initializeQueryRunner() {
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
    hashMapDataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), Author.class.getPackage());
    settings = new ElideSettingsBuilder(hashMapDataStore).withEntityDictionary(dictionary).withJoinFilterDialect(filterDialect).withSubqueryFilterDialect(filterDialect).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
    settings.getSerdes().forEach(CoerceUtil::register);
    initializeMocks();
    Elide elide = new Elide(settings);
    elide.doScans();
    runner = new QueryRunner(elide, NO_VERSION);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class GraphQLEndpointTest method setupTest.

@BeforeEach
public void setupTest() throws Exception {
    HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), Book.class.getPackage());
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    checkMappings.put(UserChecks.IS_USER_1, UserChecks.IsUserId.One.class);
    checkMappings.put(UserChecks.IS_USER_2, UserChecks.IsUserId.Two.class);
    checkMappings.put(CommitChecks.IS_NOT_USER_3, CommitChecks.IsNotUser3.class);
    elide = spy(new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withAuditLogger(audit).build()));
    elide.doScans();
    endpoint = new GraphQLEndpoint(elide);
    DataStoreTransaction tx = inMemoryStore.beginTransaction();
    // Initial data
    Book book1 = new Book();
    Author author1 = new Author();
    Author author2 = new Author();
    DisallowTransfer noShare = new DisallowTransfer();
    book1.setId(1L);
    book1.setTitle("My first book");
    book1.setAuthors(Sets.newHashSet(author1));
    author1.setId(1L);
    author1.setName("Ricky Carmichael");
    author1.setBooks(Sets.newHashSet(book1));
    author1.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Bookz", "Pulitzer Prize"), new AbstractMap.SimpleImmutableEntry<>("Lost in the Data", "PEN/Faulkner Award")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    author2.setId(2L);
    author2.setName("The Silent Author");
    author2.setBookTitlesAndAwards(Stream.of(new AbstractMap.SimpleImmutableEntry<>("Working Hard or Hardly Working", "Booker Prize")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    noShare.setId(1L);
    tx.createObject(book1, null);
    tx.createObject(author1, null);
    tx.createObject(author2, null);
    tx.createObject(noShare, null);
    tx.save(book1, null);
    tx.save(author1, null);
    tx.save(author2, null);
    tx.save(noShare, null);
    tx.commit(null);
}
Also used : HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Check(com.yahoo.elide.core.security.checks.Check) DisallowTransfer(graphqlEndpointTestModels.DisallowTransfer) AbstractMap(java.util.AbstractMap) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Book(graphqlEndpointTestModels.Book) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Author(graphqlEndpointTestModels.Author) Elide(com.yahoo.elide.Elide) CommitChecks(graphqlEndpointTestModels.security.CommitChecks) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)15 Elide (com.yahoo.elide.Elide)11 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)10 HashMap (java.util.HashMap)9 Check (com.yahoo.elide.core.security.checks.Check)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 RequestScope (com.yahoo.elide.core.RequestScope)5 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)4 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)3 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 User (com.yahoo.elide.core.security.User)3 AsyncAPIInlineChecks (com.yahoo.elide.async.models.security.AsyncAPIInlineChecks)2 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)2 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)2 DataStore (com.yahoo.elide.core.datastore.DataStore)2 DuplicateMappingException (com.yahoo.elide.core.exceptions.DuplicateMappingException)2 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)2 FirstBean (com.yahoo.elide.example.beans.FirstBean)2