/*
O * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.gui.controladores.seguridad;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Textbox;

import com.rjconsultores.ventaboletos.auditoria.AuditControl;
import com.rjconsultores.ventaboletos.entidad.AuditLog;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;

@Controller("auditModuleDetailController")
@Scope("prototype")
public class AuditModuleDetailController extends MyGenericForwardComposer {

	private static final long serialVersionUID = 1L;
	private static Logger log = LogManager.getLogger(AuditModuleDetailController.class);
	
	private Textbox txtEntityJson;

	@Override
	public void doAfterCompose(Component comp) throws Exception{

		super.doAfterCompose(comp);

		AuditLog auditLog = (AuditLog) Executions.getCurrent().getArg().get("auditLog");

		Class<?> clazz;
		try {
			clazz = Class.forName("com.rjconsultores.ventaboletos.entidad.".concat(auditLog.getEntityName()));
			Object clazzJson = AuditControl.getGson().fromJson(auditLog.getEntityDetail(), clazz);
			
			txtEntityJson.setValue(AuditControl.formatJson(clazzJson, true));
		} catch (ClassNotFoundException e) {
			log.debug("Não encontrou Classe " + "com.rjconsultores.ventaboletos.entidad.".concat(auditLog.getEntityName()));
		}		
	}
}
