use of com.haulmont.cuba.core.app.DataService in project cuba by cuba-platform.
the class ConverterHelper method fetchDynamicAttributes.
public static void fetchDynamicAttributes(Entity entity) {
if (entity instanceof BaseGenericIdEntity) {
LoadContext<BaseGenericIdEntity> loadContext = new LoadContext<>(entity.getMetaClass());
loadContext.setId(entity.getId()).setLoadDynamicAttributes(true);
DataService dataService = AppBeans.get(DataService.NAME, DataService.class);
BaseGenericIdEntity reloaded = dataService.load(loadContext);
if (reloaded != null) {
((BaseGenericIdEntity) entity).setDynamicAttributes(reloaded.getDynamicAttributes());
} else {
((BaseGenericIdEntity) entity).setDynamicAttributes(new HashMap<>());
}
}
}
use of com.haulmont.cuba.core.app.DataService in project cuba by cuba-platform.
the class Param method loadEntity.
protected Object loadEntity(String id) {
LoadContext ctx = new LoadContext(javaClass).setId(UUID.fromString(id));
DataService dataService = AppBeans.get(DataService.NAME);
return dataService.load(ctx);
}
use of com.haulmont.cuba.core.app.DataService in project cuba by cuba-platform.
the class ScreenHistorySupport method saveScreenHistory.
public void saveScreenHistory(Window window, WindowManager.OpenMode openMode) {
Security security = AppBeans.get(Security.NAME);
if (security.isEntityOpPermitted(ScreenHistoryEntity.class, EntityOp.CREATE) && window.getFrame() != null && (window.getFrame() instanceof Window.Editor) && openMode != WindowManager.OpenMode.DIALOG && (screenIds == null || screenIds.contains(window.getId()))) {
String caption = window.getCaption();
UUID entityId = null;
Frame frame = window.getFrame();
Entity entity = null;
if (frame instanceof Window.Editor) {
entity = ((Window.Editor) frame).getItem();
if (entity != null) {
if (PersistenceHelper.isNew(entity)) {
return;
}
if (StringUtils.isBlank(caption))
caption = messages.getTools().getEntityCaption(entity.getMetaClass()) + " " + entity.getInstanceName();
entityId = (UUID) entity.getId();
}
}
ScreenHistoryEntity screenHistoryEntity = metadata.create(ScreenHistoryEntity.class);
screenHistoryEntity.setCaption(StringUtils.abbreviate(caption, 255));
screenHistoryEntity.setUrl(makeLink(window));
screenHistoryEntity.setEntityId(entityId);
addAdditionalFields(screenHistoryEntity, entity);
CommitContext cc = new CommitContext(Collections.singleton(screenHistoryEntity));
DataService dataService = AppBeans.get(DataService.NAME);
dataService.commit(cc);
}
}
use of com.haulmont.cuba.core.app.DataService in project cuba by cuba-platform.
the class QueryResultTest method testSecondQuery.
@Test
public void testSecondQuery() throws SQLException {
DataService dataService = AppBeans.get(DataService.class);
LoadContext context = new LoadContext(User.class).setView(View.LOCAL);
context.setQueryString("select u from sec$User u where u.email like :email").setParameter("email", "%aaa.com");
LoadContext.Query prevQuery = new LoadContext.Query("select u from sec$User u where u.name like :name").setParameter("name", "A-%");
context.getPrevQueries().add(prevQuery);
context.setQueryKey(111);
List<Entity> entities = dataService.loadList(context);
assertEquals(10, entities.size());
List<Map<String, Object>> queryResults = getQueryResults();
assertEquals(20, queryResults.size());
}
use of com.haulmont.cuba.core.app.DataService in project cuba by cuba-platform.
the class QueryResultTest method testThirdQuery.
@Test
public void testThirdQuery() throws SQLException {
DataService dataService = AppBeans.get(DataService.class);
LoadContext context;
List<Entity> entities;
context = new LoadContext(User.class).setView(View.LOCAL);
LoadContext.Query query1 = context.setQueryString("select u from sec$User u where u.email like :email").setParameter("email", "%aaa.com");
entities = dataService.loadList(context);
assertEquals(20, entities.size());
context = new LoadContext(User.class).setView(View.LOCAL);
LoadContext.Query query2 = context.setQueryString("select u from sec$User u where u.name like :name").setParameter("name", "A-%");
context.getPrevQueries().add(query1);
context.setQueryKey(111);
entities = dataService.loadList(context);
assertEquals(10, entities.size());
context = new LoadContext(User.class).setView(View.LOCAL);
context.setQueryString("select u from sec$User u where u.firstName like :firstName").setParameter("firstName", "C-%");
context.getPrevQueries().add(query1);
context.getPrevQueries().add(query2);
context.setQueryKey(111);
entities = dataService.loadList(context);
assertEquals(5, entities.size());
}
Aggregations