@Override
  public void executeAction(
      WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params)
      throws WorkflowActionFailureException {
    if (LicenseUtil.getLevel() < 200) return; // the apis will do nothing anyway

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();
    User user = null;
    try {
      user = uWebAPI.getLoggedInUser(request);
    } catch (Exception exx) {
      throw new WorkflowActionFailureException(exx.getMessage());
    }
    Contentlet con = processor.getContentlet();

    List<InvalidLink> httpResponse = null;
    try {
      httpResponse = APILocator.getLinkCheckerAPI().findInvalidLinks(con);
    } catch (Exception e1) {
      Logger.error(this, e1.getMessage(), e1);
      throw new WorkflowActionFailureException(e1.getMessage());
    }

    // if there are unreachable URL...
    if (httpResponse.size() > 0) {
      String msg = "";
      try {
        msg = LanguageUtil.get(user, "checkURL.errorBrokenLinks");
      } catch (Exception e) {

      }
      throw new WorkflowActionFailureException(
          LinkCheckerUtil.buildPopupMsgWithLinksList(msg, httpResponse));
    }
  }
Example #2
0
  public void executeAction(
      WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params)
      throws WorkflowActionFailureException {

    String tweatThis = null;
    try {
      tweatThis = processor.getWorkflowMessage();
      if (!UtilMethods.isSet(tweatThis) && UtilMethods.isSet(params.get("fieldVar").getValue())) {
        tweatThis = processor.getContentlet().getStringProperty(params.get("fieldVar").getValue());
      }

      if (UtilMethods.isSet(tweatThis)) {

        if (tweatThis.length() > 140) {
          String error =
              LanguageUtil.get(
                  PublicCompanyFactory.getDefaultCompanyId(),
                  PublicCompanyFactory.getDefaultCompany().getLocale(),
                  "Tweet-too-long");
          if (error.equals("Tweet-too-long")) {
            error = error.replaceAll("-", " ");
          }

          throw new DotValidationException(error);
        }

        String consumerKey = null,
            consumerSecret = null,
            password = null,
            userName = null,
            accessToken = null,
            accessTokenSecret = null;

        consumerKey = params.get("consumerKey").getValue();
        consumerSecret = params.get("consumerSecret").getValue();
        accessToken = params.get("accessToken").getValue();
        accessTokenSecret = params.get("accessTokenSecret").getValue();

        String path =
            APILocator.getContentletAPI()
                .getUrlMapForContentlet(
                    processor.getContentlet(), APILocator.getUserAPI().getSystemUser(), false);

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
            .setOAuthConsumerKey(consumerKey)
            .setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessToken)
            .setOAuthAccessTokenSecret(accessTokenSecret);

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        Status stat = twitter.updateStatus(tweatThis);

        WorkflowComment comment = new WorkflowComment();
        comment.setPostedBy(processor.getUser().getUserId());
        comment.setComment("Tweeted: " + tweatThis + " twitterId:" + stat.getId());
        comment.setWorkflowtaskId(processor.getTask().getId());
        try {
          APILocator.getWorkflowAPI().saveComment(comment);
        } catch (DotDataException e) {
          Logger.error(CommentOnWorkflowActionlet.class, e.getMessage(), e);
        }
      }

    } catch (Exception e) {
      Logger.error(TwitterActionlet.class, e.getMessage());
      throw new WorkflowActionFailureException(e.getMessage());
    }
  }