Search in sources :

Example 1 with KeyValueEntity

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

the class CustomValueCollectionDatasource 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 2 with KeyValueEntity

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

the class CustomValueHierarchicalDatasource 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 3 with KeyValueEntity

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

the class ValueDatasourceDelegate method afterLoadValues.

protected void afterLoadValues(Map<String, Object> params, ValueLoadContext context, List<KeyValueEntity> entities) {
    ds.detachListener(ds.data.values());
    ds.data.clear();
    boolean hasEnumerations = ds.metaClass.getOwnProperties().stream().anyMatch(p -> p.getRange().isEnum());
    if (!hasEnumerations) {
        for (KeyValueEntity entity : entities) {
            ds.data.put(entity.getId(), entity);
            ds.attachListener(entity);
            entity.setMetaClass(ds.metaClass);
        }
    } else {
        List<MetaProperty> enumProperties = getEnumProperties(ds.metaClass);
        for (KeyValueEntity entity : entities) {
            convertEnumValues(entity, enumProperties);
            ds.data.put(entity.getId(), entity);
            ds.attachListener(entity);
            entity.setMetaClass(ds.metaClass);
        }
    }
}
Also used : MetaProperty(com.haulmont.chile.core.model.MetaProperty) KeyValueMetaProperty(com.haulmont.cuba.core.app.keyvalue.KeyValueMetaProperty) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Example 4 with KeyValueEntity

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

the class AboutWindow method init.

@Override
public void init(Map<String, Object> params) {
    BuildInfo.Content content = buildInfo.getContent();
    for (Map.Entry<String, String> entry : content.getProperties().entrySet()) {
        KeyValueEntity entity = new KeyValueEntity();
        String name = messages.getMainMessage("buildInfo." + entry.getKey());
        if (name.equals("buildInfo." + entry.getKey()))
            name = entry.getKey();
        entity.setValue("name", name);
        entity.setValue("value", entry.getValue());
        buildInfoDs.includeItem(entity);
    }
}
Also used : BuildInfo(com.haulmont.cuba.core.global.BuildInfo) Map(java.util.Map) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Example 5 with KeyValueEntity

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

the class NonEntityQueryTest method testConstraints.

@Test
public void testConstraints() throws Exception {
    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.name from sys$Server s");
        context.addProperty("name");
        List<KeyValueEntity> 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)

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