@Ignore @Test @Override public void postNotice() { NotificationStrategy ns = new MicroblogDMNotificationStrategy(m_daoConfigResource); List<Argument> arguments = configureArgs(); Assert.assertEquals("NotificationStrategy should return 0 on success", 0, ns.send(arguments)); }
@Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { log().error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); if (log().isDebugEnabled()) { log().debug("Dispatching microblog DM notification for user '" + svc.getUserId() + "' at base URL '" + svc.getBaseURL() + "' with destination user '" + destUser + "' and message '" + fullMessage + "'"); } try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { log().error("Microblog notification failed"); log().info("Failed to send DM for user '" + svc.getUserId() + "' at service URL '" + svc.getBaseURL() + "' to destination user '" + destUser + "', caught exception: " + e.getMessage()); return 1; } log().info("Microblog DM notification succeeded: DM sent with ID " + response.getId()); return 0; }
MicroblogDMNotificationStrategy extends MicroblogNotificationStrategy { @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { log().error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); if (log().isDebugEnabled()) { log().debug("Dispatching microblog DM notification for user '" + svc.getUserId() + "' at base URL '" + svc.getBaseURL() + "' with destination user '" + destUser + "' and message '" + fullMessage + "'"); } try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { log().error("Microblog notification failed"); log().info("Failed to send DM for user '" + svc.getUserId() + "' at service URL '" + svc.getBaseURL() + "' to destination user '" + destUser + "', caught exception: " + e.getMessage()); return 1; } log().info("Microblog DM notification succeeded: DM sent with ID " + response.getId()); return 0; } }
MicroblogDMNotificationStrategy extends MicroblogNotificationStrategy { @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { log().error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); if (log().isDebugEnabled()) { log().debug("Dispatching microblog DM notification for user '" + svc.getUserId() + "' at base URL '" + svc.getBaseURL() + "' with destination user '" + destUser + "' and message '" + fullMessage + "'"); } try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { log().error("Microblog notification failed"); log().info("Failed to send DM for user '" + svc.getUserId() + "' at service URL '" + svc.getBaseURL() + "' to destination user '" + destUser + "', caught exception: " + e.getMessage()); return 1; } log().info("Microblog DM notification succeeded: DM sent with ID " + response.getId()); return 0; } MicroblogDMNotificationStrategy();  MicroblogDMNotificationStrategy(Resource configResource); }
MicroblogDMNotificationStrategy extends MicroblogNotificationStrategy { @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { log().error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); if (log().isDebugEnabled()) { log().debug("Dispatching microblog DM notification for user '" + svc.getUserId() + "' at base URL '" + svc.getBaseURL() + "' with destination user '" + destUser + "' and message '" + fullMessage + "'"); } try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { log().error("Microblog notification failed"); log().info("Failed to send DM for user '" + svc.getUserId() + "' at service URL '" + svc.getBaseURL() + "' to destination user '" + destUser + "', caught exception: " + e.getMessage()); return 1; } log().info("Microblog DM notification succeeded: DM sent with ID " + response.getId()); return 0; } MicroblogDMNotificationStrategy();  MicroblogDMNotificationStrategy(Resource configResource); @Override int send(List<Argument> arguments); }
MicroblogDMNotificationStrategy extends MicroblogNotificationStrategy { @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { log().error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); if (log().isDebugEnabled()) { log().debug("Dispatching microblog DM notification for user '" + svc.getUserId() + "' at base URL '" + svc.getBaseURL() + "' with destination user '" + destUser + "' and message '" + fullMessage + "'"); } try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { log().error("Microblog notification failed"); log().info("Failed to send DM for user '" + svc.getUserId() + "' at service URL '" + svc.getBaseURL() + "' to destination user '" + destUser + "', caught exception: " + e.getMessage()); return 1; } log().info("Microblog DM notification succeeded: DM sent with ID " + response.getId()); return 0; } MicroblogDMNotificationStrategy();  MicroblogDMNotificationStrategy(Resource configResource); @Override int send(List<Argument> arguments);  }