from psdi.server import MXServer; from psdi.mbo import MboConstants; ## Passed variables ## mbo (obviously) ## record_key ## record_type ## parent ## YORN_format -- determines if YORN is stored as 0 / 1 or FALSE / TRUE ## DESC_attribute - which attribute should be used as the "description" p = mbo.getUserInfo().getPersonId(); ## get the logged-on person once d = MXServer.getMXServer().getDate(); ## get the current date u = mbo.getUniqueIDValue(); object_name = mbo.getName(); vDesc = mbo.getString(DESC_attribute)[:255]; try: aset = MXServer.getMXServer().getMboSet("AUDIT_GRE", mbo.getUserInfo()); if (mbo.toBeAdded()): ## if we are INSERTING t = 'I'; ## set the type to 'I' elif (mbo.toBeDeleted()): t = 'D'; elif (mbo.toBeUpdated()): t = 'U'; else: t = ""; try: ## get a unique batch # for this transaction...better to use this for reporting batchset = MXServer.getMXServer().getMboSet("AUTOKEY", mbo.getUserInfo()); batchset.setWhere("autokeyname = 'AUDITBATCH_GRE'"); batchset.reset(); b = batchset.getMbo(0); batch = b.getInt("SEED"); b.setValue("SEED", batch + 1, 11L); batchset.save(); finally: batchset.close(); if (t in ("I", "U")): attrList = mbo.getThisMboSet().getMboSetInfo().getPersistentAttributes(); ## get the "persistent" attribute list while (attrList.hasNext()): ## loop through the persistent attributes try: mvi = attrList.next(); a = mvi.isEAuditEnabled(); ## figure out if we are audit-enabled n = mvi.getAttributeName(); ## get the attribute name v = mbo.getMboValue(n); ## get the attribute value data (we use this for "previous" and "next" values) i = v.getInitialValue().asString()[:3999]; x = v.getCurrentValue().asString()[:3999]; if (mvi.getType() == "YORN" and YORN_format == "FRIENDLY"): i = "TRUE" if i == "1" else "FALSE"; x = "TRUE" if x == "1" else "FALSE"; ## service.error("GRE", "MESSAGE", ["field = " + n + " audit = " + str(a) + "modified = " + str(v.isModified())]) if (v.isModified() and a and i != x): ## if we were modified and if we are auditable ## if (True): currentATTR = n; a = aset.add(); ## add an audit row ## write all the values to the audit row in the AUDIT_GRE table a.setValue("OBJECTNAME", object_name, 11L); a.setValue("ATTRIBUTENAME", n, 11L); a.setValue("RECORDKEY", record_key, 11L); a.setValue("CLASS", record_type, 11L); a.setValue("BATCH", batch, 11L); ## here is that batch number a.setValue("CHANGEBY", p, 11L); ## who did it a.setValue("CHANGEDATE", d, 11L); ## when it happened a.setValue("PREVIOUSVALUE", i, 11L); ## what the OLD value was a.setValue("NEWVALUE", x, 11L); ## what the NEW value is a.setValue("EAUDITTYPE", t, 11L); ## the transaction type a.setValue("UNIQUEID", u, 11L); ## the unique ID a.setValue("PARENT", parent, 11L); ## the parent a.setValue("DESCRIPTION", vDesc, 11L); ## the description except: varX = 1; ldList = mbo.getThisMboSet().getMboSetInfo().getLongDescriptionAttributes(); ## get the "long description" attribute list while (ldList.hasNext()): ## loop through the long description attributes try: mvi = ldList.next(); a = mvi.isEAuditEnabled(); ## figure out if we are audit-enabled n = mvi.getAttributeName() + "_LONGDESCRIPTION"; ## get the attribute name v = mbo.getMboValue(n); ## get the attribute value data (we use this for "previous" and "next" values i = v.getInitialValue().asString()[:3900]; x = v.getCurrentValue().asString()[:3900]; if (v.isModified() and a and i != x): ## if we were modified and if we are auditable currentATTR = n; a = aset.add(); ## add an audit row ## write all the values to the audit row in the AUDIT_GRE table a.setValue("OBJECTNAME", object_name, 11L); a.setValue("ATTRIBUTENAME", n, 11L); a.setValue("RECORDKEY", record_key, 11L); a.setValue("CLASS", record_type, 11L); a.setValue("BATCH", batch, 11L); ## here is that batch number a.setValue("CHANGEBY", p, 11L); ## who did it a.setValue("CHANGEDATE", d, 11L); ## when it happened a.setValue("PREVIOUSVALUE", i, 11L); ## what the OLD value was a.setValue("NEWVALUE", x, 11L); ## what the NEW value is a.setValue("EAUDITTYPE", t, 11L); ## the transaction type a.setValue("UNIQUEID", u, 11L); ## the unique ID a.setValue("PARENT", parent, 11L); ## the parent a.setValue("DESCRIPTION", vDesc, 11L); ## the description except: varX = 1; if (t == "D"): a = aset.add(); a.setValue("OBJECTNAME", object_name, 11L); a.setValue("RECORDKEY", record_key, 11L); a.setValue("CLASS", record_type, 11L); a.setValue("BATCH", batch, 11L); ## here is that batch number a.setValue("CHANGEBY", p, 11L); ## who did it a.setValue("CHANGEDATE", d, 11L); ## when it happened a.setValue("EAUDITTYPE", t, 11L); ## the transaction type a.setValue("UNIQUEID", u, 11L); ## the unique ID a.setValue("PARENT", parent, 11L); ## the parent a.setValue("DESCRIPTION", vDesc, 11L); ## the description aset.save(); ## save the audit set finally: aset.close();