ModelSharingMessageBuilder.java

  1. /*
  2.  * The coLAB project
  3.  * Copyright (C) 2022-2023 AlbaSim, MEI, HEIG-VD, HES-SO
  4.  *
  5.  * Licensed under the MIT License
  6.  */
  7. package ch.colabproject.colab.api.model.token.tools;

  8. import ch.colabproject.colab.api.controller.token.TokenMessageBuilder;
  9. import ch.colabproject.colab.api.model.token.ModelSharingToken;
  10. import java.text.MessageFormat;

  11. /**
  12.  * To build the body of the message to send for an model sharing token.
  13.  *
  14.  * @author sandra
  15.  */
  16. public class ModelSharingMessageBuilder {

  17.     // TODO

  18.     /** Title */
  19.     private static final String MESSAGE_HEAD_TITLE = "Co.LAB model sharing";

  20.     /** Picture */
  21.     private static final String MESSAGE_PICTURE = "<svg\n"
  22.         + "            width=\"230\"\n"
  23.         + "            height=\"230\"\n"
  24.         + "            id=\"Layer_1\"\n"
  25.         + "            xmlns=\"http://www.w3.org/2000/svg\"\n"
  26.         + "            viewBox=\"0 0 384.66 396.62\"\n"
  27.         + "          >\n"
  28.         + "            <path\n"
  29.         + "              fill=\"#50BFD5\"\n"
  30.         + "              d=\"M384.7,192.3c0,106.2-86.1,192.3-192.3,192.3S0,298.6,0,192.3S86.1,0,192.3,0S384.7,86.1,384.7,192.3\n"
  31.         + "            L384.7,192.3z\"\n"
  32.         + "            />\n"
  33.         + "            <g>\n"
  34.         + "              <path\n"
  35.         + "                fill=\"#F1F2F2\"\n"
  36.         + "                d=\"M83,55.5h222.2c1.7,0,3,1.6,3,3.6v263c0,2-1.3,3.6-3,3.6H83c-1.7,0-3-1.6-3-3.6v-263\n"
  37.         + "                C80,57.1,81.3,55.5,83,55.5L83,55.5z\"\n"
  38.         + "              />\n"
  39.         + "              <rect\n"
  40.         + "                x=\"106.4\"\n"
  41.         + "                y=\"78.6\"\n"
  42.         + "                fill=\"#D1B511\"\n"
  43.         + "                width=\"113.7\"\n"
  44.         + "                height=\"57\"\n"
  45.         + "              />\n"
  46.         + "              <rect\n"
  47.         + "                x=\"230.5\"\n"
  48.         + "                y=\"183.7\"\n"
  49.         + "                fill=\"#D1B511\"\n"
  50.         + "                width=\"51.3\"\n"
  51.         + "                height=\"57\"\n"
  52.         + "              />\n"
  53.         + "              <rect\n"
  54.         + "                x=\"106.4\"\n"
  55.         + "                y=\"145.5\"\n"
  56.         + "                fill=\"#D1B511\"\n"
  57.         + "                width=\"113.7\"\n"
  58.         + "                height=\"96.1\"\n"
  59.         + "              />\n"
  60.         + "              <rect\n"
  61.         + "                x=\"229.8\"\n"
  62.         + "                y=\"76.5\"\n"
  63.         + "                fill=\"#D1B511\"\n"
  64.         + "                width=\"51.3\"\n"
  65.         + "                height=\"96.1\"\n"
  66.         + "              />\n"
  67.         + "              <rect\n"
  68.         + "                x=\"106.4\"\n"
  69.         + "                y=\"251.9\"\n"
  70.         + "                fill=\"#D1B511\"\n"
  71.         + "                width=\"174.7\"\n"
  72.         + "                height=\"54.5\"\n"
  73.         + "              />\n"
  74.         + "              <rect\n"
  75.         + "                x=\"118.2\"\n"
  76.         + "                y=\"91.5\"\n"
  77.         + "                fill=\"#FFE20F\"\n"
  78.         + "                width=\"39.3\"\n"
  79.         + "                height=\"33\"\n"
  80.         + "              />\n"
  81.         + "              <rect\n"
  82.         + "                x=\"168.3\"\n"
  83.         + "                y=\"91.5\"\n"
  84.         + "                fill=\"#FFE20F\"\n"
  85.         + "                width=\"38.8\"\n"
  86.         + "                height=\"33\"\n"
  87.         + "              />\n"
  88.         + "              <rect x=\"239.6\" y=\"195.7\" fill=\"#FFE20F\" width=\"33\" height=\"33\" />\n"
  89.         + "              <rect\n"
  90.         + "                x=\"118.5\"\n"
  91.         + "                y=\"262.6\"\n"
  92.         + "                fill=\"#FFE20F\"\n"
  93.         + "                width=\"38.8\"\n"
  94.         + "                height=\"33\"\n"
  95.         + "              />\n"
  96.         + "            </g>\n"
  97.         + "            <g>\n"
  98.         + "              <circle fill=\"#E05D11\" cx=\"304.8\" cy=\"305.3\" r=\"79.4\" />\n"
  99.         + "              <circle fill=\"#FFFFFF\" cx=\"329.1\" cy=\"271.6\" r=\"16.9\" />\n"
  100.         + "              <circle fill=\"#FFFFFF\" cx=\"270.1\" cy=\"305.5\" r=\"16.9\" />\n"
  101.         + "              <circle fill=\"#FFFFFF\" cx=\"329.1\" cy=\"340.2\" r=\"16.9\" />\n"
  102.         + "              <rect\n"
  103.         + "                x=\"297.9\"\n"
  104.         + "                y=\"251.9\"\n"
  105.         + "                transform=\"matrix(0.5 0.866 -0.866 0.5 400.3593 -116.5156)\"\n"
  106.         + "                fill=\"#FFFFFF\"\n"
  107.         + "                width=\"6.5\"\n"
  108.         + "                height=\"73\"\n"
  109.         + "              />\n"
  110.         + "              <rect\n"
  111.         + "                x=\"298.6\"\n"
  112.         + "                y=\"286.9\"\n"
  113.         + "                transform=\"matrix(-0.5 0.866 -0.866 -0.5 732.8752 223.7727)\"\n"
  114.         + "                fill=\"#FFFFFF\"\n"
  115.         + "                width=\"6.5\"\n"
  116.         + "                height=\"73\"\n"
  117.         + "              />\n"
  118.         + "            </g>\n"
  119.         + "          </svg>";

  120.     /** Header 1 */
  121.     private static final String MESSAGE_HEADING = "Hi ! You have been shared a project model.";

  122.     /** Header 2 */
  123.     private static final String MESSAGE_SUBHEADING = "{0} invites you to use {1}.";

  124.     /** Information */
  125.     private static final String MESSAGE_INFO = "<p>Click on the link below to start colabbing with the model.</p>";

  126.     /** Label of the link */
  127.     private static final String MESSAGE_LINK_LABEL = "Get the model";

  128.     private ModelSharingMessageBuilder() {
  129.         // private constructor
  130.     }

  131.     /**
  132.      * Build a HTML body to send a message for the model sharing token
  133.      *
  134.      * @param token the model sharing token
  135.      * @param link  the link in order to consume the token
  136.      *
  137.      * @return the HTML body of the message to send
  138.      */
  139.     public static String build(ModelSharingToken token, String link) {
  140.         String subHeading = MessageFormat.format(MESSAGE_SUBHEADING,
  141.             token.getSender() != null
  142.                 ? token.getSender()
  143.                 : "Someone",
  144.             token.getProject() != null
  145.                 ? "the model <i>" + token.getProject().getName() + "</i>"
  146.                 : "a co.LAB model");

  147.         return new TokenMessageBuilder(token)
  148.             .headTitle(MESSAGE_HEAD_TITLE)
  149.             .picture(MESSAGE_PICTURE)
  150.             .heading(MESSAGE_HEADING)
  151.             .subheading(subHeading)
  152.             .info(MESSAGE_INFO)
  153.             .linkHref(link)
  154.             .linkLabel(MESSAGE_LINK_LABEL)
  155.             // let default footer
  156.             .build();
  157.     }

  158. }