Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10619 from bigbluebutton/bbb-soffice-disable-update
Disable libreoffice document update ( speed up the conversion )
  • Loading branch information
ffdixon committed Oct 8, 2020
2 parents 38b51ea + db413c5 commit 71fe1ea
Showing 1 changed file with 6 additions and 19 deletions.
Expand Up @@ -16,13 +16,10 @@
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/

package org.bigbluebutton.presentation.imp;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.bigbluebutton.presentation.ConversionMessageConstants;
import org.bigbluebutton.presentation.SupportedFileTypes;
import org.bigbluebutton.presentation.UploadedPresentation;
Expand All @@ -32,29 +29,30 @@
import org.jodconverter.local.office.LocalOfficeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.star.document.UpdateDocMode;
import com.google.gson.Gson;

public class OfficeToPdfConversionService {
private static Logger log = LoggerFactory.getLogger(OfficeToPdfConversionService.class);

private OfficeDocumentValidator2 officeDocumentValidator;
private final OfficeManager officeManager;
private final LocalConverter documentConverter;
private boolean skipOfficePrecheck = false;

public OfficeToPdfConversionService() throws OfficeException {
final Map<String, Object> loadProperties = new HashMap<>();
loadProperties.put("Hidden", true);
loadProperties.put("ReadOnly", true);
loadProperties.put("UpdateDocMode", UpdateDocMode.NO_UPDATE);
officeManager = LocalOfficeManager
.builder()
.portNumbers(8100, 8101, 8102, 8103, 8104)
.build();
documentConverter = LocalConverter
.builder()
.officeManager(officeManager)
.loadProperties(loadProperties)
.filterChain(new OfficeDocumentConversionFilter())
.build();
}

/*
* Convert the Office document to PDF. If successful, update
* UploadPresentation.uploadedFile with the new PDF out and
Expand All @@ -74,7 +72,6 @@ public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) {
Gson gson = new Gson();
String logStr = gson.toJson(logData);
log.warn(" --analytics-- data={}", logStr);

pres.setConversionStatus(ConversionMessageConstants.OFFICE_DOC_CONVERSION_INVALID_KEY);
return pres;
}
Expand All @@ -89,7 +86,6 @@ public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) {
Gson gson = new Gson();
String logStr = gson.toJson(logData);
log.info(" --analytics-- data={}", logStr);

makePdfTheUploadedFileAndSetStepAsSuccess(pres, pdfOutput);
} else {
Map<String, Object> logData = new HashMap<>();
Expand All @@ -107,51 +103,42 @@ public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) {
}
return pres;
}

public void initialize(UploadedPresentation pres) {
pres.setConversionStatus(ConversionMessageConstants.OFFICE_DOC_CONVERSION_FAILED_KEY);
}

private File setupOutputPdfFile(UploadedPresentation pres) {
File presentationFile = pres.getUploadedFile();
String filenameWithoutExt = presentationFile.getAbsolutePath().substring(0,
presentationFile.getAbsolutePath().lastIndexOf('.'));
return new File(filenameWithoutExt + ".pdf");
}

private boolean convertOfficeDocToPdf(UploadedPresentation pres,
File pdfOutput) {
Office2PdfPageConverter converter = new Office2PdfPageConverter();
return converter.convert(pres.getUploadedFile(), pdfOutput, 0, pres, documentConverter);
}

private void makePdfTheUploadedFileAndSetStepAsSuccess(UploadedPresentation pres, File pdf) {
pres.setUploadedFile(pdf);
pres.setConversionStatus(ConversionMessageConstants.OFFICE_DOC_CONVERSION_SUCCESS_KEY);
}

public void setOfficeDocumentValidator(OfficeDocumentValidator2 v) {
officeDocumentValidator = v;
}

public void setSkipOfficePrecheck(boolean skipOfficePrecheck) {
this.skipOfficePrecheck = skipOfficePrecheck;
}

public void start() {
try {
officeManager.start();
} catch (OfficeException e) {
log.error("Could not start Office Manager", e);
}
}

public void stop() {
try {
officeManager.stop();
} catch (OfficeException e) {
log.error("Could not stop Office Manager", e);
}

}
}

0 comments on commit 71fe1ea

Please sign in to comment.