Search in sources :

Example 1 with DataService

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<>());
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) LoadContext(com.haulmont.cuba.core.global.LoadContext) DataService(com.haulmont.cuba.core.app.DataService)

Example 2 with DataService

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);
}
Also used : DataService(com.haulmont.cuba.core.app.DataService)

Example 3 with DataService

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);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Entity(com.haulmont.cuba.core.entity.Entity) Frame(com.haulmont.cuba.gui.components.Frame) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) DataService(com.haulmont.cuba.core.app.DataService)

Example 4 with DataService

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());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) User(com.haulmont.cuba.security.entity.User) LoadContext(com.haulmont.cuba.core.global.LoadContext) DataService(com.haulmont.cuba.core.app.DataService) Test(org.junit.Test)

Example 5 with DataService

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());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) LoadContext(com.haulmont.cuba.core.global.LoadContext) DataService(com.haulmont.cuba.core.app.DataService) Test(org.junit.Test)

Aggregations

DataService (com.haulmont.cuba.core.app.DataService)12 Entity (com.haulmont.cuba.core.entity.Entity)6 Test (org.junit.Test)5 LoadContext (com.haulmont.cuba.core.global.LoadContext)4 User (com.haulmont.cuba.security.entity.User)3 UserSession (com.haulmont.cuba.security.global.UserSession)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Server (com.haulmont.cuba.core.entity.Server)1 Frame (com.haulmont.cuba.gui.components.Frame)1 Window (com.haulmont.cuba.gui.components.Window)1 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)1 Permission (com.haulmont.cuba.security.entity.Permission)1 Presentation (com.haulmont.cuba.security.entity.Presentation)1 Role (com.haulmont.cuba.security.entity.Role)1 ScreenHistoryEntity (com.haulmont.cuba.security.entity.ScreenHistoryEntity)1 UserSubstitution (com.haulmont.cuba.security.entity.UserSubstitution)1 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)1