use of com.haulmont.cuba.security.entity.UserSubstitution in project cuba by cuba-platform.
the class WebUserIndicator method refreshUserSubstitutions.
@Override
public void refreshUserSubstitutions() {
component.removeAllComponents();
UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
List<UserSubstitution> substitutions = getUserSubstitutions();
User user = uss.getUserSession().getUser();
AppUI ui = AppUI.getCurrent();
String substitutedUserCaption = getSubstitutedUserCaption(user);
if (substitutions.isEmpty()) {
userComboBox = null;
userNameLabel = new Label(substitutedUserCaption);
userNameLabel.setStyleName("c-user-select-label");
userNameLabel.setSizeUndefined();
if (ui.isTestMode()) {
userNameLabel.setCubaId("currentUserLabel");
}
component.addComponent(userNameLabel);
component.setDescription(substitutedUserCaption);
} else {
userNameLabel = null;
userComboBox = new CubaComboBox();
userComboBox.setFilteringMode(FilteringMode.CONTAINS);
userComboBox.setNullSelectionAllowed(false);
userComboBox.setImmediate(true);
if (ui.isTestMode()) {
userComboBox.setCubaId("substitutedUserSelect");
userComboBox.setId(ui.getTestIdManager().getTestId("substitutedUserSelect"));
}
userComboBox.setStyleName("c-user-select-combobox");
userComboBox.addItem(user);
userComboBox.setItemCaption(user, substitutedUserCaption);
for (UserSubstitution substitution : substitutions) {
User substitutedUser = substitution.getSubstitutedUser();
userComboBox.addItem(substitutedUser);
userComboBox.setItemCaption(substitutedUser, getSubstitutedUserCaption(substitutedUser));
}
UserSession session = uss.getUserSession();
userComboBox.select(session.getSubstitutedUser() == null ? session.getUser() : session.getSubstitutedUser());
userComboBox.addValueChangeListener(new SubstitutedUserChangeListener(userComboBox));
component.addComponent(userComboBox);
component.setDescription(null);
}
adjustWidth();
adjustHeight();
}
use of com.haulmont.cuba.security.entity.UserSubstitution in project cuba by cuba-platform.
the class WebUserIndicator method getUserSubstitutions.
protected List<UserSubstitution> getUserSubstitutions() {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
DataService dataService = AppBeans.get(DataService.NAME);
UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
LoadContext<UserSubstitution> ctx = new LoadContext<>(UserSubstitution.class);
LoadContext.Query query = ctx.setQueryString("select us from sec$UserSubstitution us " + "where us.user.id = :userId and (us.endDate is null or us.endDate >= :currentDate) " + "and (us.startDate is null or us.startDate <= :currentDate) " + "and (us.substitutedUser.active = true or us.substitutedUser.active is null) order by us.substitutedUser.name");
query.setParameter("userId", uss.getUserSession().getUser().getId());
query.setParameter("currentDate", timeSource.currentTimestamp());
ctx.setView("app");
return dataService.loadList(ctx);
}
Aggregations