Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(slide) : #MAG-545 fix description and title flow #394

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.cgi.magneto.core.enums;

public enum SlideResourceType {
TITLE("title"),
DESCRIPTION("description"),
TEXT("text"),
IMAGE("image"),
VIDEO("video"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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:
Expand Down
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 fr.cgi.magneto.helper.I18nHelper;

public class SlideProperties {
private String title;
Expand All @@ -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;
Expand All @@ -22,94 +24,20 @@ 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) {
if (type == null)
return false;

switch (type) {
case TITLE:
return isValidForTitle();
case DESCRIPTION:
return isValidForDescription();
case TEXT:
return isValidForText();
case FILE:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
43 changes: 41 additions & 2 deletions backend/src/main/java/fr/cgi/magneto/model/slides/SlideTitle.java
Original file line number Diff line number Diff line change
@@ -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;

}
}
Loading