Skip to content

Commit

Permalink
[26870] Service angepasst mit isSupportedFile (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored Jan 17, 2025
1 parent badc155 commit 86f797a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.EnumSet;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -21,6 +22,7 @@
import ch.elexis.core.documents.DocumentStore;
import ch.elexis.core.exceptions.ElexisException;
import ch.elexis.core.model.IDocument;
import ch.elexis.core.model.MimeType;
import ch.elexis.core.services.IConfigService;
import ch.elexis.core.services.IDocumentConverter;
import io.swagger.client.ApiException;
Expand All @@ -35,6 +37,11 @@ public class JodRestDocumentConverter implements IDocumentConverter {
@Reference
private IConfigService configService;

private static final EnumSet<MimeType> SUPPORTED_MIME_TYPES = EnumSet.of(MimeType.doc, MimeType.docx, MimeType.xls,
MimeType.xlsx, MimeType.odt, MimeType.ods, MimeType.odp, MimeType.rtf,
MimeType.txt, MimeType.html, MimeType.csv, MimeType.jpg, MimeType.jpeg, MimeType.png, MimeType.bmp,
MimeType.gif, MimeType.tiff, MimeType.svg);

@Override
public Optional<File> convertToPdf(IDocument document) {
ConverterControllerApi apiInstance = new ConverterControllerApi();
Expand Down Expand Up @@ -133,4 +140,14 @@ private boolean isServiceAvailable(String serverHost, int serverPort, Integer ti
}
return false;
}

@Override
public boolean isSupportedFile(IDocument document) {
if (document == null || StringUtils.isBlank(document.getExtension())) {
return false;
}
String extension = document.getExtension().toLowerCase();
MimeType mimeType = MimeType.getByExtension(extension);
return SUPPORTED_MIME_TYPES.contains(mimeType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.events.IEventBroker;
Expand Down Expand Up @@ -103,12 +102,8 @@ public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) GlobalInboxEntry

new GlobalInboxUtil().removeFiles(globalInboxEntry);

// update document preview with imported document
if (StringUtils.containsIgnoreCase(document.getMimeType(), "pdf")) { //$NON-NLS-1$
eventBroker.send(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, document);
} else if (StringUtils.containsIgnoreCase(document.getMimeType(), "docx")) {
eventBroker.post(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, document);
}

eventBroker.send(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, document);

boolean automaticBilling = configService.getLocal(Preferences.PREF_AUTOBILLING, false);
if (automaticBilling && AutomaticBilling.isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ public int compare(Viewer viewer, Object e1, Object e2) {

if (globalInboxEntry != null) {
File mainFile = globalInboxEntry.getPdfPreviewFile();
if (globalInboxEntry.getMimetype().toLowerCase().contains("pdf")) { //$NON-NLS-1$
try {
IDocument mainFileDocument = FileDocument.of(mainFile);
eventBroker.post(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, mainFileDocument);
} catch (IOException e) {
LoggerFactory.getLogger(getClass()).warn("Exception", e); //$NON-NLS-1$
}
}
}
});
tv.addDoubleClickListener(new IDoubleClickListener() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IToolTipProvider;
Expand Down Expand Up @@ -86,12 +85,8 @@ public void singleClicked(IInboxElement element) {
if (isProviderFor(element)) {
IDocumentHandle document = (IDocumentHandle) obj;
if (document != null && !document.isCategory()) {
if (StringUtils.containsIgnoreCase(document.getMimeType(), "pdf")) { //$NON-NLS-1$
ContextServiceHolder.get().postEvent(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, document);
}
else if (StringUtils.containsIgnoreCase(document.getMimeType(), "docx")) { //$NON-NLS-1$
ContextServiceHolder.get().postEvent(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, document);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,7 @@ public void modifyText(ModifyEvent e) {
viewer.addSelectionChangedListener(ev -> {
IDocumentHandle docHandle = (IDocumentHandle) ev.getStructuredSelection().getFirstElement();
if (docHandle != null && !docHandle.isCategory()) {
if (StringUtils.containsIgnoreCase(docHandle.getMimeType(), "pdf")) { //$NON-NLS-1$
eventBroker.post(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, docHandle);
} else if (StringUtils.containsIgnoreCase(docHandle.getMimeType(), "docx")) { //$NON-NLS-1$
eventBroker.post(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, docHandle);
}
eventBroker.post(ElexisUiEventTopics.EVENT_PREVIEW_MIMETYPE_PDF, docHandle);
}
});
makeActions();
Expand Down

0 comments on commit 86f797a

Please sign in to comment.