Search in sources :

Example 6 with KeyValueEntity

use of com.haulmont.cuba.core.entity.KeyValueEntity in project cuba by cuba-platform.

the class NonEntityQueryTest method testAggregates.

@Test
public void testAggregates() throws Exception {
    ValueLoadContext context = ValueLoadContext.create();
    ValueLoadContext.Query query = context.setQueryString("select count(u) from sec$User u where u.id = :id1 or u.id = :id2");
    query.setParameter("id1", TestSupport.ADMIN_USER_ID);
    query.setParameter("id2", TestSupport.ANONYMOUS_USER_ID);
    context.addProperty("count");
    List<KeyValueEntity> list = dataManager.loadValues(context);
    assertEquals(1, list.size());
    KeyValueEntity e = list.get(0);
    assertEquals(Long.valueOf(2), e.getValue("count"));
}
Also used : KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Example 7 with KeyValueEntity

use of com.haulmont.cuba.core.entity.KeyValueEntity in project cuba by cuba-platform.

the class NonEntityQueryTest method testDeniedAttribute.

@Test
public void testDeniedAttribute() throws Exception {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login(USER_NAME_1, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        ValueLoadContext context = ValueLoadContext.create();
        context.setQueryString("select s.name from sys$Server s");
        context.addProperty("name");
        List<KeyValueEntity> list = dataManager.secure().loadValues(context);
        assertEquals(1, list.size());
        KeyValueEntity e = list.get(0);
        assertNull(e.getValue("name"));
        context = ValueLoadContext.create();
        context.setQueryString("select count(s.id) from sys$Server s where s.name = 'someServer'");
        context.addProperty("count");
        try {
            dataManager.secure().loadValues(context);
            fail();
        } catch (AccessDeniedException e1) {
        }
        context = ValueLoadContext.create();
        context.setQueryString("select s.name, count(s.id) from sys$Server s group by s.name");
        context.addProperty("name");
        context.addProperty("count");
        try {
            dataManager.secure().loadValues(context);
            fail();
        } catch (AccessDeniedException e1) {
        }
        context = ValueLoadContext.create();
        context.setQueryString("select count(s.id) from sys$Server s join sec$User u on u.login = s.name");
        context.addProperty("count");
        try {
            dataManager.secure().loadValues(context);
            fail();
        } catch (AccessDeniedException e1) {
        }
        context = ValueLoadContext.create();
        context.setQueryString("select count(sn) from sys$Server s, sys$EntitySnapshot sn");
        context.addProperty("count");
        list = dataManager.secure().loadValues(context);
        assertEquals(0, list.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Example 8 with KeyValueEntity

use of com.haulmont.cuba.core.entity.KeyValueEntity in project cuba by cuba-platform.

the class NonEntityQueryTest method testInMemoryAndSeveralConstraints.

@Test
public void testInMemoryAndSeveralConstraints() throws Exception {
    ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
    configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "false");
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login(USER_NAME_2, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        ValueLoadContext context = ValueLoadContext.create();
        context.setQueryString("select s.viewXml from sys$EntitySnapshot s");
        context.addProperty("viewXml");
        List<KeyValueEntity> list = dataManager.secure().loadValues(context);
        assertEquals(1, list.size());
        context = ValueLoadContext.create();
        context.setQueryString("select s.name, sn.viewXml from sys$Server s, sys$EntitySnapshot sn");
        context.addProperty("name");
        context.addProperty("viewXml");
        list = dataManager.secure().loadValues(context);
        assertEquals(0, list.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Example 9 with KeyValueEntity

use of com.haulmont.cuba.core.entity.KeyValueEntity in project cuba by cuba-platform.

the class CustomValueGroupDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    Collection<KeyValueEntity> entities = getEntities(params);
    detachListener(data.values());
    data.clear();
    if (entities != null) {
        for (KeyValueEntity entity : entities) {
            data.put(entity.getId(), entity);
            attachListener(entity);
            entity.setMetaClass(metaClass);
        }
    }
}
Also used : KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Example 10 with KeyValueEntity

use of com.haulmont.cuba.core.entity.KeyValueEntity in project cuba by cuba-platform.

the class ValueDatasourceDelegate method loadData.

protected void loadData(Map<String, Object> params) {
    if (ds.needLoading()) {
        ValueLoadContext context = beforeLoadValues(params);
        if (context == null) {
            return;
        }
        try {
            List<KeyValueEntity> entities = ds.dataSupplier.loadValues(context);
            afterLoadValues(params, context, entities);
        } catch (Throwable e) {
            ds.dataLoadError = e;
        }
    }
}
Also used : ValueLoadContext(com.haulmont.cuba.core.global.ValueLoadContext) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Aggregations

KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)12 Test (org.junit.Test)6 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)3 UserSession (com.haulmont.cuba.security.global.UserSession)3 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 ConfigStorageService (com.haulmont.cuba.core.app.ConfigStorageService)1 KeyValueMetaProperty (com.haulmont.cuba.core.app.keyvalue.KeyValueMetaProperty)1 BuildInfo (com.haulmont.cuba.core.global.BuildInfo)1 ValueLoadContext (com.haulmont.cuba.core.global.ValueLoadContext)1 Map (java.util.Map)1