Search in sources :

Example 1 with EntitySnapshot

use of io.jmix.audit.entity.EntitySnapshot in project jmix by jmix-framework.

the class EntitySnapshotDataStoreImpl method save.

@Override
public EntitySnapshotModel save(EntitySnapshotModel entitySnapshotModel) {
    EntitySnapshot entitySnapshot = entitySnapshotModelConverter.createEntitySnapshot(entitySnapshotModel);
    entitySnapshot = unconstrainedDataManager.save(entitySnapshot);
    return entitySnapshotModelConverter.createEntitySnapshotModel(entitySnapshot);
}
Also used : EntitySnapshot(io.jmix.audit.entity.EntitySnapshot)

Example 2 with EntitySnapshot

use of io.jmix.audit.entity.EntitySnapshot in project jmix by jmix-framework.

the class EntitySnapshotDataStoreImpl method findLastSnapshot.

@Override
public EntitySnapshotModel findLastSnapshot(Object entity, MetaClass entityMetaClass) {
    MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(entityMetaClass);
    LoadContext<EntitySnapshot> lx = new LoadContext<EntitySnapshot>(metadata.getClass(EntitySnapshot.class)).setQuery(new LoadContext.Query(format("select e from audit_EntitySnapshot e where e.entityMetaClass = :metaClass and" + " e.entity.%s = :entityId order by e.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass))).setParameter("metaClass", metaClass.getName()).setParameter("entityId", referenceToEntitySupport.getReferenceId(entity)).setMaxResults(1));
    return entitySnapshotModelConverter.createEntitySnapshotModel(unconstrainedDataManager.load(lx));
}
Also used : EntitySnapshot(io.jmix.audit.entity.EntitySnapshot) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 3 with EntitySnapshot

use of io.jmix.audit.entity.EntitySnapshot in project jmix by jmix-framework.

the class EntitySnapshotDataStoreImpl method findLastSnapshotById.

@Override
public EntitySnapshotModel findLastSnapshotById(Object referenceId, MetaClass metaClass) {
    MetaClass originalMetaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass);
    LoadContext<EntitySnapshot> entitySnapshotLoadContext = new LoadContext<EntitySnapshot>(metadata.getClass(EntitySnapshot.class)).setQuery(new LoadContext.Query(String.format("select e from audit_EntitySnapshot e where e.entityMetaClass = :metaClass and" + " e.entity.%s = :entityId order by e.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(originalMetaClass))).setParameter("metaClass", originalMetaClass.getName()).setParameter("entityId", referenceId).setMaxResults(1));
    return entitySnapshotModelConverter.createEntitySnapshotModel(unconstrainedDataManager.load(entitySnapshotLoadContext));
}
Also used : EntitySnapshot(io.jmix.audit.entity.EntitySnapshot) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 4 with EntitySnapshot

use of io.jmix.audit.entity.EntitySnapshot in project jmix by jmix-framework.

the class EntitySnapshotModelConverter method createEntitySnapshot.

public EntitySnapshot createEntitySnapshot(EntitySnapshotModel entitySnapshotModel) {
    if (entitySnapshotModel == null) {
        return null;
    }
    EntitySnapshot entitySnapshot = metadata.create(EntitySnapshot.class);
    ReferenceToEntity referenceToEntity = metadata.create(ReferenceToEntity.class);
    referenceToEntity.setEntityId(entitySnapshotModel.getEntityId());
    referenceToEntity.setIntEntityId(entitySnapshotModel.getIntEntityId());
    referenceToEntity.setLongEntityId(entitySnapshotModel.getLongEntityId());
    referenceToEntity.setStringEntityId(entitySnapshotModel.getStringEntityId());
    entitySnapshot.setEntity(referenceToEntity);
    entitySnapshot.setSnapshotXml(entitySnapshotModel.getSnapshotXml());
    entitySnapshot.setSnapshotDate(entitySnapshotModel.getSnapshotDate());
    entitySnapshot.setCreatedBy(entitySnapshotModel.getCreatedBy());
    entitySnapshot.setCreatedDate(entitySnapshotModel.getCreatedDate());
    entitySnapshot.setSysTenantId(entitySnapshotModel.getSysTenantId());
    entitySnapshot.setFetchPlanXml(entitySnapshotModel.getFetchPlanXml());
    entitySnapshot.setEntityMetaClass(entitySnapshotModel.getEntityMetaClass());
    entitySnapshot.setAuthorUsername(entitySnapshotModel.getAuthorUsername());
    return entitySnapshot;
}
Also used : EntitySnapshot(io.jmix.audit.entity.EntitySnapshot) ReferenceToEntity(io.jmix.data.entity.ReferenceToEntity)

Aggregations

EntitySnapshot (io.jmix.audit.entity.EntitySnapshot)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 ReferenceToEntity (io.jmix.data.entity.ReferenceToEntity)1