@GET @Path("/clearMybatisCache") @Produces({"application/json"}) public Response clearCache(@QueryParam("key") String param1) { String appkey = Config.Current().Database.AppKey.Value; if (param1 == null) { return Response.status(200).entity("Please provide the pass key.").build(); } if (param1.equals(appkey)) { try { MyBatis.SessionFactory.ClearCache(); } catch (Exception e) { log.error("Unable to Clear Cache"); return Response.status(200).entity("Unable to remove Cache").build(); } Config.ClearConfig(); return Response.status(200).entity("Removed Cache").build(); } else { return Response.status(200).entity("Invalid Key").build(); } }
public class SomsVerolliAuditService { static Logger log = Logger.getLogger(SomsVerolliAuditService.class.getName()); private static SimpleDateFormat _dateFormat = new SimpleDateFormat(Config.Current().Common.Date.DateFormatWithTime); public static boolean logAudit( String context, String status, String data, String message, Notification notification) { boolean isLogCaptured = false; try { MyBatis.SessionFactoryAudit.Insert( "com.dal.SomsVerolliLogMapper.insertAudit", populatedAuditFields(context, status, data, message, notification)); isLogCaptured = true; } catch (Exception exp) { log.error("Error occurred while logging events for audit", exp); exp.printStackTrace(); } return isLogCaptured; } public static boolean logSomsAudit( String context, String status, String data, String message, Notification notification) { boolean isLogCaptured = false; try { Source source = populatedSourceFields(data); MyBatis.SessionFactoryAudit.Insert("com.dal.SomsVerolliLogMapper.insertSource", source); MyBatis.SessionFactoryAudit.Insert( "com.dal.SomsVerolliLogMapper.insertAudit", populatedAuditFields(context, status, source.getId(), message, notification)); isLogCaptured = true; } catch (Exception exp) { log.error("Error occurred while logging events for audit", exp); exp.printStackTrace(); } return isLogCaptured; } private static Source populatedSourceFields(String message) { Source source = new Source(); source.Id = UUID.randomUUID().toString(); source.StartDate = _dateFormat.format(new Date()); source.UpdateDate = _dateFormat.format(new Date()); source.Message = message; return source; } private static SomsVerolliLog populatedAuditFields( String context, String status, String data, String message, Notification notification) { SomsVerolliLog somsVerolliAudit = new SomsVerolliLog(); try { somsVerolliAudit.Id = UUID.randomUUID().toString(); somsVerolliAudit.EntryDate = _dateFormat.format(new Date()); somsVerolliAudit.IPAddress = getIPAddress(); somsVerolliAudit.Status = status; somsVerolliAudit.Context = context; somsVerolliAudit.Message = message; somsVerolliAudit.DataProcessed = data; somsVerolliAudit.notificationId = notification.Id; somsVerolliAudit.triggerId = notification.TriggerId; } catch (Exception exception) { exception.printStackTrace(); } return somsVerolliAudit; } private static String getIPAddress() { InetAddress ipAddress = null; try { ipAddress = InetAddress.getLocalHost(); // System.out.println("IP:"+ipAddress.getHostAddress()); // log.info("IP:"+ipAddress.getHostAddress()); } catch (Exception e) { log.error("Exception occurred while fetching IP address for logging audit", e); e.printStackTrace(); } return ipAddress.getHostAddress(); } }