Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: Update the order of the notes notification section - EXO-73571 - Meeds-io/MIPs#129  (#1119)

feat: Include properties in note export/import - EXO-73694 - Meeds-io/MIPs#129 (#1077)

Include properties in note export/import

feat: Include note properties in import/export notes - EXO-73694 - Meeds-io/MIPs#129 (#1099)

Include note properties in import/export notes

fix: fix processing featured images while export a note - EXO-73694 - Meeds-io/MIPs#129

fix processing featured images while export a note

feat: Reactivate cropping drawer usage for note featured image property - EXO-73967 - Meeds-io/MIPs#129 (#1103)

Reactivate cropping drawer usage for note featured image property

fix: Ui/ux issues in note create/switch translation - EXO-73222, EXO-74157 - Meeds-io/MIPs#129 (#1108)

Ui/ux issues in note create/switch translation:

- featured image not reset when automatic translation is not available
while creating a new translation
- "draft saving..." message remains displayed when adding a new
translation while the automatic translation is not available
- switch between translations enables the save button without existing
of draft

feat: Add a limit on note summary property value - EXO-74215 - Meeds-io/MIPs#129 (#1111)

Add a limit on note summary property value

feat: Update note action menu icons font size - EXO-74218 - Meeds-io/MIPs#129 (#1112)

Update note action menu icons font size

feat: Displaying the note title limit warning message only when trying to add more than the limit - EXO-74261 - Meeds-io/MIPs#129 (#1118)

feat: Disable save button when editing note properties - EXO-74267 - Meeds-io/MIPs#129 (#1125)

feat: Add tooltip to properties button - EXO-74272 - Meeds-io/MIPs#129 (#1131)

fix: Fix displaying content detail for public sites - EXO-74419 - Meeds-io/MIPs#129  (#1140)
  • Loading branch information
sofyenne authored and azayati committed Oct 11, 2024
1 parent 0bdade4 commit f8c9b18
Show file tree
Hide file tree
Showing 62 changed files with 641 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.LinkedList;
import java.util.List;

