Search in sources :

Example 1 with EntityAudit

use of org.motechproject.mds.domain.EntityAudit in project motech by motech.

the class AllEntityAudits method createAudit.

public EntityAudit createAudit(Entity entity, String username) {
    EntityAudit audit = new EntityAudit();
    audit.setOwnerUsername(username);
    audit.setModificationDate(DateUtil.nowUTC());
    audit.setVersion(entity.getEntityVersion());
    audit.setName(entity.getName());
    audit.setClassName(entity.getClassName());
    audit.setNamespace(entity.getNamespace());
    audit.setTableName(entity.getTableName());
    audit.setModule(entity.getModule());
    for (Field field : entity.getFields()) {
        Field tmp = field.copy();
        tmp.setId(null);
        audit.addField(tmp);
    }
    for (Lookup lookup : entity.getLookups()) {
        audit.addLookup(lookup.copy(entity.getFields()));
    }
    if (entity.getRestOptions() != null) {
        RestOptions restOptions = entity.getRestOptions().copy();
        restOptions.setEntity(audit);
        audit.setRestOptions(restOptions);
    }
    if (entity.getTracking() != null) {
        Tracking tracking = entity.getTracking().copy();
        tracking.setEntity(audit);
        audit.setTracking(tracking);
    }
    return create(audit);
}
Also used : EntityAudit(org.motechproject.mds.domain.EntityAudit) Field(org.motechproject.mds.domain.Field) Tracking(org.motechproject.mds.domain.Tracking) Lookup(org.motechproject.mds.domain.Lookup) RestOptions(org.motechproject.mds.domain.RestOptions)

Aggregations

EntityAudit (org.motechproject.mds.domain.EntityAudit)1 Field (org.motechproject.mds.domain.Field)1 Lookup (org.motechproject.mds.domain.Lookup)1 RestOptions (org.motechproject.mds.domain.RestOptions)1 Tracking (org.motechproject.mds.domain.Tracking)1