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