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"));
}
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);
}
}
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);
}
}
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);
}
}
}
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;
}
}
}
Aggregations