protected EntityLogAttr getAttrToSave(EntityLogAttr entityLogAttr, EntityLogItem itemToSave) { EntityLogAttr attr = itemToSave.getAttributes().stream() .filter(a -> a.getName().equals(entityLogAttr.getName())) .findFirst() .orElse(null); if (attr == null) { attr = metadata.create(EntityLogAttr.class); attr.setName(entityLogAttr.getName()); itemToSave.getAttributes().add(attr); } return attr; }
protected void setAttributeOldValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave) { EntityLogAttr attr = getAttrToSave(entityLogAttr, itemToSave); attr.setOldValue(entityLogAttr.getOldValue()); attr.setOldValueId(entityLogAttr.getOldValueId()); }
protected void setAttributeNewValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave) { EntityLogAttr attr = getAttrToSave(entityLogAttr, itemToSave); attr.setValue(entityLogAttr.getValue()); attr.setValueId(entityLogAttr.getValueId()); }
@MetaProperty public String getDisplayValue() { return getDisplayValue(getValue()); }
continue; EntityLogAttr attr = new EntityLogAttr(); attr.setLogItem(item); attr.setName(name); attr.setValue(properties.getProperty(name)); attr.setValueId(properties.getProperty(name + VALUE_ID_SUFFIX)); attr.setOldValue(properties.getProperty(name + OLD_VALUE_SUFFIX)); attr.setOldValueId(properties.getProperty(name + OLD_VALUE_ID_SUFFIX)); attr.setMessagesPack(properties.getProperty(name + MP_SUFFIX)); attributes.sort((o1, o2) -> Ordering.natural().compare(o1.getName(), o2.getName()));
.filter(entityLogAttr -> entityLogAttr.getName().equals(attributeName)) .findFirst() .ifPresent(entityLogAttr -> setAttributeOldValue(entityLogAttr, itemToSave)); .filter(entityLogAttr -> entityLogAttr.getName().equals(attributeName)) .findFirst() .ifPresent(entityLogAttr -> setAttributeNewValue(entityLogAttr, itemToSave)); properties.setProperty(attr.getName(), attr.getValue()); if (attr.getValueId() != null) { properties.setProperty(attr.getName() + EntityLogAttr.VALUE_ID_SUFFIX, attr.getValueId()); if (attr.getOldValue() != null) { properties.setProperty(attr.getName() + EntityLogAttr.OLD_VALUE_SUFFIX, attr.getOldValue()); if (attr.getOldValueId() != null) { properties.setProperty(attr.getName() + EntityLogAttr.OLD_VALUE_ID_SUFFIX, attr.getOldValueId()); if (attr.getMessagesPack() != null) { properties.setProperty(attr.getName() + EntityLogAttr.MP_SUFFIX, attr.getMessagesPack());
@MetaProperty public String getDisplayName() { String entityName = getLogItem().getEntity(); String message; com.haulmont.chile.core.model.MetaClass metaClass = getClassFromEntityName(entityName); if (metaClass != null) { Messages messages = AppBeans.get(Messages.NAME); message = messages.getTools().getPropertyCaption(metaClass, getName()); } else { return getName(); } return (message != null ? message : getName()); }
@MetaProperty public String getDisplayOldValue() { return getDisplayValue(getOldValue()); }
public String getLocValue(String value) { if (Strings.isNullOrEmpty(value)) return value; String entityName = getLogItem().getEntity(); com.haulmont.chile.core.model.MetaClass metaClass = getClassFromEntityName(entityName); if (metaClass != null) { com.haulmont.chile.core.model.MetaProperty property = metaClass.getProperty(name); if (property != null && property.getRange().isEnum()) { try { Enum caller = Enum.valueOf((Class<Enum>) property.getJavaType(), value); Messages messages = AppBeans.get(Messages.NAME); return messages.getMessage(caller); } catch (IllegalArgumentException ignored) {} } } if (!StringUtils.isBlank(messagesPack)) { Messages messages = AppBeans.get(Messages.NAME); return messages.getMessage(messagesPack, value); } else { return value; } } }
@MetaProperty public String getLocOldValue() { return getLocValue(oldValue); }
protected String getDisplayValue(String value) { if (StringUtils.isEmpty(value)) { return value; } final String entityName = getLogItem().getEntity(); com.haulmont.chile.core.model.MetaClass metaClass = getClassFromEntityName(entityName); if (metaClass != null) { com.haulmont.chile.core.model.MetaProperty property = metaClass.getProperty(getName()); if (property != null) { if (property.getRange().isDatatype()) { return value; } else if (property.getRange().isEnum()) { String nameKey = property.getRange().asEnumeration().getJavaClass().getSimpleName() + "." + value; String packageName = property.getRange().asEnumeration().getJavaClass().getPackage().getName(); Messages messages = AppBeans.get(Messages.NAME); return messages.getMessage(packageName, nameKey); } else { return value; } } else { return value; } } else { return value; } }
@MetaProperty public String getLocValue() { return getLocValue(value); }