use of io.jmix.audit.entity.EntityLogAttr in project jmix by jmix-framework.
the class EntityLogImpl method internalRegisterModify.
protected EntityLogItem internalRegisterModify(Object entity, @Nullable AttributeChanges changes, MetaClass metaClass, String storeName, Set<String> attributes) {
EntityLogItem item = null;
Date ts = timeSource.currentTimestamp();
Set<String> dirty = calculateDirtyFields(entity, changes);
Set<EntityLogAttr> entityLogAttrs;
EntityLogItem.Type type;
if (isSoftDeleteEntityRestored(entity, dirty)) {
type = EntityLogItem.Type.RESTORE;
entityLogAttrs = createLogAttributes(entity, attributes, changes);
} else {
type = EntityLogItem.Type.MODIFY;
Set<String> dirtyAttributes = new HashSet<>();
for (String attributePath : attributes) {
if (metadataTools.isAdditionalProperty(metaClass, attributePath)) {
if (dirty.contains(attributePath)) {
dirtyAttributes.add(attributePath);
}
continue;
}
MetaPropertyPath propertyPath = metaClass.getPropertyPath(attributePath);
Preconditions.checkNotNullArgument(propertyPath, "Property path %s isn't exists for type %s", attributePath, metaClass.getName());
if (dirty.contains(attributePath)) {
dirtyAttributes.add(attributePath);
} else if (!stores.getAdditional().isEmpty()) {
String idAttributePath = getIdAttributePath(propertyPath, storeName);
if (idAttributePath != null && dirty.contains(idAttributePath)) {
dirtyAttributes.add(attributePath);
}
}
}
entityLogAttrs = createLogAttributes(entity, dirtyAttributes, changes);
}
if (!entityLogAttrs.isEmpty() || type == EntityLogItem.Type.RESTORE) {
item = metadata.create(EntityLogItem.class);
item.setEventTs(ts);
item.setUsername(findUsername());
item.setType(type);
item.setEntity(extendedEntities.getOriginalOrThisMetaClass(metaClass).getName());
item.setEntityInstanceName(metadataTools.getInstanceName(entity));
item.getEntityRef().setObjectEntityId(referenceToEntitySupport.getReferenceId(entity));
item.setAttributes(entityLogAttrs);
}
return item;
}
use of io.jmix.audit.entity.EntityLogAttr in project jmix by jmix-framework.
the class EntityLogImpl method computeChanges.
protected void computeChanges(EntityLogItem itemToSave, List<EntityLogItem> sameEntityList) {
Set<String> attributes = sameEntityList.stream().flatMap(entityLogItem -> entityLogItem.getAttributes().stream().map(EntityLogAttr::getName)).collect(Collectors.toSet());
processAttributes(itemToSave, sameEntityList, attributes);
Properties properties = new Properties();
for (EntityLogAttr attr : itemToSave.getAttributes()) {
properties.setProperty(attr.getName(), Strings.nullToEmpty(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());
}
}
if (itemToSave.getType() == EntityLogItem.Type.MODIFY) {
sameEntityList.stream().filter(entityLogItem -> entityLogItem.getType() == EntityLogItem.Type.CREATE).findFirst().ifPresent(entityLogItem -> itemToSave.setType(EntityLogItem.Type.CREATE));
}
itemToSave.setChanges(getChanges(properties));
}
use of io.jmix.audit.entity.EntityLogAttr in project jmix by jmix-framework.
the class EntityLogImpl method setAttributeOldValue.
protected void setAttributeOldValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave) {
EntityLogAttr attr = getAttrToSave(entityLogAttr, itemToSave);
attr.setOldValue(entityLogAttr.getOldValue());
attr.setOldValueId(entityLogAttr.getOldValueId());
}
use of io.jmix.audit.entity.EntityLogAttr in project jmix by jmix-framework.
the class EntityLogImpl method getAttrToSave.
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;
}
use of io.jmix.audit.entity.EntityLogAttr in project jmix by jmix-framework.
the class EntityLogImpl method setAttributeNewValue.
protected void setAttributeNewValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave) {
EntityLogAttr attr = getAttrToSave(entityLogAttr, itemToSave);
attr.setValue(entityLogAttr.getValue());
attr.setValueId(entityLogAttr.getValueId());
}
Aggregations