diff --git a/backend/src/main/java/fr/cgi/magneto/core/enums/SlideResourceType.java b/backend/src/main/java/fr/cgi/magneto/core/enums/SlideResourceType.java index 24426d46..c1044e90 100644 --- a/backend/src/main/java/fr/cgi/magneto/core/enums/SlideResourceType.java +++ b/backend/src/main/java/fr/cgi/magneto/core/enums/SlideResourceType.java @@ -1,6 +1,8 @@ package fr.cgi.magneto.core.enums; public enum SlideResourceType { + TITLE("title"), + DESCRIPTION("description"), TEXT("text"), IMAGE("image"), VIDEO("video"), diff --git a/backend/src/main/java/fr/cgi/magneto/factory/SlideFactory.java b/backend/src/main/java/fr/cgi/magneto/factory/SlideFactory.java index 0bd0877b..04519907 100644 --- a/backend/src/main/java/fr/cgi/magneto/factory/SlideFactory.java +++ b/backend/src/main/java/fr/cgi/magneto/factory/SlideFactory.java @@ -1,8 +1,8 @@ package fr.cgi.magneto.factory; import fr.cgi.magneto.core.enums.SlideResourceType; -import fr.cgi.magneto.model.slides.*; import fr.cgi.magneto.model.properties.SlideProperties; +import fr.cgi.magneto.model.slides.*; public class SlideFactory { @@ -12,6 +12,11 @@ public Slide createSlide(SlideResourceType type, SlideProperties properties) { } switch (type) { + case TITLE: + return new SlideTitle(properties.getTitle(), properties.getDescription(), properties.getOwnerName(), + properties.getModificationDate(), properties.getResourceData(), properties.getContentType()); + case DESCRIPTION: + return new SlideDescription(properties.getTitle(), properties.getDescription()); case TEXT: return new SlideText(properties.getTitle(), properties.getDescription()); case FILE: diff --git a/backend/src/main/java/fr/cgi/magneto/model/properties/SlideProperties.java b/backend/src/main/java/fr/cgi/magneto/model/properties/SlideProperties.java index 54b8ccfa..3ef4b202 100644 --- a/backend/src/main/java/fr/cgi/magneto/model/properties/SlideProperties.java +++ b/backend/src/main/java/fr/cgi/magneto/model/properties/SlideProperties.java @@ -1,6 +1,7 @@ package fr.cgi.magneto.model.properties; import fr.cgi.magneto.core.enums.SlideResourceType; +import fr.cgi.magneto.helper.I18nHelper; public class SlideProperties { private String title; @@ -12,6 +13,7 @@ public class SlideProperties { private String fileName; private byte[] resourceData; private String contentType; + private I18nHelper i18nHelper; private String ownerName; private String modificationDate; @@ -22,87 +24,9 @@ public class SlideProperties { private SlideProperties() { } - public static class Builder { - private final SlideProperties properties; - - public Builder() { - properties = new SlideProperties(); - } - - public Builder title(String title) { - properties.title = title; - return this; - } - - public Builder description(String description) { - properties.description = description; - return this; - } - - public Builder caption(String caption) { - properties.caption = caption; - return this; - } - - public Builder content(String content) { - properties.content = content; - return this; - } - - public Builder resourceUrl(String resourceUrl) { - properties.resourceUrl = resourceUrl; - return this; - } - - public Builder resourceId(String resourceId) { - properties.resourceId = resourceId; - return this; - } - - public Builder contentType(String contentType) { - properties.contentType = contentType; - return this; - } - - public Builder fileName(String fileName) { - properties.fileName = fileName; - return this; - } - - public Builder resourceData(byte[] resourceData) { - properties.resourceData = resourceData; - return this; - } - - // Propriétés spécifiques board - public Builder ownerName(String ownerName) { - properties.ownerName = ownerName; - return this; - } - - public Builder modificationDate(String modificationDate) { - properties.modificationDate = modificationDate; - return this; - } - - public Builder resourceNumber(Integer resourceNumber) { - properties.resourceNumber = resourceNumber; - return this; - } - - public Builder isShare(Boolean isShare) { - properties.isShare = isShare; - return this; - } - - public Builder isPublic(Boolean isPublic) { - properties.isPublic = isPublic; - return this; - } - - public SlideProperties build() { - return properties; - } + private boolean isValidForTitle() { + return title != null && description != null && ownerName != null && modificationDate != null + && resourceData != null && contentType != null; } public boolean isValidForType(SlideResourceType type) { @@ -110,6 +34,10 @@ public boolean isValidForType(SlideResourceType type) { return false; switch (type) { + case TITLE: + return isValidForTitle(); + case DESCRIPTION: + return isValidForDescription(); case TEXT: return isValidForText(); case FILE: @@ -130,6 +58,14 @@ public boolean isValidForType(SlideResourceType type) { } } + public I18nHelper getI18nHelper() { + return i18nHelper; + } + + private boolean isValidForDescription() { + return title != null && description != null; + } + private boolean isValidForText() { return title != null && description != null; } @@ -211,4 +147,92 @@ public Boolean getIsShare() { public Boolean getIsPublic() { return isPublic; } + + public static class Builder { + private final SlideProperties properties; + + public Builder() { + properties = new SlideProperties(); + } + + public Builder title(String title) { + properties.title = title; + return this; + } + + public Builder description(String description) { + properties.description = description; + return this; + } + + public Builder caption(String caption) { + properties.caption = caption; + return this; + } + + public Builder content(String content) { + properties.content = content; + return this; + } + + public Builder resourceUrl(String resourceUrl) { + properties.resourceUrl = resourceUrl; + return this; + } + + public Builder resourceId(String resourceId) { + properties.resourceId = resourceId; + return this; + } + + public Builder contentType(String contentType) { + properties.contentType = contentType; + return this; + } + + public Builder fileName(String fileName) { + properties.fileName = fileName; + return this; + } + + public Builder resourceData(byte[] resourceData) { + properties.resourceData = resourceData; + return this; + } + + // Propriétés spécifiques board + public Builder ownerName(String ownerName) { + properties.ownerName = ownerName; + return this; + } + + public Builder modificationDate(String modificationDate) { + properties.modificationDate = modificationDate; + return this; + } + + public Builder resourceNumber(Integer resourceNumber) { + properties.resourceNumber = resourceNumber; + return this; + } + + public Builder isShare(Boolean isShare) { + properties.isShare = isShare; + return this; + } + + public Builder isPublic(Boolean isPublic) { + properties.isPublic = isPublic; + return this; + } + + public Builder i18nHelper(I18nHelper i18nHelper) { + properties.i18nHelper = i18nHelper; + return this; + } + + public SlideProperties build() { + return properties; + } + } } \ No newline at end of file diff --git a/backend/src/main/java/fr/cgi/magneto/model/slides/SlideDescription.java b/backend/src/main/java/fr/cgi/magneto/model/slides/SlideDescription.java index 36f00dd0..d9a0e7fa 100644 --- a/backend/src/main/java/fr/cgi/magneto/model/slides/SlideDescription.java +++ b/backend/src/main/java/fr/cgi/magneto/model/slides/SlideDescription.java @@ -1,15 +1,35 @@ package fr.cgi.magneto.model.slides; +import fr.cgi.magneto.core.constants.Slideshow; +import fr.cgi.magneto.helper.SlideHelper; +import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.xslf.usermodel.XSLFSlide; +import org.apache.poi.xslf.usermodel.XSLFTextBox; +import org.apache.poi.xslf.usermodel.XSLFTextParagraph; +import org.apache.poi.xslf.usermodel.XSLFTextRun; public class SlideDescription extends Slide { - public SlideDescription(String description) { + public SlideDescription(String title, String description) { + this.title = title; this.description = description; } @Override public Object createApacheSlide(XSLFSlide newSlide) { - return null; + + SlideHelper.createTitle(newSlide, title, + Slideshow.DESCRIPTION_TITLE_HEIGHT, Slideshow.DESCRIPTION_TITLE_FONT_SIZE, TextParagraph.TextAlign.LEFT); + + XSLFTextBox textBox = SlideHelper.createContent(newSlide); + + XSLFTextParagraph paragraph = textBox.addNewTextParagraph(); + paragraph.setTextAlign(TextParagraph.TextAlign.LEFT); + XSLFTextRun textRun = paragraph.addNewTextRun(); + textRun.setText(description); + textRun.setFontSize(Slideshow.DESCRIPTION_FONT_SIZE); + textRun.setFontFamily(Slideshow.DEFAULT_FONT); + + return newSlide; } } diff --git a/backend/src/main/java/fr/cgi/magneto/model/slides/SlideTitle.java b/backend/src/main/java/fr/cgi/magneto/model/slides/SlideTitle.java index 66cfd7c1..a6940ddd 100644 --- a/backend/src/main/java/fr/cgi/magneto/model/slides/SlideTitle.java +++ b/backend/src/main/java/fr/cgi/magneto/model/slides/SlideTitle.java @@ -1,16 +1,55 @@ package fr.cgi.magneto.model.slides; +import fr.cgi.magneto.core.constants.Slideshow; +import fr.cgi.magneto.helper.SlideHelper; +import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.xslf.usermodel.XSLFSlide; +import org.apache.poi.xslf.usermodel.XSLFTextBox; +import org.apache.poi.xslf.usermodel.XSLFTextParagraph; +import org.apache.poi.xslf.usermodel.XSLFTextRun; public class SlideTitle extends Slide { private final String title; + private final String description; + private final String ownerName; + private final String modificationDate; + private final byte[] resourceData; + private final String contentType; - public SlideTitle(String title) { + public SlideTitle(String title, String description, String ownerName, String modificationDate, byte[] resourceData, + String contentType) { this.title = title; + this.description = description; + this.ownerName = ownerName; + this.modificationDate = modificationDate; + this.resourceData = resourceData; + this.contentType = contentType; } @Override public Object createApacheSlide(XSLFSlide newSlide) { - return null; + // TITRE + SlideHelper.createTitle(newSlide, title, Slideshow.MAIN_TITLE_HEIGHT, + Slideshow.MAIN_TITLE_FONT_SIZE, TextParagraph.TextAlign.CENTER); + + XSLFTextBox textBox = SlideHelper.createContent(newSlide); + + XSLFTextParagraph paragraph = textBox.addNewTextParagraph(); + paragraph.setTextAlign(TextParagraph.TextAlign.CENTER); + XSLFTextRun textRun = paragraph.addNewTextRun(); + textRun.setText(ownerName); + textRun.setFontSize(Slideshow.CONTENT_FONT_SIZE); + + XSLFTextParagraph paragraph2 = textBox.addNewTextParagraph(); + paragraph2.setTextAlign(TextParagraph.TextAlign.CENTER); + XSLFTextRun textRun2 = paragraph2.addNewTextRun(); + textRun2.setText(modificationDate); + textRun2.setFontSize(Slideshow.CONTENT_FONT_SIZE); + + SlideHelper.createImage(newSlide, resourceData, contentType, + Slideshow.MAIN_CONTENT_MARGIN_TOP, Slideshow.MAIN_IMAGE_CONTENT_HEIGHT); + + return newSlide; + } } \ No newline at end of file diff --git a/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultExportService.java b/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultExportService.java index 48695dd0..6278f176 100644 --- a/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultExportService.java +++ b/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultExportService.java @@ -22,7 +22,8 @@ import io.vertx.core.logging.LoggerFactory; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.sl.usermodel.TextParagraph; -import org.apache.poi.xslf.usermodel.*; +import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.apache.poi.xslf.usermodel.XSLFSlide; import org.entcore.common.user.UserInfos; import java.util.*; @@ -145,21 +146,24 @@ private Future createFreeLayoutSlideObjects(Board board, UserInfos XMLSlideShow ppt = new XMLSlideShow(); ppt.setPageSize(new java.awt.Dimension(1280, 720)); + SlideFactory slideFactory = new SlideFactory(); + // TITRE + Slide titleSlide = createTitleSlide(board, slideFactory, documents, i18nHelper); XSLFSlide newTitleSlide = ppt.createSlide(); - createTitleSlide(newTitleSlide, board, documents, i18nHelper); + titleSlide.createApacheSlide(newTitleSlide); + + // DESCRIPTION + Slide descriptionSlide = createDescriptionSlide(board, slideFactory, i18nHelper); + XSLFSlide newDescriptionSlide = ppt.createSlide(); + descriptionSlide.createApacheSlide(newDescriptionSlide); + return serviceFactory.cardService().getAllCardsByBoard(board, user) .map(fetchedCards -> { // Créer une map des cartes récupérées pour un accès rapide Map cardMap = fetchedCards.stream() .collect(Collectors.toMap(Card::getId, card -> card)); - SlideFactory slideFactory = new SlideFactory(); - - //DESCRIPTION - XSLFSlide descriptionApacheSlide = createDescriptionSlide(board, i18nHelper); - ppt.createSlide().importContent(descriptionApacheSlide); - // Utiliser l'ordre des cartes du Board for (Card boardCard : board.cards()) { String cardId = boardCard.getId(); @@ -194,17 +198,22 @@ private Future createFreeLayoutSlideObjects(Board board, UserInfos }); } - private Future createSectionLayoutSlideObjects(Board board, UserInfos user, JsonObject slideShowData, List> documents, I18nHelper i18nHelper) { XMLSlideShow ppt = new XMLSlideShow(); ppt.setPageSize(new java.awt.Dimension(1280, 720)); + SlideFactory slideFactory = new SlideFactory(); + // TITRE + Slide titleSlide = createTitleSlide(board, slideFactory, documents, i18nHelper); XSLFSlide newTitleSlide = ppt.createSlide(); - createTitleSlide(newTitleSlide, board, documents, i18nHelper); + titleSlide.createApacheSlide(newTitleSlide); - SlideFactory slideFactory = new SlideFactory(); + // DESCRIPTION + Slide descriptionSlide = createDescriptionSlide(board, slideFactory, i18nHelper); + XSLFSlide newDescriptionSlide = ppt.createSlide(); + descriptionSlide.createApacheSlide(newDescriptionSlide); return this.serviceFactory.sectionService().createSectionWithCards(board, user) .map(sections -> { @@ -240,62 +249,6 @@ private Future createSectionLayoutSlideObjects(Board board, UserIn }); } - private XSLFSlide createTitleSlide(XSLFSlide newTitleSlide, Board board, List> documents, - I18nHelper i18nHelper) { - - SlideHelper.createTitle(newTitleSlide, board.getTitle(), Slideshow.MAIN_TITLE_HEIGHT, - Slideshow.MAIN_TITLE_FONT_SIZE, TextParagraph.TextAlign.CENTER); - - XSLFTextBox textBox = SlideHelper.createContent(newTitleSlide); - - XSLFTextParagraph paragraph = textBox.addNewTextParagraph(); - paragraph.setTextAlign(TextParagraph.TextAlign.CENTER); - XSLFTextRun textRun = paragraph.addNewTextRun(); - textRun.setText(i18nHelper.translate("magneto.slideshow.created.by") + board.getOwnerName() + ","); - textRun.setFontSize(Slideshow.CONTENT_FONT_SIZE); - - XSLFTextParagraph paragraph2 = textBox.addNewTextParagraph(); - paragraph2.setTextAlign(TextParagraph.TextAlign.CENTER); - XSLFTextRun textRun2 = paragraph2.addNewTextRun(); - textRun2.setText(i18nHelper.translate("magneto.slideshow.updated.the") + board.getModificationDate()); - textRun2.setFontSize(Slideshow.CONTENT_FONT_SIZE); - - String imageUrl = board.getImageUrl(); - String imageId = imageUrl.substring(imageUrl.lastIndexOf('/') + 1); - Map documentData = documents.stream() - .filter(doc -> imageId.equals(doc.get(Field.DOCUMENTID))) - .findFirst() - .orElse(null); - if (documentData != null) { - Buffer documentBuffer = (Buffer) documentData.get(Field.BUFFER); - String fileExtension = (String) documentData.get(Field.EXTENSION); - if (documentBuffer != null) { - SlideHelper.createImage(newTitleSlide, documentBuffer.getBytes(), fileExtension, - Slideshow.MAIN_CONTENT_MARGIN_TOP, Slideshow.MAIN_IMAGE_CONTENT_HEIGHT); - } - } - return newTitleSlide; - } - - private XSLFSlide createDescriptionSlide(Board board, I18nHelper i18nHelper) { - XMLSlideShow ppt = new XMLSlideShow(); - XSLFSlide slide = ppt.createSlide(); - - SlideHelper.createTitle(slide, i18nHelper.translate("magneto.create.board.description"), - Slideshow.DESCRIPTION_TITLE_HEIGHT, Slideshow.DESCRIPTION_TITLE_FONT_SIZE, TextParagraph.TextAlign.LEFT); - - XSLFTextBox textBox = SlideHelper.createContent(slide); - - XSLFTextParagraph paragraph = textBox.addNewTextParagraph(); - paragraph.setTextAlign(TextParagraph.TextAlign.LEFT); - XSLFTextRun textRun = paragraph.addNewTextRun(); - textRun.setText(board.getDescription()); - textRun.setFontSize(Slideshow.DESCRIPTION_FONT_SIZE); - textRun.setFontFamily(Slideshow.DEFAULT_FONT); - - return slide; - } - private Slide createSlideFromCard(Card card, SlideFactory slideFactory, JsonObject slideShowData, List> documents) { SlideProperties.Builder propertiesBuilder = new SlideProperties.Builder() @@ -348,4 +301,37 @@ private Slide createSlideFromCard(Card card, SlideFactory slideFactory, JsonObje return slideFactory.createSlide(resourceType, propertiesBuilder.build()); } + + private Slide createTitleSlide(Board board, SlideFactory slideFactory, List> documents, + I18nHelper i18nHelper) { + SlideProperties.Builder propertiesBuilder = new SlideProperties.Builder() + .title(board.getTitle()) + .description(board.getDescription()); + + String imageUrl = board.getImageUrl(); + String imageId = imageUrl.substring(imageUrl.lastIndexOf('/') + 1); + Map documentData = documents.stream() + .filter(doc -> imageId.equals(doc.get(Field.DOCUMENTID))) + .findFirst() + .orElse(null); + Buffer documentBuffer = (Buffer) documentData.get(Field.BUFFER); + String contentType = documentData != null ? (String) documentData.get(Field.CONTENTTYPE) : ""; + + propertiesBuilder + .ownerName(i18nHelper.translate("magneto.slideshow.created.by") + board.getOwnerName() + ",") + .modificationDate(i18nHelper.translate("magneto.slideshow.updated.the") + board.getModificationDate()) + .resourceData(documentBuffer != null ? documentBuffer.getBytes() : null) + .contentType(contentType); + + return slideFactory.createSlide(SlideResourceType.TITLE, propertiesBuilder.build()); + } + + private Slide createDescriptionSlide(Board board, SlideFactory slideFactory, + I18nHelper i18nHelper) { + SlideProperties.Builder propertiesBuilder = new SlideProperties.Builder() + .title(i18nHelper.translate("magneto.create.board.description")) + .description(board.getDescription()); + + return slideFactory.createSlide(SlideResourceType.DESCRIPTION, propertiesBuilder.build()); + } } \ No newline at end of file