/** {@inheritDoc} */
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {

    try {

      final List<CitrusTestLinkFileBean> beanList =
          this.fileHandler.readFromDirectory(this.directory);

      if ((null != beanList) && (!beanList.isEmpty())) {

        for (final CitrusTestLinkFileBean beanFile : beanList) {

          final CitrusTestLinkBean bean = beanFile.getBean();

          bean.setUrl(this.url);
          bean.setKey(this.devKey);

          this.handler.writeToTestLink(bean);

          this.handleResponse(bean, beanFile.getFile());
        }
      } else {

        this.getLog().error("No CITRUS test cases found in directory [ " + this.directory + " ]");
      }
    } catch (final Exception ex) {

      this.getLog().error("Exception caught!", ex);
    }
  }
  /**
   * Depending on the response values build response and log the result.
   *
   * @param bean CITRUS TestLink bean holding response.
   * @param file DOCUMENT ME!
   */
  private void handleResponse(final CitrusTestLinkBean bean, final File file) {

    // there was some error writing to TestLink, log it
    final StringBuilder builder = new StringBuilder();

    // check if there was some writing to TestLink
    if (null != bean.getResponseState()) {

      // check if writing to TestLink was successful
      if (bean.getResponseState().booleanValue()) {

        // YEAH it was
        this.getLog()
            .info(
                "+++===+++ Writing to TestLink was successful for [ "
                    + bean.getId()
                    + " ] +++===+++");

        if (!FileUtils.delete(file)) {

          this.getLog().error("Could not delete file [ " + file + " ]");
        }

        // done with response successful
        return;
      }
    }

    builder.append("\n+++===+++\n");
    builder.append("Failure writing to TestLink");

    if (!bean.getResponseList().isEmpty()) {

      builder.append(" due to \n");

      for (final String response : bean.getResponseList()) {

        builder.append(response);
        builder.append("\n");
      }
    } else {

      builder.append("!\n");
    }

    if (null != bean.getResponseCause()) {

      builder.append("\nException caught:\n");
      builder.append(ConvertUtils.throwableToString(bean.getResponseCause()));
      builder.append("\n");
    }

    builder.append("\n+++===+++\n");

    this.getLog().error(builder.toString());
  }