Removes files and codes not used anymore
This commit is contained in:
parent
894d15614c
commit
5c1271cf0d
@ -1,29 +0,0 @@
|
||||
package org.bigbluebutton.presentation.imp;
|
||||
|
||||
import org.jodconverter.core.office.OfficeContext;
|
||||
import org.jodconverter.local.filter.Filter;
|
||||
import org.jodconverter.local.filter.FilterChain;
|
||||
import org.jodconverter.local.office.utils.Lo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.sheet.XCalculatable;
|
||||
|
||||
public class OfficeDocumentConversionFilter implements Filter {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(OfficeDocumentConversionFilter.class);
|
||||
|
||||
@Override
|
||||
public void doFilter(OfficeContext context, XComponent document, FilterChain chain)
|
||||
throws Exception {
|
||||
|
||||
log.info("Applying the OfficeDocumentConversionFilter");
|
||||
Lo.qiOptional(XCalculatable.class, document).ifPresent((x) -> {
|
||||
log.info("Turn AutoCalculate off");
|
||||
x.enableAutomaticCalculation(false);
|
||||
});
|
||||
|
||||
chain.doFilter(context, document);
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/**
|
||||
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
||||
*
|
||||
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation; either version 3.0 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.bigbluebutton.presentation.imp;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.sun.star.document.UpdateDocMode;
|
||||
import org.bigbluebutton.presentation.ConversionMessageConstants;
|
||||
import org.bigbluebutton.presentation.SupportedFileTypes;
|
||||
import org.bigbluebutton.presentation.UploadedPresentation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class OfficeToPdfConversion {
|
||||
private static Logger log = LoggerFactory.getLogger(OfficeToPdfConversion.class);
|
||||
private OfficeDocumentValidator2 officeDocumentValidator;
|
||||
private boolean skipOfficePrecheck = false;
|
||||
private String presOfficeConversionExec = null;
|
||||
/*
|
||||
* Convert the Office document to PDF. If successful, update
|
||||
* UploadPresentation.uploadedFile with the new PDF out and
|
||||
* UploadPresentation.lastStepSuccessful to TRUE.
|
||||
*/
|
||||
public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) {
|
||||
initialize(pres);
|
||||
if (SupportedFileTypes.isOfficeFile(pres.getFileType())) {
|
||||
// Check if we need to precheck office document
|
||||
if (!skipOfficePrecheck && officeDocumentValidator.isValid(pres)) {
|
||||
Map<String, Object> logData = new HashMap<>();
|
||||
logData.put("meetingId", pres.getMeetingId());
|
||||
logData.put("presId", pres.getId());
|
||||
logData.put("filename", pres.getName());
|
||||
logData.put("logCode", "problems_office_to_pdf_validation");
|
||||
logData.put("message", "Problems detected prior to converting the file to PDF.");
|
||||
Gson gson = new Gson();
|
||||
String logStr = gson.toJson(logData);
|
||||
log.warn(" --analytics-- data={}", logStr);
|
||||
pres.setConversionStatus(ConversionMessageConstants.OFFICE_DOC_CONVERSION_INVALID_KEY);
|
||||
return pres;
|
||||
}
|
||||
File pdfOutput = setupOutputPdfFile(pres);
|
||||
if (convertOfficeDocToPdf(pres, pdfOutput)) {
|
||||
Map<String, Object> logData = new HashMap<>();
|
||||
logData.put("meetingId", pres.getMeetingId());
|
||||
logData.put("presId", pres.getId());
|
||||
logData.put("filename", pres.getName());
|
||||
logData.put("logCode", "office_to_pdf_success");
|
||||
logData.put("message", "Successfully converted office file to pdf.");
|
||||
Gson gson = new Gson();
|
||||
String logStr = gson.toJson(logData);
|
||||
log.info(" --analytics-- data={}", logStr);
|
||||
makePdfTheUploadedFileAndSetStepAsSuccess(pres, pdfOutput);
|
||||
} else {
|
||||
Map<String, Object> logData = new HashMap<>();
|
||||
logData.put("meetingId", pres.getMeetingId());
|
||||
logData.put("presId", pres.getId());
|
||||
logData.put("filename", pres.getName());
|
||||
logData.put("logCode", "office_to_pdf_failed");
|
||||
logData.put("message", "Failed to convert " + pres.getUploadedFile().getAbsolutePath() + " to Pdf.");
|
||||
Gson gson = new Gson();
|
||||
String logStr = gson.toJson(logData);
|
||||
log.warn(" --analytics-- data={}", logStr);
|
||||
pres.setConversionStatus(ConversionMessageConstants.OFFICE_DOC_CONVERSION_FAILED_KEY);
|
||||
return 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) {
|
||||
boolean success = false;
|
||||
int attempts = 0;
|
||||
while(!success) {
|
||||
final Map<String, Object> loadProperties = new HashMap<>();
|
||||
loadProperties.put("Hidden", true);
|
||||
loadProperties.put("ReadOnly", true);
|
||||
loadProperties.put("UpdateDocMode", UpdateDocMode.NO_UPDATE);
|
||||
|
||||
success = Office2PdfPageConverter.convert(pres.getUploadedFile(), pdfOutput, 0, pres, presOfficeConversionExec);
|
||||
|
||||
if(!success) {
|
||||
if(++attempts != 3) {
|
||||
//Try again
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
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 setPresOfficeConversionExec(String presOfficeConversionExec) {
|
||||
this.presOfficeConversionExec = presOfficeConversionExec;
|
||||
}
|
||||
|
||||
}
|
||||
|
120
bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java
Executable file → Normal file
120
bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java
Executable file → Normal file
@ -17,34 +17,26 @@
|
||||
*
|
||||
*/
|
||||
package org.bigbluebutton.presentation.imp;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.sun.star.document.UpdateDocMode;
|
||||
import org.bigbluebutton.presentation.ConversionMessageConstants;
|
||||
import org.bigbluebutton.presentation.SupportedFileTypes;
|
||||
import org.bigbluebutton.presentation.UploadedPresentation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bigbluebutton.presentation.ConversionMessageConstants;
|
||||
import org.bigbluebutton.presentation.SupportedFileTypes;
|
||||
import org.bigbluebutton.presentation.UploadedPresentation;
|
||||
import org.jodconverter.core.office.OfficeException;
|
||||
import org.jodconverter.core.office.OfficeUtils;
|
||||
import org.jodconverter.local.LocalConverter;
|
||||
import org.jodconverter.local.office.ExternalOfficeManager;
|
||||
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);
|
||||
|
||||
public class OfficeToPdfConversion {
|
||||
private static Logger log = LoggerFactory.getLogger(OfficeToPdfConversion.class);
|
||||
private OfficeDocumentValidator2 officeDocumentValidator;
|
||||
private final ArrayList<ExternalOfficeManager> officeManagers;
|
||||
private ExternalOfficeManager currentManager = null;
|
||||
private boolean skipOfficePrecheck = false;
|
||||
private int sofficeBasePort = 0;
|
||||
private int sofficeManagers = 0;
|
||||
private String sofficeWorkingDirBase = null;
|
||||
public OfficeToPdfConversionService() throws OfficeException {
|
||||
officeManagers = new ArrayList<>();
|
||||
}
|
||||
private String presOfficeConversionExec = null;
|
||||
/*
|
||||
* Convert the Office document to PDF. If successful, update
|
||||
* UploadPresentation.uploadedFile with the new PDF out and
|
||||
@ -113,31 +105,13 @@ public class OfficeToPdfConversionService {
|
||||
loadProperties.put("Hidden", true);
|
||||
loadProperties.put("ReadOnly", true);
|
||||
loadProperties.put("UpdateDocMode", UpdateDocMode.NO_UPDATE);
|
||||
LocalConverter documentConverter = LocalConverter
|
||||
.builder()
|
||||
.officeManager(currentManager)
|
||||
.loadProperties(loadProperties)
|
||||
.filterChain(new OfficeDocumentConversionFilter())
|
||||
.build();
|
||||
|
||||
// success = Office2PdfPageConverter.convert(pres.getUploadedFile(), pdfOutput, 0, pres, documentConverter);
|
||||
success = Office2PdfPageConverter.convert(pres.getUploadedFile(), pdfOutput, 0, pres, "");
|
||||
success = Office2PdfPageConverter.convert(pres.getUploadedFile(), pdfOutput, 0, pres, presOfficeConversionExec);
|
||||
|
||||
if(!success) {
|
||||
// In case of failure, try with other open Office Manager
|
||||
|
||||
if(++attempts != officeManagers.size()) {
|
||||
// Go to next Office Manager ( if the last retry with the first one )
|
||||
int currentManagerIndex = officeManagers.indexOf(currentManager);
|
||||
|
||||
boolean isLastManager = ( currentManagerIndex == officeManagers.size()-1 );
|
||||
if(isLastManager) {
|
||||
currentManager = officeManagers.get(0);
|
||||
if(++attempts != 3) {
|
||||
//Try again
|
||||
} else {
|
||||
currentManager = officeManagers.get(currentManagerIndex+1);
|
||||
}
|
||||
} else {
|
||||
// We tried to use all our office managers and it's still failing
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -159,67 +133,9 @@ public class OfficeToPdfConversionService {
|
||||
this.skipOfficePrecheck = skipOfficePrecheck;
|
||||
}
|
||||
|
||||
public void setSofficeBasePort(int sofficeBasePort) {
|
||||
this.sofficeBasePort = sofficeBasePort;
|
||||
public void setPresOfficeConversionExec(String presOfficeConversionExec) {
|
||||
this.presOfficeConversionExec = presOfficeConversionExec;
|
||||
}
|
||||
|
||||
public void setSofficeManagers(int sofficeServiceManagers) {
|
||||
this.sofficeManagers = sofficeServiceManagers;
|
||||
}
|
||||
|
||||
public void setSofficeWorkingDirBase(String sofficeWorkingDirBase) {
|
||||
this.sofficeWorkingDirBase = sofficeWorkingDirBase;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
log.info("Starting LibreOffice pool with " + sofficeManagers + " managers, starting from port " + sofficeBasePort);
|
||||
|
||||
for(int managerIndex = 0; managerIndex < sofficeManagers; managerIndex ++) {
|
||||
Integer instanceNumber = managerIndex + 1; // starts at 1
|
||||
|
||||
try {
|
||||
final File workingDir = new File(sofficeWorkingDirBase + String.format("%02d", instanceNumber));
|
||||
|
||||
if(!workingDir.exists()) {
|
||||
workingDir.mkdir();
|
||||
}
|
||||
|
||||
ExternalOfficeManager officeManager = ExternalOfficeManager
|
||||
.builder()
|
||||
.connectTimeout(2000L)
|
||||
.retryInterval(500L)
|
||||
.portNumber(sofficeBasePort + managerIndex)
|
||||
.connectOnStart(false) // If it's true and soffice is not available, exception is thrown here ( we don't want exception here - we want the manager alive trying to reconnect )
|
||||
.workingDir(workingDir)
|
||||
.build();
|
||||
|
||||
// Workaround for jodconverter not calling makeTempDir when connectOnStart=false (issue 211)
|
||||
Method method = officeManager.getClass().getSuperclass().getDeclaredMethod("makeTempDir");
|
||||
method.setAccessible(true);
|
||||
method.invoke(officeManager);
|
||||
// End of workaround for jodconverter not calling makeTempDir
|
||||
|
||||
officeManager.start();
|
||||
officeManagers.add(officeManager);
|
||||
} catch (Exception e) {
|
||||
log.error("Could not start Office Manager " + instanceNumber + ". Details: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (officeManagers.size() == 0) {
|
||||
log.error("No office managers could be started");
|
||||
return;
|
||||
}
|
||||
|
||||
currentManager = officeManagers.get(0);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
officeManagers.forEach(officeManager -> officeManager.stop() );
|
||||
} catch (Exception e) {
|
||||
log.error("Could not stop Office Manager", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user