Search in sources :

Example 96 with Entity

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

the class UpdateDetachedTest method testDataService.

@Test
public void testDataService() throws Exception {
    Permission p;
    DataService ds = AppBeans.get(DataService.NAME);
    LoadContext<Permission> ctx = new LoadContext<>(Permission.class);
    ctx.setId(permissionId);
    ctx.setView(new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name")));
    p = ds.load(ctx);
    assertNotNull(p);
    p.setTarget("newTarget");
    CommitContext commitCtx = new CommitContext(Collections.singleton(p));
    Set<Entity> entities = ds.commit(commitCtx);
    Permission result = null;
    for (Entity entity : entities) {
        if (entity.equals(p))
            result = (Permission) entity;
    }
    result = reserialize(result);
    assertTrue(PersistenceHelper.isDetached(result));
    assertNotNull(result.getRole());
    assertTrue(PersistenceHelper.isDetached(result.getRole()));
    assertTrue(PersistenceHelper.isLoaded(result, "role"));
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Entity(com.haulmont.cuba.core.entity.Entity) Permission(com.haulmont.cuba.security.entity.Permission) DataService(com.haulmont.cuba.core.app.DataService) Test(org.junit.Test)

Example 97 with Entity

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

the class EntitySqlGenerationServiceBean method reload.

protected Entity reload(Entity entity) {
    String storeName = metadataTools.getStoreName(entity.getMetaClass());
    if (storeName == null)
        throw new RuntimeException("Cannot determine data store for " + entity);
    try (Transaction tx = persistence.createTransaction(storeName)) {
        Entity reloaded = persistence.getEntityManager(storeName).find(entity.getClass(), entity.getId(), createFullView(entity.getMetaClass()));
        if (reloaded != null) {
            entity = reloaded;
        }
        tx.commit();
    }
    return entity;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Transaction(com.haulmont.cuba.core.Transaction)

Example 98 with Entity

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

the class CubaFoldersPane method saveFolder.

public Folder saveFolder(Folder folder) {
    CommitContext commitContext = new CommitContext(Collections.singleton(folder));
    Set<Entity> res = dataService.commit(commitContext);
    for (Entity entity : res) {
        if (entity.equals(folder))
            return (Folder) entity;
    }
    return null;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity)

Example 99 with Entity

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

the class ScreenHistoryBrowse method init.

@Override
public void init(Map<String, Object> params) {
    LinkColumnHelper.initColumn(historyTable, "caption", entity -> {
        close("windowClose");
        openUrl(entity);
    });
    historyTable.addAction(new ShowLinkAction(historyTable.getDatasource(), entity -> entity != null ? ((ScreenHistoryEntity) entity).getUrl() : ""));
}
Also used : LinkColumnHelper(com.haulmont.cuba.gui.app.LinkColumnHelper) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Table(com.haulmont.cuba.gui.components.Table) App(com.haulmont.cuba.web.App) HashMap(java.util.HashMap) AppBeans(com.haulmont.cuba.core.global.AppBeans) Inject(javax.inject.Inject) List(java.util.List) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) Configuration(com.haulmont.cuba.core.global.Configuration) LinkHandler(com.haulmont.cuba.web.sys.LinkHandler) WebConfig(com.haulmont.cuba.web.WebConfig) Map(java.util.Map) ShowLinkAction(com.haulmont.cuba.web.gui.components.ShowLinkAction) Entity(com.haulmont.cuba.core.entity.Entity) ShowLinkAction(com.haulmont.cuba.web.gui.components.ShowLinkAction)

Example 100 with Entity

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

the class ScreensLinkHandlerProcessor method getParamsMap.

protected Map<String, Object> getParamsMap(Map<String, String> requestParams) {
    Map<String, Object> params = new HashMap<>();
    String paramsStr = requestParams.get("params");
    if (paramsStr == null)
        return params;
    String[] entries = paramsStr.split(",");
    for (String entry : entries) {
        String[] parts = entry.split(":");
        if (parts.length != 2) {
            log.warn("Invalid parameter: {}", entry);
            return params;
        }
        String name = parts[0];
        String value = parts[1];
        EntityLoadInfo info = EntityLoadInfo.parse(value);
        if (info != null) {
            Entity entity = loadEntityInstance(info);
            if (entity != null)
                params.put(name, entity);
        } else if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            params.put(name, BooleanUtils.toBoolean(value));
        } else {
            params.put(name, value);
        }
    }
    return params;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) HashMap(java.util.HashMap)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)203 MetaClass (com.haulmont.chile.core.model.MetaClass)51 MetaProperty (com.haulmont.chile.core.model.MetaProperty)44 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)40 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)18 Test (org.junit.Test)15 Inject (javax.inject.Inject)14 java.util (java.util)12 EntityManager (com.haulmont.cuba.core.EntityManager)11 ParseException (java.text.ParseException)11 Element (org.dom4j.Element)11 Logger (org.slf4j.Logger)11 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)10 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)9 LoggerFactory (org.slf4j.LoggerFactory)9 Query (com.haulmont.cuba.core.Query)8 Server (com.haulmont.cuba.core.entity.Server)8 Transaction (com.haulmont.cuba.core.Transaction)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 Collectors (java.util.stream.Collectors)7