<#ftl encoding="UTF-8">
<#--
  NOTE: When saving this FTL on Control Tower, remove this comment, otherwise FTL may work incorrectly!

  Template variables:
    Table 1.1:
    ----------
    - transaction.getAttribute("entityName") - Entity name.
    - transaction.getAttribute("dateOfInvestigation") - Date of investigation.
    - transaction.getAttribute("workerName") - Worker name.
    - transaction.getAttribute("overallRecommendation") - Overall Recommendation (Final results from the Manual Task with a decision to investigate the entity or not).
    - transaction.getAttribute("articlesReviewed") - How many articles reviewed.
    - transaction.getAttribute("suggestedKeywords") - Keywords suggested by model. [LIST]
    - transaction.getAttribute("highRiskCountriesRelations") - High risk countries relations. [LIST]
    - transaction.getAttribute("manualTaskLink") - Link to the manual task.
    Table 1.2 and 3.x tables:
    -------------------------
    - transaction.docs[0..N].textLink - If this attribute is set, the document is relevant. If the attribute is not set, the document is irrelevant.
    - transaction.docs[0..N].getAttribute("title") - Title.
    - transaction.docs[0..N].getAttribute("publishingDate") - Publishing date.
    - transaction.docs[0..N].getAttribute("classificationModelScore") - Classification model score.
    - transaction.docs[0..N].getAttribute("triggeredCountries") - Triggered countries. [LIST]
    - transaction.docs[0..N].getAttribute("suspiciousPhrases") - If an articles triggers further investigation present emphasized by a worker suspicious phrase in Manual Task. [LIST]
    - transaction.docs[0..N].originalDocumentLink - Original link to the article.
    - transaction.docs[0..N].origin.originalDocumentLink - Archive link to the article.
    - transaction.docs[0..N].htmlExcerpt - Article html body excerpt.
 -->
