Commit 1a6f11c0 by Tuomas Riihimäki

IrcStuff

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