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