Commit 1a6f11c0 by Tuomas Riihimäki

IrcStuff

1 parent ad194633
...@@ -44,22 +44,24 @@ import fi.codecrew.moya.model.User; ...@@ -44,22 +44,24 @@ import fi.codecrew.moya.model.User;
* Session Bean implementation class SercurityBean * Session Bean implementation class SercurityBean
*/ */
@Stateless @Stateless
@TransactionManagement(TransactionManagementType.BEAN) //@TransactionManagement(TransactionManagementType.BEAN)
public class LoggingBean implements LoggingBeanLocal { public class LoggingBean implements LoggingBeanLocal {
private static final boolean DEBUG = true; private static final boolean DEBUG = true;
private final Logger logger = org.slf4j.LoggerFactory private final Logger logger = org.slf4j.LoggerFactory
.getLogger(LoggingBean.class); .getLogger(LoggingBean.class);
@EJB // @EJB
private LogEntryTypeFacade typeFacade; // private LogEntryTypeFacade typeFacade;
@EJB // @EJB
private LogEntryFacade entryFacade; // private LogEntryFacade entryFacade;
@EJB @EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
@EJB
private MoyaEventSender sender;
@Resource // @Resource
UserTransaction utx; // UserTransaction utx;
// @Override // @Override
// public LogEntry logPermissionDenied(User user, Exception exception) { // public LogEntry logPermissionDenied(User user, Exception exception) {
...@@ -113,28 +115,25 @@ public class LoggingBean implements LoggingBeanLocal { ...@@ -113,28 +115,25 @@ public class LoggingBean implements LoggingBeanLocal {
public LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, public LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user,
Object... description) { Object... description) {
LogEntry entry = null; LogEntry entry = null;
if (event == null) if (event == null) {
{
event = eventbean.getCurrentEvent(); event = eventbean.getCurrentEvent();
} }
try { try {
String desc = toString(description); String desc = toString(description);
utx.begin(); logger.warn("Sending logmsg {}", desc);
LogEntryType type = typeFacade.findOrCreate(paramType); //LogEntryType type = typeFacade.findOrCreate(paramType);
entry = new LogEntry(Calendar.getInstance()); // entry = new LogEntry(Calendar.getInstance());
entry.setParentEvent(event); // entry.setParentEvent(event);
entry.setType(type); // entry.setType(type);
entry.setDescription(desc); // entry.setDescription(desc);
entry.setUser(user); // entry.setUser(user);
entryFacade.create(entry); // entryFacade.create(entry);
if (DEBUG) { String msg = "SECURITY DEBUG: Type: \"" + paramType.name() +
logger.debug( "\" user \"" + paramType.name() +
"SECURITY DEBUG: Type: \"{}\" user \"{}\", description \"{}\"", "\", description \"" + ((user == null) ? "null" : user.getLogin()) + "\"" + desc;
new String[] { paramType.name(), sender.sendMessage(msg);
(user == null) ? "null" : user.getLogin(), desc }); // utx.commit();
}
utx.commit();
} catch (Exception e) { } catch (Exception e) {
logger.warn("Exception at SecurityBean", e); logger.warn("Exception at SecurityBean", e);
} }
......
...@@ -52,6 +52,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -52,6 +52,7 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BotBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
...@@ -73,6 +74,9 @@ public class IrcServlet extends HttpServlet { ...@@ -73,6 +74,9 @@ public class IrcServlet extends HttpServlet {
private PermissionBeanLocal permBean; private PermissionBeanLocal permBean;
private final ArrayList<IrcBot> bots = new ArrayList<>(); private final ArrayList<IrcBot> bots = new ArrayList<>();
@EJB
private BotBeanLocal botbean;
/** /**
* @see HttpServlet#HttpServlet() * @see HttpServlet#HttpServlet()
*/ */
...@@ -81,10 +85,6 @@ public class IrcServlet extends HttpServlet { ...@@ -81,10 +85,6 @@ public class IrcServlet extends HttpServlet {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
private class EventListener {
}
@EJB @EJB
private PlaceBeanLocal placebean; private PlaceBeanLocal placebean;
...@@ -92,23 +92,10 @@ public class IrcServlet extends HttpServlet { ...@@ -92,23 +92,10 @@ public class IrcServlet extends HttpServlet {
* @see Servlet#init(ServletConfig) * @see Servlet#init(ServletConfig)
*/ */
public void init(ServletConfig config) throws ServletException { public void init(ServletConfig config) throws ServletException {
IrcBot bot = new IrcBot("irc.cc.tut.fi", "#codecrew.ry", "moya-bot"); IrcBot bot = new IrcBot("irc.cc.tut.fi", "#moya-debug", "moya-bot");
bot.addCmdListener("places", new IrcPlaceFetcher(placebean)); botbean.add(bot);
bots.add(bot); bots.add(bot);
bot.start(); bot.start();
bot.addCmdListener("foo", new IrcBotListener() {
@Override
public String getUsageMessage() {
// TODO Auto-generated method stub
return null;
}
@Override
public void executeIrc(IrcBot bot, String data) {
bot.say("");
}
});
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!