1 21 package com.jaspersoft.jasperserver.war.action; 22 23 import java.util.List ; 24 25 import org.springframework.webflow.action.FormAction; 26 import org.springframework.webflow.Event; 27 import org.springframework.webflow.RequestContext; 28 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService; 29 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria; 30 import com.jaspersoft.jasperserver.api.common.domain.LogEvent; 31 import com.jaspersoft.jasperserver.api.engine.common.service.LoggingService; 32 33 public class LogEventAction extends FormAction 34 { 35 36 private LoggingService loggingService; 37 private static final String SHOW_ALL_EVENTS = "showAll"; 38 private static final String SHOW_UNREAD_EVENTS = "showUnread"; 39 private static final String SHOW_EVENTS = "showEvents"; 40 41 42 public LoggingService getLoggingService() 43 { 44 return loggingService; 45 } 46 47 public void setLoggingService(LoggingService loggingService) 48 { 49 this.loggingService = loggingService; 50 } 51 52 53 public Event getEvents(RequestContext context) throws Exception 54 { 55 List events = null; 56 57 String show = (String ) context.getFlowScope().get(SHOW_EVENTS); 58 if (SHOW_ALL_EVENTS.equals(show)) 59 events = loggingService.getUserEvents(null); 60 else if (SHOW_UNREAD_EVENTS.equals(show)) 61 events = loggingService.getUnreadEvents(null); 62 else 63 events = loggingService.getUserEvents(null); 64 65 context.getFlowScope().put("events", events); 66 67 return success(); 68 } 69 72 public Event changeEventsType(RequestContext context) throws Exception 73 { 74 String show = context.getRequestParameters().get(SHOW_EVENTS); 75 context.getFlowScope().put(SHOW_EVENTS, show); 76 return success(); 77 } 78 79 80 private long[] getIds(RequestContext context) 81 { 82 String [] stringIds; 83 long[] ids; 84 85 if (context.getRequestParameters().contains("selectedIds")) 86 { 87 Object parameter = context.getRequestParameters().getMap().get("selectedIds"); 88 if (parameter instanceof String ) 89 stringIds = new String []{(String )parameter}; 90 else 91 stringIds = (String [])parameter; 92 93 ids = new long[stringIds.length]; 94 for (int i = 0; i < stringIds.length; i++) 95 ids[i] = Long.parseLong(stringIds[i]); 96 return ids; 97 } 98 return null; 99 } 100 101 public Event delete(RequestContext context) throws Exception 102 { 103 long[] ids = getIds(context); 104 if (ids != null) 105 loggingService.delete(null, ids); 106 return success(); 107 } 108 109 public Event markAsRead(RequestContext context) throws Exception 110 { 111 long[] ids = getIds(context); 112 if (ids != null) { 113 for (int i = 0; i < ids.length; i++) { 114 LogEvent event = loggingService.getLogEvent(null, ids[i]); 115 if (event.getState() != LogEvent.STATE_READ) { 116 event.setState(LogEvent.STATE_READ); 117 loggingService.update(event); 118 } 119 } 120 } 121 return success(); 122 } 123 124 125 public Event markAsUnread(RequestContext context) throws Exception 126 { 127 long[] ids = getIds(context); 128 if (ids != null) { 129 for (int i = 0; i < ids.length; i++) { 130 LogEvent event = loggingService.getLogEvent(null, ids[i]); 131 if (event.getState() != LogEvent.STATE_UNREAD) { 132 event.setState(LogEvent.STATE_UNREAD); 133 loggingService.update(event); 134 } 135 } 136 } 137 return success(); 138 } 139 140 141 144 public Event setupViewForm(RequestContext context) throws Exception 145 { 146 String id = context.getRequestParameters().get("eventId"); 147 try { 148 LogEvent event = loggingService.getLogEvent(null, Long.parseLong(id)); 149 if (event.getState() == LogEvent.STATE_UNREAD) { 150 event.setState(LogEvent.STATE_READ); 151 loggingService.update(event); 152 } 153 context.getRequestScope().put("event", event); 154 return success(); 155 } catch(NumberFormatException e) { 156 return error(); 157 } 158 } 159 160 } 161 | Popular Tags |