@Override public void receive(LockInfo message) { LockKey key = new LockKey(message.getEntityName(), message.getEntityId()); if (message.getUser() != null) { LockInfo lockInfo = locks.get(key); if (lockInfo == null || lockInfo.getSince().before(message.getSince())) { locks.put(key, message); } } else { locks.remove(key); } }
/** * Pessimistic lock before start of editing, if it is configured for the entity. */ protected boolean lockIfNeeded(Entity entity) { MetaClass metaClass = getMetaClassForLocking(entity); LockInfo lockInfo = AppBeans.get(LockService.class).lock(metaClass.getName(), entity.getId().toString()); if (lockInfo == null) { justLocked = true; } else if (!(lockInfo instanceof LockNotSupported)) { showNotification( messages.getMainMessage("entityLocked.msg"), String.format(messages.getMainMessage("entityLocked.desc"), lockInfo.getUser().getLogin(), AppBeans.get(DatatypeFormatter.class).formatDateTime(lockInfo.getSince()) ), Frame.NotificationType.HUMANIZED ); return false; } return true; }
/** * Pessimistic lock before start of editing, if it is configured for the entity. */ protected boolean lockIfNeeded(Entity entity) { LockService lockService = getBeanLocator().get(LockService.class); LockInfo lockInfo = lockService.lock(getLockName(), entity.getId().toString()); if (lockInfo == null) { justLocked = true; } else if (!(lockInfo instanceof LockNotSupported)) { Messages messages = getBeanLocator().get(Messages.class); DatatypeFormatter datatypeFormatter = getBeanLocator().get(DatatypeFormatter.class); Notifications notifications = getScreenContext().getNotifications(); notifications.create(NotificationType.HUMANIZED) .withCaption(messages.getMainMessage("entityLocked.msg")) .withDescription(String.format(messages.getMainMessage("entityLocked.desc"), lockInfo.getUser().getLogin(), datatypeFormatter.formatDateTime(lockInfo.getSince()))) .show(); return false; } return true; }
.withDescription( messages.formatMainMessage("entityLocked.desc", lockInfo.getUser().getLogin(), datatypeFormatter.formatDateTime(lockInfo.getSince()) ))
messages.getMainMessage("entityLocked.msg"), String.format(messages.getMainMessage("entityLocked.desc"), lockInfo.getUser().getLogin(), Datatypes.getNN(Date.class).format(lockInfo.getSince(), userSessionSource.getLocale()) ),