use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class WebDatePicker method setDateRangeByProperty.
protected void setDateRangeByProperty(MetaProperty metaProperty) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
if (metaProperty.getAnnotations().get(Past.class.getName()) != null) {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
Date currentTimestamp = timeSource.currentTimestamp();
Calendar calendar = Calendar.getInstance(sessionSource.getLocale());
calendar.setTime(currentTimestamp);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
setRangeEnd(calendar.getTime());
} else if (metaProperty.getAnnotations().get(Future.class.getName()) != null) {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
Date currentTimestamp = timeSource.currentTimestamp();
Calendar calendar = Calendar.getInstance(sessionSource.getLocale());
calendar.setTime(currentTimestamp);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, 1);
setRangeStart(calendar.getTime());
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class FileDownloadHelper method makeUrl.
/**
* Creates URL for downloading a file.
*
* @param fd file descriptor
* @param attachment sets Content-Disposition: attachment
* @return URL string
*/
public static String makeUrl(FileDescriptor fd, boolean attachment) {
StringBuilder sb = new StringBuilder();
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
sb.append("dispatch/download?").append("s=").append(sessionSource.getUserSession().getId()).append("&").append("f=").append(fd.getId());
if (attachment)
sb.append("&a=true");
return sb.toString();
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class WindowCreationHelper method applyUiPermissions.
/**
* Apply UI permissions to a frame.
*
* @param container frame
*/
public static void applyUiPermissions(Frame container) {
Window window = container instanceof Window ? (Window) container : ComponentsHelper.getWindow(container);
if (window == null) {
log.warn(String.format("Unable to find window for container %s with id '%s'", container.getClass(), container.getId()));
return;
}
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = sessionSource.getUserSession();
String screenId = window.getId();
Map<String, Integer> uiPermissions = userSession.getPermissionsByType(PermissionType.UI);
for (Map.Entry<String, Integer> permissionEntry : uiPermissions.entrySet()) {
String target = permissionEntry.getKey();
String targetComponentId = getTargetComponentId(target, screenId);
if (targetComponentId != null) {
if (targetComponentId.contains("[")) {
applyCompositeComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else if (targetComponentId.contains(">")) {
applyComponentActionPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else {
applyComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
}
}
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class ListEditorHelper method getValueCaption.
public static String getValueCaption(Object v, ListEditor.ItemType itemType, TimeZone timeZone) {
if (v == null)
return null;
switch(itemType) {
case ENTITY:
if (v instanceof Instance)
return ((Instance) v).getInstanceName();
else
return v.toString();
case STRING:
return (String) v;
case DATE:
return Datatypes.getNN(java.sql.Date.class).format(v);
case DATETIME:
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = userSessionSource.getUserSession();
if (timeZone != null) {
return ((TimeZoneAwareDatatype) Datatypes.getNN(Date.class)).format(v, userSession.getLocale(), timeZone);
} else {
return Datatypes.getNN(Date.class).format(v, userSession.getLocale());
}
case INTEGER:
return Datatypes.getNN(Integer.class).format(v);
case LONG:
return Datatypes.getNN(Long.class).format(v);
case BIGDECIMAL:
return Datatypes.getNN(BigDecimal.class).format(v);
case DOUBLE:
return Datatypes.getNN(Double.class).format(v);
case ENUM:
return AppBeans.get(Messages.class).getMessage((Enum) v);
case UUID:
return Datatypes.getNN(java.util.UUID.class).format(v);
default:
throw new IllegalStateException("Unknown item type");
}
}
use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class DateValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null)
return;
boolean result;
if (value instanceof String) {
try {
Datatype datatype = Datatypes.getNN(java.sql.Date.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
datatype.parse((String) value, sessionSource.getLocale());
result = true;
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Date;
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
Aggregations