Skip to content

Commit

Permalink
feat(slide): add constants for slideshow paths and update SlideMedia …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
ThomasSevagen committed Feb 27, 2025
1 parent 0ef51d9 commit 3e2633a
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ public class CollectionsConstant {
public static final String CARD_COLLECTION = "magneto.cards";
public static final String SECTION_COLLECTION = "magneto.sections";
public static final String BOARD_VIEW_COLLECTION = "magneto.boards.access";
public static final String I18N_SLIDESHOW_OWNER = "magneto.slideshow.owner";
public static final String I18N_SLIDESHOW_UPDATED = "magneto.slideshow.updated.the";
public static final String I18N_SLIDESHOW_MAGNETS = "magneto.slideshow.magnets";
public static final String I18N_SLIDESHOW_SHARED = "magneto.slideshow.shared";
public static final String I18N_SLIDESHOW_PLATFORM = "magneto.slideshow.platform";

public static final String WORKSPACE_DOCUMENTS = "documents";
}
11 changes: 5 additions & 6 deletions backend/src/main/java/fr/cgi/magneto/core/constants/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class Field {
public static final String CURSOR = "cursor";
public static final String FIRSTBATCH = "firstBatch";


// CARD FIELD

public static final String BOARDID = "boardId";
Expand Down Expand Up @@ -125,7 +124,6 @@ public class Field {

public static final String NUMBER = "number";


// METADATA FIELD

public static final String NAME = "name";
Expand Down Expand Up @@ -189,7 +187,7 @@ public class Field {

public static final String BOARDURL = "boardUrl";

//Import Export
// Import Export
public static final String RAPPORT = "rapport";

public static final String RESSOURCE_NUMBER = "resourcesNumber";
Expand All @@ -212,7 +210,7 @@ public class Field {
public static final String USER_2 = "User";
public static final String USERIDS = "userIds";

//FAVORITE
// FAVORITE
public static final String FAVORITE = "favorite";
public static final String FAVORITE_LIST = "favoriteList";
public static final String ISFAVORITE = "isFavorite";
Expand All @@ -232,13 +230,14 @@ public class Field {
public static final String GROUP_TYPE = "groupType";
public static final String GROUP = "Group";
public static final String MEMBERS = "members";
//notification Folder
// notification Folder
public static final String FOLDERTITLE = "folderTitle";
public static final String FOLDERURL = "folderUrl";
public static final String BOARDNAME = "boardName";

//EXPORT SLIDE
// EXPORT SLIDE
public static final String SLIDE_OBJECTS = "slideObjects";
public static final String BOARD_IMAGE_ID = "boardImageId";
public static final String BUFFER = "buffer";
public static final String FILE = "file";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fr.cgi.magneto.core.constants;

public class MagnetoPaths {
public static final String MAGNETO_BOARD = "magneto#/board/";
public static final String VIEW = "/view";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class Slideshow {
public static final int CONTENT_MARGIN_TOP = 140;
public static final int MAIN_CONTENT_MARGIN_TOP = 300;
public static final Double CONTENT_FONT_SIZE = 36.0;
public static final int SLIDE_BOARD_CONTENT_MARGIN_TOP = 450;

// Constantes pour les images
public static final int MAIN_IMAGE_CONTENT_HEIGHT = 400;
public static final int IMAGE_CONTENT_HEIGHT = 480;
public static final int BOARD_IMAGE_CONTENT_HEIGHT = 250;

// Constantes content_type prefixes
public static final String CONTENT_TYPE_AUDIO = "audio/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public Slide createSlide(SlideResourceType type, SlideProperties properties) {
properties.getModificationDate(),
properties.getResourceNumber(),
properties.getIsShare(),
properties.getIsPublic());
properties.getIsPublic(),
properties.getCaption(),
properties.getLink(),
properties.getContentType(), properties.getResourceData(), properties.getI18ns());

default:
throw new IllegalArgumentException("Unsupported slide type: " + type);
}
Expand Down
102 changes: 100 additions & 2 deletions backend/src/main/java/fr/cgi/magneto/helper/SlideHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.cgi.magneto.helper;

import fr.cgi.magneto.core.constants.CollectionsConstant;
import fr.cgi.magneto.core.constants.Slideshow;
import fr.cgi.magneto.model.slides.SlideMedia;
import io.vertx.core.json.JsonObject;

import java.awt.Color;
import java.awt.Graphics2D;
Expand All @@ -16,6 +18,7 @@
import javax.xml.namespace.QName;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
import org.apache.poi.xslf.usermodel.XSLFPictureData;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
Expand Down Expand Up @@ -102,7 +105,7 @@ public static XSLFTextBox createContent(XSLFSlide slide) {
}

public static XSLFPictureShape createImage(XSLFSlide slide, byte[] pictureData, String fileContentType,
int contentMarginTop, int imageContentHeight) {
int contentMarginTop, int imageContentHeight, Boolean alignLeft) {
XMLSlideShow ppt = slide.getSlideShow();

XSLFPictureData pic = ppt.addPicture(pictureData, getPictureTypeFromContentType(fileContentType));
Expand All @@ -119,7 +122,7 @@ public static XSLFPictureShape createImage(XSLFSlide slide, byte[] pictureData,
newWidth = (int) (imageContentHeight * imgRatio);
}

int x = Slideshow.MARGIN_LEFT + (Slideshow.WIDTH - newWidth) / 2;
int x = alignLeft ? Slideshow.MARGIN_LEFT : Slideshow.MARGIN_LEFT + (Slideshow.WIDTH - newWidth) / 2;
int y = contentMarginTop + (imageContentHeight - newHeight) / 2;

XSLFPictureShape shape = slide.createPicture(pic);
Expand All @@ -128,6 +131,84 @@ public static XSLFPictureShape createImage(XSLFSlide slide, byte[] pictureData,
return shape;
}

public static XSLFTextBox createLink(XSLFSlide slide, String url) {
// Créer une zone de texte pour le lien
XSLFTextBox linkBox = slide.createTextBox();
int linkPositionY = Slideshow.MARGIN_TOP_TITLE + Slideshow.TITLE_HEIGHT + 10;
// Positionner la zone de texte en utilisant les constantes existantes

linkBox.setAnchor(new Rectangle(
Slideshow.MARGIN_LEFT,
linkPositionY,
Slideshow.WIDTH,
50));

// Créer un paragraphe pour le texte du lien
XSLFTextParagraph paragraph = linkBox.addNewTextParagraph();
paragraph.setTextAlign(TextAlign.LEFT);

// Créer un TextRun avec l'URL comme texte affiché
XSLFTextRun textRun = paragraph.addNewTextRun();
textRun.setText(url);
textRun.setFontSize(Slideshow.CONTENT_FONT_SIZE);
textRun.setFontColor(new Color(0, 0, 255)); // Bleu pour indiquer un lien
textRun.setUnderlined(true); // Souligné pour indiquer un lien

// Utiliser XSLFHyperlink pour créer le lien
XSLFHyperlink hyperlink = textRun.createHyperlink();
hyperlink.setAddress(url);

return linkBox;
}

public static XSLFTextBox createBoardInfoList(XSLFSlide slide, String ownerName, String modificationDate,
int resourceNumber,
boolean isShare, boolean isPublic, JsonObject i18ns) {
// Créer une zone de texte pour la liste
XSLFTextBox infoBox = slide.createTextBox();

int listPositionY = Slideshow.MAIN_CONTENT_MARGIN_TOP;
infoBox.setAnchor(
new Rectangle(Slideshow.WIDTH - Slideshow.MARGIN_LEFT * 2, listPositionY, Slideshow.WIDTH, 200));

XSLFTextParagraph paragraph1 = infoBox.addNewTextParagraph();
paragraph1.setSpaceBefore(0.0);
XSLFTextRun textRun1 = paragraph1.addNewTextRun();
textRun1.setText("• " + i18ns.getString(CollectionsConstant.I18N_SLIDESHOW_OWNER) + ownerName);
textRun1.setFontSize(Slideshow.CONTENT_FONT_SIZE);

if (modificationDate != null && !modificationDate.isEmpty()) {
XSLFTextParagraph paragraphDate = infoBox.addNewTextParagraph();
XSLFTextRun textRunDate = paragraphDate.addNewTextRun();
textRunDate.setText(
"• " + i18ns.getString(CollectionsConstant.I18N_SLIDESHOW_UPDATED) + formatDate(modificationDate));
textRunDate.setFontSize(Slideshow.CONTENT_FONT_SIZE);
}

XSLFTextParagraph paragraph2 = infoBox.addNewTextParagraph();
XSLFTextRun textRun2 = paragraph2.addNewTextRun();
textRun2.setText("• " + resourceNumber + " " + i18ns.getString(CollectionsConstant.I18N_SLIDESHOW_MAGNETS));
textRun2.setFontSize(Slideshow.CONTENT_FONT_SIZE);

// 3. Tableau partagé (si applicable)
if (isShare) {
XSLFTextParagraph paragraph3 = infoBox.addNewTextParagraph();
XSLFTextRun textRun3 = paragraph3.addNewTextRun();
textRun3.setText("• " + i18ns.getString(CollectionsConstant.I18N_SLIDESHOW_SHARED));
textRun3.setFontSize(Slideshow.CONTENT_FONT_SIZE);
}

// 4. Tableau de la plateforme
if (isPublic) {
XSLFTextParagraph paragraph4 = infoBox.addNewTextParagraph();
XSLFTextRun textRun4 = paragraph4.addNewTextRun();
textRun4.setText("• " + i18ns.getString(CollectionsConstant.I18N_SLIDESHOW_PLATFORM));
textRun4.setFontSize(Slideshow.CONTENT_FONT_SIZE);
}

return infoBox;
}

public static XSLFPictureShape createMedia(XSLFSlide slide, byte[] mediaData, String fileContentType,
SlideMedia.MediaType mediaType) {

Expand Down Expand Up @@ -506,4 +587,21 @@ private static String getExtensionFromContentType(String contentType) {
}
}
}

private static String formatDate(String dateString) {
if (dateString == null || dateString.isEmpty()) {
return "";
}

try {
java.text.SimpleDateFormat inputFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

java.text.SimpleDateFormat outputFormat = new java.text.SimpleDateFormat("dd/MM/yyyy");

java.util.Date date = inputFormat.parse(dateString);
return outputFormat.format(date);
} catch (java.text.ParseException e) {
return dateString;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.cgi.magneto.model.properties;

import fr.cgi.magneto.core.enums.SlideResourceType;
import io.vertx.core.json.JsonObject;

public class SlideProperties {
private String title;
Expand All @@ -12,6 +13,8 @@ public class SlideProperties {
private String fileName;
private byte[] resourceData;
private String contentType;
private String link;
private JsonObject i18ns;

private String ownerName;
private String modificationDate;
Expand Down Expand Up @@ -64,6 +67,16 @@ public Builder contentType(String contentType) {
return this;
}

public Builder link(String link) {
properties.link = link;
return this;
}

public Builder i18ns(JsonObject i18ns) {
properties.i18ns = i18ns;
return this;
}

public Builder fileName(String fileName) {
properties.fileName = fileName;
return this;
Expand Down Expand Up @@ -147,11 +160,16 @@ private boolean isValidForMedia() {
}

private boolean isValidForBoard() {
return ownerName != null
return title != null && ownerName != null
&& link != null
&& caption != null
&& modificationDate != null
&& resourceNumber != null
&& isShare != null
&& isPublic != null;
&& contentType != null
&& resourceData != null
&& isPublic != null
&& !i18ns.isEmpty();
}

// Getters
Expand All @@ -167,7 +185,6 @@ public String getCaption() {
return caption;
}


public String getContent() {
return content;
}
Expand All @@ -184,6 +201,14 @@ public String getContentType() {
return contentType;
}

public String getLink() {
return link;
}

public JsonObject getI18ns() {
return i18ns;
}

public String getFileName() {
return fileName;
}
Expand Down
36 changes: 31 additions & 5 deletions backend/src/main/java/fr/cgi/magneto/model/slides/SlideBoard.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
package fr.cgi.magneto.model.slides;

import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.xslf.usermodel.XSLFSlide;

import fr.cgi.magneto.core.constants.Slideshow;
import fr.cgi.magneto.helper.SlideHelper;
import io.vertx.core.json.JsonObject;

public class SlideBoard extends Slide {
private final String ownerName;
private final String link;
private final String modificationDate;
private final int magnetNumber;
private final int resourceNumber;
private final boolean isShare;
private final boolean isPublic;
private final String caption;
private final String fileContentType;
private byte[] resourceData;
private JsonObject i18ns;

public SlideBoard(String title, String description, String ownerName, String modificationDate, int magnetNumber,
boolean isShare, boolean isPublic) {
public SlideBoard(String title, String description, String ownerName, String modificationDate, int resourceNumber,
boolean isShare, boolean isPublic, String caption, String link, String contentType,
byte[] resourceData, JsonObject i18ns) {
this.title = title;
this.description = description;
this.ownerName = ownerName;
this.modificationDate = modificationDate;
this.magnetNumber = magnetNumber;
this.resourceNumber = resourceNumber;
this.caption = caption;
this.isShare = isShare;
this.isPublic = isPublic;
this.link = link;
this.fileContentType = contentType;
this.resourceData = resourceData;
this.i18ns = i18ns;

}

@Override
public Object createApacheSlide(XSLFSlide newSlide) {
return null;
SlideHelper.createTitle(newSlide, title, Slideshow.TITLE_HEIGHT, Slideshow.TITLE_FONT_SIZE,
TextParagraph.TextAlign.LEFT);
SlideHelper.createLink(newSlide, link);
SlideHelper.createImage(newSlide, resourceData, fileContentType, Slideshow.MAIN_CONTENT_MARGIN_TOP,
Slideshow.BOARD_IMAGE_CONTENT_HEIGHT, true);
SlideHelper.createBoardInfoList(newSlide, ownerName, modificationDate, resourceNumber, isShare, isPublic,
i18ns);
SlideHelper.createLegend(newSlide, caption);

return newSlide;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Object createApacheSlide(XSLFSlide newSlide) {
break;
default:
SlideHelper.createImage(newSlide, resourceData, fileContentType, Slideshow.CONTENT_MARGIN_TOP,
Slideshow.IMAGE_CONTENT_HEIGHT);
Slideshow.IMAGE_CONTENT_HEIGHT, false);
}
SlideHelper.createLegend(newSlide, caption);

Expand Down
Loading

0 comments on commit 3e2633a

Please sign in to comment.