Search in sources :

Example 11 with LoadContext

use of com.haulmont.cuba.core.global.LoadContext in project cuba by cuba-platform.

the class SeveralFetchGroupsTest method testLoadTariffVersions.

@Test
public void testLoadTariffVersions() {
    LoadContext<SeveralFetchGroups_TariffVersion> loadContext = new LoadContext<>(SeveralFetchGroups_TariffVersion.class);
    loadContext.setQueryString("select e from test$SeveralFetchGroups_TariffVersion e order by e.name asc");
    loadContext.setView("tariffVersion.withParent");
    List<SeveralFetchGroups_TariffVersion> result = dataManager.loadList(loadContext);
    for (SeveralFetchGroups_TariffVersion version : result) {
        Assert.assertNotNull(version.getParent());
    }
}
Also used : SeveralFetchGroups_TariffVersion(com.haulmont.cuba.testmodel.severalfetchgroups.SeveralFetchGroups_TariffVersion) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Example 12 with LoadContext

use of com.haulmont.cuba.core.global.LoadContext in project cuba by cuba-platform.

the class SoftDeleteNotFoundDeletedTest method testLoadDeletedObject.

@Test
public void testLoadDeletedObject() {
    View taskView_Message = new View(SoftDelete_Task.class).addProperty("message");
    View taskView_Service = new View(SoftDelete_Task.class).addProperty("service", new View(SoftDelete_Service.class).addProperty("code"));
    View taskValueView = new View(SoftDelete_TaskValue.class).addProperty("task", taskView_Message);
    View projectView = new View(SoftDelete_Project.class).addProperty("name").addProperty("aValue", taskValueView).addProperty("task", taskView_Service);
    LoadContext<SoftDelete_Project> loadContext = new LoadContext<>(SoftDelete_Project.class).setView(projectView).setId(projectId);
    SoftDelete_Project project = dataManager.load(loadContext);
    Assert.assertNotNull(project);
    Assert.assertNotNull(project.getTask());
    Assert.assertTrue(project.getTask().isDeleted());
}
Also used : SoftDelete_Task(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Task) SoftDelete_TaskValue(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_TaskValue) LoadContext(com.haulmont.cuba.core.global.LoadContext) SoftDelete_Project(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Project) View(com.haulmont.cuba.core.global.View)

Example 13 with LoadContext

use of com.haulmont.cuba.core.global.LoadContext in project cuba by cuba-platform.

the class UserSwitchLinkHandlerProcessor method loadUser.

protected User loadUser(UUID userId, User user) {
    if (user.getId().equals(userId))
        return user;
    LoadContext loadContext = new LoadContext(UserSubstitution.class);
    LoadContext.Query query = new LoadContext.Query("select su from sec$UserSubstitution us join us.user u " + "join us.substitutedUser su where u.id = :id and su.id = :userId and " + "(us.endDate is null or us.endDate >= :currentDate) and (us.startDate is null or us.startDate <= :currentDate)");
    query.setParameter("id", user);
    query.setParameter("userId", userId);
    query.setParameter("currentDate", timeSource.currentTimestamp());
    loadContext.setQuery(query);
    List<User> users = dataService.loadList(loadContext);
    return users.isEmpty() ? null : users.get(0);
}
Also used : User(com.haulmont.cuba.security.entity.User) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Example 14 with LoadContext

use of com.haulmont.cuba.core.global.LoadContext in project cuba by cuba-platform.

the class SuggestionFieldQueryLoader method loadQuery.

protected void loadQuery(SuggestionField suggestionField, Element element) {
    Element queryElement = element.element("query");
    if (queryElement != null) {
        final boolean escapeValue;
        String stringQuery = queryElement.getStringValue();
        String searchFormat = queryElement.attributeValue("searchStringFormat");
        String view = queryElement.attributeValue("view");
        String escapeValueForLike = queryElement.attributeValue("escapeValueForLike");
        if (StringUtils.isNotEmpty(escapeValueForLike)) {
            escapeValue = Boolean.valueOf(escapeValueForLike);
        } else {
            escapeValue = false;
        }
        String entityClassName = queryElement.attributeValue("entityClass");
        if (StringUtils.isNotEmpty(entityClassName)) {
            suggestionField.setSearchExecutor((searchString, searchParams) -> {
                DataSupplier supplier = suggestionField.getFrame().getDsContext().getDataSupplier();
                Class<Entity> entityClass = ReflectionHelper.getClass(entityClassName);
                if (escapeValue) {
                    searchString = QueryUtils.escapeForLike(searchString);
                }
                searchString = applySearchFormat(searchString, searchFormat);
                LoadContext loadContext = LoadContext.create(entityClass);
                if (StringUtils.isNotEmpty(view)) {
                    loadContext.setView(view);
                }
                loadContext.setQuery(LoadContext.createQuery(stringQuery).setParameter("searchString", searchString));
                // noinspection unchecked
                return supplier.loadList(loadContext);
            });
        } else {
            throw new GuiDevelopmentException(String.format("Field 'entityClass' is empty in component %s.", suggestionField.getId()), getContext().getFullFrameId());
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Aggregations

LoadContext (com.haulmont.cuba.core.global.LoadContext)14 User (com.haulmont.cuba.security.entity.User)5 DataService (com.haulmont.cuba.core.app.DataService)4 Entity (com.haulmont.cuba.core.entity.Entity)4 Test (org.junit.Test)3 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 DataManager (com.haulmont.cuba.core.global.DataManager)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 EntityLoadInfo (com.haulmont.cuba.core.global.EntityLoadInfo)1 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)1 View (com.haulmont.cuba.core.global.View)1 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 Group (com.haulmont.cuba.security.entity.Group)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1