/** * Current portal session * * @return current user session instance */ public static PortalSession getUserSession() { return (PortalSession) getSource().getUserSession(); }
@Inject public void setUserSessionSource(UserSessionSource userSessionSource) { this.locale = userSessionSource.getLocale(); }
@Override public String getCurrentUserLogin() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getUser().getLogin() : null; }
protected Locale getCurrentLocale() { Locale locale; if (userSessionSource.checkCurrentUserSession()) { locale = userSessionSource.getLocale(); } else { locale = messages.getTools().getDefaultLocale(); } return locale; } }
/** * Parse Date (date and time) using {@code dateTimeFormat} string specified in the main message pack. * <p>Takes into account time zone if it is set for the current user session.</p> * @return Date value or null if a blank string is provided */ @Nullable public Date parseDateTime(String str) throws ParseException { TimeZone timeZone = uss.getUserSession().getTimeZone(); Datatype<Date> datatype = datatypeRegistry.getNN(Date.class); if (datatype instanceof DateTimeDatatype) { return ((DateTimeDatatype) datatype).parse(str, uss.getLocale(), timeZone); } return datatype.parse(str, uss.getLocale()); }
@Override public List<SearchFolder> loadSearchFolders() { log.debug("Loading SearchFolders"); StopWatch stopWatch = new Slf4JStopWatch("SearchFolders"); stopWatch.start(); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(SearchFolder.class); TypedQuery<SearchFolder> q = em.createQuery("select f from "+ effectiveMetaClass.getName() +" f " + "left join f.user u on u.id = ?1 " + "where (u.id = ?1 or u is null) " + "order by f.sortOrder, f.name", SearchFolder.class); q.setViewName("searchFolders"); q.setParameter(1, userSessionSource.currentOrSubstitutedUserId()); List<SearchFolder> list = q.getResultList(); tx.commit(); return list; } finally { tx.end(); stopWatch.stop(); } }
/** * Format Date (date and time) using {@code dateTimeFormat} string specified in the main message pack. * <p>Takes into account time zone if it is set for the current user session.</p> * @return string representation or empty string if the value is null */ public String formatDateTime(@Nullable Date value) { TimeZone timeZone = uss.getUserSession().getTimeZone(); Datatype<Date> datatype = datatypeRegistry.getNN(Date.class); if (datatype instanceof DateTimeDatatype) { return ((DateTimeDatatype) datatype).format(value, uss.getLocale(), timeZone); } return datatype.format(value, uss.getLocale()); }
@MetaProperty(related = {"snapshotDate,author"}) public String getLabel() { String name = ""; if (author != null && StringUtils.isNotEmpty(this.author.getCaption())) { name += this.author.getCaption() + " "; } Datatype datatype = Datatypes.getNN(Date.class); UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME); if (userSessionSource != null && userSessionSource.checkCurrentUserSession()) { name += datatype.format(snapshotDate, userSessionSource.getLocale()); } return StringUtils.trim(name); }
@Override public boolean isSpecificPermitted(String name) { return userSessionSource.getUserSession().isSpecificPermitted(name); }
@Inject protected void setUserSessionSource(UserSessionSource userSessionSource) { this.locale = userSessionSource.getLocale(); }
@Override protected Locale getUserLocale() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getLocale() : messageTools.getDefaultLocale(); }
@Override public String format(Object o) { if (o != null) { Datatype datatype = Datatypes.get(o.getClass()); if (datatype != null) { if (userSessionSource.checkCurrentUserSession()) { return datatype.format(o, userSessionSource.getLocale()); } else { return datatype.format(o); } } else if (o instanceof Enum) { return messages.getMessage((Enum) o); } else if (o instanceof Instance) { return ((Instance) o).getInstanceName(); } else { return String.valueOf(o); } } else { return null; } } }
protected boolean isGlobalAppFolderPermitted() { return userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.appFolder.global"); } }
@Inject public void setUserSessionSource(UserSessionSource userSessionSource) { this.locale = userSessionSource.getLocale(); }
@Override public UUID getCurrentUserId() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getUser().getId() : null; } }
protected void addCommonContext(Map<String, Object> context) { context.put("userSession", userSessionSource.getUserSession()); context.put("dataManager", dataManager); context.put("security", security); context.put("metadata", metadata); context.put("invalid", new MethodClosure(this, "invalidThrowMethod")); }
@Inject public void setUserSessionSource(UserSessionSource userSessionSource) { this.locale = userSessionSource.getLocale(); }
@Override protected Locale getUserLocale() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getLocale() : messageTools.getDefaultLocale(); }
@Override public boolean isScreenPermitted(String windowAlias) { return userSessionSource.getUserSession().isScreenPermitted(windowAlias); }
@Inject public void setUserSessionSource(UserSessionSource userSessionSource) { this.locale = userSessionSource.getLocale(); }