<#if (transaction??)>
  <#assign EMPTY_PLACEHOLDER = ""/>
  <#assign NA_PLACEHOLDER = "n/a"/>
  <#assign TBD_PLACEHOLDER = "Not available in current version"/>
  <#assign NO_ARTICLES_PLACEHOLDER = "No articles found for the given entity"/>
  <#assign EMPTY_LIST = []/>
  <#assign relevantDocs = 0/>
  <#if transaction.docs?? && transaction.docs?size gt 0>
    <#list transaction.docs as document>
      <#if document.textLink?? && document.textLink?length gt 0>
        <#assign relevantDocs++/>
      </#if>
    </#list>
  </#if>

  <html>
  <head>
  <style type="text/css">
    body {
        font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
      	font-size: 11px;
    }

    h1, h2, h3 {
        font-family: "Segoe UI", Arial, sans-serif;
        font-weight: 500;
    }

    h1 {
        color: #3E8799;
    }
    h2 {
        color: #3E8799;
        padding-bottom: 4px;
        border-bottom: 2px solid #61ADBF;
    }
    h3 {
        color: black;
    }

    ol {
        margin: 0;
        padding: 0 2px 0 25px;
        list-style: disc outside none;
    }
    ul {
        margin: 0;
        padding: 0 2px 0 25px;
        list-style: disc outside none;
    }
    li {
        margin: 0;
        padding: 0;
    }

    table {
      	font-family: Calibri;
      	font-size: 11px;
    }
    table.table-1-1 {
        border-collapse: collapse;
        width: 70%;
        border: 1px solid black;
    }
    table.table-1-1 td {
        padding: 2px 4px;
        word-wrap: break-word;
        vertical-align: top;
    }
    table.table-1-1 .overall-recommendation {
        color: red;
    }
    table.table-1-1 td:nth-child(odd) {
        background: #61ADBF;
        border-right: 1px solid black;
        color: white;
    }
    table.table-1-1 td:nth-child(even) {
        border-bottom: 1px solid black;
    }

    table.table-1-2 {
        border-collapse: collapse;
        width: 100%;
    }
    table.table-1-2 tr th {
        background: #61ADBF;
        color: white;
    }
    table.table-1-2 td, table.table-1-2 th {
        padding: 2px 4px;
        border: 2px solid #61ADBF;
        word-wrap: break-word;
        vertical-align: top;
    }
    table.table-1-2 td.link {
        word-break: break-all;
    }
    table.table-1-2 tr.row-odd {
        background: #DFEEF2;
    }
    table.table-1-2 tr.row-even {
        background: white;
    }

    table.table-3-1 {
        border-collapse: collapse;
        width: 100%;
    }
    table.table-3-1 tr th {
        background: #61ADBF;
        color: white;
    }
    table.table-3-1 th, table.table-3-1 td {
        padding: 2px 4px;
        border: 2px solid #61ADBF;
        word-wrap: break-word;
        vertical-align: top;
    }
    table.table-3-1 td.link {
        word-break: break-all;
    }

    span.suspiciousCountries {
        background: #00FFFF;
    }
    span.suspiciousPEPs {
        background: #00FF00;
    }
    span.keyPhrases {
        background: #FFFF00;
    }

    @media print {
        .break-before {
            page-break-before: always;
        }
    }
  </style>
  </head>
  <body>
    <h1>Negative News Analysis</h1>
    <p style="font-size:14px">
      <strong>Entity: ${transaction.getAttribute("entityName")!EMPTY_PLACEHOLDER}</strong><br/>
      <em>${transaction.getAttribute("dateOfInvestigation")!EMPTY_PLACEHOLDER}</em>
    </p>

    <h2>1 Summary</h2>

    <h3>1.1 Investigation Overview</h3>

    <table class="table-1-1">
      <tr>
        <td><strong>Overall Recommendation</strong></td>
        <td class="overall-recommendation"><strong>${transaction.getAttribute("overallRecommendation")!EMPTY_PLACEHOLDER}</strong></td>
      </tr>
      <tr>
        <td><strong>Negative News Articles</strong></td>
        <td>
          <#assign articlesReviewed = transaction.getAttribute("articlesReviewed")!0/>
          ${articlesReviewed}&nbsp;
          <#if relevantDocs gt 0>
            <#assign percentDocs = (100 * transaction.getAttribute("articlesReviewed")?number / relevantDocs)?round/>
            of ${relevantDocs} (${percentDocs}%)
          </#if>
        </td>
      </tr>
      <tr>
        <td><strong>Search Terms</strong></td>
        <td>
          <#if (transaction.getAttribute("suggestedKeywords")??)>
            <#assign searchTermsList = transaction.getAttribute("suggestedKeywords")?eval!EMPTY_LIST/>
            <#if searchTermsList?size gt 0>
              <ul>
                <#list searchTermsList as searchTerm>
                  <li>${searchTerm}</li>
                </#list>
              </ul>
            <#else>
              ${EMPTY_PLACEHOLDER}
            </#if>
          <#else>
            ${EMPTY_PLACEHOLDER}
          </#if>
        </td>
      </tr>
      <tr>
        <td><strong>Sanctioned Country Relationships Found</strong></td>
        <td>
          <#if (transaction.getAttribute("highRiskCountriesRelations")??)>
            <#assign sanctionedCountryRelationshipsList = transaction.getAttribute("highRiskCountriesRelations")?eval!EMPTY_LIST/>
            <#if sanctionedCountryRelationshipsList?size gt 0>
              <ol>
                <#list sanctionedCountryRelationshipsList as sanctionedCountry>
                  <li>${sanctionedCountry}</li>
                </#list>
              </ol>
            <#else>
              ${EMPTY_PLACEHOLDER}
            </#if>
          <#else>
            ${EMPTY_PLACEHOLDER}
          </#if>
        </td>
      </tr>
      <tr>
        <td><strong>Politically Exposed Persons (PEP) Relationships Found</strong></td>
        <td>${TBD_PLACEHOLDER}</td>
      </tr>
      <tr>
        <td style="border-top:1px solid black;"><strong>Analyst(s)</strong></td>
        <td>${transaction.getAttribute("workerName")!EMPTY_PLACEHOLDER}</td>
      </tr>
      <tr>
        <td><strong>Full Data Audit</strong></td>
        <td>
          <#if transaction.getAttribute('manualTaskLink')??>
            <a target="_blank" href="${transaction.getAttribute('manualTaskLink')}">${transaction.getAttribute('manualTaskLink')}</a>
          <#else>
            ${EMPTY_PLACEHOLDER}
          </#if>
        </td>
      </tr>
    </table>

    <h3>1.2 News Article Summary</h3>

    <#if transaction.docs?? && transaction.docs?size gt 0>
      <table class="table-1-2">
        <tr>
          <th><strong>Title</strong></th>
          <th><strong>Date</strong></th>
          <th><strong>Score</strong></th>
          <th><strong>Suspicious Countries</strong></th>
          <th><strong>Suspicious PEPs</strong></th>
          <th><strong>Key Phrases from article</strong></th>
          <th><strong>Links</strong></th>
        </tr>
        <#assign docRowOdd = true/>
        <#-- Iterrate over relevant docs -->
        <#list transaction.docs as document>
          <#if document.textLink?? && document.textLink?length gt 0>
            <tr class="${docRowOdd?then('row-odd','row-even')}">
              <td><strong>${document.getAttribute("title")!EMPTY_PLACEHOLDER}</strong></td>
              <td>${document.getAttribute("publishingDate")!EMPTY_PLACEHOLDER}</td>
              <td>${document.getAttribute("classificationModelScore")!EMPTY_PLACEHOLDER}</td>
              <td>
                <#if (document.getAttribute("triggeredCountries")??)>
                  <#assign triggeredCountriesList = document.getAttribute("triggeredCountries")?eval!EMPTY_LIST/>
                  <#if triggeredCountriesList?size gt 0>
                    <ul>
                      <#list triggeredCountriesList as triggeredCountry>
                        <li>${triggeredCountry}</li>
                      </#list>
                    </ul>
                  <#else>
                    ${EMPTY_PLACEHOLDER}
                  </#if>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
              <td>${TBD_PLACEHOLDER}</td>
              <td>
                <#if (document.getAttribute("suspiciousPhrases")??)>
                  <#assign suspiciousPhrasesList = document.getAttribute("suspiciousPhrases")?eval!EMPTY_LIST/>
                  <#if suspiciousPhrasesList?size gt 0>
                    <ul>
                      <#list suspiciousPhrasesList as suspiciousPhrase>
                        <li>${suspiciousPhrase}</li>
                      </#list>
                    </ul>
                  <#else>
                    ${EMPTY_PLACEHOLDER}
                  </#if>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
              <td class="link">
                <#if (document.originalDocumentLink??) || (document.origin?? && document.origin.originalDocumentLink??)>
                  <ul>
                    <#if (document.originalDocumentLink??)>
                      <li>Original: <a target="_blank" href="${document.originalDocumentLink}">${document.originalDocumentLink}</a></li>
                    </#if>
                    <#if (document.origin?? && document.origin.originalDocumentLink??)>
                      <li>Archive: <a target="_blank" href="${document.origin.originalDocumentLink}">${document.origin.originalDocumentLink}</a></li>
                    </#if>
                    <li>S3 link: <a target="_blank" href="${document.textLink}">${document.textLink}</a></li>
                  </ul>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
            </tr>
            <#assign docRowOdd = !docRowOdd/>
          </#if>
        </#list>
        <#-- Iterrate over irrelevant docs -->
        <#list transaction.docs as document>
          <#if !(document.textLink?? && document.textLink?length gt 0)>
            <tr class="${docRowOdd?then('row-odd','row-even')}">
              <td><strong>${NA_PLACEHOLDER}</strong></td>
              <td>${NA_PLACEHOLDER}</td>
              <td>${NA_PLACEHOLDER}</td>
              <td>${NA_PLACEHOLDER}</td>
              <td>${NA_PLACEHOLDER}</td>
              <td>${NA_PLACEHOLDER}</td>
              <td class="link">
                <#if (document.originalDocumentLink??) || (document.origin?? && document.origin.originalDocumentLink??)>
                  <ul>
                    <#if (document.originalDocumentLink??)>
                      <li>Original: <a target="_blank" href="${document.originalDocumentLink}">${document.originalDocumentLink}</a></li>
                    </#if>
                    <#if (document.origin?? && document.origin.originalDocumentLink??)>
                      <li>Archive: <a target="_blank" href="${document.origin.originalDocumentLink}">${document.origin.originalDocumentLink}</a></li>
                    </#if>
                  </ul>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
            </tr>
            <#assign docRowOdd = !docRowOdd/>
          </#if>
        </#list>
      </table>
    <#else>
      ${NO_ARTICLES_PLACEHOLDER}
    </#if>

    <h2>2 Explaining This Report</h2>
    <ul>
      <li><strong>Recommendations</strong> are an aggregated assessment based on a multi-step process incorporating automation and manual review.</li>
      <li><strong>Score</strong> is a model-based assessment of the relevance of the entity towards some level of suspicious activity, given on a 0.00 to 1.00 scale,
          with 1.00 being the most relevant.</li>
      <li><strong>Suspicious Countries</strong> include the existence and relevance of flagged countries within the articles and related to the entities, respectively.
      <li><strong>PEPs</strong> include the existence and relevance of flagged Politically Exposed Persons (PEPs) within the articles and related to the entities, respectively.</li>
      <li><strong>Article Sourcing</strong> is from Google News via an automated query.</li>
      <li><strong>Article Analysis</strong> is first performed by a machine learning model to prioritize articles which are then all reviewed by the Analyst.
          All assessments performed by the Analyst are fed back into the model which retrains to bet better over time.</li>
    </ul>

    <p>See the executed business process: <a target="_blank" href="${transaction.getAttribute('manualTaskLink')}">${transaction.getAttribute('manualTaskLink')}</a></p>

    <h2>3 Individual News Articles</h2>

    <#if relevantDocs gt 0>
      <#assign iDoc = 0/>
      <#list transaction.docs as document>
        <#if document.textLink?? && document.textLink?length gt 0>
          <#assign iDoc++/>
          <h3 class="break-before">3.${iDoc} ${document.getAttribute("title")!EMPTY_PLACEHOLDER}</h3>
          <table class="table-3-1">
            <tr>
              <th><strong>Date</strong></th>
              <th><strong>Score</strong></th>
              <th><strong>Suspicious Countries</strong></th>
              <th><strong>Suspicious PEPs</strong></th>
              <th><strong>Key Phrases from article</strong></th>
              <th><strong>Links</strong></th>
            </tr>
            <tr>
              <td><strong>${document.getAttribute("publishingDate")!EMPTY_PLACEHOLDER}</strong></td>
              <td>${document.getAttribute("classificationModelScore")!EMPTY_PLACEHOLDER}</td>
              <td>
                <#if (document.getAttribute("triggeredCountries")??)>
                  <#assign triggeredCountriesList = document.getAttribute("triggeredCountries")?eval!EMPTY_LIST/>
                  <#if triggeredCountriesList?size gt 0>
                    <ul>
                      <#list triggeredCountriesList as triggeredCountry>
                        <li><span class="suspiciousCountries">${triggeredCountry}</span></li>
                      </#list>
                    </ul>
                  <#else>
                    ${EMPTY_PLACEHOLDER}
                  </#if>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
              <td>${TBD_PLACEHOLDER}</td>
              <td>
                <#if (document.getAttribute("suspiciousPhrases")??)>
                  <#assign suspiciousPhrasesList = document.getAttribute("suspiciousPhrases")?eval!EMPTY_LIST/>
                  <#if suspiciousPhrasesList?size gt 0>
                    <ul>
                      <#list suspiciousPhrasesList as suspiciousPhrase>
                        <li><span class="keyPhrases">${suspiciousPhrase}</span></li>
                      </#list>
                    </ul>
                  <#else>
                    ${EMPTY_PLACEHOLDER}
                  </#if>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
              <td class="link">
                <#if (document.originalDocumentLink??) || (document.origin?? && document.origin.originalDocumentLink??)>
                  <ul>
                    <#if (document.originalDocumentLink??)>
                      <li>Original: <a target="_blank" href="${document.originalDocumentLink}">${document.originalDocumentLink}</a></li>
                    </#if>
                    <#if (document.origin?? && document.origin.originalDocumentLink??)>
                      <li>Archive: <a target="_blank" href="${document.origin.originalDocumentLink}">${document.origin.originalDocumentLink}</a></li>
                    </#if>
                    <li>S3 link: <a target="_blank" href="${document.textLink}">${document.textLink}</a></li>
                  </ul>
                <#else>
                  ${EMPTY_PLACEHOLDER}
                </#if>
              </td>
            </tr>
          </table>

          <p>
            ${document.getAttribute("htmlExcerpt")!EMPTY_PLACEHOLDER}
          </p>
        </#if>
      </#list>
    <#else>
      ${NO_ARTICLES_PLACEHOLDER}
    </#if>
  </body>
  </html>
</#if>