import io.meeds.notes.model.NotePageProperties;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -57,6 +58,8 @@ public class NoteToExport {

private LinkedList<String> ancestors;

private NotePageProperties properties;

public NoteToExport() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,40 @@
@Data
public class ExportAction {

public static final String GETTING_NOTES = "GETTING_NOTES";
public static final String UPDATING_NOTES_PARENTS = "UPDATING_NOTES_PARENTS";
public static final String CREATING_CONTENT_DATA = "CREATING_CONTENT_DATA";
public static final String UPDATING_IMAGES_URLS = "UPDATING_IMAGES_URLS";
public static final String CREATING_ZIP_FILE = "CREATING_ZIP_FILE";
public static final String CLEANING_TEMP_FILE = "CLEANING_TEMP_FILE";
public static final String EXPORT_DATA_CREATED = "EXPORT_DATA_CREATED";

private boolean started = false;
private boolean notesGetted = false;
private boolean notesPrepared = false;
private boolean jsonCreated = false;
private boolean imageUrlsUpdated = false;
private boolean zipCreated = false;
private boolean tempCleaned = false;
private boolean dataCreated = false;
private String action = "";
public static final String GETTING_NOTES = "GETTING_NOTES";

public static final String UPDATING_NOTES_PARENTS = "UPDATING_NOTES_PARENTS";

public static final String CREATING_CONTENT_DATA = "CREATING_CONTENT_DATA";

public static final String UPDATING_IMAGES_URLS = "UPDATING_IMAGES_URLS";

public static final String CREATING_ZIP_FILE = "CREATING_ZIP_FILE";

public static final String CLEANING_TEMP_FILE = "CLEANING_TEMP_FILE";

public static final String EXPORT_DATA_CREATED = "EXPORT_DATA_CREATED";

public static final String PROCESS_FEATURED_IMAGES = "PROCESS_FEATURED_IMAGES";

private boolean started = false;

private boolean notesGetted = false;

private boolean notesPrepared = false;

private boolean jsonCreated = false;

private boolean imageUrlsUpdated = false;

private boolean featuredImagesProcessed = false;

private boolean zipCreated = false;

private boolean tempCleaned = false;

private boolean dataCreated = false;

private String action = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@

package org.exoplatform.wiki.service;

import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
Expand All @@ -46,10 +38,16 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import io.meeds.notes.model.NoteFeaturedImage;
import io.meeds.notes.model.NotePageProperties;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.exoplatform.commons.file.model.FileInfo;
import org.exoplatform.commons.file.model.FileItem;
import org.exoplatform.commons.file.services.FileService;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.component.RequestLifeCycle;
import org.exoplatform.services.log.ExoLogger;
Expand All @@ -63,8 +61,9 @@
import org.exoplatform.wiki.model.Page;
import org.exoplatform.wiki.model.Wiki;
import org.exoplatform.wiki.model.WikiType;
import org.springframework.util.MimeTypeUtils;

public class ExportThread implements Runnable {
public class ExportThread implements Runnable {

private static final Log log = ExoLogger.getLogger(ExportThread.class);

Expand All @@ -77,6 +76,8 @@ public class ExportThread implements Runnable {
private static final String EXPORT_ZIP_PREFIX = "exportzip";

private static final String TEMP_DIRECTORY_PATH = "java.io.tmpdir";

private static final String FEATURED_IMAGES_DIRECTORY = "featuredImages";

private final NoteService noteService;

Expand All @@ -88,52 +89,46 @@ public class ExportThread implements Runnable {

private final ExportData exportData;

private final FileService fileService;

public ExportThread(NoteService noteService,
WikiService wikiService,
NotesExportService notesExportService,
HTMLUploadImageProcessor htmlUploadImageProcessor,
ExportData exportData) {
ExportData exportData,
FileService fileService) {
this.noteService = noteService;
this.wikiService = wikiService;
this.notesExportService = notesExportService;
this.htmlUploadImageProcessor = htmlUploadImageProcessor;
this.exportData = exportData;
this.fileService = fileService;
}

public static void cleanUp(File file) throws IOException {
if (Files.exists(file.toPath())) {
Files.delete(file.toPath());
public static void cleanUp(List<File> files) throws IOException {
for (File file : files) {
if (Files.exists(file.toPath())) {
Files.delete(file.toPath());
}
}
}

public static File zipFiles(String zipFileName,
List<File> addToZip,
List<List<File>> addToZip,
NotesExportService notesExportService,
int exportId) throws IOException {

String zipPath = System.getProperty(TEMP_DIRECTORY_PATH) + File.separator + zipFileName;
FileOutputStream fos = new FileOutputStream(zipPath);
List<File> files = addToZip.getFirst();
List<File> featuredImages = addToZip.getLast();
try (ZipOutputStream zipOut = new ZipOutputStream(fos)) {
for (File fileToZip : addToZip) {
ExportResource exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource.getStatus().equals(ExportStatus.CANCELLED.name())) {
return null;
}
try (FileInputStream fis = new FileInputStream(fileToZip)) {
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
fis.close();
} catch (IOException e) {
log.warn("cannot add the file: {} to the zip", fileToZip.getName());
}
}
addFilesToZip(zipOut, files, exportId, null, notesExportService);
addFilesToZip(zipOut, featuredImages, exportId, FEATURED_IMAGES_DIRECTORY, notesExportService);
zipOut.close();
fos.close();
} catch (InterruptedIOException e) {
return null;
} catch (IOException e) {
log.warn("cannot zip files");
}
Expand All @@ -152,23 +147,25 @@ public void run() {
exportData.getNotesToExportIds(),
exportData.isExportAll(),
exportData.getIdentity());
} catch (IOException e) {
} catch (Exception e) {
log.error("cannot Export Notes", e);
} finally {
RequestLifeCycle.end();
}
}

public void processExport(int exportId, String[] notesToExportIds, boolean exportAll, Identity identity) throws IOException {
public void processExport(int exportId, String[] notesToExportIds, boolean exportAll, Identity identity) throws Exception {

File zipFile = null;
List<List<File>> listFiles = new ArrayList<>();
List<File> featuredImages = new ArrayList<>();
ExportResource exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource != null) {
exportResource.setStatus(ExportStatus.IN_PROGRESS.name());
exportResource.getAction().setStarted(true);
exportResource.getAction().setAction(ExportAction.GETTING_NOTES);
Page note_ = null;
List<NoteToExport> noteToExportList = new ArrayList();
List<NoteToExport> noteToExportList = new ArrayList<>();
if (exportAll) {
for (String noteId : notesToExportIds) {
try {
Expand Down Expand Up @@ -228,6 +225,7 @@ public void processExport(int exportId, String[] notesToExportIds, boolean expor
note.getWikiId(),
note.getWikiType(),
note.getWikiOwner());
noteToExport.setProperties(note.getProperties());
noteToExport.setContent(processImagesForExport(note));
noteToExport.setContent(processNotesLinkForExport(noteToExport));
LinkedList<String> ancestors = getNoteAncestorsIds(noteToExport.getId());
Expand Down Expand Up @@ -306,18 +304,20 @@ public void processExport(int exportId, String[] notesToExportIds, boolean expor
String fileName = "";
String filePath = "";
exportResource.getAction().setJsonCreated(true);
processNoteFeaturedImages(exportResource, notesExport.getNotes(), featuredImages);
exportResource.getAction().setAction(ExportAction.UPDATING_IMAGES_URLS);
while (contentUpdated.contains(IMAGE_URL_REPLACEMENT_PREFIX)) {
fileName = contentUpdated.split(IMAGE_URL_REPLACEMENT_PREFIX)[1].split(IMAGE_URL_REPLACEMENT_SUFFIX)[0];
filePath = System.getProperty(TEMP_DIRECTORY_PATH) + File.separator + fileName;
files.add(new File(filePath));
contentUpdated = contentUpdated.replace(IMAGE_URL_REPLACEMENT_PREFIX + fileName + IMAGE_URL_REPLACEMENT_SUFFIX, "");
}
listFiles.add(files);
listFiles.add(featuredImages);
exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource.getStatus().equals(ExportStatus.CANCELLED.name())) {
for (File file : files) {
cleanUp(file);
}
cleanUp(files);
cleanUp(featuredImages);
notesExportService.removeExportResource(exportId);
return;
}
Expand All @@ -328,24 +328,22 @@ public void processExport(int exportId, String[] notesToExportIds, boolean expor
files.add(temp);
exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource.getStatus().equals(ExportStatus.CANCELLED.name())) {
for (File file : files) {
cleanUp(file);
}
cleanUp(files);
cleanUp(featuredImages);
notesExportService.removeExportResource(exportId);
return;
}
exportResource.getAction().setAction(ExportAction.CREATING_ZIP_FILE);
String zipName = EXPORT_ZIP_PREFIX + exportId + EXPORT_ZIP_EXTENSION;
exportResource.setZipFile(zipFile);
zipFile = zipFiles(zipName, files, notesExportService, exportId);
zipFile = zipFiles(zipName, listFiles, notesExportService, exportId);
exportResource.setZipFile(zipFile);
exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource.getStatus().equals(ExportStatus.CANCELLED.name())) {
for (File file : files) {
cleanUp(file);
}
cleanUp(files);
cleanUp(featuredImages);
if (zipFile != null) {
cleanUp(zipFile);
cleanUp(List.of(zipFile));
}
notesExportService.removeExportResource(exportId);
return;
Expand All @@ -366,9 +364,8 @@ public void processExport(int exportId, String[] notesToExportIds, boolean expor
exportResource.setStatus(ExportStatus.ZIP_CREATED.name());
exportResource.getAction().setZipCreated(true);
exportResource.getAction().setAction(ExportAction.CLEANING_TEMP_FILE);
for (File file : files) {
cleanUp(file);
}
cleanUp(files);
cleanUp(featuredImages);
exportResource.getAction().setAction(ExportAction.EXPORT_DATA_CREATED);
}
}
Expand Down Expand Up @@ -411,8 +408,13 @@ private NoteToExport getParentOfNoteFromExistingNotes(LinkedList<String> ancesto
public NoteToExport getNoteToExport(NoteToExport note, int exportId) throws WikiException,
IOException,
InterruptedException {

try {
note.setContent(processImagesForExport(noteService.getNoteById(note.getId())));
Page page = noteService.getNoteById(note.getId());
if (page != null) {
note.setProperties(page.getProperties());
note.setContent(processImagesForExport(page));
}
} catch (Exception e) {
log.warn("Cannot process images for note {}", note.getId());
}
Expand Down Expand Up @@ -586,4 +588,61 @@ private LinkedList<String> getNoteAncestorsIds(LinkedList<String> ancestorsIds,
return ancestorsIds;
}

private void processNoteFeaturedImages(ExportResource exportResource,
List<NoteToExport> notesToExport,
List<File> files) throws Exception {
exportResource.getAction().setAction(ExportAction.PROCESS_FEATURED_IMAGES);
if (notesToExport != null) {
for (NoteToExport noteToExport : notesToExport) {
if (noteToExport != null) {
if (noteToExport.getProperties() != null) {
NotePageProperties properties = noteToExport.getProperties();
NoteFeaturedImage featuredImage = properties.getFeaturedImage();
if (featuredImage != null) {
FileItem imageFile = fileService.getFile(featuredImage.getId());
if (imageFile != null && imageFile.getFileInfo() != null) {
FileInfo fileInfo = imageFile.getFileInfo();
String extension = "." + MimeTypeUtils.parseMimeType(fileInfo.getMimetype()).getSubtype();
String filePath = System.getProperty(TEMP_DIRECTORY_PATH) + File.separator + featuredImage.getId() + extension;
File file = new File(filePath);
FileUtils.copyInputStreamToFile(imageFile.getAsStream(), file);
files.add(file);
}
}
}
processNoteFeaturedImages(exportResource, noteToExport.getChildren(), files);
}
}
}
exportResource.getAction().setFeaturedImagesProcessed(true);
}

private static void addFilesToZip(ZipOutputStream zipOut,
List<File> files,
int exportId,
String parentDirectory,
NotesExportService notesExportService) throws IOException {
if (parentDirectory != null) {
ZipEntry directoryEntry = new ZipEntry(parentDirectory + File.separator);
zipOut.putNextEntry(directoryEntry);
}
for (File fileToZip : files) {
ExportResource exportResource = notesExportService.getExportRessourceById(exportId);
if (exportResource.getStatus().equals(ExportStatus.CANCELLED.name())) {
throw new InterruptedIOException();
}
try (FileInputStream fis = new FileInputStream(fileToZip)) {
String name = parentDirectory != null ? parentDirectory + File.separator + fileToZip.getName() : fileToZip.getName();
ZipEntry zipEntry = new ZipEntry(name);
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
} catch (IOException e) {
log.warn("cannot add the file: {} to the zip", fileToZip.getName());
}
}
}
}
Loading

0 comments on commit f8c9b18

Please sign in to comment.